HAProxy community

Key-value mapping: Route by IP

I am using a key - value mapping in HAProxy like this:

use_backend %[req.hdr(host),lower,map_dom(/etc/haproxy/clusters.map)] if !letsencrypt-acl

/etc/haproxy/clusters.map is filled with domain and backend mappings. This works well.

Now, I also need to be able to route by IP. In other words, I want to be able to add an IP to the map file (/etc/haproxy/clusters.map) with a corresponding backend. In order to do this, I changed my config to:

use_backend %[req.hdr(host),lower,map_dom(/etc/haproxy/clusters.map)] if !letsencrypt-acl
use_backend %[req.hdr(ip),lower,map_dom(/etc/haproxy/clusters.map)]
use_backend bk_letsencrypt if letsencrypt-acl

This actually seems to work well, but is this the recommended way to go about this?

If would use a different map file for ip addresses, and map_ip instead of map_dom for that.

Everything else depends on your use-case.

What IP? Because you seem to be looking at the HTTP request header “IP”. Is that what you want?

Is that what you want?