0

I have HAProxy configured with a single front end that accepts both HTTP and HTTPS connections. All backends are HTTP only.

I would like to force certain paths to use HTTPS (/Login etc) so HAProxy returns a redirect for these paths when it receives a request on HTTP.

2
  • Not knowing haproxy too well, but redirect is documented quite well... cbonte.github.io/haproxy-dconv/…
    – lazyfrosch
    Oct 30, 2015 at 10:21
  • 2
    To be honest, there's no good reason to do this. Just serve your entire site via HTTPS. Your clients will appreciate it and you'll get better search rankings. And it's just the right thing to do.
    – EEAA
    Oct 30, 2015 at 12:02

2 Answers 2

2

I went for the following which works perfectly in my case:

frontend yadayada
  ...
  acl Secure dst_port 443
  acl Login path_beg /login
  redirect scheme https code 301 if Login !Secure
0

For URI's ending on /Login, path_end is probably most appropriate:

https://stackoverflow.com/questions/20606544/haproxy-url-based-routing-with-load-balancing

Your config will then look like this (incomplete, for illustration).

frontend http
acl secure path_end -i /Login #matches path ending with "/Login"

use_backend secure_server    if secure

backend secure_server
   redirect scheme https if ! secure

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .