# Route http-request based on destination IP

**URL:** <https://discourse.haproxy.org/t/route-http-request-based-on-destination-ip/2576>\
**Category:** Help!\
**Created:** [June 7, 2018, 2:05pm UTC](https://discourse.haproxy.org/t/route-http-request-based-on-destination-ip/2576 "2018-06-07T14:05:43Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![raaj4smile](https://avatars.discourse-cdn.com/v4/letter/r/838e76/32.png) [@raaj4smile](https://discourse.haproxy.org/u/raaj4smile)\
**Post date:** [June 7, 2018, 2:05pm UTC](https://discourse.haproxy.org/t/route-http-request-based-on-destination-ip/2576/1 "2018-06-07T14:05:43Z")

</div>

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](http://www.domain1.net)  
acl host\_2 hdr(host) -i [www.domain2.net](http://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

---

<div class="post-metadata">

**Author:** ![lukastribus](https://avatars.discourse-cdn.com/v4/letter/l/7ea924/32.png) [@lukastribus](https://discourse.haproxy.org/u/lukastribus)\
**Post date:** [June 7, 2018, 2:28pm UTC](https://discourse.haproxy.org/t/route-http-request-based-on-destination-ip/2576/2 "2018-06-07T14:28:56Z")

</div>

Sure, the destination IP is saved in the [dst](http://cbonte.github.io/haproxy-dconv/1.7/configuration.html#7.3.3-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…

---

<div class="post-metadata">

**Author:** ![Baptiste](https://avatars.discourse-cdn.com/v4/letter/b/cab0a1/32.png) [@Baptiste](https://discourse.haproxy.org/u/Baptiste)\
**Post date:** [June 7, 2018, 6:35pm UTC](https://discourse.haproxy.org/t/route-http-request-based-on-destination-ip/2576/3 "2018-06-07T18:35:29Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![raaj4smile](https://avatars.discourse-cdn.com/v4/letter/r/838e76/32.png) [@raaj4smile](https://discourse.haproxy.org/u/raaj4smile)\
**Post date:** [June 8, 2018, 6:34am UTC](https://discourse.haproxy.org/t/route-http-request-based-on-destination-ip/2576/4 "2018-06-08T06:34:00Z")

</div>

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.
