Skip to content

Instantly share code, notes, and snippets.

@brasey
Last active March 15, 2019 14:39
Show Gist options
  • Star 7 You must be signed in to star a gist
  • Fork 3 You must be signed in to fork a gist
  • Save brasey/a7562b0b47731a0fc44b68ed7fec3c63 to your computer and use it in GitHub Desktop.
Save brasey/a7562b0b47731a0fc44b68ed7fec3c63 to your computer and use it in GitHub Desktop.
HAProxy behind AWS ELB: how to force HTTPS?

HAProxy behind AWS ELB: how to force HTTPS?

What are you trying to solve

You have some nodes in AWS that you want to load balance.

You want to use the magical scaling properties of ELB.

You want to do some things that ELB doesn't do, like force HTTPS (or add headers, or something else).

The architecture

Set up an ASG of HAProxy nodes that associates with your ELB.

Include these lines in your haproxy.cfg

  acl http req.hdr(X-Forwarded-Proto) http
  redirect scheme https if http

How does this work?

Amazon conveniently sets the X-Forwarded-Proto header on incoming requests. See this doc for more info.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment