6

I'm trying to start nginx on my Mac OS X using the command sudo nginx

It fails with the following error

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

I try to stop the Apache service by using sudo apachectl stop

This throws me the following error

launchctl: Error unloading: org.apache.httpd

According to this answer it most likely means that Apache is already not running

Then I tried to figure what is running on the Port 80 using sudo lsof -i:80

This outputs to this

Google    441 jaskaran   68u  IPv4 0xa3f4d891ed1a8373      0t0  TCP 192.168.1.45:50993->www.google:http (ESTABLISHED)
Google    441 jaskaran  143u  IPv4 0xa3f4d891ed054b5b      0t0  TCP 192.168.1.45:51017->www.scorecardresearch.com:http (ESTABLISHED)
Google    441 jaskaran  150u  IPv4 0xa3f4d891eb9a1b5b      0t0  TCP 192.168.1.45:51018->www.scorecardresearch.com:http (ESTABLISHED)
Google    441 jaskaran  152u  IPv4 0xa3f4d891ed1a4373      0t0  TCP 192.168.1.45:51019->www.scorecardresearch.com:http (ESTABLISHED)
Google    441 jaskaran  156u  IPv4 0xa3f4d891ed071b5b      0t0  TCP 192.168.1.45:51020->www.scorecardresearch.com:http (ESTABLISHED)

The output to this command keeps on changing with time.

How do I get nginx to work?

Yin Yang
  • 273

1 Answers1

1

Before attempting to start nginx, check if something is already running on port '8080' as follows. I say port "8080", because that's the port number shown in the error message you posted:

$ sudo netstat -nlp | grep ':8080' tcp 0 0 0.0.0.0:8080 0.0.0.0:* LISTEN 2355/nginx
tcp6 0 0 :::8080 :::* LISTEN 2355/nginx

In my case, that's showing a process named "nginx" with the Process ID of 2355 running on port 8080.

You try can issuing a kill -TERM 2355 to the related process ID to get to stop (assuming you don't want it running), and then confirm with netstat, as shown above. Change "2355" to match your own process ID.

You may still get the error even if you've confirmed that nothing is running on that part before you try to start to nginx. In that case, your Nginx may have conflicting entries regarding that port. Search your Nginx configuration for 8080. If there are multiple mentions, review the docs for the related configuration to confirm you haven't used it too many times.