window下nginx注册成服务

时间:2023-03-09 06:49:54
window下nginx注册成服务

1. a.下载windows版nginx (http://nginx.org/download/nginx-1.10.0.zip),并且下载注册服务工具,

  b.下载地址: http://repo.jenkins-ci.org/releases/com/sun/winsw/winsw/1.18/winsw-1.18-bin.exe下载该工具后,将其放在 Nginx安装目录下,并重命名为nginx-service.exe

  c.创建配置文件nginx-service.xml(名字要和工具名一样),创建nginx-service.exe.config(为支持NET 4.0 runtime,默认只支持NET 2.0 runtime)

2.nginx-service.xml 内容如下:(其中的路径地址是nginx.exe的目录,不能是中文目录)

<service>
<id>nginx</id>
<name>Nginx Service</name>
<description>High Performance Nginx Service</description> <logpath>D:\nginx\nginx-1.5.\logs</logpath>
<log mode="roll-by-size">
<sizeThreshold></sizeThreshold>
<keepFiles></keepFiles>
</log>
<executable>D:\nginx\nginx-1.5.\nginx.exe</executable>
<startarguments>-p D:\nginx\nginx-1.5.</startarguments> <stopexecutable>D:\nginx\nginx-1.5.\nginx.exe</stopexecutable>
<stoparguments>-p D:\nginx\nginx-1.5. -s stop</stoparguments>
</service>

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

<configuration>
<startup>
<supportedRuntime version="v2.0.50727" />
<supportedRuntime version="v4.0" />
</startup>
<runtime>
<generatePublisherEvidence enabled="false"/>
</runtime>
</configuration>

4.在cmd中运行如下命令安装windows服务

 nginx-service.exe install

5.出现以下情况说明设置成功:

window下nginx注册成服务