HAProxy redirecting http to https (ssl)

Jon Chu picture Jon Chu · Nov 5, 2012 · Viewed 170k times · Source

I'm using HAProxy for load balancing and only want my site to support https. Thus, I'd like to redirect all requests on port 80 to port 443.

How would I do this?

Edit: We'd like to redirect to the same url on https, preserving query params. Thus, http://foo.com/bar would redirect to https://foo.com/bar

Answer

Jay Taylor picture Jay Taylor · May 13, 2013

I found this to be the biggest help:

Use HAProxy 1.5 or newer, and simply add the following line to the frontend config:

redirect scheme https code 301 if !{ ssl_fc }