Hello list, I'm configuring a couple of maps used to route requests based on 
hostname and path. The map lay out is pretty much like this:

    sub.tld/path1 name_backend1
    ...

I have some distinct ways to match a request: str, beg, dir, reg, using their 
map converter derivatives.

    map_str()
        sub.tld/path/exact-match-based name_backend1
        ...

    map_beg()
        sub.tld/path/beginning-based name_backend2
        ...

    map_dir()
        sub.tld/path/subdir-based name_backend3
        ...

    map_reg()
        sub.tld/path/regex-based name_backend4
        ...


Here is a haproxy frontend snippet:

    http-request set-var(req.backend) base,map_str(/dir/to/map_str)
    http-request set-var(req.backend) base,map_beg(/dir/to/map_beg) if !{ 
var(req.backend) -m found }
    http-request set-var(req.backend) base,map_dir(/dir/to/map_dir) if !{ 
var(req.backend) -m found }
    http-request set-var(req.backend) base,map_reg(/dir/to/map_reg) if !{ 
var(req.backend) -m found }

Everything works pretty good provided that paths under the same hostname 
doesn't overlap each other, or if they overlap, they belong to the same 
matching pattern. However we have scenarios like this:

    map_reg() -- sub.tld/path/sub[0-9]/?.* name_backend1
    map_beg() -- sub.tld/path name_backend2
    map_reg() -- sub.tld/p[a-z].* name_backend3

The order of the lines states the precedence - first match should win, but the 
way my config was built doesn't allow to implement this. /path/sub1 will proxy 
to backend2 if map_beg() comes first (backend1 should win), and /path/x will 
proxy to backend3 if map_reg() comes first (backend2 should win). I'm using 
maps due to performance reasons, we've currently about 20k lines of 
hostname+path and about 5k backends.

To the best of my knowledge I'll need to create several maps per match type, 
and reorder them accordingly - but maybe I'm missing something here. Any advice?

~jm


Reply via email to