AWS:安全组允许从私有实例访问面向互联网的负载均衡器

AWS: Security Group to allow access internet-facing Load balancer to be accessed from private instances

我的问题是 this 的扩展版本。

在我的例子中,安全组必须限制对 Load Balancer 1 的访问。它必须有一些列入白名单的 IP。那么,我可以将哪些 IP 放在这里以允许从 Auto Scaling Group 2 私有实例访问 Load Balancer 1?

我试过将NAT网关的弹性IP设置为白名单IP,成功了。我想了解为什么绝对有必要将此 IP 放在安全组中以从 相同 VPC.

的私有子网实例访问面向 Internet 的 ALB

I have tried putting the Elastic IP of NAT Gateway as a whitelisted IP and it works. I want to understand why it is absolutely necessary to put this IP in Security Group to access the internet-facing ALB from the private subnet instance of the same VPC.

因为私有子网中的实例查找 public 负载均衡器的 DNS,将其解析为其 public 互联网 IP,然后尝试连接到该 IP,该 IP 被路由通过 NAT 网关。

据我所知,没有办法让 public 弹性负载均衡器也可以解析为 VPC 内的私有 IP。因此,您必须通过 NAT 网关才能从您的私有 IP 访问 public 负载均衡器。

另一种设置是创建第三个私有负载均衡器,它也指向 Auto-Scale 组 #1 中的实例,并让您的私有子网实例与该负载均衡器通信。

如果您采用第三种负载均衡器方法,您将创建一个新的目标组,将该组分配给您现有的 auto-scaling 组,并将新的负载均衡器指向新的目标组。关键是一个目标组只能由一个应用程序负载均衡器使用,但实例可以属于多个目标组并且auto-scaling组可以有多个目标组。