关于如何在Windows操作系统中配置Nginx开机自启动,解决方案如下:
一、下载文件服务启动执行文件WinSW.NET4.exe
下载地址:https://github.com/winsw/winsw/releases
下载最新稳动版即可,我用的是2.10.3: https://github.com/winsw/winsw/releases/tag/v2.10.3
下载后放入nginx文件夹并改名为service.exe,如下图:
二、在nginx文件夹下新建一个 service.xml 文件,内容如下:
<!-- service.xml -->
<service>
<id>nginx</id>
<name>nginx</name>
<description>nginx</description>
<logpath>E:\nginx-1.16.1\</logpath>
<logmode>roll</logmode>
<depend></depend>
<executable>E:\nginx-1.16.1\nginx.exe</executable>
<stopexecutable>E:\nginx-1.16.1\nginx.exe -s stop</stopexecutable>
</service>
注意:其中有三个nginx根目录路径需改为自己机器的。
三、在nginx根目录下,以管理员身份运行cmd命令 service.exe install即可安装为系统服务,再运行 service.exe start 启动服务:
E:\nginx-1.16.1>service.exe install
2021-01-21 10:05:26,489 INFO - Installing the service with id 'nginx'
E:\nginx-1.16.1>service.exe start
2021-01-21 10:06:07,489 INFO - Starting the service with id 'nginx'
E:\nginx-1.16.1>
查看服务,已安装为系统服务:
四、相关命令:
注册系统服务:service.exe install
卸载系统服务:service.exe uninstall
停止系统服务:service.exe stop
启动系统服务:service.exe start