简体   繁体   中英

Automatically redirect HTTP to HTTPS in AWS ELB

I want to redirect all of my HTTP requests to https in AWS. I use ELB for ssl certificate and using ubuntu(64-bit) os.

You have two options:

1) Use cloudfront in front of your ELB, and configure it to force everything to HTTPS

2) Add a rewrite rule to your web server configuration to redirect to https. Note that you will need to check X-Forwarded-Proto to determine if the original request was secure or not.

The new Application ELB can redirect HTTP to HTTPS. Just open Listeners tab and follow View/edit rules link for the HTTP : 80 listener. Then, you just edit default rule, remove default action and select Redirect option. Here you can set protocol (default is https), define custom port, modify server name, path, query string etc.

You cannot use only ELB to redirect request from HTTP to HTTPS. You must install some Reverse Proxy tools (like nginx or vanish, apache) to redirect all HTTP Request to HTTPS.Your ELB will listen both HTTP/HTTPS but your server will rewrite HTTP requests. For example from aws https://aws.amazon.com/premiumsupport/knowledge-center/redirect-http-https-elb/

2019+

AWS Application Load Balancers now supports HTTPS redirection.

On the console go to EC2 > Load balancers > your load balancer > listeners

Here you should have 2 rules: HTTP : 80 and HTTPS : 443

You just have to:

  • edit the HTTP : 80 rule
  • remove the forward rule and add a redirect rule to port 443 (picture 1)
  • save and you should see something like picture 2

在此输入图像描述

在此输入图像描述

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM