nginx - nginx: [emerg] bind() to [::]:80 failed (98: Address already in use)

前端 未结 18 1316
醉酒成梦
醉酒成梦 2020-11-28 17:36

All of a sudden I am getting the below nginx error

 * Restarting nginx
 * Stopping nginx nginx
   ...done.
 * Starting nginx nginx
nginx: [emerg] bind() to [         


        
相关标签:
18条回答
  • 2020-11-28 18:05

    I met similar problem. the log is like below

    2018/10/31 12:54:20 [emerg] 128005#128005: bind() to 0.0.0.0:80 failed (98: Address already in use)
    2018/10/31 12:54:20 [emerg] 128005#128005: bind() to 0.0.0.0:443 failed (98: Address already in use)
    2018/10/31 12:54:20 [emerg] 128005#128005: bind() to [::]:80 failed (98: Address already in use)
    2018/10/31 12:54:20 [emerg] 128005#128005: bind() to 0.0.0.0:80 failed (98: Address already in use)
    2018/10/31 12:54:20 [emerg] 128005#128005: bind() to 0.0.0.0:443 failed (98: Address already in use)
    2018/10/31 12:54:20 [emerg] 128005#128005: bind() to [::]:80 failed (98: Address already in use)
    2018/10/31 12:54:20 [emerg] 128005#128005: bind() to 0.0.0.0:80 failed (98: Address already in use)
    2018/10/31 12:54:20 [emerg] 128005#128005: bind() to 0.0.0.0:443 failed (98: Address already in use)
    2018/10/31 12:54:20 [emerg] 128005#128005: bind() to [::]:80 failed (98: Address already in use)
    2018/10/31 12:54:20 [emerg] 128005#128005: bind() to 0.0.0.0:80 failed (98: Address already in use)
    2018/10/31 12:54:20 [emerg] 128005#128005: bind() to 0.0.0.0:443 failed (98: Address already in use)
    2018/10/31 12:54:20 [emerg] 128005#128005: bind() to [::]:80 failed (98: Address already in use)
    2018/10/31 12:54:20 [emerg] 128005#128005: bind() to 0.0.0.0:80 failed (98: Address already in use)
    2018/10/31 12:54:20 [emerg] 128005#128005: bind() to 0.0.0.0:443 failed (98: Address already in use)
    2018/10/31 12:54:20 [emerg] 128005#128005: bind() to [::]:80 failed (98: Address already in use)
    2018/10/31 12:54:20 [emerg] 128005#128005: still could not bind()
    2018/10/31 12:54:23 [alert] 127997#127997: unlink() "/run/nginx.pid" failed (2: No such file or directory)
    2018/10/31 22:40:48 [info] 36948#36948: Using 32768KiB of shared memory for push module in /etc/nginx/nginx.conf:68
    2018/10/31 22:50:40 [emerg] 37638#37638: duplicate listen options for [::]:80 in /etc/nginx/sites-enabled/default:18
    2018/10/31 22:51:33 [info] 37787#37787: Using 32768KiB of shared memory for push module in /etc/nginx/nginx.conf:68
    

    The last [emerg] shows that duplicate listen options for [::]:80 which means that there are more than one nginx block file containing [::]:80.

    My solution is to remove one of the [::]:80 setting

    P.S. you probably have default block file. My advice is to keep this file as default server for port 80. and remove [::]:80 from other block files

    0 讨论(0)
  • 2020-11-28 18:05

    I had several *.save files (emergency dumps from nano) from different NGINX config files in my sites-avilable dir. Once I deleted these .save files, NGINX restarted fine. I assumed these were harmless since there were no corresponding symlinks, but I guess I was wrong.

    0 讨论(0)
  • 2020-11-28 18:06

    My case is different, I had to kill running Nginx to restart it.

    Instead of

    sudo systemctl restart nginx
    

    I had to use:

    sudo pkill -f nginx & wait $!
    sudo systemctl start nginx
    
    0 讨论(0)
  • 2020-11-28 18:08

    i fixed this by running sudo apachectl stop - turns out apache was running in the background and prevented nginx from starting on the desired port.

    On ubuntu run sudo /etc/init.d/apache2 stop

    0 讨论(0)
  • 2020-11-28 18:08

    If problem persists after trying any of the above solutions, Restart your server once. It worked for me :)

    0 讨论(0)
  • 2020-11-28 18:09

    My issue was that I had overlapping listen directives. I have managed to figure out overlapping directives by running

    grep -r listen /etc/nginx/*
    

    Two files were listening at the same port:

    /etc/nginx/conf.d/default.conf:           listen 80;  
    /etc/nginx/sites-enabled/default.conf:    listen 80;
    
    0 讨论(0)
提交回复
热议问题