如果从同一实例转发,则 Amazon Web Services 负载均衡器转发到侦听器不起作用

Amazon Web Services load balancer forwarding to listener does not work if forwarding from the same instance

我在 Amazon Web Services 中设置了以下情况:AWS setup。

来自 Internet 的请求通过端口 443 进入负载均衡器,侦听器确保此流量被转发到端口 8080 上的实例(到应用程序 A)。 负载均衡器上的另一个侦听器将流量从端口 8041 转发到实例上的端口 8050(到应用程序 B)。 应用程序 A 可能会在端口 8041 上对负载均衡器执行 REST 调用,最终会到达应用程序 B。

入站规则设置 sg-1 图上的安全组:

入站规则设置sg-2 图上的安全组:

不幸的是,应用程序 A 无法通过端口 8041 上的负载均衡器访问应用程序 B。 但是,一旦我允许来自所有来源(而不是特定安全组)的上述端口上的入站连接,应用程序突然可以在端口 8041 上对应用程序 B 进行 REST 调用。

我怀疑这可能与 sg-1 中的实例通过负载平衡器再次进入 sg-1 有关。 应用程序 B 被负载均衡器报告 "healthy",因此连接到端口 8041 上的负载均衡器或转发到实例的端口 8050 似乎有问题。

我已经尝试通过其内部 DNS 名称直接调用应用程序 B,而不是通过应用程序 A 中的负载平衡器调用应用程序 B。这可行。

我没主意了。我的配置似乎没问题,但还是打不通。任何帮助将不胜感激。

When you specify a security group as the source for a rule, this allows instances associated with the source security group to access instances in the security group. (...) Incoming traffic is allowed based on the private IP addresses of the instances that are associated with the source security group (and not the public IP or Elastic IP addresses).

当您的应用程序 A 连接到(外部)负载均衡器时,它将连接到 LB public IP,以应用程序 A public IP 作为源地址,因此 sg-1 ID 不能'不得在 sg-2 规则中使用。我在这里看到 2 个选项:

  1. 创建另一个 Internal Load Balancer,并使用它从应用 A 访问应用 B(LB 名称将解析为私有 IP,安全组 ID 可用于规则)
  2. 不要在 sg-2 规则中使用 appA 安全组 ID,而是使用 appA public IP 地址(如果您希望 appA public IP 地址发生任何变化,这可能不是最佳选择)