Automation Ninja's Dojo

HAproxy – backend and domain management using map

This is quick write up how to use single line for easy backend mapping within HAproxy. This has been showed to me by my buddy while challenging current configuration which started to grow.

The first thing you will need to have is to create a map file. Its structure its simple – first column is what comes is , second is what comes out. So for our domain mapping we can have file with domain name and respective backend i.e.

Next is just configuration line on your front end associating domains with backends based on the host header


And that is it 🙂 you have now got your self really dynamic configuration


2 thoughts on “HAproxy – backend and domain management using map

  1. That looks really convenient and quick configuration method.
    What about multiple backends? Is there any example also for tcp frontend?

    1. Hi,

      Havent tested for TCP based backends but I think it would follow the same principal. The solution shown here worked without any problems with multibackend environment by just having multiple entries in the map file.

Leave a Reply

Your email address will not be published. Required fields are marked *

%d bloggers like this: