nginx加入Windows服務開機自啟動


目標:將nginx加入Windows服務,實現開機自啟動

 

需要用到工具winsw,到該目錄下,下載最新版winsw

http://repo.jenkins-ci.org/releases/com/sun/winsw/winsw/

源碼: https://github.com/winsw/winsw

 

新建個nginx目錄,將winsw-2.9.0-bin.exe拷貝到該目錄下並重命名為nginx-service.exe

該目錄下新建nginx-service.xml(exe與xml文件名要一致)

<!-- nginx-service.xml -->
<service>
  <id>nginx</id>
  <name>nginx</name>
  <description>This service runs nginx system.</description>
  <executable>D:\nginx\nginx.exe</executable>
  <startarguments>
    -c
    D:\nginxWebUI\nginx.conf
    -p
    D:\nginx
  </startarguments>
  
  <stopexecutable>D:\nginx\nginx.exe</stopexecutable>
  <stoparguments>
    -p
    D:\nginx
    -s
    stop
  </stoparguments>
  
  <log mode="roll"></log>
</service>

 

在該目錄下shift+右鍵,打開cmd,執行

nginx-service.exe install  # 安裝服務(默認開機自啟)
nginx-service.exe start    # 啟動服務

nginx-service.exe uninstall  # 卸載服務

 

 

同樣的,可以添加nginxWebUI對應的xml來安裝服務

<!-- nginx-webui-service.xml -->
<service>
  <id>nginx-webui</id>
  <name>nginx-webui</name>
  <description>This service runs nginxWebUI system.</description>
  <!-- <env name="JENKINS_HOME" value="%BASE%"/>  -->
  <executable>java</executable>
  <arguments>-Xmx64m -jar D:\nginxWebUI\nginxWebUI.jar --server.port=8086 --project.home=D:\nginxWebUI\</arguments>
  <log mode="roll"></log>
</service>

 

常用排查命令

netstat -aon | findstr 0:8086

tasklist | findstr 進程號或進程名

taskkill /f /im 進程號或進程名

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM