将nginx安装为windows服务

一、nginx版本:nginx-1.20.2;windows版本:win11,将nginx解压,要保证nginx的目录不含空格

二、下载winsw,下载地址为:https://repo.jenkins-ci.org/artifactory/releases/com/sun/winsw/winsw/

三、将winsw-2.9.0-bin.exe复制到nginx目录下,并重命名为nginx-service.exe

四、在nginx目录下新增文件nginx-service.xml,内容为:

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

五、在nginx目录下新增文件nginx-service.exe.xml

 1 <?xml version="1.0" encoding="UTF-8" ?>
 2 <configuration>
 3     <startup>
 4         <supportedRuntime version="v2.0.50727" />
 5         <supportedRuntime version="v4.0" />
 6     </startup>
 7     <runtime>
 8         <generatePublisherEvidence enabled="false" />
 9     </runtime>
10 </configuration>

完成后的目录结构如下:

 

 六、以管理员身份打开cmd,输入:nginx-service.exe install,执行完成后nginx就增加到windows服务中,服务名称为nginx

七、如果想删除nginx服务,在cmd窗口中执行:SC delete nginx

posted @ 2022-04-26 11:47  疯狗强尼  阅读(5366)  评论(0编辑  收藏  举报