4
votes

In HAProxy is it possible to write an ACL for virtual hosts redirection (one rule for all Virtual Hosts)

Example say

if header contains backend-name.domain.com ---> use the backend with the name backend-name

It should work like,

a.domain.com -----> backend a
b.domain.com -----> backend b

with out explicitly writing ACLs for a and b separately.

Here I need one ACL for all domain based routing, as I'm using a wildcard DNS for all sub-domains of domain.com resolve to HAProxy IP.

I'm dynamically adding and removing back-ends, its hard to write ACLs for every new front-end using script.

Thanks in advance.

1

1 Answers

2
votes

Simply use this:

frontend generic
  # foo.host.com --> foo
  use_backend %[req.hdr(host),lower,field(1,'.')]

backend foo
   ...

backend bar
   ...