https://www.cnblogs.com/zhi-leaf/p/6274290.html
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.config
<?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命令是否以管理員身份打開的。

