1. 程式人生 > 其它 >Windows安裝nginx服務

Windows安裝nginx服務

1、測試版本

  nginx版本:nginx-1.10.2;windows版本:win10

2、下載winsw。

  當前最新版本為:winsw-2.0.1-bin.exe。下載地址:http://repo.jenkins-ci.org/releases/com/sun/winsw/winsw/2.0.1/winsw-2.0.1-bin.exe。

3、將winsw-2.0.1-bin.exe複製到nginx目錄下(保證nginx的目錄不含空格),並重命名為nginx-service.exe。

4、在nginx目錄下新增檔案nginx-service.xml。

<?xml version="1.0" encoding="UTF-8" ?>
<service>
    <id>nginx</id>
    <name>nginx</name>
    <description>High Performance Nginx Service</description>
    <logpath>D:\nginx-1.10.2\logs</logpath>
    <log mode="roll-by-size">
        <sizeThreshold>10240</sizeThreshold>
        <keepFiles>8</keepFiles>
    </log>
    <executable>D:\nginx-1.10.2\nginx.exe</executable>
    <startarguments>-p D:\nginx-1.10.2</startarguments>
    <stopexecutable>D:\nginx-1.10.2\nginx.exe</stopexecutable>
    <stoparguments>-p D:\nginx-1.10.2 -s stop</stoparguments>
</service>

5、在nginx目錄下新增檔案nginx-service.exe.xml

<?xml version="1.0" encoding="UTF-8" ?>
<configuration>
    <startup>
        <supportedRuntime version="v2.0.50727" />
        <supportedRuntime version="v4.0" />
    </startup>
    <runtime>
        <generatePublisherEvidence enabled="false" />
    </runtime>
</configuration>

6、檔案結構如下:

7、啟用windows自帶的.Net Framework服務。

8、使用管理員身份執行cmd。

  右鍵“C:\Windows\System32\cmd.exe”,選擇“已管理員身份執行”。

9、執行命令:nginx-service.exe install。

執行完成後可以檢視nginx服務

10、啟動nginx,訪問nginx成功。

11、解除安裝nginx服務,在cmd命令視窗下執行:nginx-service.exe uninstall。

提示:1、若出現“WMI.WmiException: AccessDenied”錯誤,請檢測cmd命令是否以管理員身份開啟的。