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

标签 amazon-web-services amazon-ec2 tcp load-balancing

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

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

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

  • 443/tcp 来自 0.0.0.0/0(互联网连接)
  • 来自 sg-2 的 8041/tcp(来自应用程序 A 的连接)

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

  • 22/tcp 来自 0.0.0.0/0 (SSH)
  • 来自 sg-1 的 8050/tcp(连接到应用程序 B)
  • 来自 sg-1 的 8080/tcp(连接到应用程序 A)

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

我怀疑这可能与 sg-1 中的实例通过负载平衡器再次进入 sg-1 有关。 应用程序 B 被负载均衡器报告为“健康”,因此连接到端口 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 名称将解析为私有(private) IP,并且安全组 ID 可以在规则中使用)
  2. 不要在 sg-2 规则中使用 appA 安全组 ID,而是使用 appA 公共(public) IP 地址(如果您希望 appA 公共(public) IP 地址发生任何变化,这可能不是最佳选择)

关于amazon-web-services - 如果从同一实例转发,则 Amazon Web Services 负载均衡器转发到监听器不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45331059/

相关文章:

amazon-ec2 - AWS 上的 NVMe 究竟是什么?

gradle - Gitlab CI Runner卡住,ssh没有响应

linux - 在 linux 内核 3.13 中找不到 tcp_autocorking 和 tcp_abc 文件

amazon-web-services - 如何从AWS Lambda函数获取返回响应

linux - 将文件从 Amazon S3 同步到本地

amazon-web-services - ASP.NETCore Signalr 在 AWS 上不起作用

http - 将 HTTP 请求映射到 HTTP 响应

amazon-web-services - AWS API Gateway 不能有多个路径?

php - Nginx - 无法打开流 : Permission denied in/var/www/example. com

c# - 如何使TCP套接字保持事件状态并检测断开连接?