HAProxy community

HAproxy > mapfile backendselection with directory

Hey Guys, quite new here and also quite the beginner. I would like to match a domain and directory with my map file and i am wondering how to do this the best way.

As far as i can determine the backend selection currently functions with

use_backend %[req.hdr(host),lower,map_dom(mapfile.txt,bk_defaultbackend)]

with a mapfile.txt containing something like this:

sub.domain.tld bk_subdomain

when navigating to sub.domain.tld the properbackend will be selected. however i would like to be able to forward directories e.g

sub.domain.tld/dir bk_otherbackend

which does not work with map_dom in the usebackend code. How would i go about this ? and how would i rewrite this line?

use_backend %[req.hdr(host),lower,map_dom(mapfile.txt,bk_defaultbackend)]

Use base instead:

Something like (untested):

use_backend %[base,lower,map_beg(mapfile.txt,bk_defaultbackend)]

Correction: map_beg instead of base_beg

I will give this a try and report back ! Thank you !

1 Like

some updates? really interested in how it worked out. thanks

So when i change my backend selection in this way, it doesn’t break anything which is good. Some of my redirects work half way through some don’t. not really sure tbh. I need some more time testing it.

In order to test this better i have to set up two static webservers. i’ll report back

doesn’t work for me. are you still here? want to ask you something if you don’t mind.

It works for me, I actually tested it a few days ago.

Please stop asking if you can ask, and just ask your question. If it is related to this thread, then you ask here, otherwise you open a new thread. But asking if you can ask a question actually is a waste of both our time. Thank you.

so it works for you that if you have in your map file

test.tld/site1 backend_siteone
test.tld/site2 backend_sitetwo  

it selects the proper backend when you navigate to either?

My testcase was slightly different, but yes, that’s how it is supposed to work.