AWS ALB redirection issue; http -> https

Yoon Kim
Yoon Kim
Jul 28, 2017 · 2 min read

If you’re using AWS ALB (application load balancer) and your website is running on https only, you might need to redirect all http traffics to https.

I had …

  1. curl -I http://example.comhttps://example.com : Not working; get 204 (“HTTP/1.1 204 No Content”)
  2. curl -I http://www.example.comhttps://example.com : working; get (“HTTP/1.1 301 Moved Permanently”)
  3. http://example.com →https://example.com on Browsers(but some of users were not.)
  4. My nginx configuration was quite correct about redirection(80 -> 443)
  5. ALB had 2 listeners as below
Load balancer : Listeners
Target group’s Configuration of WEB-HTTPS

After digging a little bit… the https target group passed a http request as https(443 port) to nginx(Instance) and nginx served(skip server:80 configuration) as https even though it was a http request…. I switched from ELB to ALB. It’s my biggest mistake ever. 🤣

ELB configuration

Anyway.. long story short;

There is the instance port in ELB configuration but for ALB is not. So if you want to redirect http to https correctly, you should create another target group for http then add the http target group to your ALB listener as 80 port.

Load balancer : Listeners; http and https
Target group’s Configuration of WEB-HTTP

All behaviors are working as expected now.


Yoon Kim

Written by

Yoon Kim

Cool.

Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch
Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore
Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade