1.将Nginx-Service解压到Nginx目录下
下载地址:https://download.csdn.net/download/ounumman/12667375
2.修改nginx-service.xml文件:
<service>
<id>nginx</id>
<name>nginx</name>
<description>nginx</description>
<logpath>D:\nginx\logs\</logpath>
<logmode>roll</logmode>
<depend></depend>
<executable>D:\nginx\nginx.exe</executable>
<stopexecutable>D:\nginx\nginx.exe -s stop</stopexecutable>
</service>
<!-- - name为服务名
- logpath指定nginx日志文件地址
- D:\nginx\nginx.exe为nginx可执行应用程序文件位置
-->
3.管理员身份打开cmd,进入nginx目录,执行命令:
nginx-service.exe install //安装系统服务
nginx-service.exe uninstall //删除系统服务
nginx-service.exe stop //停止系统服务
nginx-service.exe start //启动系统服务
完整命令
D:\nginx>nginx-service.exe -h
A wrapper binary that can be used to host executables as Windows services
Available commands:
- 'install' - install the service to Windows Service Controller
- 'uninstall' - uninstall the service
- 'start' - start the service (must be installed before)
- 'stop' - stop the service
- 'restart' - restart the service
- 'restart!' - self-restart (can be called from child processes)
- 'status' - check the current status of the service
- 'test' - check if the service can be started and then stopped
- 'version' - print the version info
- 'help' - print the help info (aliases: -h,--help,-?,/?)
Extra options:
- '/redirect' - redirect the wrapper's STDOUT and STDERR to the specified file