为何要装成服务
每次重启电脑后都需要手动启动nginx太麻烦了。因为我是比较懒的人。
下载Winsw
下载地址:https://github.com/kohsuke/winsw/releases
下载该工具后,将其放在 Nginx安装目录下,并重命名为nginx-service.exe.
新建配置文件nginx-service.xml
内容如下:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 | <service> <id>nginx</id> <name>nginx</name> <description>nginx</description> <logpath>D:\nginx-1.15.5\logs\</logpath> <logmode>roll</logmode> <depend></depend> <executable>D:\nginx-1.15.5\nginx.exe</executable> <stopexecutable>D:\nginx-1.15.5\nginx.exe -s stop</stopexecutable> </service> |
name为服务名
logpath指定nginx日志文件地址
D:\nginx-1.15.5\nginx.exe为nginx可执行应用程序文件位置
安装
管理员身份打开cmd,进入nginx目录,执行命令:
1 | nginx-service.exe install |
nginx-service.exe uninstall命令可删除对应的系统服务
nginx-service.exe stop命令可停止对应的系统服务
nginx-service.exe start命令可启动对应的系统服务