Windows下Nginx开机启动

我们可以借助Windows Service Wrapper小工具【需要.net 4.0环境】,将Nginx转换为Windows服务,这样就可以在开机时自动启动Nginx了。

下载后将该工具放入Nginx的安装目录下,并且将其重命名为 nginx-service.exe ,在该目录下新建 nginx-service.xml 文件,写入配置信息,配置好了之后就可以通过这个将Nginx注册为Windows服务。

 
<!-- nginx-service.xml -->
<service>
    <id>nginx</id>
    <name>nginx</name>
    <description>nginx</description>
    <logpath>D:web
ginx</logpath>
    <logmode>roll</logmode>
    <depend></depend>
    <executable>D:web
ginx
ginx.exe</executable>
    <stopexecutable>D:web
ginx
ginx.exe -s stop</stopexecutable>
</service>

以上内容配置好了之后,在nginx安装目录下以管理员运行命令:. ginx-service.exe install 就成功将其注册为Windows服务了,然后运行 . ginx-service.exe start 启动服务。这时我们可以在Windows任务管理器的服务中查看该是否成功启动。

注:

  • nginx-service.exe install 命令可注册对应的系统服务
  • nginx-service.exe uninstall 命令可删除对应的系统服务
  • nginx-service.exe stop 命令可停止对应的系统服务
  • nginx-service.exe start 命令可启动对应的系统服务
原文地址:https://www.cnblogs.com/shuaichao/p/13840486.html