HAProxy dynamic server addresses HAProxy dynamic server addresses nginx nginx

HAProxy dynamic server addresses


Assuming you're happy with trusting the IP in the header of the second request, then yes, you can do it with use-server:

backend bk_foo  [...]  server srv_0a_00_01_05 10.0.1.5:80 weight 100  server srv_0a_00_02_05 10.0.2.5:80 weight 100  use-server %[req.hdr(x-backend-ip),lower,map_str(/etc/haproxy/hdr2srv.map,srv_any)] if { req.hdr(x-backend-ip),lower,map_str(/etc/haproxy/hdr2srv.map) -m found }

Contents of /etc/haproxy/hdr2srv.map:

#ip srv_name# hex of IP used for names in this example10.0.1.5  srv_0a_00_01_0510.0.2.5  srv_0a_00_02_05

If you need to down one of the servers, you should dynamically update the map to remove it, so that the requests with the header set get redirected again.

If you have multiple backends, you can do similar with use_backend.