1

I'm running on a server that has Apache on port 80. I also have nginx installed, and just one conf file in /etc/nginx/sites-enabled which has listen 8888; specified. This works perfectly fine.

Now, I added a second conf file for a different vhost within /etc/nginx/sites-enabled, listening on port 7979. When I run sudo service nginx restart, I get:

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.

Nowhere in any file within /etc/nginx is port 80 mentioned! And the only reason I used a different port (7979) is because if both vhosts had port 8888, one would simply redirect to the other, even though they have different server_name values.

What's going on here?

CaptSaltyJack
  • 628
  • 2
  • 13
  • 34
  • 2
    Probably you have server block without `listen` directive. In that case nginx defaults to `listen 80;`. Usually there is on in `/etc/nginx/nginx.conf`. – Alexey Ten Oct 27 '14 at 06:19
  • @AlexeyTen Ah man, caught again by a missing semicolon! If you post an answer, I'll give you the checkmark. – CaptSaltyJack Oct 27 '14 at 10:23

2 Answers2

0

If you have a server block without a listen directive, Nginx will default to 80.

source: Server Fault: Nginx tries to run on port 80 but the configs have been removed

ki9
  • 1,169
  • 1
  • 10
  • 18
0

do this and i'm sure you'll find the answer

cd /etc/nginx
grep -r 80 *

Sometimes if you do something like delete the default vhost and then upgrade it re-installs it back and that uses port 80

So if nginx isn't using it find what is

fuser 80/tcp

That will list the any pid using port 80.. then you can grep for it

ps aux | grep pid#
Mike
  • 21,910
  • 7
  • 55
  • 79