Amazon web services 运行状况检查失败,代码为:[502]

Amazon web services 运行状况检查失败,代码为:[502],amazon-web-services,amazon-ec2,aws-application-load-balancer,Amazon Web Services,Amazon Ec2,Aws Application Load Balancer,我想说的是,我不是一个经验丰富的技术人员,但我一直试图通过在线课程学习AWS,我被困在一个特定的点上: 我已经创建了两个目标组,每个目标组由两个EC2Linux实例组成,每个实例都有一些简单的代码作为用户数据的一部分 #/bin/bash yum update -y yum install httpd -y systemctl start httpd systemctl enable httpd cd /var/www/html echo "This is an INSTANCE" > i

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

我已经创建了两个目标组,每个目标组由两个EC2Linux实例组成,每个实例都有一些简单的代码作为用户数据的一部分

#/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]”。我已经尝试了我能想到的一切,我甚至试着做了一些研究,但没有弄明白

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


有人有什么想法吗?

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

如果没有
#,则它将不会作为脚本执行

调试负载平衡器时,一个好的过程是:

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

另外,请注意,
systemctl
amazonlinux2上正常工作,但不能在“amazonlinux2”(v1)上正常工作。

HTTP 502错误的标题是
坏网关

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

还提到了其他可能的原因:


(*)额外资源-

实例的SGs如何?他们允许ALB的安全小组进入吗?非常感谢你,约翰!成功了!很难相信一个“!”就有这么大的不同。谢谢你的提示。就像我说的,我不是一个程序员,我感谢你的友好和耐心的回应。是的!非常感谢。真不敢相信我错过了这个。我的协议是HTTP,但我的目标组协议是HTTPS。将我的协议更新为HTTP解决了这个问题。非常感谢。
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.