windows下安装Nginx 为 Windows服务

1.下载ngix1.15.9,并解压到D盘根目录下

    http://nginx.org/download/nginx-1.15.9.zip


2.将Nginx设置为Windows服务 

    需要借助"Windows Service Wrapper"小工具,项目地址: https://github.com/kohsuke/winsw

    下载地址: http://repo.jenkins-ci.org/releases/com/sun/winsw/winsw/1.18/winsw-1.18-bin.exe

    下载该工具后,将其放在 Nginx安装目录下,并重命名为nginx-service.exe,

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

创建后:

3.修改配置文件

nginx-service.xml 内容如下:

<service>
  <id>nginx</id>
  <name>nginx</name>
  <description>High Performance Nginx Service</description>
  <logpath>D:\nginx-1.15.9\logs</logpath>
  <log mode="roll-by-size">
    <sizeThreshold>10240</sizeThreshold>
    <keepFiles>8</keepFiles>
  </log>
  <executable>D:\nginx-1.15.9\nginx.exe</executable>
  <startarguments>-p D:\nginx-1.15.9\nginx</startarguments>
  <stopexecutable>D:\nginx-1.15.9\nginx.exe</stopexecutable>
  <stoparguments>-p D:\nginx-1.15.9\nginx -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窗口,将Nginx安装为服务
D:\nginx-1.15.9\nginx-service.exe install

# 启动nginx
net start nginx
# 停止nginx
net stop nginx

猜你喜欢

转载自blog.csdn.net/a1513049385/article/details/88365183