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:


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
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 failed (98: Address already in use)
[emerg]: bind() to failed (98: Address already in use)
[emerg]: bind() to failed (98: Address already in use)
[emerg]: bind() to failed (98: Address already in use)
[emerg]: bind() to failed (98: Address already in use)
[emerg]: still could not bind()
  • Apache says something is listening to port 80 on IP So something else is binding to port 80. What does your netstat say is listening? – Bart Silverstrim Nov 14 '11 at 15:11
  • Does this help? sudo lsof -i tcp:80 COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME apache2 1459 root 3u IPv4 1871631190 0t0 TCP localhost:www (LISTEN) apache2 1462 www-data 3u IPv4 1871631190 0t0 TCP localhost:www (LISTEN) apache2 1463 www-data 3u IPv4 1871631190 0t0 TCP localhost:www (LISTEN) apache2 1464 www-data 3u IPv4 1871631190 0t0 TCP localhost:www (LISTEN) apache2 1466 www-data 3u IPv4 1871631190 0t0 TCP localhost:www (LISTEN) apache2 1467 www-data 3u IPv4 1871631190 0t0 TCP localhost:www (LISTEN) – cchiera Nov 14 '11 at 15:17
  • Per the link above NginX listens to my server ip on port 80 and apache listens to the local host on port 80. – cchiera Nov 14 '11 at 15:18
  • The problem seems that both are listening on the same ip and port. I'd start by checking your /etc/nginx.conf (not mentioned in the guide you linked) for a listen directive in the default server. Then grep all the Apache configuration files for Listen and NameVirtualHost directives. You can start one and use netstat to check which IPs it is listening on to determine which server is the problem. Additionally, there is no reason to have Apache listening on port 80 - you could just as easily make it 81 or 8080, etc. (Although, the latter probably won't help in this case) – cyberx86 Nov 14 '11 at 15:22
  • Cyberx86, There is no /etc/nginx.conf file that I can see. There is a /etc/nginx file. Is that the one you are referencing? – cchiera Nov 14 '11 at 15:27

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.

  • @heavymark I don't see any output from the grep command in your comment. Is that intentional, or you simply forgot to paste it? :-) – Vladimir Blaskov Nov 14 '11 at 15:41
  • Vladimir, thanks I've been trying to figure out the command to do just that. When I ran yours I get follow: pastie.org/2862176 At first, promising except the /default file it referenced per the original link, that is disabled, and it only uses my domain file. Also in that file, the 80 it referes to is commented out. And in the .conf file I finally found the two references about listen are also already commented out. Any more ideas? – cchiera Nov 14 '11 at 15:47
  • I clicked enter to return to the next line but it submitted it, and then when I was typing the rest it said it was too late to edit the comment, so had to do a new one. – cchiera Nov 14 '11 at 15:48
  • To note, I swapped out my server external ip with my.ip.address and my server domain with example.com for privacy. – cchiera Nov 14 '11 at 15:49
  • To also add I searched apache as well and got the following which looks correct. I can add the local ip infront of the the ssl ports but the error seems to be about 80 so don't think that would fix the problem. grep -r 'Listen ' /etc/apache2/* /etc/apache2/ports.conf:Listen /etc/apache2/ports.conf: Listen 443 /etc/apache2/ports.conf: Listen 443 – cchiera Nov 14 '11 at 15:57

I had almost the same issue. (Ubuntu 10.04, 2 real IPs, one for Apache and one for nginx). Solution: every server {...} block in configuration files MUST have listen a.b.c.d:80 directive. Otherwise nginx tries to use all available IPs.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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