本文来源 :https://www.cnblogs.com/lujiulong/p/9025066.html

**下载安装nginxnginx下载地址 : http://nginx.org/en/download.html

本次采用的 window nginx 1.15.8

添加服务

需要借助”Windows Service Wrapper”小工具,下载地址 https://github.com/kohsuke/winsw/releases
image.png
选择适合的版本;
编写本文章时 使用的 winsw-v2.2.0 WinSW.NET4.exe

下载后放在nginx目录下,并修改名字为nginx-service.exe
创建配置文件nginx-service.exe.config 和 nginx-service.xml
nginx-service.xml的内容如下:

  1. <service>
  2. <id>nginx</id>
  3. <name>Nginx Service</name>
  4. <description>High Performance Nginx Service</description>
  5. <logpath>C:\Program Files\nginx\logs</logpath>
  6. <log mode="roll-by-size">
  7. <sizeThreshold>10240</sizeThreshold>
  8. <keepFiles>8</keepFiles>
  9. </log>
  10. <executable>C:\Program Files\nginx\nginx.exe</executable>
  11. <startarguments>-p C:\Program Files\nginx</startarguments>
  12. <stopexecutable>C:\Program Files\nginx\nginx.exe</stopexecutable>
  13. <stoparguments>-p C:\Program Files\nginx -s stop</stoparguments>
  14. </service>

nginx-service.exe.config内容如下:

  1. <configuration>
  2. <startup>
  3. <supportedRuntime version="v2.0.50727" />
  4. <supportedRuntime version="v4.0" />
  5. </startup>
  6. <runtime>
  7. <generatePublisherEvidence enabled="false"/>
  8. </runtime>
  9. </configuration>

最后用cmd命令进入nginx目录安装服务

  1. nginx-service.exe install

收工!