Windows 添加nginx到服务

一、下载nginx

地址:http://nginx.org/en/download.html   (稳定版)

 

 解压到相应的磁盘,本文是:E:\nginx\nginx-1.18.0

 

二、添加服务

需要借助"Windows Service Wrapper"小工具,下载地址: http://repo.jenkins-ci.org/releases/com/sun/winsw/winsw/
本文选择:http://repo.jenkins-ci.org/releases/com/sun/winsw/winsw/2.9.0/winsw-2.9.0-bin.exe
下载后放在nginx目录下,并修改名字为nginx-service.exe
创建配置文件nginx-service.exe.config 和 nginx-service.xml
 
nginx-service.xml的内容如下:
<service>
  <id>nginx</id>
  <name>Nginx Service</name>
  <description>High Performance Nginx Service</description>
  <logpath>E:\nginx\nginx-1.18.0\logs</logpath>
  <log mode="roll-by-size">
    <sizeThreshold>10240</sizeThreshold>
    <keepFiles>8</keepFiles>
  </log>
  <executable>E:\nginx\nginx-1.18.0\nginx.exe</executable>
  <startarguments>-p E:\nginx\nginx-1.18.0</startarguments>
  <stopexecutable>E:\nginx\nginx-1.18.0\nginx.exe</stopexecutable>
  <stoparguments>-p E:\nginx\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命令进入到nginx目录安装服务

 

 

卸载服务命令: sc  delete  服务名

 

posted @ 2020-11-19 10:03  浅雨凉  阅读(1369)  评论(0编辑  收藏  举报