1. 程式人生 > >windows 安裝Nginx並建立為Windows服務

windows 安裝Nginx並建立為Windows服務

安裝Nginx

下載windows版nginx (http://nginx.org/download/nginx-1.10.0.zip),之後解壓到需要放置的位置(D:\xampp\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:\xampp\nginx\logs</logpath>
  <log mode="roll-by-size">
    <sizeThreshold>10240</sizeThreshold>
    <keepFiles>8</keepFiles>
  </log>
  <executable>D:\xampp\nginx\nginx.exe</executable>
  <startarguments>-p D:\xampp\nginx</startarguments>
  <stopexecutable>D:\xampp\nginx\nginx.exe</stopexecutable>
  <stoparguments>-p D:\xampp\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:\xampp\nginx\nginx-service.exe install

之後就可以在Windows服務面板中啟動服務了

瀏覽器中就可以正常訪問了