Add nginx.exe as Windows system service (like Apache)?

前端 未结 9 1070
面向向阳花
面向向阳花 2020-12-04 07:08

I set up NGINX as a front end server for static content and I use Apache as a back-end server for other thing.

The thing is I can\'t find a logical answer that allow

9条回答
  •  一生所求
    2020-12-04 07:17

    How to do it with Windows Service Wrapper

    (Note: There are easier alternatives by now - see also solutions described here below using chocolatey package manager by suneg and using NSSM directly from Adamy)

    1. Download the latest version of Windows Service Wrapper via github or nuget.
      • Current version as of this writing is v2.2.0
      • Since v2.x executables for .NET2.0 and .NET4.0 are available - others only on demand.
    2. Rename winsw-*.exe to something like nginxservice.exe.
      • This is the name that will show up for the process that owns your nginx process.
    3. Place an XML file next to the exe with the same base name, e.g. nginxservice.xml. The contents should be like below (verify your nginx location).

      
        nginx
        nginx
        nginx
        c:\nginx\nginx.exe
        c:\nginx\
        roll
        
        -p
        c:\nginx
        c:\nginx\nginx.exe
        -p
        c:\nginx
        -s
        stop
      
      
      • You can find up to date details about the configuration on the config github page, a generic example showing all possible options here and an installation guide.
    4. Run the command nginxservice.exe install as administrator.

    You will now have an nginx service in your Services! (It is set to start automatically on boot; if you want to start your server, you must manually start the service (net start nginx).)


    Detailed description of correctly setting up nginx as a Windows Service: http://web.archive.org/web/20150819035021/http://misterdai.yougeezer.co.uk/posts/2009/10/16/nginx-windows-service/

    Additional info not contained in above blog post:

    You can find the latest version of the Windows Service Wrapper also via this Maven Repository: http://repo.jenkins-ci.org

    Examples for Maven + Gradle:

    
        com.sun.winsw
        winsw
        2.2.0
        bin
        exe
    
    
    
        jenkinsci
        jenkinsci-releases
        http://repo.jenkins-ci.org/releases
    
    
    compile "com.sun.winsw:winsw:2.2.0"
    
    repositories {
        mavenCentral()
        maven { url http://repo.jenkins-ci.org/releases }
    }
    

提交回复
热议问题