On Sun, Jan 17, 2016 at 6:54 PM, Michel Blanc <m...@mbnet.fr> wrote:
> Dear all,
>
> I am trying to get haproxy routing to a specific server if a header
> (with the server nickname) is set.
>
> My first guess was that the following config snipped would do it:
>
>   backend ...
>     acl force_backend req.hdr(X-Want-Backend) -m found
>     use_server %[req.hdr(X-Want-Backend)] if force_backend
>
> But this is rejected by HAproxy (version 1.5.14)
>
>   unable to find server '%[req.hdr(X-Want-Backend)]' referenced in a
> 'use-server' rule
>
> Can this be done ? I would like to avoid the "long" alternative where
> each server is explicitly listed.
>
> If yes, what happens at run time when a value that doesn't map to a real
> server is passed in the header ?
>
> Thanks !
>
> M
> --
> Michel Blanc
> { :github => "@leucos", :twitter => "@b9m", :gpg => "0X24B35C22" }
>


You don't want dynamic backend, but dynamic server, and it doesn't work.
You can do a dirty trick: enable cookie based persistence, without
setting the cookie value and rewrite your HTTP header into the cookie
used for persistence.
Some kind of:

backend bk_srv
 http-request set-header Cookie MyCookie=%[req.hdr(X-Want-Backend)]
 cookie MyCookie insert indirect
 server s1 1.0.0.1:8082 cookie s1
 server s2 1.0.0.2:8082 cookie s2

Baptiste

Reply via email to