Route http-request based on destination IP

Hi,

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 www.domain1.net
acl host_2 hdr(host) -i www.domain2.net
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,
Nagaraj

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

acl destination1 dst 192.168.1.1
acl destination2 dst 192.168.1.2
acl destination3 dst 192.168.1.3

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:

192.168.0.1 application1

192.168.0.2 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.