将 EC2 弹性负载均衡器从 HTTP 重定向到 HTTPS

编程入门 行业动态 更新时间:2024-10-28 06:31:44
本文介绍了将 EC2 弹性负载均衡器从 HTTP 重定向到 HTTPS的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我想将所有 HTTP 请求重定向到

使用 CLI 也可以达到同样的目的,如这里.

也可以在 Cloudformation 中执行此操作,您需要在其中设置一个 Listener 对象,如下所示:

HttpListener:类型:AWS::ElasticLoadBalancingV2::Listener特性:LoadBalancerArn: !Ref LoadBalancer端口:80协议:HTTP默认操作:- 类型:重定向重定向配置:协议:HTTPS状态代码:HTTP_301端口:443

如果您仍在使用 Classic Load Balancer,请使用其他人描述的 NGINX 配置之一.

I want to redirect all the HTTP request to https request on ELB. I have two EC2 instances. I am using nginx for the server. I have tried a rewriting the nginx conf files without any success. I would love some advice on it.

解决方案

AWS Application Load Balancers now support native HTTP to HTTPS redirect.

To enable this in the console, do the the following:

  • Go to your Load Balancer in EC2 and tab "Listeners"
  • Select "View/edit rules" on your HTTP listener
  • Delete all rules except for the default one (bottom)
  • Edit default rule: choose "Redirect to" as an action, leave everything as default and enter "443" as a port.
  • The same can be achieved by using the CLI as described here.

    It is also possible to do this in Cloudformation, where you need to set up a Listener object like this:

    HttpListener: Type: AWS::ElasticLoadBalancingV2::Listener Properties: LoadBalancerArn: !Ref LoadBalancer Port: 80 Protocol: HTTP DefaultActions: - Type: redirect RedirectConfig: Protocol: HTTPS StatusCode: HTTP_301 Port: 443

    If you still use Classic Load Balancers, go with one of the NGINX configs described by the others.

    更多推荐

    将 EC2 弹性负载均衡器从 HTTP 重定向到 HTTPS

    本文发布于:2023-11-23 23:42:20,感谢您对本站的认可!
    本文链接:https://www.elefans.com/category/jswz/34/1623203.html
    版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
    本文标签:均衡器   负载   弹性   重定向   HTTP

    发布评论

    评论列表 (有 0 条评论)
    草根站长

    >www.elefans.com

    编程频道|电子爱好者 - 技术资讯及电子产品介绍!