下載 https://github.com/kohsuke/winsw/releases 下的這個文件 WinSW.NET4.exe 放在Nginx的安裝目錄下,並且將其重命名為 nginx-service.exe
在該目錄下新建 nginx-service.xml 文件,寫入配置信息,配置好了之后就可以通過這個將Nginx注冊為Windows服務。
<!-- 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任務管理器的服務中查看該是否成功啟動。
注:
nginx-service.exe install 命令可注冊對應的系統服務
nginx-service.exe uninstall 命令可刪除對應的系統服務
nginx-service.exe stop 命令可停止對應的系統服務
nginx-service.exe start 命令可啟動對應的系統服務