nginx for windows安装为服务运行

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/QWERTY1994/article/details/88907273

下载winsw

地址:https://github.com/kohsuke/winsw

有两个版本winsw2.X 和 winsw1.X ,winsw1.X已经停止更新了,只做维护和修复

winsw2.x又分为.NET Frameworks 2.0 and 4.0版本,选择适合自己的!

解压以后如下

选择适合自己的版本 !

有两个xml文件,一个是简单配置文件(只有server的名字,描述,以及要包装成的.exe路径),

另一个是明细详细配置文件,还有日志文件,日志格式,启动模式(自启,手动等)等明细配置

将WinSw.NET2.exe (或WinSw.NET4.exe)和随便一个xml文件拷贝到nginx根目录,将文件重命名!

 

重命名成一样的名字就可以了!

编写配置文件

<configuration>
  
  <!-- ID of the service. It should be unique accross the Windows system-->
  <id>nginx</id>
  <!-- Display name of the service -->
  <name>服务的名字</name>
  <!-- Service description -->
  <description>描述</description>
  
 
  <executable>%BASE%\nginx.exe</executable>
<!-- 日志路径-->
  <logpath>%BASE%\logs\winsw</logpath>
    <!--参考:https://github.com/kohsuke/winsw/blob/master/doc/loggingAndErrorReporting.md-->
  <log mode="roll-by-size-time">
      <sizeThreshold>10240</sizeThreshold>
      <pattern>yyyyMMdd</pattern>
      <autoRollAtTime>00:00:00</autoRollAtTime>
      <zipOlderThanNumDays>10</zipOlderThanNumDays>
      <zipDateFormat>yyyyMM</zipDateFormat>
  </log>
</configuration>

 然后使用管理员命令窗口到nginx根目录下,用你重命名后的名字去执行以下命令

例如:nginx-install.exe install   安装服务

  • install to install the service to Windows Service Controller. This command requires some preliminary steps described in the Installation Guide.
  • uninstall to uninstall the service. The opposite operation of above.
  • start to start the service. The service must have already been installed.
  • stop to stop the service.
  • restart to restart the service. If the service is not currently running, this command acts like start.
  • status to check the current status of the service.
    • This command prints one line to the console.
      • NonExistent indicates the service is not currently installed
      • Started to indicate the service is currently running
      • Stopped to indicate that the service is installed but not currently running.

猜你喜欢

转载自blog.csdn.net/QWERTY1994/article/details/88907273