Search code examples
haproxy

HAProxy dynamic configuration


Here is my setup:

  • we do have one external load balancer (AWS) attached to root domain mydomain.com
  • external load balancer forward traffic to HAProxy instance, and haproxy have to forward it further to on of two internal load balancers
  • we have 2 internal load balancers, first point to latest version of our app, second to minus one version
  • each of our client can have 1 to many subdomains like sub1.mydomain.com, sub2. sub3
  • some subdomains should be redirected to old version, some to new, so same client can have old and new in subdomains

Basically:

 sub1.mydomain.com -> latest-load-balancer
 sub2.mydomain.com -> older-load-balancer

The problem is how to setup this routing, we can't stop/start haproxy for each new subdomain. And it could be more them 10k of that subdomains in future.


Solution

    1. haproxy can use maps to decide which backend (internal load balancer) to use, based on the domain.
    2. haproxy can be reloaded instead of restarted when the map changes.
    3. If you do not wish to even reload, you could pass map commands to the unix socket, thus changing the map in realtime.