1. 程式人生 > >利用WindowsServiceWrapper(WinSW)將nginx包裝為系統服務

利用WindowsServiceWrapper(WinSW)將nginx包裝為系統服務

只需要 配置 ice rip utf-8 http 下載 release -c

1、WindowsServiceWrapper(WinSW)

Github:https://github.com/kohsuke/winsw/

下載地址:http://repo.jenkins-ci.org/releases/com/sun/winsw/winsw/

介紹:A wrapper executable that can be used to host any executable as an Windows service, in a liberal license

  (一個可執行文件的包裝器,可以托管任何可執行文件作為windows服務)

2、將nginx作為windows系統服務是使用nginx做為web服務器的windows系統的剛需

好處:一方面,可以保證nginx隨著系統運行而運行(比如重新啟動),只需要將nginx服務設為自動運行即可,不需要手動操作

   另一方面,不受用戶的登錄或註銷影響(用戶註銷會將當前用戶運行的所有程序退出)

3、下載WinSw

4、將下載後的文件(如 winsw-2.1.2-bin.exe )拷貝至nginx根目錄,將重命名為nginx-service.exe

5、在nginx根目錄下創建 nginx-service.xml 文件,內容如下

<?xml version="1.0" encoding="UTF-8" ?>

<service>

 <id>Nginx</
id> <name>Nginx</name> <description>本服務用於加載Nginx服務,請確保開機啟動。</description> <logpath>C:\nginx\logs</logpath> <executable>nginx.exe</executable> <stopexecutable>nginx.exe</stopexecutable> <stopargument>-s</stopargument>
<stopargument>stop</stopargument> <logmode>rotate</logmode> </service>

6、做完4、5兩個步驟配置就基本完成了,以下是安裝及卸載的命令

7、打開dos命令行工具,並定位到nginx根目錄

安裝

nginx-service.exe install

卸載

nginx-service.exe uninstall

8、用命令行運行或停止nginx服務

net start nginx

net stop nginx

利用WindowsServiceWrapper(WinSW)將nginx包裝為系統服務