Nginx + uWSGI on a fresh Ubuntu install - bind error port 80

I know this is a common problem usually having to do with apache or another service already running on port 80 and I have done a lot of searching and running netstat and still have not figured out why I am getting this error.

I rebuilt my slice, did a fresh install of Ubuntu 10.04 and setup nginx + uwsgi. It worked and I was able to see my Django site. I then installed Postgres8.4 and the rest of the stack needed for Geodjango from this link.

After that was done I tried to restart nginx and I get this error:

sudo /etc/init.d/nginx start
Starting nginx: the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok
configuration file /usr/local/nginx/conf/nginx.conf test is successful
[emerg]: bind() to 0.0.0.0:80 failed (98: Address already in use)
[emerg]: bind() to 0.0.0.0:80 failed (98: Address already in use)
[emerg]: bind() to 0.0.0.0:80 failed (98: Address already in use)
[emerg]: bind() to 0.0.0.0:80 failed (98: Address already in use)
[emerg]: bind() to 0.0.0.0:80 failed (98: Address already in use)
[emerg]: still could not bind()

I have nginx set to listen 80. Here's an output from netstat -l --numeric-ports | grep 80:

tcp        0      0 0.0.0.0:80              0.0.0.0:*               LISTEN     
tcp        0      0 127.0.0.1:8000          0.0.0.0:*               LISTEN

Output from sudo lsof +M -i4:

nginx    2330     root    8u  IPv4   3195      0t0  TCP *:www (LISTEN)
nginx    2331 www-data    8u  IPv4   3195      0t0  TCP *:www (LISTEN)
uwsgi    2335        s    4u  IPv4   3259      0t0  TCP localhost:8000 (LISTEN)
uwsgi    2352        s    4u  IPv4   3259      0t0  TCP localhost:8000 (LISTEN)
uwsgi    2353        s    4u  IPv4   3259      0t0  TCP localhost:8000 (LISTEN)
uwsgi    2354        s    4u  IPv4   3259      0t0  TCP localhost:8000 (LISTEN)
uwsgi    2355        s    4u  IPv4   3259      0t0  TCP localhost:8000 (LISTEN)

Anyone have any other ideas how I can figure out what is blocking port 80?

edit

Paste of my /etc/init.d/nginx script here: http://dpaste.com/hold/400937/


Solution 1:

Shouldn't you have issued restart as an argument to your init script?

I would expect

sudo /etc/init.d/nginx start

to complain if nginx was already running. Which it sounds like it was.

Solution 2:

fuser -n tcp 80 will show you a PID of process using port 80.

Solution 3:

netstat -plan

will provide you the process name then use killall -9

and restart you nginx