健康检查失败,代码为:[502]



我想说的是,我不是一个经验丰富的技术人员,但我一直试图通过在线课程学习AWS,但我被困在了一个特定的点上:

我创建了两个目标组,每个目标组由两个EC2-linux实例组成,并将一些简单的代码作为每个实例的用户数据的一部分。

#/bin/bash
yum update -y
yum install httpd -y
systemctl start httpd
systemctl enable httpd
cd /var/www/html
echo "This is an INSTANCE" > index.html

然后,我创建了一个带有HTTP侦听器(端口80(的应用程序负载均衡器。ALB与使用绝对具有公共访问权限的安全组的子网相关联(我在其他具有公共访问权的演习中使用了相同的安全组(

但每次,两个目标组都会显示">
健康检查失败,代码为:[502]"的描述。我已经试过了我能想到的一切,我甚至试过做一些研究,但都想不通。

在任何人生气之前,我以前没有使用过Stack溢出,所以如果这是一个重复的线程,我很抱歉,但在我看到的其他线程中,还有其他更复杂的情况。

有人有什么想法吗?

HTTP 502错误的标题是Bad gateway

我遇到了同样的错误,这是因为健康检查是通过不同的协议(HTTP(和目标组协议(HTTPS(配置的。

这里提到了其他可能的原因:

HTTP 502: Bad gateway
Possible causes:
- The load balancer received a TCP RST from the target when attempting to establish a connection.
- The load balancer received an unexpected response from the target, such as "ICMP Destination unreachable (Host unreachable)", when attempting to establish a connection. Check whether traffic is allowed from the load balancer subnets to the targets on the target port.
- The target closed the connection with a TCP RST or a TCP FIN while the load balancer had an outstanding request to the target. Check whether the keep-alive duration of the target is shorter than the idle timeout value of the load balancer.
- The target response is malformed or contains HTTP headers that are not valid.
- The load balancer encountered an SSL handshake error or SSL handshake timeout (10 seconds) when connecting to a target.
- The deregistration delay period elapsed for a request being handled by a target that was deregistered. Increase the delay period so that lengthy operations can complete.
- The target is a Lambda function and the response body exceeds 1 MB.
- The target is a Lambda function that did not respond before its configured timeout was reached.

(*(其他资源-如何排除和修复应用程序负载平衡器运行状况检查失败的问题?

您的脚本从未运行过,因为用户数据需要以#!开头,但您的脚本仅以#开头。

如果没有#!,那么它将不会作为脚本执行。

当调试负载均衡器的情况时,一个好的过程是:

  • 尝试直接访问实例,以确认它们作为web服务器进行响应。如果没有,请登录到实例并检查/var/log/cloud-init-output.log,查看用户数据是否生成了任何错误
  • 检查安全组以确认它们配置正确,通常为:
    • 负载均衡器(ELB-SG(上的一个安全组,允许来自Internet的入站web流量
    • AmazonEC2实例(App-SG(上的安全组,允许来自ELB-SG的入站web流量。即App-SG具体引用ELB-SG

此外,请注意systemctlAmazon Linux 2上正常工作,但在"Amazon Linux"(v1(上则不然。

最新更新