1

I'm trying to connect my port 7979 to nginx and it doesn't work. I was on localhost:7979/myproject/app/index.php but when I restarted my mac and I updated it, I now see the error message:

ERR_CONNECTION_REFUSED

When I try sudo nginx I see the following messages.

nginx: [emerg] bind() to 0.0.0.0:80 failed (48: Address already in use)
nginx: [emerg] bind() to 0.0.0.0:443 failed (48: Address already in use)
nginx: [emerg] bind() to 0.0.0.0:306 failed (48: Address already in use)
nginx: [emerg] bind() to 0.0.0.0:80 failed (48: Address already in use)
nginx: [emerg] bind() to 0.0.0.0:443 failed (48: Address already in use)
nginx: [emerg] bind() to 0.0.0.0:306 failed (48: Address already in use)
nginx: [emerg] bind() to 0.0.0.0:80 failed (48: Address already in use)
nginx: [emerg] bind() to 0.0.0.0:443 failed (48: Address already in use)
nginx: [emerg] bind() to 0.0.0.0:306 failed (48: Address already in use)
nginx: [emerg] bind() to 0.0.0.0:80 failed (48: Address already in use)
nginx: [emerg] bind() to 0.0.0.0:443 failed (48: Address already in use)
nginx: [emerg] bind() to 0.0.0.0:306 failed (48: Address already in use)
nginx: [emerg] bind() to 0.0.0.0:80 failed (48: Address already in use)
nginx: [emerg] bind() to 0.0.0.0:443 failed (48: Address already in use)
nginx: [emerg] bind() to 0.0.0.0:306 failed (48: Address already in use)
nginx: [emerg] still could not bind()

Port 80 is functioning. If I go to localhost:80 I see this message in the html page:

Default website Congratulations, your Nginx seems to work just fine. :)

Why am I unable to use port 7979?

Sam M
  • 4,136
  • 4
  • 29
  • 42

2 Answers2

0

I changed the root and the port and it worked on site-available/default. The root by default wasn't good i don't know why it changed when i restarted my mac. THan

0

It's difficult to troubleshoot with this little info available. So first:

An error message like nginx: [emerg] bind() to 0.0.0.0:80 failed (48: Address already in use) indicates that something is already listening on port 80 and hence nginx can't do that as well when you start it.

Assuming your configuration files are perfectly ok, you'll have to figure out what is already listening on ports 80, 443 and 306. It might be an instance of nginx that's running with an older configuration but without much more details thats' just a guess.

See what processes are running:

$ ps -ax

See if there's an nginx instance running:

$ ps -ax | grep nginx

Netstat can give you what ports are being listened to:

$ nestat -an | grep LISTEN

To find out which process is listening to a given port:

$ sudo lsof -i :631

(631 is just an example)

What I suspect: you're starting nginx while it's already running. If it's already running, you should restart it instead of starting a new copy.

This might be of help: https://serverfault.com/questions/225948/how-to-restart-nginx-on-mac-os-x In essence:

$ sudo nginx -s reload

Just a warning I don't run nginx on macOS, but it should work if nginx on macOS reacts like it does on FreeBSD (which macOS uses as a long distant base)