HAproxy domain name for mapping backend for route-based routing (url)

Does HAProxy support a domain name for mapping a backend for route-based routing.

It currently supports maps for vhost:

frontend xyz
   <other_lines>
   use_backend backend1 if { hdr(Host) -i myapp.domain1.com }
   use_backend backend2 if { hdr(Host) -i myapp.domain2.com }

Can be rewritten using maps as:

frontend xyz
   <other_lines>
   use_backend %[req.hdr(host),lower,map_dom(/path/to/map,default)]

With map file contents like:

#domainname  backendname
myapp.domain1.com backend1
myapp.domain2.com backend2

But if routing is based on paths, as shown in the example below:

frontend xyz
   acl host_server_myapp hdr(host) -i myapp.domain.com
   acl path_path1 path_beg /path1
   acl path_path2 path_beg /path2
   use_backend backend1 if host_server_myapp path_path1
   use_backend backend2 if host_server_myapp path_path2

Is it possible to have a mapping for this utility? Using basehdr (host) instead can give the whole path, but it will not have the flexibility of domains, because base- string comparison. Is there any other way to convert this to haproxy cards.

+4
source share
1 answer

Layer 7 base fetch -

, .

... map_beg(), .

use_backend %[base,map_beg(/etc/haproxy/testmap.map,default)]

/etc/haproxy/testmap.map , , . default ( map_beg() - , , ).

, HAProxy , .

, :

example.com/foo     this-backend # note, also matches /foo/ba 
example.com/foo/bar that-backend # note, matches /foo/bar
example.org/foo     some-other-backend

(, example.com www.example.com , , ), regsub() , :

use_backend %[base,regsub(^www\.,,i),map_beg(/etc/haproxy/testmap.map,default)]
+5

All Articles