简体   繁体   English

AWS CloudFormation 应用程序负载均衡器 - 如何将 HTTP 侦听器重定向到 HTTPS 侦听器?

[英]AWS CloudFormation Application Load Balancer - how to redirect HTTP listener to HTTPS listener?

I am trying to write a CloudFormation template for ALB, but got stuck on the point where I would like to redirect ALB's HTTP listener's traffic to HTTPS listener.我正在尝试为 ALB 编写 CloudFormation 模板,但卡在了我想将 ALB 的 HTTP 侦听器的流量重定向到 HTTPS 侦听器的点上。 Docs mention only forwarding/redirection to the target group.文档只提到转发/重定向到目标组。

I am aware that it is achievable using the web interface (AWS Console), which I want to avoid.我知道使用我想避免的 Web 界面(AWS 控制台)可以实现它。 Also handling it on the server is a no go for me.在服务器上处理它也不适合我。

Is this ALB's feature simply not implemented in CloudFormation, but exists in Console?这个 ALB 的功能是否根本没有在 CloudFormation 中实现,但存在于控制台中?

On November 19, 2018 Amazon introduced the RedirectConfig for the Elastic Load Balancer Listener. 2018 年 11 月 19 日,Amazon 为 Elastic Load Balancer Listener 引入了 RedirectConfig。 This listener type is also used for the Application Load Balancer (ALB).此侦听器类型也用于应用程序负载均衡器 (ALB)。

Below you find an example configuration for the usual HTTP to HTTPS redirect .下面是通常的HTTP 到 HTTPS 重定向的示例配置。 Replace 'PublicLoadBalancerBackend' with your load balancers CloudFormation object.将“PublicLoadBalancerBackend”替换为您的负载均衡器 CloudFormation 对象。

  PublicLoadBalancerHttpRedirectListener:
    Type: AWS::ElasticLoadBalancingV2::Listener
    DependsOn:
      - PublicLoadBalancerBackend
    Properties:
      DefaultActions:
        - RedirectConfig:
            Host: "#{host}"
            Path: "/#{path}"
            Port: 443
            Protocol: "HTTPS"
            Query: "#{query}"
            StatusCode: HTTP_301
          Type: redirect
      LoadBalancerArn: !Ref 'PublicLoadBalancerBackend'
      Port: 80
      Protocol: HTTP

CloudFormation Documentation on the RedirectConfig: https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-elasticloadbalancingv2-listener-redirectconfig.html RedirectConfig 上的 CloudFormation 文档: https : //docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-elasticloadbalancingv2-listener-redirectconfig.html

CloudFormation Documentation on the Listener Action: https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-elasticloadbalancingv2-listener-defaultactions.html有关侦听器操作的 CloudFormation 文档: https : //docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-elasticloadbalancingv2-listener-defaultactions.html

Looks like for now the only option is to write a custom resource to manage it.看起来现在唯一的选择是编写一个自定义资源来管理它。 See: https://github.com/jheller/alb-rule for a solid example to either implement - or use as a base for your own implementation.请参阅: https : //github.com/jheller/alb-rule一个可靠的例子来实现 - 或用作您自己实现的基础。 (I have no affiliation with the above code - just found for my own need to do the exact same thing) (我与上面的代码没有任何关系 - 只是为了我自己需要做同样的事情而发现的)

事实证明,到目前为止, redirect尚未在 CF 中实现,可悲的是,AWS- source预计会发生什么。

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

相关问题 将 https 侦听器添加到 AWS Application Load Balancer 时出现问题 - Trouble when adding https listener to AWS Application Load Balancer AWS在Load Balancer Listener上设置https SSL - AWS set https SSL on Load Balancer Listener 如何在 aws 经典负载均衡器上重定向 http -> https? - How to redirect http -> https on aws classic load balancer? 使用 Application Load Balancer 将 http 重定向到 https - Redirect http to https using Application Load Balancer AWS EC2将HTTP重定向到HTTPS槽式负载均衡器 - AWS EC2 redirect HTTP to HTTPS trough load balancer AWS 负载均衡器附加:80 到 url 上 http 到 https 301 重定向 - AWS Load Balancer appends :80 to url on http to https 301 redirect 通过应用程序负载平衡器将HTTP重定向到https不能在iPhone Safari中使用 - http to https redirect via application load balancer not working in iphone safari 应用程序负载平衡器+ Nginx http到https重定向使502错误的网关 - Application Load Balancer + Nginx http to https redirect gives 502 Bad Gateway 如何在AWS Elastic Load Balancer上启用HTTPS? - How to enable HTTPS on AWS Elastic Load Balancer? 端口 443 上负载均衡器后面的 HTTP 到 HTTPS 重定向 - HTTP to HTTPS redirect behind Load Balancer on port 443
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM