博客园  :: 首页  :: 管理

今天在一台服务器上使用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的支持,可以参考笔者的另一篇文章

<<关于Linux从内核启动选项中开启对ipv6的支持>> 

 

尊重别人的劳动成果 转载请务必注明出处:https://www.cnblogs.com/5201351/p/17099497.html