Route http-request based on destination IP


Our application makes internal calls to multiple domains and subdomains. The domain names are resolved ( from /etc/hosts file within application servers) by multiple load balancer IPs. I have around 500 websites resolved to different LB IPs with a different backend for each ip. I want to route the request to different backend based on the destination ip ( LB ip) but my requests from the application servers would be to the domains/subdomains.

I can route the traffic based on the domain like below.

frontend https-in
acl host_1 hdr(host) -i
acl host_2 hdr(host) -i
use_backend worker_1 if host_1
use_backend worker_2 if host_2

But this way, I have to write 1000 of ACLs as per my current requirement. Is there an option to route based on the destination ip? or any other feature that helps to achieve this as simple as possible?

Thanks in Advance,

Sure, the destination IP is saved in the dst variable.

acl destination1 dst
acl destination2 dst
acl destination3 dst

That said, I’m not sure maintaining huge host files scales better…

1 Like

I would use a map

use-backend %[dat,map(ip2backend)]

with some content like this: application1 application2

Hello lukastribus,

You saved my life. Your solution worked like a charm.

Thanks a lot for your help.

@Baptiste12h: I haven’t try your solution. But, Thank you very much for your reply.