方法 1
把nginx.exe 生成快捷方式,放入该路径下(必须登录操作系统,才会触发)
C:\ProgramData\Microsoft\Windows\Start Menu\Programs\StartUp
方法2
使用微软自带的定时任务
以管理员运行cmd,创建任务:
schtasks /create /tn "start-nginx" /tr "D:\opt\nginx.exe" /sc onlogon /ru System
删除任务:
schtasks /delete /tn "start-nginx"
方法3
生成nginx服务
1、下载winSW
64位系统:https://github.com/winsw/winsw/releases/download/v2.10.3/WinSW.NET4.exe
32位系统: https://github.com/winsw/winsw/releases/download/v2.10.3/WinSW.NET2.exe
2、配置
将 WinSW.NET4.exe 复制到 D:\opt\nginx目录中,修改文件名称为 nginxService.exe
在 nginxService.exe 同目录中,新建一个空的 nginxService.xml 文件
名字要与nginxService.exe 名字前缀保持一致,但后缀是xml)
nginxService.xml 的内容:
<service>
<id>nginx</id>
<name>nginx</name>
<description>nginx</description>
<logpath>D:\opt\nginx-1.18.0</logpath>
<logmode>roll</logmode>
<depend></depend>
<executable>D:\opt\nginx-1.18.0\nginx.exe</executable>
<stopexecutable>D:\opt\nginx-1.18.0\nginx.exe -s stop</stopexecutable>
</service>
在当前目录打开cmd
nginxService.exe install
安装成功后,去服务里面启动 nginx服务,设置成开机自启