利用WinSW将Nginx注册为Windows服务
一、下载工具
创建windows服务用到一个小工具WinSW:https://github.com/kohsuke/winsw/releases(下载 .exe 文件即可,根据系统选择,Win 10 选择 .NET4 版本,以下选择 .NET2 版本),将其重命名为 service.exe
二、修改配置文件 service.xml
<service>
<id>nginx</id>
<name>nginx</name>
<description>nginx</description>
<logpath>E:\MyFiles\Desktop\nginx-1.18.0\logs\</logpath>
<logmode>roll</logmode>
<depend></depend>
<executable>E:\MyFiles\Desktop\nginx-1.18.0\nginx.exe</executable>
<stopexecutable>E:\MyFiles\Desktop\nginx-1.18.0\nginx.exe -s stop</stopexecutable>
</service>
将标注的地方改为nginx实际安装的位置
三、注册服务
# 注册服务
.\service.exe install
# 删除服务
.\service.exe uninstall
四、启动服务
# 启动服务 nginx-服务id
net start nginx
# 关闭服务
net stop nginx