将Nginx添加到windows服务中

  1. 下载windows版nginx,解压。
  2. 下载一个安装工具winsw-1.18-bin.exe.点击下载
  3. 下载后改个名字:service.exe,放到nginx目录下。
  4. 在nginx安装目录下新建service.xml
    nginx-path为nginx根目录,注意修改为自己的目录,下面的id为服务名称,用来删除服务。
<service> 
    <id>nginx-load-balance</id>
    <name>NginxLoadBanlanceService</name>
    <description>使用nginx负载均衡</description>
      <logpath>nginx-path\logs</logpath>  
    <log mode="roll-by-size">   
        <sizeThreshold>10240</sizeThreshold>
        <keepFiles>8</keepFiles>
    </log>
      <executable>nginx-path\nginx.exe</executable>  
    <startarguments>-p nginx-path</startarguments>
    <stopexecutable>nginx-path\nginx.exe</stopexecutable>
    <stoparguments>-p nginx-path -s stop</stoparguments>
</service>
  1. 新建service.exe.config配置文件。
<configuration>
  <startup>
        <supportedRuntime version="v2.0.50727" />     <supportedRuntime version="v4.0" />
   </startup>
   <runtime>
        <generatePublisherEvidence enabled="false"/>
    </runtime>
</configuration>
  1. 最后目录结构。
    在这里插入图片描述
  2. nginx的根目录打开dos,输入命令:service.exe install。
  3. 查看windows服务列表,启动。
    在这里插入图片描述
  4. 访问
    在这里插入图片描述
  5. 如何删除服务?在dos输入:sc delete nginx-load-balance。

猜你喜欢

转载自blog.csdn.net/qwqw3333333/article/details/88866700