如何在网络负载均衡器中将端口 80 重定向到 443

Abi*_*mar 6 amazon-web-services aws-cloudformation

farwardtotargetgroup:      
  Type: AWS::ElasticLoadBalancingV2::Listener
  Properties: 
    Certificates: 
     - CertificateArn: !Ref cert
    DefaultActions: 
      - TargetGroupArn: !Ref target-group
        Type: forward
    LoadBalancerArn: !Ref nlb
    Port: 443 
    Protocol: TLS
redirectto443:      
  Type: AWS::ElasticLoadBalancingV2::Listener
  Properties: 
    DefaultActions: 
      - RedirectConfig: 
          Port: 443
          StatusCode: HTTP_301 
        Type: redirect 
    LoadBalancerArn: !Ref nlb
    Port: 80 
    Protocol: TLS
Run Code Online (Sandbox Code Playgroud)

当我执行模板时,我得到:

操作类型“重定向”对于网络负载均衡器无效(服务:AmazonElasticLoadBalancingV2;状态代码:400;错误代码:InvalidLoadBalancerAction;

Chr*_*ams 7

仅应用程序负载均衡器支持重定向规则,网络负载均衡器不支持重定向规则。

如果您可以为您的应用程序使用应用程序负载均衡器,那么您将能够使用它。

来自文档

[应用程序负载均衡器] 用于创建重定向操作的信息。仅当类型为重定向时指定。

  • 您的网络服务器或应用程序本身将需要。原因是网络负载均衡器并非主要针对 Web 应用程序,而是旨在提高性能。它在第 4 层运行,而 ALB 在第 7 层运行。Http 在第 7 层运行,因此只有在这一层才会发生 (2认同)