借助"Windows Service Wrapper"工具
步骤一
下载exe文件: http://repo.jenkins-ci.org/releases/com/sun/winsw/winsw/1.18/winsw-1.18-bin.exe
步骤二
下载该工具后,将其放在 Nginx安装目录下,并重命名为nginx-service.exe
步骤三
创建配置文件nginx-service.xml(名字要和工具名一样), xml内容:
<service>
<id>nginx</id>
<name>Nginx Service</name>
<description>High Performance Nginx Service</description>
<logpath>E:\install\nginx-1.18.0\logs</logpath>
<log mode="roll-by-size">
<sizeThreshold>10240</sizeThreshold>
<keepFiles>8</keepFiles>
</log>
<executable>E:\install\nginx-1.18.0\nginx.exe</executable>
<startarguments>-p E:\install\nginx-1.18.0</startarguments>
<stopexecutable>E:\install\nginx-1.18.0\nginx.exe</stopexecutable>
<stoparguments>-p E:\install\nginx-1.18.0 -s stop</stoparguments>
</service>
步骤四
创建nginx-service.exe.config
内容:
<configuration>
<startup>
<supportedRuntime version="v2.0.50727" />
<supportedRuntime version="v4.0" />
</startup>
<runtime>
<generatePublisherEvidence enabled="false"/>
</runtime>
</configuration>
步骤五
在cmd中运行如下命令安装windows服务
nginx-service.exe install
最后到服务中启动就可以了
|