Windows 怎么样设置nginx开机自启动(亲测有效)

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这个服务了  然后点击启动便可  默认开机自启

  • 2
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值