简体   繁体   English

AWS - 目标组负载均衡器

[英]AWS - Target Group Load Balancer

I have a load balancer and an Nginx that sits behind the LB.我有一个负载均衡器和一个位于 LB 后面的 Nginx。

Below is the nginx config.下面是 nginx 配置。

upstream app {
    server service_discovery_name.local:5005;
}

server {   // Reverse proxy for VPC ES to be available on public

    listen 80;

    location / {
        proxy_pass vpc-es-domain-url;
        proxy_redirect off;
        proxy_set_header Host $host;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    }
}

server {  // reverse proxy for django app

    listen 8005;

    location / {
        proxy_pass http://app;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header Host $host;
        proxy_redirect off;
    }
}

I've a listener attached to the ALB, listening at port 80 , that forwards the traffic to the target IP.我有一个连接到 ALB 的侦听器,在端口80上侦听,它将流量转发到目标 IP。 The target group has the private IP of the Nginx container.目标组拥有 Nginx 容器的私有 IP。 I use Fargate-ECS container.我使用 Fargate-ECS 容器。

Now when I route to ALB_url:80 , it opens up the elasticsearch.现在,当我路由到ALB_url:80时,它会打开 elasticsearch。 However, when I route to ALB_url:8005 , it fails to load anything.但是,当我路由到ALB_url:8005时,它无法加载任何内容。 The django_app is running at port 5005 , check by explicitly browsing to the IP=:5005. django_app 在端口5005上运行,通过显式浏览到 IP=:5005 进行检查。

I believe the nginx config is right.我相信 nginx 配置是正确的。 I want my traffic to be routed via ALB -> Nginx -> apps .我希望我的流量通过ALB -> Nginx -> apps路由。 What exactly am I missing?我到底错过了什么?

When you configure an ALB you must create a listener, specify the port and the action(forward the request to Target Group or make redirects), you can create a multiples listener using different ports, for example, you can have a listener listening in 80 port and doing redirects to HTTPs and another listener with 443 port forwarding the request to Target Group.配置 ALB 时必须创建侦听器,指定端口和操作(将请求转发到目标组或进行重定向),您可以使用不同的端口创建多个侦听器,例如,您可以让侦听器在 80 中侦听端口并重定向到 HTTPs 和另一个具有 443 端口的侦听器将请求转发到目标组。

According to that, I understand that your configuration is: - ALB listening in 80 port and sending the request to Target Group.据此,我了解您的配置是: - ALB 监听 80 端口并将请求发送到目标组。 - Target Group listening in 80 port and sending the request to Fargate Task(nginx server) - 目标组监听 80 端口并将请求发送到 Fargate 任务(nginx 服务器)

When you route to ALB_URL:80 the request is forwarded to Target Group by 80 port and the request is sending to Fargate task.当您路由到 ALB_URL:80 时,请求通过 80 端口转发到目标组,并且请求正在发送到 Fargate 任务。 But when you route to ALB_URL:8005 that will no work because the ALB doesn't have a listener for that port.但是,当您路由到 ALB_URL:8005 时,这将不起作用,因为 ALB 没有该端口的侦听器。

You can create a listener with 8005 port that forwards the request to a Target Group listening in the 8005. with this configuration when you route ALB_url:8005 the request will be sent to TG created and then will send to the Fargate task and will take the configuration into the Nginx config.您可以使用 8005 端口创建一个侦听器,将请求转发到在 8005 中侦听的目标组。使用此配置,当您路由 ALB_url:8005 时,请求将被发送到创建的 TG,然后将发送到 Fargate 任务,并将获取配置到 Nginx 配置中。

ALB---> listener 80 ----> Target Groupt port 80 ----> ECS Task Nginx ALB---> listener 80 ----> Target Groupt port 80 ----> ECS Task Nginx

ALB---> listener 8005 ---> Target Groupt port 8005 ----> ECS Task Nginx ALB---> listener 8005 ---> Target Groupt 端口 8005 ----> ECS 任务 Nginx

Don't forget to validate the Security groups to allow 8005 port不要忘记验证安全组以允许 8005 端口

https://docs.aws.amazon.com/elasticloadbalancing/latest/application/load-balancer-target-groups.html#target-group-routing-configuration https://docs.aws.amazon.com/elasticloadbalancing/latest/application/load-balancer-target-groups.html#target-group-routing-configuration

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 多容器负载均衡器 AWS 的目标组 - target group for multiple containers load balancer AWS AWS - 将现有负载均衡器添加到目标组 - AWS - Add existing load balancer to target group AWS 中的负载均衡器、侦听器目标、目标组之间有什么区别? - what is the difference between a load balancer, listener target, target group in AWS? AWS 中的负载均衡器和目标组有什么区别? - What's the difference between a load balancer and target group in AWS? AWS 负载均衡器规则:带有到目标组的查询参数的转发路径 - AWS Load Balancer Rules: Forward path with query parameters to Target Group AWS 应用程序负载均衡器:使用 IP 地址创建目标组 - AWS Application load Balancer : Create Target group with IP address AWS Load Balancer可将流量路由到具有多个微服务的一个目标组 - AWS Load Balancer to route traffic to one target group with multiple microservices AWS App Load-Balancer 的侦听器是针对目标还是目标组? - Does the AWS App Load-Balancer's Listener address a Target or a Target Group? aws - terraform 网关负载均衡器目标 - aws - terraform Gateway load balancer target 为 alb 创建目标组(应用程序负载均衡器) - Creating a target group for a alb (application load balancer )
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM