我已经构建了以下基础架构,以便与AWS Fargate一起使用 .

ECS管理私有子网中的容器,流量通过公共子网通过面向Internet的ALB路由到它们 .

通过NAT网关控制对私有子网中容器的Internet访问 .

我创建了一个git repo来演示手头的问题
https://github.com/GreenyMcDuff/aws-fargate-public

Warning: It will cost you money to run this

需要Terraform v0.11.7或更高版本

enter image description here

以下是安全组规则:

alb-sg

+----------------+----------+------+------------+
| Ingress/Egress | Protocol | Port |   Source   |
+----------------+----------+------+------------+
| Ingress        | TCP      | 80   | 0.0.0.0/0  |
| Egress         | All      | All  | 0.0.0.0/0  |
+----------------+----------+------+------------+

ecs-tasks-sg

+----------------+----------+---------+-----------+
| Ingress/Egress | Protocol |  Port   |  Source   |
+----------------+----------+---------+-----------+
| Ingress        | TCP      | 80      | 0.0.0.0/0 |
| Ingress        | TCP      | 1-65535 | alb-sg-id |
| Egress         | All      | All     | 0.0.0.0/0 |
+----------------+----------+---------+-----------+

这是路线表

public route table

+-------------+--------+
| Destination | Target |
+-------------+--------+
| 10.0.0.0/16 | local  |
| 0.0.0.0/0   | igw-id |
+-------------+--------+

private route table

+-------------+--------+
| Destination | Target |
+-------------+--------+
| 10.0.0.0/16 | local  |
| 0.0.0.0/0   | nat-id |
+-------------+--------+

所以几乎所有东西似乎都在起作用 . 我正在发布的容器是docker hub的 httpd:2.4 图像 .

  • 图像已成功下载

  • 容器启动并进入 RUNNING 状态 .

  • elb Health 检查通过

  • 我've launched a windows EC2 instance in my public subnet, RDP' d,并在Internet Explorer中浏览容器ip并按预期获取页面

我正在假设这是一个路由或安全组问题,因为上述几点 .

问题是,当我尝试浏览网站,在容器上运行时,通过点击应用程序负载均衡器DNS名称( xxxx.AWS_REGION.elb.amazonaws.com ),我得到一个"This site can't be reached"错误 .

关于为什么会发生这种情况的任何解释都将受到极大的欢迎 .

如果有任何更多信息有用,请告诉我,我会尽力提供 .