下载Windows Service Wrapper 工具
项目地址: https://github.com/kohsuke/winsw
下载地址: http://repo.jenkins-ci.org/releases/com/sun/winsw/winsw/2.1.2/winsw-2.1.2-bin.exe
1、下载该工具后,将其放在 Nginx安装目录下,并重命名为nginx-service.exe。
2、创建配置文件nginx-service.xml(名字要和工具名一样)。
3、创建nginx-service.exe.config(为支持NET 4.0 runtime,默认只支持NET 2.0 runtime)
<service>
<id>nginx</id>
<name>Nginx Service</name>
<description>High Performance Nginx Service</description>
<logpath>D:\nginx-1.20.2\logs</logpath>
<log mode="roll-by-size">
<sizeThreshold>10240</sizeThreshold>
<keepFiles>8</keepFiles>
</log>
<executable>D:\nginx-1.9.3\nginx.exe</executable>
<startarguments>-p D:\nginx-1.20.2\nginx</startarguments>
<stopexecutable>D:\nginx-1.20.2\nginx.exe</stopexecutable>
<stoparguments>-p D:\nginx-1.20.2\nginx -s stop</stoparguments>
</service>
<configuration>
<startup>
<supportedRuntime version="v2.0.50727" />
<supportedRuntime version="v4.0" />
</startup>
<runtime>
<generatePublisherEvidence enabled="false"/>
</runtime>
</configuration>
在cmd中运行如下命令安装windows服务
nginx-service.exe install #安装Windows服务
nginx-service.exe uninstall #卸载Windows服务
nginx-service.exe start #启动Windows服务
nginx-service.exe stop #停止Windows服务