Take the 2-minute tour ×
Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

This question already has an answer here:

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?

share|improve this question

marked as duplicate by poige, Ward, mdpc, Michael Hampton Jul 19 at 18:10

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

4  
Note that you get an error regarding port 8080 (bind() to 0.0.0.0:8080) so you should check which process is listening on that, not on 80. Use lsof -i:8080 or sudo netstat -a -n | grep 80 to find the blocking process –  LightningIsMyName Jul 12 '14 at 15:15
    
Also, the lsof command shows both incoming & outgoing connections on the listed port; the results you're seeing are outgoing connections to port 80 on various remote servers, not activity on your server's port 80. –  Gordon Davisson Jul 12 '14 at 18:06
    
@LightningIsMyName lsof -i:8080 shows no output. I tried changing the port from 8080 to 80 in my nginx.conf file but I'm still getting the same error. Any suggestions? –  Yin Yang Jul 14 '14 at 8:39
    
When you change to port 80, are you running nginx as root? It's required to bind to port 80. Also, if you run ps aux|grep -i apache do you see any apache processes running? How about ps aux|grep http ? If it says something is bound to a port, it generally is because something is, I can't say that I've seen an anomaly to this. –  SprintCycle Oct 8 '14 at 17:44
    
This usually means you have 2 conflicting listen statements throughout your config somewhere. Do a grep -i listen in all your config directories. –  Aaron May 15 at 17:20

1 Answer 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.

share|improve this answer

Not the answer you're looking for? Browse other questions tagged or ask your own question.