How to make HAProxy's SSL redirect and path rewrite (with reqrep) work at the same time?

If I understand correctly this is your scenario

1- User sends a request to http://site.com/appA
2- haproxy redirect http to https
3- haproxy choose backend
4- haproxy needs to remove /appA from path and sends the request to backend .

frontend http-in
    bind 0.0.0.0:80
    http-request redirect scheme https
    default_backend maintenance

frontend https-in
    bind 0.0.0.0:443 ssl crt /etc/haproxy/certs alpn h2,http/1.1
    http-request add-header X-Forwarded-Proto https
    acl appA_url url_beg /appA
    use_backend appA if appA_url
    default_backend maintenance

backend appA
    balance roundrobin
    http-request set-uri %[url,regsub(^/appA,/,)] if { path_beg /appA }
    server web1 127.0.0.1:5001 check

backend maintenance
    balance roundrobin
1 Like