HAProxy community

Haproxy always uses the default backend for rewritten url



I am trying to use haproxy to direct users to different backends depending on the url in the browser.
All the backends have the same real URL (https://<backend>:8443/backurl).
But with my configuration, haproxy always uses default backend to serve the page, after rewriting.
Please how can I fix this, and make haproxy use only the designated backend, instead of using the default?
Also when I remove the default backend line, haproxy returns a 503 error message.

frontend incoming-in
    bind *:443 ssl crt /usr/local/etc/haproxy/ssl/domain.pem
    option http-server-close
    option forwardfor
    cookie SRVNAME insert
    reqadd X-Forwarded-Proto:\ https
    reqadd X-Forwarded-Port:\ 443
    # set HTTP Strict Transport Security (HTST) header
    rspadd  Strict-Transport-Security:\ max-age=15768000
    #ACLs and URL rewrites...    
    acl url_1  url_beg /back1url
    acl url_2 url_beg /back2url
    acl url_3  url_beg /back3url
    use_backend back_1-backurl  if url_1
    use_backend back_3-backurl if url_3
    use_backend back_2-backurl if url_2
    default_backend back_1-backurl

backend back_1-backurl
    cookie JSESSIONID prefix nocache
    reqrep ^([^\ ]*\ /)back1url[/]?(.*)     \1backurl\2
    server back_1 cookie back_1 ssl verify none

backend back_2-backurl
    cookie JSESSIONID prefix nocache
    reqrep ^([^\ ]*\ /)back2url[/]?(.*)     \1backurl\2
    server back_2 cookie back_2 ssl verify none

backend back_3-backurl
    cookie JSESSIONID prefix nocache
    reqrep ^([^\ ]*\ /)back3url[/]?(.*)     \1backurl\2
    server back_3 cookie back_3 ssl verify none`

Thanks a lot in advance!


Hopefully someone will help me soon, I had to separate the backends with individual frontends, which was not the goal


If you access /back1url, /back2url, /back3url, haproxy will reoute to the correct backend. If you browser accesses /backurl, the default backend will be selected as per your configuration.

I assume your intention is to keep using /backurl in your browser, but then you do not have the information for haproxy to decide which backend to use.

You could use different hostnames for this, so instead of the path you use the hostname to route to the correct backend.