SvennD
Running Nginx on Bash for Windows 10
June 24, 2016

Running Nginx on Bash for Windows 10

Posted on June 24, 2016  •  3 minutes  • 512 words  •  Suggest Changes

I normally go for Apache as my go-to webserver, lately however I got a liking to Nginx, for no real reasons except for the fact it has a nicer config layout. (a bad reason is a reason non the less) So when I installed Bash for Windows 10, I when and tried Nginx, sadly it didn’t work, and still doesn’t work nicely. I however got it running, this is how : First, install Nginx.

Then I wanted to ignite Nginx, but that did not work, starting Nginx failed cause of port 80 was in use.

2016/06/24 11:37:22 [emerg] 2710#0: bind() to 0.0.0.0:80 failed (98: Address already in use)

Since I am running two systems (Linux and Windows 10) there are plenty of places to look. I started with the location I know best and was most unlikely the problem : Linux.  Using netstat -tulpn | grep 80 I verified nothing was running on this freshly installed UbuntuBash. So onto W10, I know Skype, Apache, … uses port 80, but that did not run, so the hunt continued. I finally found -using resmon.exe- under Listener-port  the problem, port 80 was being used by System (PID 4) … not something you can easily kill …

PID 4 (Sytem) was listening on port 80. (no longer seen here)

I dug a bit further and found this useful post. You have to stop some service, this is done using :

net stop http in Windows 10 (in dutch)

C:\WINDOWS\system32>net stop http
De volgende services zijn afhankelijk van de HTTP Service-service.
Als u de HTTP Service-service stopt, worden deze services eveneens gestopt.

   World Wide Web Publishing-service
   SSDP Discovery
   Print Spooler
   HomeGroup Provider
   Function Discovery Resource Publication
   Function Discovery Provider Host

Wilt u doorgaan met deze bewerking? (J/N) [N]: j
De World Wide Web Publishing-service-service wordt gestopt.
De World Wide Web Publishing-service-service is gestopt.

De SSDP Discovery-service wordt gestopt.
De SSDP Discovery-service is gestopt.

De Print Spooler-service wordt gestopt.
De Print Spooler-service is gestopt.

De HomeGroup Provider-service wordt gestopt.
De HomeGroup Provider-service is gestopt.

De Function Discovery Resource Publication-service wordt gestopt.
De Function Discovery Resource Publication-service is gestopt.

De Function Discovery Provider Host-service wordt gestopt.
De Function Discovery Provider Host-service is gestopt.


De HTTP Service-service is gestopt.

After that I retried nginx to once again be shown an error :

2806#0: ioctl(FIOASYNC) failed while spawning "worker process" (22: Invalid argument)

That was solved using this -still open- bugreport on github. The essence is add the following to /etc/nginx/nginx.conf :

master_process off;
#daemon off;

Now to be honest I have got no idea, what any of those parameters do.  (note) I tried w/o the daemon parameter and it works as well, so I only use master_process and everything seems to “work”. (different from the solution on github!)

After this, Nginx is running nicely on my BashOnWindows. Pretty nice work, Windows !

// update  28/06

On my second machine I also had to change /etc/nginx/sites-available/default the following line :

server {
        listen 80 default_server;
        listen [::]:80 default_server ipv6only=on;

to

server {
        listen 80 default_server;
        #listen [::]:80 default_server ipv6only=on;

This probably cause some ipv6 problem. (this is development only anyway!)

 

Support

If you enjoyed this website, consider buying me a Dr. Pepper

Buy me a Dr PepperBuy me a Dr Pepper