Nginx bind to :80 failed, address already in use

Discussion in 'Installation/Configuration' started by msp, Mar 31, 2013.

  1. msp

    msp Member

    I think this is unrelated to my other post from a few minutes ago.

    When I install and start Nginx as part of ISPConfig3 setup, I get:

    Code:
    Starting nginx: nginxnginx: [emerg] bind() to [::]:80 failed (98: Address already in use)
    nginx: [emerg] bind() to [::]:80 failed (98: Address already in use)
    nginx: [emerg] bind() to [::]:80 failed (98: Address already in use)
    nginx: [emerg] bind() to [::]:80 failed (98: Address already in use)
    nginx: [emerg] bind() to [::]:80 failed (98: Address already in use)
    nginx: [emerg] still could not bind()
    netstat -tap gives:

    Code:
    Active Internet connections (servers and established)
    Proto Recv-Q Send-Q Local Address           Foreign Address         State       PID/Program name
    tcp        0      0 *:imaps                 *:*                     LISTEN      2355/dovecot
    tcp        0      0 *:pop3s                 *:*                     LISTEN      2355/dovecot
    tcp        0      0 localhost.localdom:9000 *:*                     LISTEN      7230/php-fpm.conf)
    tcp        0      0 localhost.localdo:10024 *:*                     LISTEN      2136/amavisd (maste
    tcp        0      0 *:43113                 *:*                     LISTEN      1522/rpc.statd
    tcp        0      0 *:mysql                 *:*                     LISTEN      2102/mysqld
    tcp        0      0 *:pop3                  *:*                     LISTEN      2355/dovecot
    tcp        0      0 *:imap2                 *:*                     LISTEN      2355/dovecot
    tcp        0      0 *:sunrpc                *:*                     LISTEN      1510/portmap
    tcp        0      0 *:ssh                   *:*                     LISTEN      1804/sshd
    tcp        0      0 *:smtp                  *:*                     LISTEN      2344/master
    tcp        0    248 doris.insistendo.co:ssh b0fa9154.bb.sky.c:50711 ESTABLISHED 2394/0
    tcp6       0      0 [::]:ssh                [::]:*                  LISTEN      1804/sshd
    Halp!
     
  2. markc

    markc Member

    This may be completely unrelated but perhaps you have overlapping listen directives...
    Code:
    grep -r listen /etc/nginx/*
     
  3. msp

    msp Member

    The output of that command is:

    Code:
    /etc/nginx/nginx.conf:#         listen     localhost:110;
    /etc/nginx/nginx.conf:#         listen     localhost:143;
    /etc/nginx/sites-available/default:     listen 80;
    /etc/nginx/sites-available/default:     listen [::]:80 default_server;
    /etc/nginx/sites-available/default:     # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
    /etc/nginx/sites-available/default:#    listen 8000;
    /etc/nginx/sites-available/default:#    listen somename:8080;
    /etc/nginx/sites-available/default:#    listen 443;
    /etc/nginx/sites-enabled/default:       listen 80;
    /etc/nginx/sites-enabled/default:       listen [::]:80 default_server;
    /etc/nginx/sites-enabled/default:       # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
    /etc/nginx/sites-enabled/default:#      listen 8000;
    /etc/nginx/sites-enabled/default:#      listen somename:8080;
    /etc/nginx/sites-enabled/default:#      listen 443;
    
    Third line shows Nginx is set to listen on localhost port 80, right?
     
  4. markc

    markc Member

    See if either of these makes a difference...

    /etc/nginx/sites-enabled/default:# listen [::]:80 default_server;
    /etc/nginx/sites-enabled/default: listen [::]:80 default_server ipv6_only=on;
     
  5. msp

    msp Member

    So I edited /etc/nginx/sites-enabled/default and commented-out the line

    Code:
    listen [::]:80 default_server;
    And then restarted nginx. This time it didn't return the error, but said "nginx is running."

    I'm guessing this was me telling nginx to stop listening on the IPv6 port?
     
  6. markc

    markc Member

    Maybe it needs to be this to tell this 2nd listen statement to be ipv6 only...

    listen [::]:80 default_server ipv6_only=on;

    or, just leave it commented out if you are not going to be using ipv6 at all.
     

Share This Page