# Using map file in backend config / dynamic backends?

**URL:** <https://discourse.haproxy.org/t/using-map-file-in-backend-config-dynamic-backends/4702>\
**Category:** Help!\
**Created:** [January 8, 2020, 5:39pm UTC](https://discourse.haproxy.org/t/using-map-file-in-backend-config-dynamic-backends/4702 "2020-01-08T17:39:54Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![gilchristt](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.haproxy.org/gilchristt/32/938_2.png) [@gilchristt](https://discourse.haproxy.org/u/gilchristt)\
**Post date:** [January 8, 2020, 5:39pm UTC](https://discourse.haproxy.org/t/using-map-file-in-backend-config-dynamic-backends/4702/1 "2020-01-08T17:39:54Z")

</div>

Hi all

I _think_ that what I want to do can’t be done but I might as well throw it out there to check.

I’ve a hosted solution were multiple customers connect to customer specific URLs and get redirected to unique backends. These backends connect to a Docker swarm where the connection is identical for each customer except for the port they connect to (dedicated interface servers running in Docker)

So for example

> frontend fe-frontdoor  
> blah blah blah…  
> use\_backend dockerSwarmPort1000 if { hdr(host) -i [customerjohn.myservice.com](http://customerjohn.myservice.com) }  
> use\_backend dockerSwarmPort1001 if { hdr(host) -i [customerpaul.myservice.com](http://customerpaul.myservice.com) }  
> use\_backend dockerSwarmPort1002 if { hdr(host) -i [customerringo.myservice.com](http://customerringo.myservice.com) }

> backend dockerSwarmPort1000  
> server docker01 192.168.1.1:1000  
> server docker02 192.168.1.2:1000  
> server docker03 192.168.1.3:1000

> backend dockerSwarmPort1001  
> server docker01 192.168.1.1:1001  
> server docker02 192.168.1.2:1001  
> server docker03 192.168.1.3:1001

I appreciate I can use map files for the front end but is it possible to do the same or similar with the backend to save me having to create hundreds of practically identical backends.

I’m assuming not as you’d need to pass some sort of parameter to the generic backend and I’m not aware of HAProxy supporting this?

Any alternative approaches also welcome.

Thanks

---

<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:** [January 8, 2020, 7:45pm UTC](https://discourse.haproxy.org/t/using-map-file-in-backend-config-dynamic-backends/4702/2 "2020-01-08T19:45:45Z")

</div>

Try using [http-request set-dst-port](https://cbonte.github.io/haproxy-dconv/2.0/configuration.html#4.2-http-request%20set-dst-port) and a map statement as expression.

---

<div class="post-metadata">

**Author:** ![gilchristt](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.haproxy.org/gilchristt/32/938_2.png) [@gilchristt](https://discourse.haproxy.org/u/gilchristt)\
**Post date:** [January 9, 2020, 8:02pm UTC](https://discourse.haproxy.org/t/using-map-file-in-backend-config-dynamic-backends/4702/3 "2020-01-09T20:02:24Z")

</div>

Thanks Lukas, that looks like it’ll do exactly what I need
