Search code examples
http-redirecthaproxy

HAproxy: Redirect to https in backend


My workplace has a HAproxy which we use for routing to webservers needing only one public IP. Some of our customers want https some do not.

I would like to enforce https on a per backend basis.

I found this, only it does not say if this config is for frontend or backend. Maybe it will work for both?

http-request redirect location [code ] [] []

or this:

mode http

redirect scheme https if !{ ssl_fc }

So I thought Id put this in some of the backends:

http-request redirect location https://www.somedomain.com [code 301]

Will this work? Our lab env. is tied up so I cannot test it in a timely fashion.


Solution

  • I created my own test backend.. This works:

    backend lb_customername
              mode http
              redirect scheme https if !{ ssl_fc }
    
              balance roundrobin
    
              server server1 10.0.0.51:80 maxconn 200
              server server2 10.0.0.52:80 maxconn 200