I'm building an haproxy config file that has multiple front and backends. It's going to be several hundred lines long and I'd rather split it up into separate files for each of the different websites that I want to loadbalance.
Does HAProxy offer the ability to link to partial config files from the main haproxy.cfg file?
When HAProxy Enterprise is used as a reverse proxy in front of your backend servers, a frontend section defines the IP addresses and ports that clients can connect to. You may add as many frontend sections as needed to expose various websites or applications to the internet.
The maxcon attributes represent a load factor multiplier that is used to compute the maximum number of connections that HAProxy allows for backends.
The HAProxy configuration file is normally called /usr/local/etc/haproxy/haproxy. cnf and is usually in a directory similar to /usr/local/etc/haproxy . The configuration file shows a single backend to explain the changes to requests and responses that the HAProxy needs to make.
Global. At the top of your HAProxy configuration file is the global section, identified by the word global on its own line. Settings under global define process-wide security and performance tunings that affect HAProxy at a low level.
Configuration files can't be linked together from a configuration directive.
However HAProxy can load multiple configuration files from its command line, using the -f
switch multiple times:
haproxy -f conf/http-defaults -f conf/http-listeners -f conf/tcp-defaults -f conf/tcp-listeners
If you want to be flexible with the amount of config files you can even specify a directory like this: -f /etc/haproxy
. The files will then be used in their lexical order, newer files overriding older files. See the mailing list for an example, if provides links to the documentation. This information can be found in the management guide, not the regular docs.
Stumbled on this answer where the author created scripts to imitate nginx disable enable sites functionality. In the haproxy init.d startup he uses script loop to build the haproxy -f commands concatenation.
/etc/init.d/haproxy:
EXTRAOPTS=`for FILE in \`find /etc/haproxy/sites-enabled -type l | sort -n\`; do CONFIGS="$CONFIGS -f $FILE"; done; echo $CONFIGS`
haensite
script:
#!/bin/bash if [[ $EUID -ne 0 ]]; then echo "You must be a root user" 2>&1 exit 1 fi if [ $# -lt 1 ]; then echo "Invalid number of arguments" exit 1 fi echo "Enabling $1..." cd /etc/haproxy/sites-enabled ln -s ../sites-available/$1 ./ echo "To activate the new configuration, you need to run:" echo " /etc/init.d/haproxy restart"
hadissite
script:
#!/bin/bash if [[ $EUID -ne 0 ]]; then echo "You must be a root user" 2>&1 exit 1 fi if [ $# -lt 1 ]; then echo "Invalid number of arguments" exit 1 fi echo "Disabling $1..." rm -f /etc/haproxy/sites-enabled/$1 echo "To activate the new configuration, you need to run:" echo " /etc/init.d/haproxy restart"
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With