将EC2 Elastic Load Balancer从HTTP重定向到HTTPS [英] Redirecting EC2 Elastic Load Balancer from HTTP to HTTPS

查看:162
本文介绍了将EC2 Elastic Load Balancer从HTTP重定向到HTTPS的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想将所有HTTP请求重定向到 ELB 上的https请求.我有两个EC2实例.我正在为服务器使用Nginx.我尝试重写nginx conf文件没有任何成功.我希望就此提出一些建议.

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应用程序负载均衡器现在支持将本地HTTP重定向到HTTPS.

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

要在控制台中启用此功能,请执行以下操作:

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

  1. 在EC2中转到您的负载均衡器,然后选择监听器"
  2. 在HTTP侦听器上选择查看/编辑规则"
  3. 删除默认规则(底部)以外的所有规则
  4. 编辑默认规则:选择重定向到"作为操作,将所有内容保留为默认值,然后输入"443"作为端口.

通过使用CLI,如这里.

还可以在Cloudformation中执行此操作,在该情况下,您需要像这样设置Listener对象:

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

如果您仍在使用经典负载均衡器,请使用其他配置中描述的NGINX配置之一.

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

这篇关于将EC2 Elastic Load Balancer从HTTP重定向到HTTPS的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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