我第一次进入 AWS 时遇到了一个尝试设置负载均衡器 (ELB) 的问题。
到目前为止,我已经使用 ECS 创建了 2 个 EC2 实例,它们运行一个容器,每个实例都有一个监听端口 3000 的应用程序。
对于每个实例,我都可以浏览到指定端口 3000 的 IPv4 公共(public) IP 并访问容器化应用程序。我能够按预期登录并使用该应用程序。
所以我认为接下来要做的正确的事情是设置一个 ELB,它不仅可以平衡负载(!)而且还可以处理端口转发。
ELB 有一个 80 端口的监听器,我有一个目标组,我在 3000 端口上注册了我的 ECS 实例。
然后,我将 ELB 的 DNS 名称(即 my-load-balancer-123456789.eu-west-1.elb.amazonaws.com
)弹出到我的浏览器中,并显示了我的应用程序的登录页面。
一切都很好,直到我真正登录。然后我会看到错误消息:
ERR_TOO_MANY_REDIRECTS: my-load-balancer-123456789.eu-west-1.elb.amazonaws.com redirected you too many times.
我有 2 个问题
1:为什么会发生重定向循环?
2:我应该知道哪些诊断工具可以帮助我将来解决此类问题?
更新:顺便说一句,我已尝试清除所有浏览器 cookie。
任何帮助表示赞赏。
最佳答案
当您有由服务器本身完成的重定向时,这个问题很常见。 AWS 有一个 guide关于如何预防这些问题。
The following leads to an infinite loop of redirection between the load balancer and the backend web server:
- The rewrite rule on the web server for directing HTTP requests to HTTPS forces requests to use port 443 for HTTPS traffic on the load balancer.
- The load balancer still sends requests to the backend web server on port 80.
- The backend web server redirects requests to port 443 on the load balancer.
The error ERR_TOO_MANY_REDIRECTS is returned, and the requests are never served.
To resolve this, change your web server’s rewrite rule using the X-Forwarded-Proto header of the HTTP request to apply only if the client protocol is HTTP. Ignore the rewrite rule for all other protocols used by the client.
Note: If you're using Application Load Balancers, use redirect actions to redirect traffic instead.
关于amazon-web-services - AWS 负载均衡器 ERR_TOO_MANY_REDIRECTS,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42715718/