HAProxy community

Using map file in backend config / dynamic backends?

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 }
use_backend dockerSwarmPort1001 if { hdr(host) -i customerpaul.myservice.com }
use_backend dockerSwarmPort1002 if { hdr(host) -i customerringo.myservice.com }

backend dockerSwarmPort1000
server docker01
server docker02
server docker03

backend dockerSwarmPort1001
server docker01
server docker02
server docker03

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.


Try using http-request set-dst-port and a map statement as expression.

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