将 EC2 弹性负载均衡器从 HTTP 重定向到 HTTPS [英] Redirecting EC2 Elastic Load Balancer from HTTP to HTTPS

查看:41
本文介绍了将 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:

  1. Go to your Load Balancer in EC2 and tab "Listeners"
  2. Select "View/edit rules" on your HTTP listener
  3. Delete all rules except for the default one (bottom)
  4. 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的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆