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

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
3  
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 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 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 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 at 17:44

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.