Simple method for doing http -> https frontend redirects in HAProxy?


#1

I have a site doing simple reverse proxying (https 443 haproxy frontend --> http 8080 on the backend).

Is there a simple config entry for HAProxy to force http 80 requests on the front end, to redirect to https 443 on the front end and then get proxied to the backend?


#2

Just make sure your frontend also binds on port 80 and add this line somewhere near the top of your frontend definition (request processing stops at this line and the client gets externally redirected to the same URL with HTTPS):
http-request redirect scheme https if !{ ssl_fc }

Check out the docs here:
http://cbonte.github.io/haproxy-dconv/1.7/configuration.html#http-request
http://cbonte.github.io/haproxy-dconv/1.7/configuration.html#4.2-redirect%20scheme