# Dynamic use\_backend?

**URL:** <https://discourse.haproxy.org/t/dynamic-use-backend/9491>\
**Category:** Configuration Samples\
**Created:** [February 13, 2024, 10:40am UTC](https://discourse.haproxy.org/t/dynamic-use-backend/9491 "2024-02-13T10:40:17Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Rickard\_505](https://avatars.discourse-cdn.com/v4/letter/r/5f9b8f/32.png) [@Rickard\_505](https://discourse.haproxy.org/u/Rickard_505)\
**Post date:** [February 13, 2024, 10:40am UTC](https://discourse.haproxy.org/t/dynamic-use-backend/9491/1 "2024-02-13T10:40:17Z")

</div>

How can i get the ACL and USE\_BACKEND below to a dynamic one (or two) liner(s) ?  
the domain in ACL - has the info needed for the backend statement imho. (either by its own name or its value)

and - yes - I NEED to use **ssl\_fc\_sni** since traffic is a mix of websockets and normal http that needs to be offloaded coming in on same ip/port (in both cases)

mode http  
log global  
option dontlognull  
option log-separate-errors  
option httplog  
option http-server-close  
option forwardfor  
acl https ssl\_fc  
http-request set-header X-Forwarded-Proto http if !https  
http-request set-header X-Forwarded-Proto https if https  
timeout client 30000  
tcp-request inspect-delay 5s  
acl cust1 ssl\_fc\_sni -i **[cust1.abc.com](http://cust1.abc.com)**  
acl cust2 ssl\_fc\_sni -i [cust2.abc.com](http://cust2.abc.com)  
acl cust3 ssl\_fc\_sni -i [cust2.abc.com](http://cust2.abc.com)  
acl cust4 ssl\_fc\_sni -i [cust2.abc.com](http://cust2.abc.com)  
acl cust5 ssl\_fc\_sni -i [cust5.abc.com](http://cust5.abc.com)  
use\_backend bkr\_**[cust1.abc.com](http://cust1.abc.com)**\_ipvANY if cust1  
use\_backend bkr\_cust2.abc.com\_ipvANY if cust2  
use\_backend bkr\_cust3.abc.com\_ipvANY if cust3  
use\_backend bkr\_cust4.abc.com\_ipvANY if cust4  
use\_backend bkr\_cust5.abc.com\_ipvANY if cust5

---

<div class="post-metadata">

**Author:** ![mario.almeida](https://avatars.discourse-cdn.com/v4/letter/m/c2a13f/32.png) [@mario.almeida](https://discourse.haproxy.org/u/mario.almeida)\
**Post date:** [February 16, 2024, 12:31pm UTC](https://discourse.haproxy.org/t/dynamic-use-backend/9491/2 "2024-02-16T12:31:47Z")

</div>

Create a map file /etc/haproxy/backends.map with below content

[cust1.abc.com](http://cust1.abc.com) bkr\_cust2.abc.com\_ipvANY  
[cust2.abc.com](http://cust2.abc.com) bkr\_cust2.abc.com\_ipvANY

and in frontend, use this

use\_backend %[req.hdr(host),host\_only,lower,map\_dom(/etc/haproxy/backends.map)]

---

<div class="post-metadata">

**Author:** ![Rickard\_505](https://avatars.discourse-cdn.com/v4/letter/r/5f9b8f/32.png) [@Rickard\_505](https://discourse.haproxy.org/u/Rickard_505)\
**Post date:** [September 20, 2024, 1:12pm UTC](https://discourse.haproxy.org/t/dynamic-use-backend/9491/3 "2024-09-20T13:12:04Z")

</div>

Unfortunatly i need to check domain with SSL\_FC\_SNI, (IOT things that uses websockets)

SSL\_FC\_SNI is only 100% reliable way I have found out so far.

---

<div class="post-metadata">

**Author:** ![adarragon](https://avatars.discourse-cdn.com/v4/letter/a/7bcc69/32.png) [@adarragon](https://discourse.haproxy.org/u/adarragon)\
**Post date:** [September 24, 2024, 2:59pm UTC](https://discourse.haproxy.org/t/dynamic-use-backend/9491/4 "2024-09-24T14:59:01Z")

</div>

You may still use @mario.almeida mapping suggestion, any fetch that converts to string may actually be used

Something like this:  
`use_backend %[ssl_fc_sni,lower,map_dom(/etc/haproxy/backends.map)]`

---

<div class="post-metadata">

**Author:** ![Rickard\_505](https://avatars.discourse-cdn.com/v4/letter/r/5f9b8f/32.png) [@Rickard\_505](https://discourse.haproxy.org/u/Rickard_505)\
**Post date:** [September 27, 2024, 10:53am UTC](https://discourse.haproxy.org/t/dynamic-use-backend/9491/5 "2024-09-27T10:53:17Z")

</div>

I wish i could, but SSL\_FC\_SNI does not seem to work for that, works fine with hostname and other things…
