Vyankatesh Kudtarkar
Vyankatesh Kudtarkar

Reputation: 13

HAProxy not redirecting http to https (ssl)

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

 frontend httpfront
    mode http
    bind *:80
    redirect scheme https code 301 if !{ ssl_fc }

Upvotes: 1

Views: 5596

Answers (1)

qwsj
qwsj

Reputation: 456

You need configure frontend for 443 port.

frontend (port 80) -> frontend (port 443) -> backend

Check my example:

frontend httpfront
    mode http
    bind *:80
    redirect scheme https code 301 if !{ ssl_fc }

frontend httpsfront
    mode tcp
    bind *:443
    default_backend app

backend app
    mode tcp
    balance roundrobin
    server server01 10.10.10.11:443 check
    server server02 10.10.10.12:443 check

Upvotes: 4

Related Questions