I'm trying to setup nginx on Ubuntu 11.04. I have followed the roughly the directions found here: http://library.linode.com/frameworks/sinatra/debian-6-squeeze . I know it is for Debian, but I basically took those steps and then googled "How to do x in ubuntu 11.04" Although, I did pull the init scripts from their library.
Starting 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()
The command: 'sudo lsof -i:80' returns nothing running on port 80.
How do I troubleshoot this or any ideas on what maybe going wrong?
I saw Nginx + uWSGI on a fresh Ubuntu install - bind error port 80 and tried restarting the computer and running it once and I get the same error. After running it once, I then ran the lsof command.
UPDATE
sudo netstat -ltnp returns:
Active Internet connections (only servers) Proto Recv-Q Send-Q Local Address
Foreign Address State PID/Program name
tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN 1998/sshd
tcp6 0 0 :::22 :::* LISTEN 1998/sshd
nestat -a returns:
Active Internet connections (servers and established)
Proto Recv-Q Send-Q Local Address Foreign Address State
tcp 0 0 *:ssh *:* LISTEN
tcp 0 176 matterhorn.noahc.ne:ssh 173-26-190-206.cl:26467 ESTABLISHED
tcp6 0 0 [::]:ssh [::]:* LISTEN
udp 0 0 matterhorn.noahc.:35332 10504.x.rootbsd.net:ntp ESTABLISHED
udp 0 0 matterhorn.noahc.:53298 tick.tadatv.com:ntp ESTABLISHED
udp 0 0 matterhorn.noahc.:54371 ns1.baribault.net:ntp ESTABLISHED
udp 0 0 matterhorn.noahc.:38304 tardis.chpc.utah.ed:ntp ESTABLISHED
Active UNIX domain sockets (servers and established)
Proto RefCnt Flags Type State I-Node Path
unix 2 [ ACC ] STREAM LISTENING 684 @/com/ubuntu/upstart
unix 2 [ ] DGRAM 730 @/org/kernel/udev/udevd
unix 6 [ ] DGRAM 4316 /dev/log
unix 2 [ ] DGRAM 11447
unix 3 [ ] STREAM CONNECTED 10466
unix 3 [ ] STREAM CONNECTED 10465
unix 2 [ ] DGRAM 11411
unix 3 [ ] STREAM CONNECTED 2958
unix 3 [ ] STREAM CONNECTED 2957
unix 2 [ ] DGRAM 4518
unix 2 [ ] DGRAM 2902
unix 2 [ ] DGRAM 2614
unix 3 [ ] STREAM CONNECTED 1284 @/com/ubuntu/upstart
unix 3 [ ] STREAM CONNECTED 4131
unix 3 [ ] DGRAM 733
unix 3 [ ] DGRAM 732
unix 3 [ ] STREAM CONNECTED 1038 @/com/ubuntu/upstart
unix 3 [ ] STREAM CONNECTED 2088
One possibility is that, for some reason, nginx is binding to port 80 twice.
If it tries to do this it will fail. An example might be binding to IPV6 and IPV4, or binding it to public ip and the wildcard ip.
Check your nginx config to make sure that it is only binding once.
Try:
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