如何排查请求 CLB 服务报错 ERR_TOO_MANY_REDIREC问题

网络云上网络技术服务知识库
问题描述

请求负载均衡 CLB 报错: xxx.xx.com 将您重定向的次数过多 ERR_TOO_MANY_REDIRECTS

排查过程
  1. 使用 curl 命令或者打开浏览器 F12 查看返回状态码以及 header,以 curl 命令为例。
xxx@xxx ~ % curl -voa  https://访问域名或IP地址/
# 可以使用 -k 跳过 https 证书验证  


  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
  0     0    0     0    0     0      0      0 --:--:-- --:--:-- --:--:--     0*   Trying xxx.xxx.67.36...
* TCP_NODELAY set
* Connected to xxxx port 80 (#0)
> GET / HTTP/1.1
> Host: xxxx
> User-Agent: curl/7.64.1
> Accept: */*
> 
< HTTP/1.1 302 Moved Temporarily
< Server: nginx
< Date: Thu, 24 Mar 2022 10:41:43 GMT
< Content-Type: text/html
< Content-Length: 145
< Connection: keep-alive
< Location: http://xxxx/
< Vary: Accept-Encoding
< 
{ [145 bytes data]
100   145  100   145    0     0   5370      0 --:--:-- --:--:-- --:--:--  5370
* Connection #0 to host xxxx left intact
* Closing connection 0
  1. 查看返回的 302 状态码和 Location ,这里如果使用 http/https 监听器可以选择开启访问日志功能,根据 status 和 upstream_status 两个字段来判断 302 状态码的返回位置。
[http] [xxx +08:00] [xxx] [51728] [GET /xxx HTTP/1.1] [Mozilla/5.0 zgrab/0.x] [xxx] [-] [116] [-] [-] [xxx] [5370585125] [1] [192.168.1.171] [xxx] [xxx] [80] [146.493] [302] [363] [0.001] [-] [xm] [xxx:80] [0.000] [0.000] [0.000] [302]
  1. 在日志中最后一个字段为 upstream_status,可以判断该状态为后端服务返回。
  2. 登录后端服务器检查,找到 nginx.conf 配置查看是否有rewrite 配置。下面是 Nginx 配置文件,在 server 模块中看到空 server_name 会命中 rewrite 规则,return 302 http://hosthosturi;
    server {
        listen       80;
        listen       [::]:80;
        server_name  _;
        root         /usr/share/nginx/html;
        if ($http_x_forwarded_proto = 'http')
        {
                return 302 http://$host$uri;
          }
        # Load configuration files for the default server block.
        include /etc/nginx/default.d/*.conf;

        error_page 404 /404.html;
        location = /404.html {
        }

        error_page 500 502 503 504 /50x.html;
        location = /50x.html {
        }
    }
    server {
        listen       80;
        listen       [::]:80;
        server_name  www.a.com;
        root         /usr/share/nginx/html;
        # Load configuration files for the default server block.
        include /etc/nginx/default.d/*.conf;

        error_page 404 /404.html;
        location = /404.html {
        }

        error_page 500 502 503 504 /50x.html;
        location = /50x.html {
        }
    }
  1. 如上配置会导致请求到达服务后,被重定向回请求的域名和 URI, 则会出现无限循环导致浏览器报错ERR_TOO_MANY_REDIRECTS
解决方案
  1. 查看业务是否需要配置对应的 rewrite 规则,如不需要则删除相关配置 。
  2. 检查业务请求域名是否正确,如示例中 server_name www.a.com,请根据业务域名配置对应 server_name 。

如果您有其他问题,欢迎您联系火山引擎技术支持服务

261
0
0
0
相关产品
评论
未登录
看完啦,登录分享一下感受吧~
暂无评论