run nginx as windows service

NSSM is very nice, but there is another alternative: The PowerShell Cmdlet New-Service

Here is just a simple example:

$params = @{
    Name = "MyService"
    BinaryPathName = "path/to/exe"
    DisplayName = "My Service"
    StartupType = "Automatic"
    Description = "Description of my service"
}
New-Service @params

https://docs.microsoft.com/en-us/powershell/module/microsoft.powershell.management/new-service?view=powershell-6


Just stumbled here and managed to get things working with this free open source alternative: https://nssm.cc/

It basically is just a GUI to help you create a service. Steps I used:

  1. Download NGinx (http://nginx.org/en/download.html) and uzip to C:\foobar\nginx
  2. Download nssm (https://nssm.cc/)
  3. Run "nssm install nginx" from the command line
  4. In NSSM gui do the following:
  5. On the application tab: set path to C:\foobar\nginx\nginx.exe, set startup directory to C:\foorbar\nginx
  6. On the I/O tab type "start nginx" on the Input slow. Optionally set C:\foobar\nginx\logs\service.out.log and C:\foobar\nginx\logs\service.err.log in the output and error slots.
  7. Click "install service". Go to services, start "nginx". Hit http://localhost:80 and you should get the nginx logon. Turn off the service, disable browser cache and refresh, screen should now fail to load.

You should be good to go from then on.