关于nginx-启动报错nginx: [emerg] socket() [::]:80 failed (97: Address family not supported by protocol)
Posted on 2023-02-07 18:51 520_1351 阅读(1894) 评论(0) 编辑 收藏 举报今天在一台服务器上使用yum安装了nginx,然后启动报错:nginx: [emerg] socket() [::]:80 failed (97: Address family not supported by protocol)
先说一下环境,
OS Release :Red Hat Enterprise Linux release 8.1 (Ootpa)
nginx version: nginx/1.14.1
[使用nginx -v可以看到版本,大写的V除了版本,还可以看到configure options]
安装完成后,启动报错,再进一步看报错详情,如下:
[root@QQ-5201351 ~]# systemctl restart nginx Job for nginx.service failed because the control process exited with error code. See "systemctl status nginx.service" and "journalctl -xe" for details. [root@QQ-5201351 ~]# systemctl status nginx ● nginx.service - The nginx HTTP and reverse proxy server Loaded: loaded (/usr/lib/systemd/system/nginx.service; disabled; vendor preset: disabled) Active: failed (Result: exit-code) since Tue 2023-02-07 18:37:22 CST; 7s ago Process: 2482 ExecStartPre=/usr/sbin/nginx -t (code=exited, status=1/FAILURE) Process: 2480 ExecStartPre=/usr/bin/rm -f /run/nginx.pid (code=exited, status=0/SUCCESS) Feb 07 18:37:22 QQ-5201351 systemd[1]: Starting The nginx HTTP and reverse proxy server... Feb 07 18:37:22 QQ-5201351 nginx[2482]: nginx: the configuration file /etc/nginx/nginx.conf syntax is ok Feb 07 18:37:22 QQ-5201351 nginx[2482]: nginx: [emerg] socket() [::]:80 failed (97: Address family not supported by protocol) Feb 07 18:37:22 QQ-5201351 nginx[2482]: nginx: configuration file /etc/nginx/nginx.conf test failed Feb 07 18:37:22 QQ-5201351 systemd[1]: nginx.service: Control process exited, code=exited status=1 Feb 07 18:37:22 QQ-5201351 systemd[1]: nginx.service: Failed with result 'exit-code'. Feb 07 18:37:22 QQ-5201351 systemd[1]: Failed to start The nginx HTTP and reverse proxy server. [root@QQ-5201351 ~]#
其实也可以通过 nginx -t 检查配置文件,会显示配置文件错误
[root@QQ-5201351 ~]# nginx -t nginx: the configuration file /etc/nginx/nginx.conf syntax is ok nginx: [emerg] socket() [::]:80 failed (97: Address family not supported by protocol) nginx: configuration file /etc/nginx/nginx.conf test failed
通过报错,可以看出,实际是提示系统不支持ipv6,因为公司本身也没有用到ipv6,因此可以直接将配置文件的ipv6监听部分注释掉即可
解决方法>>>>>>>>:
1、编辑/etc/nginx/nginx.conf 配置文件,找到如下部分
server { listen 80 default_server; listen [::]:80 default_server;
2、注释掉ipv6监听的那一行就可以了,最后如下
server { listen 80 default_server; #listen [::]:80 default_server;
这时再通过nginx -t 或者 直接启动nginx,就不会有报错了~
另外,还有一种方法,那就是让OS开启对ipv6的支持,可以参考笔者的另一篇文章
尊重别人的劳动成果 转载请务必注明出处:https://www.cnblogs.com/5201351/p/17099497.html
作者:一名卑微的IT民工
出处:https://www.cnblogs.com/5201351
本博客所有文章仅用于学习、研究和交流目的,欢迎非商业性质转载。
由于博主的水平不高,文章没有高度、深度和广度,只是凑字数,不足和错误之处在所难免,希望大家能够批评指出。
博主是利用读书、参考、引用、复制和粘贴等多种方式打造成自己的文章,请原谅博主成为一个卑微的IT民工!