fedora26中解决nginx: [emerg] bind() to [::]:80 failed (98: Address already in use)

我在fedora26中启动nginx服务时遇到过以上问题

nginx: [warn] could not build optimal types_hash, you should increase either types_hash_max_size: 2048 or types_hash_bucket_size: 64; ignoring types_hash_bucket_size
nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
nginx: [emerg] bind() to [::]: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 [::]: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 [::]: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 [::]: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 [::]:80 failed (98: Address already in use)
nginx: [emerg] still could not bind()


然后使用netstat -lntp | grep 80查看端口占用情况时发现

tcp        0      0 0.0.0.0:80              0.0.0.0:*               LISTEN      3433/nginx: master  
tcp6       0      0 :::80                   :::*                    LISTEN      3433/nginx: master

原来是nginx先监听了ipv4的80端口之后又监听了ipv6的80端口,于是就重复占用了。于是杀死nginx进程

killall -9 nginx

然后重启nginx就可以了。

但是,发现每次启动均有如下的步骤,为了不必要的麻烦,我们可以修改nginx配置文件

vim /etc/nginx/nginx.conf

listen 80; 

listen [::]:80 default_server;

改为

listen 80; 

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

重启即可。

你可能感兴趣的:(日常收获)