我的负载均衡器为什么会响应“坏网关”?

huangapple go评论39阅读模式
英文:

Why is my load balancer responding with bad gateway?

问题

我在EC2机器上没有运行任何Web服务器,但我仍然从位于其前面的负载均衡器收到502坏网关错误消息。
为什么在EC2机器前没有负载均衡器时会出现网关错误,而没有网关错误,而只是超时。

英文:

I don't have any web server running on my EC2 machine, but I still get a 502 bad gateway message from the load balancer in front of it.

Why do I get bad gateway error from the load balancer, but no bad gateway error, when there is no load balancer in front of the EC2 machine, but just a time out.

答案1

得分: 1

负载均衡器定期对其目标机器进行健康检查,即发送HTTP或TCP请求(根据您的配置)。这样它就知道其目标池中哪些机器是健康的,可以处理请求,哪些不能。毕竟,它的目标是在多台机器之间平衡负载

当您的EC2机器没有运行的Web服务器时,其健康检查失败,负载均衡器将视其为不可用。因为显然在池中没有其他健康的机器,负载均衡器无法将任何请求转发到任何地方,因此会返回502 Bad Gateway状态。

与直接访问您的EC2机器时只是超时不同,负载均衡器的情况下仍然有东西可以接受和处理HTTP请求,并返回适当的HTTP错误代码。当您根本没有Web服务器时,连接无法被任何东西接受,因此只能超时。

英文:

The load balancer regularly does health checks on its target machines, i.e. it sends an HTTP or TCP request (as you have configured it). This way it knows what machines in its target pool are healthy and can take requests and which can't. It's supposed to balance the load between multiple machines after all.

When your EC2 machine does not have a running web server, its health check fails and it's seen as unavailable by the load balancer. Since apparently there's no other healthy machine in the pool, the load balancer cannot forward any requests to anything, and thus answers with a 502 Bad Gateway status.

The difference to just timing out when you try to access your EC2 machine directly is that in the case of a load balancer, there's still something that can accept and handle HTTP requests and return appropriate HTTP error codes. When you simply have no web server whatsoever, the connection cannot be accepted by anything and thus can only time out.

huangapple
  • 本文由 发表于 2023年2月8日 22:31:54
  • 转载请务必保留本文链接:https://go.coder-hub.com/75387274.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定