HAProxy community

Selecting backend based on vhost and part of URL


Hi there.
I’ve been looking for similar thread but no luck.

I’ve microservices infrastracture (lot of docker containers with applications) with canary release.
Canary release is based on Host header, and application is selected by URL, ex. color_green.mysite.com/MyFirstApplication/api/…

Similarly for MySecondApplication, and so on. Each application in each color has own backend.

At the beginning i’ve created number_of_colors x number_of_apps ACL and matched to backend.

First optimalization, I’ve created variable, assigned string to them (vhost based):

http-request set-var(req.backend_color) str(“AHHG”) if vhostname_devahhappsg
http-request set-var(req.backend_color) str(“AHHB”) if vhostname_devahhappsb

Thanks to that, I’m selecting backend with this variable:
use_backend backend_%[var(req.backend_color)]_MDULogCollector if MDULogCollector

MDULogCollector acl looks like:
acl MDULogCollector path_beg -i /MDULogCollector/

How can I fetch first portion of url and select backend like:
use_backend backend_%[var(req.backend_color)]_%[function_or_variable] if ACL_selecting_app ?

I don’t want to create thousands of ACL if I can use one or two.

Regards, Artur