简体   繁体   English

AWS 负载均衡器 502

[英]AWS Load Balancer 502

I have microservices(in different programming languages) running on an EC2 instance.我在 EC2 实例上运行微服务(使用不同的编程语言)。 On production I notice a few 502 Bad Gateway Errors when these services try to interact with each other.在生产中,当这些服务尝试相互交互时,我注意到一些 502 Bad Gateway Errors。 Also in the logs of the requested service it doesn't show any api call is being hit同样在请求的服务的日志中,它没有显示任何 api 调用正在被命中

example service A calls service B, but in service B logs there is nothing to indicate that a call came from service A.示例服务 A 调用服务 B,但在服务 B 日志中没有任何内容表明呼叫来自服务 A。

Can it be AWS load balancer issue?可能是 AWS 负载均衡器问题吗? Any help would be appreciated.任何帮助,将不胜感激。 Thanks in advance.提前致谢。

Solution tried: We tried making http/https connection agents in each service but still we get this issue.尝试的解决方案:我们尝试在每个服务中创建 http/https 连接代理,但仍然出现此问题。

Update: In lb logs, the api is logged, but the target response code shows "-" whereas lb response code shows 502 or 504. Does it mean that lb is not able to handle the traffic or my application?更新:在 lb 日志中,api 已记录,但目标响应代码显示“-”,而 lb 响应代码显示 502 或 504。这是否意味着 lb 无法处理流量或我的应用程序?

Also what can be the possible solution?还有可能的解决方案是什么?

We had the same problem.我们遇到了同样的问题。

In our setup, an AWS Application ELB has a target group of 4 EC2 instances.在我们的设置中,AWS 应用程序 ELB 的目标组包含 4 个 EC2 实例。 On each of the EC2 instances, there is an Apache2 which forwards to a Tomcat.在每个 EC2 实例上,都有一个转发到 Tomcat 的 Apache2。

The ELB has a default connection KeepAlive of 60 seconds. ELB 的默认连接 KeepAlive 为 60 秒。 Apache2 has a default connection KeepAlive of 5 seconds. Apache2 的默认连接 KeepAlive 为 5 秒。 If the 5 seconds are over, the Apache2 closes its connection and resets the connection with the ELB.如果 5 秒结束,Apache2 将关闭其连接并重置与 ELB 的连接。 However, if a request comes in at precisely the right time, the ELB will accept it, decide which host to forward it to, and in that moment, the Apache closes the connection.然而,如果一个请求恰好在正确的时间到来,ELB 将接受它,决定将它转发到哪个主机,并且在那一刻,Apache 关闭连接。 This will result in said 502 error code.这将导致上述 502 错误代码。

The solution is: When you have cascading proxies/LBs, either align their KeepAlive timeouts, or - preferrably - even make them a little longer the further down the line you get.解决方案是:当你有级联代理/LB 时,要么对齐它们的 KeepAlive 超时,或者 - 最好 - 甚至让它们越长越长。

We set the ELB timeout to 60 seconds and the Apache2 timeout to 120 seconds.我们将 ELB 超时设置为 60 秒,将 Apache2 超时设置为 120 秒。 Problem gone.问题没了。

Health checks use HTTP2.健康检查使用 HTTP2。 I got my EC2 instances running NGINX to healthy by adding http2 to the listen 80.通过将http2添加到 listen 80,我使运行 NGINX 的 EC2 实例运行良好。

listen 80 default_server http2;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM