无法从 EC2 实例连接到负载均衡器

Unable to connect to a load balancer from an EC2 instance

我希望自动扩展组中的 EC2 实例能够连接到背后有 RabbitMQ 服务器的经典负载均衡器。

这是我的配置:

EC2 的安全组:

my-private-sg (sg-00xxxxxxxxxxxxxxx)

经典负载均衡器的安全组:

rabbitmq-elb-sg (sg-11xxxxxxxxxxxxxxx)

rabbitmq-elb-sg 安全组包含以下入站规则

在此配置下,EC2 中的 RabbitMQ 客户端无法连接到负载均衡器。

但是,我将源设置为AnyWhere后,它可以连接到负载均衡器。

为什么会这样?

document 表示

Another security group. This allows instances associated with the specified security group to access instances associated with this security group. 

EC2、负载均衡器和负载均衡器后面的EC2在同一个VPC中。

我使用经典的负载均衡器,因为我使用这个 terraform script 来构建 RabbitMQ 服务。

我刚刚查看了经典负载均衡器中的日志,我看到了如下内容:

2019-10-16T03:45:09.124234Z rabbitmq-elb 54.178.178.85:45990 172.31.39.217:5672 0.000274 0.000008 0.000015 - - 516 604 "- - - " "-" - -
2019-10-16T03:45:10.340119Z rabbitmq-elb 54.178.178.85:46006 172.31.0.79:5672 0.001159 0.000008 0.000015 - - 516 604 "- - - " "-" - -

54.178.178.85 是我的 EC2 实例的 public IP。

172.31.39.217172.31.0.79 是负载均衡器后面的 RabbitMQ 服务器的私有 IP。

我的经典负载均衡器是 internet-facing 负载均衡器。我改成internal后,安全组rabbitmq-elb-sg (sg-11xxxxxxxxxxxxxxx)就没有问题了。

我不必再在 Source 字段中写 AnyWhere

EC2 实例尝试通过专用网络连接到负载均衡器。将 EC2 的安全组(sg-00xxxxxxxxxxxxxxx)添加到 rabbitmq-elb-sg(sg-11xxxxxxxxxxxxxxx)的源字段仅在私有网络下有效。

但是,我仍然不确定为什么使用面向 Internet 的负载平衡器在我的情况下不起作用。

AWS Documentation哪里可以找到对这种现象的解释?