Windows 怎么样设置nginx开机自启动(亲测有效)
nginx是一款功能强大比apache还要火热的web服务软件
一般在Linux里面设置nginx自启动很容易chkconfig nginx on 或者systemcel enable nginx.service便可
但是今天在公司的一台Windows服务器上需要安装个nginx,但是重启后发现服务就自动关闭了,便在服务中去找有关nginx的服务,发现没有,于是在网上逛了一圈,发现了很多的教程,但是最终比较靠谱的只有一个(其余的也没时间做过多的尝试)
将Nginx设置为Windows服务
需要借助"Windows Service Wrapper"小工具,项目地址: https://github.com/kohsuke/winsw
下载地址: http://repo.jenkins-ci.org/releases/com/sun/winsw/winsw/1.18/winsw-1.18-bin.exe
下载该工具后,将其放在 Nginx安装目录下,并重命名为nginx-service.exe,创建配置文件nginx-service.xml(名字要和工具名一样),
创建nginx-service.exe.config(为支持NET 4.0 runtime,默认只支持NET 2.0 runtime)
注意上述文件的后缀 记得把后缀显示出来然后再修改
nginx-service.xml 内容如下:
<service> <id>nginx</id> <name>Nginx Service</name> <description>High Performance Nginx Service</description> <logpath>D:\nginx-1.14.0\nginx\logs</logpath> <log mode="roll-by-size"> <sizeThreshold>10240</sizeThreshold> <keepFiles>8</keepFiles> </log> <executable>D:\nginx-1.14.0\nginx.exe</executable> <startarguments>-p D:\nginx-1.14.0\nginx</startarguments> <stopexecutable>D:\nginx-1.14.0\nginx.exe</stopexecutable> <stoparguments>-p D:\nginx-1.14.0\nginx -s stop</stoparguments> </service>
nginx-service.exe.config 内容如下:
<configuration> <startup> <supportedRuntime version="v2.0.50727" /> <supportedRuntime version="v4.0" /> </startup> <runtime> <generatePublisherEvidence enabled="false"/> </runtime> </configuration>
在cmd中运行如下命令安装windows服务
D:\nginx-1.14.0\nginx\nginx-service.exe install
注意 这里可能会报错 必须要以超级管理员的身份运行
然后就可以在服务中发现Nginx Service这个服务了 然后点击启动便可 默认开机自启