Validate haproxy.cfg

Shawn picture Shawn · Sep 21, 2016 · Viewed 87.1k times · Source

Is there any way to validate the HAProxy haproxy.cfg file before restarting the HAProxy service? For example: There might be a small spelling/syntax error in a larger haproxy.cfg file. I searched through several forums, but was unable to find anything in relation to validating the haproxy.cfg files for syntax errors.

As of now, I use a trial and error basis on a developer machine before I upload the changes to a Production Server.

Thanks in Advance..

Answer

Shawn picture Shawn · Nov 7, 2016

The official HaProxy configuration file check was buried in the help sections.

/usr/local/sbin/haproxy --help

There are two ways to check the haproxy.cfg syntax is to use..

One way is the /usr/local/sbin/haproxy -c -V -f /etc/haproxy/haproxy.cfg which validates the file syntax. The -c switch in the command represents the Check, while the others denote "Verbose" & "file".

Another way is to sudo service haproxy configtest

I hope this helps anyone looking to check the syntax of the haproxy.cfg file before restarting the service.

Thanks & Regards

Shawn