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

12,304

Solution 1

Rebooted OSX. Worked. I think with linux would be different.

Solution 2

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
Share:
12,304

Related videos on Youtube

Ariel Nonamë
Author by

Ariel Nonamë

Updated on September 18, 2022

Comments

  • Ariel Nonamë
    Ariel Nonamë over 1 year

    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).

    • dwkns
      dwkns about 8 years
      This can happen if you have previously installed pow pow.cx it adds a pfctl rule that forwards all traffic on port 80 to the pow port. Uninstalling pow fixes the problem. It is possible to get both ngrix and pow running together but it's a little fiddly.
  • Peshraw H. Ahmed
    Peshraw H. Ahmed almost 6 years
    Sometimes we really should think simple. After 1 hour of problem I saw this and worked :)
  • ankush981
    ankush981 almost 4 years
    Restarting nginx doesn't help on MacOS.