Submit button

finnlabs uses HAProxy to balance the requests on the application servers powering our clients web applications. We recommend this fantastic piece of software to anybody as it scales almost infinitely in terms of throughput and concurrent connections. It is even that efficiently designed that under extreme loads most of the times not HAProxy becomes the bottleneck but the underlying operating system.

Unfortunately, HAProxy’s configuration is not very flexible. What was missing the most is some kind of “include” mechanism to split up the single large configuration file into smaller modules (at least in my opinion and according to posts of others in the mailing list).

As a workaround I developed a small python script which takes bits of configuration from a well-defined directory structure and assembles the single configuration file. Including a call to this script into the init script of HAProxy mimics an include mechanism. The script can be downloaded from github. A modified init script based on the one which comes with the HAProxy package of Debian (originally written by Arnaud Cornet) can also be found there. You might need to update the path values in the script.

The script expects a certain fixed directory hierarchy. The top-level directory names are fixed. The other names can be chosen arbitrarily. Note that the second level directory names end up as section names in the final configuration file. Choose your names so that they are accepted by HAProxy. An example directory tree for the configuration is given below. If you put that tree below the /etc/haproxy the script will work out of the box and create the /etc/haproxy/haproxy.cfg file.

  • global
    • 00-base
    • 10-log
  • defaults
    • 00-base
    • 10-errorfiles
  • frontends
    • my-first-frontend
      • 00-ports
      • 10-acls
      • 20-backend1
      • 21-backend2
    • my-second-frontend
  • listen
    • sect1
      • 00-base
      • 10-backend1
    • sect2
  • backends
    • my-first-backend
      • 00-base
      • 10-server1
      • 11-server2
    • my-second-backend

1 Comment

Thanks, this is very helpful and works well!

Leave a comment

If you can read this, you don't use a typical webbrowser that plays nice with CSS.
Please do not fill in anything here!

back to top