Search code examples
headerhaproxy

Haproxy dynamic backend matching request header


I am trying to find a solution for a problem I have with haproxy. Is something like this possible with haproxy if so can someone help with the right syntax or documentation?

Header: key=value
acl custom_header key=value 
use backend value

backend value
server something.value.com

The term value should be a var or place holder so I can match particular backend when the request has a particular value for the key


Solution

  • You can use the variable in the use backend directive.

    Here is a snippet the full answer is here. https://stackoverflow.com/a/61931107/6778826

    frontend fe1
      ...
      use_backend %[req.hdr(key),lower]
    
    backend value
      server something.value.com