將nginx註冊爲windows服務,只要啓動服務器不需要登錄就可以實現服務自啓動,下面簡介安裝方法。
下載命令行工具,下載網址:命令行工具(把nginx安裝爲微服務)。
<service>
<id>el-gznwmhweb</id>
<name>el-gznwmhweb</name>
<description>el-gznwmhweb(8000)</description>
<logpath>E:\nginx-1.12.2\logs\</logpath>
<logmode>roll</logmode>
<depend></depend>
<executable>E:\nginx-1.12.2\nginx.exe</executable>
<stopexecutable>E:\nginx-1.12.2\nginx.exe -s stop</stopexecutable>
</service>
- id爲服務名稱
- name爲服務顯示名稱
- logpath指定nginx日誌文件地址
- E:\nginx-1.12.2\nginx.exe爲nginx可執行應用程序文件位置
開始安裝
管理員身份打開cmd,進入nginx目錄,執行命令:
nginxservice.exe install 添加服務
這種方法有一個弊端就是服務描述(description)不能是中文。不過不用擔心,在加上一行cmd命令即可解決問題
sc description 服務名 "中文描述"
nginxservice.exe uninstall命令可刪除對應的系統服務