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?

2
  • 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, 2014 at 6:19
  • @AlexeyTen Ah man, caught again by a missing semicolon! If you post an answer, I'll give you the checkmark. Oct 27, 2014 at 10:23

2 Answers 2

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#
4
  • Already thought of that. No trace of 80. Oct 27, 2014 at 3:09
  • see my edit for more info
    – Mike
    Oct 27, 2014 at 3:16
  • I know Apache is running on port 80. That's not the problem though. The issue is that nowhere in nginx's conf files is port 80 mentioned. There are two listen directives, listen 8888 and listen 7979. Oct 27, 2014 at 3:48
  • Try adding the -w option to grep to match 80 and not 8000. Jul 28, 2020 at 14:22
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

You must log in to answer this question.

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