MacOS – Can’t get Nginx to work on port 80. Works fine on any other port

macosnginxportps

I’ve just setup Homebrew’s Nginx on Mac OS X 10.11 (El Capitan).

If I set my Ngnix config like this:

listen      127.0.0.1:8080;

listen      127.0.0.1:81;

listen      127.0.0.1:75;

It’ll work. But If I put this in there:

listen      127.0.0.1:80;

It wont. I’ll get connection refused if I go http://127.0.0.1

ps says Nginx is running, but netstat -a | grep nginx or netstat -a | grep 80 says it isn't.

Running this as root, of course (not that I need that for running on :8080

And Mac OS X Firewall’s not running.

Error log doesn’t show this anymore anymore:

2015/10/10 17:16:19 [emerg] 23906#0: bind() to 0.0.0.0:80 failed (48: Address already in use)

Any ideas? I CAN work with this running on 8080 (curiously, when I run on 8080, it opens the 80 port and redirects it to 80).

Best Answer

  • The error is as follows:

    2015/10/10 17:16:19 [emerg] 23906#0: bind() to 0.0.0.0:80 failed (48: Address already in use)
    

    That “Address already in use” says it all: Something else on your system is using port 80. Do you have web sharing enabled or perhaps Apache installed and running? The way you can check this is to run lsof like this on your system:

    sudo lsof -i -P | grep -i "80"
    

    That will strictly show you what process might be using port 80. If you are curious to see what other ports are set to “listen” on your Mac OS X system just run this command:

    sudo lsof -i -P
    
  • Related Question