2

I'm trying to run service nginx restart but I get this error:

root@user /etc/nginx/sites-enabled # service nginx restart
Restarting nginx: nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
nginx: [emerg] still could not bind()
nginx.

How can I fix this problem? I'm also running apache.

2 Answers 2

3

You can't have more than one application listening to a port on a device. You have the following choices:

  1. Remove Nginx or Apache. Just use one.

  2. Keep both and move Apache or Nginx to another port. From there you can have the port80 server proxy the other one so that it is available for certain domains (see proxy_pass or mod_proxy).

  3. Keep both and move Apache and Nginx onto distinct IP addresses or interfaces. If your server is configured to have 10.0.0.3 and 10.0.0.4 (just examples) you could give the first to Apache and the second to Nginx and both could have a port80 on their respective IPs. This has knock-on consequences for DNS but that's not hard to account for.

    This does mean you need to stop using 0.0.0.0 as a setting in both servers.

2
  • Thanks! How to change nginx to another port? Jul 3, 2013 at 10:28
  • 1
    I'd suggest learning a little more than just how to poke the port. Internet-facing servers shouldn't be deployed and forgotten about. blog.martinfjordvald.com/2010/07/nginx-primer
    – Oli
    Jul 3, 2013 at 11:04
1

You will need to change the configure port of either Apache or Nginx. After you do this you will need to restart the reconfigured servers, using the 'service' command you used.

Apache

Edit /etc/apache2/ports.conf and change the 80 on the following line:

Listen 80

for something different.

Nginx

Edit /etc/nginx/sites-enabled/default and change the 80 on the following line:

listen 80;

for something different, this should be near the top, and be in the first server { section.

3
  • Thanks. I don't have server{} section in this file (nginx.conf) dpaste.de/6XSoI - here is my full config Jul 3, 2013 at 11:29
  • Oh, Sorry, I meant /etc/nginx/sites-enabled/default
    – megubyte
    Jul 3, 2013 at 11:41
  • Thx. Still the same error :( I don't know what is wrong. Jul 3, 2013 at 12:02

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .