nginx: [emerg] still could not bind() 错误解决方法

技术运维NginxCentOS 11927

错误提示内容为:

Jan 03 14:05:52 iZ28ujmpafrZ nginx[13470]: nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
Jan 03 14:05:52 iZ28ujmpafrZ systemd[1]: nginx.service: control process exited, code=exited status=1
Jan 03 14:05:52 iZ28ujmpafrZ nginx[13470]: nginx: [emerg] still could not bind()
Jan 03 14:05:52 iZ28ujmpafrZ systemd[1]: Failed to start The nginx HTTP and reverse proxy server.
Jan 03 14:05:52 iZ28ujmpafrZ systemd[1]: Unit nginx.service entered failed state.
Jan 03 14:05:52 iZ28ujmpafrZ systemd[1]: nginx.service failed.

上面提示80端口无法绑定,用命令 netstat -ntplnetstat -ntlp|grep 80 查看端口占用情况

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:80              0.0.0.0:*               LISTEN      13159/nginx: worker 
tcp        0      0 0.0.0.0:22              0.0.0.0:*               LISTEN      1541/sshd           
tcp        0      0 127.0.0.1:9000          0.0.0.0:*               LISTEN      11260/php-fpm: mast 
tcp6       0      0 :::80                   :::*                    LISTEN      13159/nginx: worker 

这里看到被nginx占用了,但是这时候的nginx我试了既不能停止也不能启动/重启它的服务,不得不kill掉

killall -9 nginx

这时候还要注意的是 /etc/nginx/nginx.conf 中的(笔者没有遇到这个问题,直接忽略跳到重启nginx成功解决问题):

listen [::]:80 default_server;

这句配置也会导致这个错误,我们可以注释掉或写成

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

最后成功重启nginx

systemctl restart nginx

Post Comment