1. 程式人生 > >windows下安裝nginx,並新增至系統服務

windows下安裝nginx,並新增至系統服務

安裝:解壓修改配置檔案執行即可

 

新增服務

需要藉助"Windows Service Wrapper"小工具
下載地址:winsw GitHub

下載後放在nginx目錄下,並修改名字為nginx-service.exe

建立配置檔案nginx-service.exe.config 和 nginx-service.xml

nginx-service.xml的內容如下:

<service>
  <id>nginx</id>
  <name>Nginx Service</name>
  <description>High Performance Nginx Service</description>
  <logpath>C:\nginx-1.14.0\logs</logpath>
  <log mode="roll-by-size">
    <sizeThreshold>10240</sizeThreshold>
    <keepFiles>8</keepFiles>
  </log>
  <executable>C:\nginx-1.14.0\nginx.exe</executable>
  <startarguments>-p C:\nginx-1.14.0</startarguments>
  <stopexecutable>C:\nginx-1.14.0\nginx.exe</stopexecutable>
  <stoparguments>-p C:\nginx-1.14.0 -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命令進入nginx目錄安裝服務

nginx-service.exe install

刪除服務的命令

sc delete 服務名