下載 https://github.com/kohsuke/winsw/releases/tag/winsw-v2.3.0 下的這個文件 WinSW.NET4.exe 放在Nginx的安裝目錄下,而且將其重命名爲 nginx-service.exe
nginx
在該目錄下新建 nginx-service.xml 文件,寫入配置信息,配置好了以後就能夠經過這個將Nginx註冊爲Windows服務。git
<!-- nginx-service.xml -->
<service>
<id>nginx</id>
<name>nginx</name>
<description>nginx</description>
<logpath>D:nginx-1.14.0\</logpath>
<logmode>roll</logmode>
<depend></depend>
<executable>D:nginx-1.14.0\nginx.exe</executable>
<stopexecutable>D:nginx-1.14.0\nginx.exe -s stop</stopexecutable>
</service>
服務命令
以上內容配置好了以後,在nginx安裝目錄下以管理員運行命令:.\nginx-service.exe install 就成功將其註冊爲Windows服務了,而後運行 .\nginx-service.exe start 啓動服務。這時咱們能夠在Windows任務管理器的服務中查看該是否成功啓動。github
注:url
nginx-service.exe install 命令可註冊對應的系統服務
nginx-service.exe uninstall 命令可刪除對應的系統服務
nginx-service.exe stop 命令可中止對應的系統服務
nginx-service.exe start 命令可啓動對應的系統服務
spa