Windows服务器上Nginx注册服务及设置开机启动

Windows服务注册方式详见:
Windows注册服务的几种方式

本文Nginx注册Windows服务使用WinSW注册方式。

具体步骤如下:
1、根据系统类型下载对应的winsw.exe文件

WinSW下载地址:
https://github.com/winsw/winsw/releases

2、将下载的winsw.exe放在Nginx根目录,并重命名为nginx_service.exe

3、在Nginx根目录新增配置文件nginx_service.xml,具体内容如下:

<service>
  <id>nginx</id>
  <name>nginx</name>
  <description>This service runs the Nginx service.</description>
  <env name="NGINX_HOME" value="%BASE%"/>
  <logpath>%BASE%\logs</logpath>
  <log mode="roll"></log>
  <executable>%BASE%\nginx.exe</executable>
  <startarguments></startarguments>
  <stoparguments>-s stop</stoparguments>
  <depend></depend>
</service>

4、执行服务注册及启动命令

#注册服务
nginx_service.exe install

#设置服务自启动
sc config nginx start=auto

#启动nginx服务
net start nginx

#关闭nginx服务
net stop nginx

注册成功后,多次启动关闭测试nginx服务,并关机重启测试nginx自启动。

(完)

添加新评论