Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

I recently installed nginx and PHP-FPM via MacPorts on OS X 10.9 Mavericks and although it works my main error_log continuously says port 80 is in use.

2013/10/25 11:27:36 [emerg] 4510#0: bind() to 0.0.0.0:80 failed (48: Address already in use)
2013/10/25 11:27:36 [notice] 4510#0: try again to bind() after 500ms
2013/10/25 11:27:36 [emerg] 4510#0: bind() to 0.0.0.0:80 failed (48: Address already in use)
2013/10/25 11:27:36 [notice] 4510#0: try again to bind() after 500ms
2013/10/25 11:27:36 [emerg] 4510#0: bind() to 0.0.0.0:80 failed (48: Address already in use)
2013/10/25 11:27:36 [notice] 4510#0: try again to bind() after 500ms
2013/10/25 11:27:36 [emerg] 4510#0: bind() to 0.0.0.0:80 failed (48: Address already in use)
2013/10/25 11:27:36 [notice] 4510#0: try again to bind() after 500ms
2013/10/25 11:27:36 [emerg] 4510#0: bind() to 0.0.0.0:80 failed (48: Address already in use)
2013/10/25 11:27:36 [notice] 4510#0: try again to bind() after 500ms
2013/10/25 11:27:36 [emerg] 4510#0: still could not bind()

I have verified nothing else such as Apache is using port 80.

share|improve this question
    
maybe related –  that guy from over there Oct 26 '13 at 7:34
    
Thanks, but it wasn't actually related. As I mentioned in the original question, I was sure nothing was competing for port 80. When I posted the question I actually posted the correct solution for my case hoping that someone else could be helped by my hours wasted on the problem. –  crazyj Oct 28 '13 at 17:49

1 Answer 1

up vote 3 down vote accepted

When searching for a solution several places such as this one say the solution is to remove/comment out the listen directive line in the default host.

#listen       80 default_server;

Doing so didn’t change anything for me, and the main error_log continued to fill up.

Finally someone in the nginx forums troubleshooting a similar problem recommended looking at the output of

ps ax -o pid,ppid,%cpu,vsz,wchan,command|egrep '(nginx|PID)'

Which for me was

  PID  PPID  %CPU      VSZ WCHAN  COMMAND
 4963     1   0.0  2504128 -      /opt/local/bin/daemondo --label=nginx --start-cmd /opt/local/sbin/nginx ; --pid=fileauto --pidfile /opt/local/var/run/nginx/nginx.pid
 4967     1   0.0  2475388 -      nginx: master process /opt/local/sbin/nginx
 4969  4967   0.0  2476412 -      nginx: worker process
 5024  1538   0.0  2432784 -      egrep (nginx|PID)
 1969  1874   0.0  2432772 -      tail -F /opt/local/etc/nginx/logs/error.log

I noticed in the first line that the pidfile location was being set in MacPorts’ startup command --pidfile /opt/local/var/run/nginx/nginx.pid and that it was different than the location I had specified in my nginx.conf. I changed the pid entry back to match what the start command was specifying:

pid        /opt/local/var/run/nginx/nginx.pid;

After restarting nginx and tailing the error_log (tail -F /opt/local/etc/nginx/logs/error.log) I noticed the problem was fixed.

In short: If you’re using the MacPorts version of nginx you probably don’t want to mess with changing the location of the pidfile.

As an aside, if you look at other pages trying to solve this issue, specifically ones where the problem was fixed by removing the listen directive or where something else like Apache was also using port 80 you will notice that those error logs say

[emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)

and mine had

[emerg] bind() to 0.0.0.0:80 failed (48: Address already in use)

I suspect the difference between error 98 and error 48 is the difference but I wasn't able to find any description of the various errors.

share|improve this answer
    
Glory be! A solution to this annoyance which actually fixes the problem! –  Garrett Albright Dec 11 '13 at 22:08

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.