My haproxy loadbalancer currently runs using a single config file, /etc/haproxy/haproxy.cfg:
ExecStart=/usr/sbin/haproxy-systemd-wrapper -f /etc/haproxy/haproxy.cfg -p /run/haproxy.pid $OPTIONS
I want to split the haproxy.cfg to several files with less content as some of the frontend and backend definitions could be generated using Ansible and templating. Can I just simply modify the -f
argument to /etc/haproxy/*.cfg
? Or should I rather point it to a dedicated directory e.g. /etc/haproxy/conf.d
?
And a bonus question. Given the above is possible and I end up with a number of cfg files, with different frontend and backend stanzas, should I still include the global and defaults stanzas in every single cfg file?
Best Answer
You can point HAProxy to load configuration from a directory, depending on your HAProxy version that is. Also, yo do not need to enter multiple global sections in separate configuration files.
Check HAProxy Management documentation for your HAProxy server version for
-f
command line switch. Versions 1.6 and lower could only load a file, but you could add multiple-f <cfg1.cfg -f cfg2.cfg
options. This is for eg. version 1.8:But beware of how eg. multiple default section work: