NginX as a Reverse Proxy Binding Issues

apache-2.2nginx

I have a fresh Ubuntu 11 install on MediaTemple and setting up NginX as a reverse proxy. So static items are handled by NginX and the rest are handled by apache per these instructions:

http://wiki.mediatemple.net/w/(ve):Using_Nginx_as_a_Reverse_Web_Proxy

Everything went fine except when I did the last step of restarting apache and then restarting NginX. Apache restarted fine, but when I restarted NginX it gave an error about binding. I restarted the server, and then attempted to restart apache followed by NginX again. This time apache reports an error but NginX restarts fine.

* Restarting web server apache2                                                     
(98)Address already in use: make_sock: could not bind to address 127.0.0.1:80
no listening sockets available, shutting down
Unable to open logs
Action 'start' failed.
The Apache error log may have more information.

The latest errors in Apache log appear to be:

[Mon Nov 14 06:47:13 2011] [notice] caught SIGTERM, shutting down
[Mon Nov 14 06:47:14 2011] [notice] Apache/2.2.17 (Ubuntu) configured -- resuming normal operations
[Mon Nov 14 06:47:31 2011] [notice] caught SIGTERM, shutting down

Per the instructions I have the server external IP in NginX and the localhost ip in the apache locations.

I then stopped NginX restarted Apache (worked fine again) and then when restarting NginX the errors for that came back:

Restarting nginx: [emerg]: bind() to 0.0.0.0:80 failed (98: Address already in use)
[emerg]: bind() to 0.0.0.0:80 failed (98: Address already in use)
[emerg]: bind() to 0.0.0.0:80 failed (98: Address already in use)
[emerg]: bind() to 0.0.0.0:80 failed (98: Address already in use)
[emerg]: bind() to 0.0.0.0:80 failed (98: Address already in use)
[emerg]: still could not bind()
nginx.

Best Answer

It is clear from the output you pasted that nginx is trying to bind on port 80 on all available IP addresses, not only on your public address.

You should carefully review all listen directives in the relevant nginx configuration files. You can do this by running grep -r 'listen ' /etc/nginx/*.

If you find output looking like listen 80; (with no IP address specified), you should replace it with listen xx.xx.xx.xx:80, where xx.xx.xx.xx is your public IP address.