AWS负载均衡器502 [英] AWS Load Balancer 502

本文介绍了AWS负载均衡器502的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在EC2实例上运行微服务(使用不同的编程语言). 在生产中,当这些服务尝试相互交互时,我注意到一些502 Bad Gateway Errors. 此外,在所请求服务的日志中,它没有显示任何api调用被击中

I have microservices(in different programming languages) running on an EC2 instance. On production I notice a few 502 Bad Gateway Errors when these services try to interact with each other. Also in the logs of the requested service it doesn't show any api call is being hit

示例服务A呼叫服务B,但是在服务B中记录没有任何迹象表明有呼叫来自服务A.

example service A calls service B, but in service B logs there is nothing to indicate that a call came from service A.

这可能是AWS负载平衡器问题吗?任何帮助,将不胜感激.预先感谢.

Can it be AWS load balancer issue? Any help would be appreciated. Thanks in advance.

解决方案尝试: 我们尝试在每种服务中制作http/https连接代理,但仍然遇到此问题.

Solution tried: We tried making http/https connection agents in each service but still we get this issue.

更新: 在lb日志中,会记录api,但是目标响应代码显示为-",而lb响应代码显示502或504.这是否意味着lb无法处理流量或我的应用程序?

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?

还有什么可能的解决方案?

Also what can be the possible solution?

推荐答案

我们遇到了同样的问题.

We had the same problem.

在我们的设置中,AWS Application ELB具有4个EC2实例的目标组.在每个EC2实例上,都有一个Apache2,可以转发到Tomcat.

In our setup, an AWS Application ELB has a target group of 4 EC2 instances. On each of the EC2 instances, there is an Apache2 which forwards to a Tomcat.

ELB的默认连接KeepAlive为60秒. Apache2的默认连接KeepAlive为5秒.如果5秒结束,Apache2将关闭其连接并重置与ELB的连接.但是,如果请求恰好在正确的时间到达,则ELB将接受该请求,决定将请求转发到哪个主机,并且在那一刻,Apache将关闭连接.这将导致出现502错误代码.

The ELB has a default connection KeepAlive of 60 seconds. Apache2 has a default connection KeepAlive of 5 seconds. If the 5 seconds are over, the Apache2 closes its connection and resets the connection with the 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. This will result in said 502 error code.

解决方案是:当代理/LB级联时,要么调整它们的KeepAlive超时时间,要么-最好-使其更长一点,甚至更长一些.

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.

我们将ELB超时设置为60秒,将Apache2超时设置为120秒.问题消失了.

We set the ELB timeout to 60 seconds and the Apache2 timeout to 120 seconds. Problem gone.

这篇关于AWS负载均衡器502的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆