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.
Best Answer
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.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
Which for me was
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 mynginx.conf
. I changed thepid
entry back to match what the start command was specifying: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 sayand mine had
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.