6

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    
5
  • What does sudo netstat -ltnp tell you?
    – womble
    Sep 5, 2011 at 3:30
  • @womble anything else you need?
    – Noah Clark
    Sep 5, 2011 at 3:41
  • Go to command console, type this: "netstat -a" and post the results.
    – U4iK_HaZe
    Sep 5, 2011 at 7:08
  • What user are you trying to start nginx as? (the master process, not the workers) Sep 5, 2011 at 11:26
  • @Martin, I assume I'm doing it as root. I'm starting it via: "sudo /etc/init.d/nginx start"
    – Noah Clark
    Sep 5, 2011 at 12:42

3 Answers 3

9

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.

3
  • 2
    This is correct. I have two http statements. I commented out one of them and now it starts.
    – Noah Clark
    Sep 5, 2011 at 12:54
  • Note that you can bind to IPv4 and IPv6 at the same time. You can do this with listen [::]:80; syntax. I also had the problem of two things binding to port 80 on the same address family and it was because I had two conflicting server statements.
    – Azendale
    Mar 1, 2013 at 4:40
  • For me it was trying to bind to IPv6, which is not correctly configured. After commenting out the listen [::]:80; it was fine. Seems to be included in nginx' stock configuration files now.
    – BastiBen
    Mar 21, 2013 at 15:17
0

Try:

http{

    server {

        listen 80;
        listen localhost;  # <- probably will fix your problem

        location / {
        root /data/www;
        }

        location /images/ {
        root /data;
        }
    }
}
0

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

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .