Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save jeffersonsouza/9bd063d8ad3a998706752edeecebb456 to your computer and use it in GitHub Desktop.
Save jeffersonsouza/9bd063d8ad3a998706752edeecebb456 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