gpt4 book ai didi

amazon-web-services - AWS LoadBalancer 监听多个端口

转载 作者:行者123 更新时间:2023-12-04 08:05:50 40 4
gpt4 key购买 nike

我有一些应用程序在 AWS 中作为微服务运行。其中一些在端口 80 上运行,一些在端口 3000 上运行。我希望我的 ALB 监听这两个端口上的流量。然后我有一个 ListenRules 将流量引导至微服务。我想实现如下所示的目标,

Resources:
LoadBalancer:
Type: AWS::ElasticLoadBalancingV2::LoadBalancer
Properties:
Name: !Ref EnvironmentName
Subnets: !Ref Subnets
SecurityGroups:
- !Ref SecurityGroup
Tags:
- Key: Name
Value: !Ref EnvironmentName

LoadBalancerListener:
Type: AWS::ElasticLoadBalancingV2::Listener
Properties:
LoadBalancerArn: !Ref LoadBalancer
Port: [80,3000] # something like this
Protocol: HTTP
DefaultActions:
- Type: forward
TargetGroupArn: !Ref DefaultTargetGroup

最佳答案

应该对要打开的每个端口重复监听器。例如:

Resources:
LoadBalancer:
Type: AWS::ElasticLoadBalancingV2::LoadBalancer
Properties:
Name: !Ref EnvironmentName
Subnets: !Ref Subnets
SecurityGroups:
- !Ref SecurityGroup
Tags:
- Key: Name
Value: !Ref EnvironmentName

LoadBalancerListenerA:
Type: AWS::ElasticLoadBalancingV2::Listener
Properties:
LoadBalancerArn: !Ref LoadBalancer
Port: 80
Protocol: HTTP
DefaultActions:
- Type: forward
TargetGroupArn: !Ref TargetGroupForPort80

LoadBalancerListenerB:
Type: AWS::ElasticLoadBalancingV2::Listener
Properties:
LoadBalancerArn: !Ref LoadBalancer
Port: 3000
Protocol: HTTP
DefaultActions:
- Type: forward
TargetGroupArn: !Ref TargetGroupForPort3000

这还允许灵活地为每个端口设置不同的协议(protocol)(例如 HTTPS)或目标组。

关于amazon-web-services - AWS LoadBalancer 监听多个端口,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53997188/

40 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com