Url based routing


Hello All,

Greetings !

I have a very basic setup and am trying to use haproxy as reverse proxy to route requests to different servers based on my urls.

log local2 info
pidfile /run/haproxy.pid

Default SSL material locations

ca-base /etc/ssl/certs
crt-base /etc/ssl/private

log global
mode http
option httplog
option dontlognull
timeout connect 5000
timeout client 50000
timeout server 50000

listen stats
bind *:1936
stats enable
stats uri /
stats hide-version
stats auth admin:admin

frontend http
bind *:5000
mode http
default_backend srvc_default

acl workspace path_end -i /cb
use_backend srvc_workspace if workspace

#http-request set-path / if workspace

backend srvc_workspace
balance roundrobin
server server1 myapp
mode http
cookie QPP prefix

backend srvc_default
balance roundrobin
#server qppworkspace qppworkspace:3000
server qppworkspac google.com
listen default
bind *:4242

My sample configuration is shown above.

If I hit the url server/cb, it takes me to the desired server but appends /cb to that url, so essentially I get an error 404 as myserver/cb does not exist.

I just want to route the request if my path contains /cb but /cb should not be part of the final url that reaches my back end.

Thanks again for helping



use this rule inside the backend

backend srvc_workspace
balance roundrobin
http-request set-uri %[url,regsub(^/cb,/,)] if { path_beg /cb }
server server1 myapp
mode http
cookie QPP prefix