Example configuration of HAProxy Community Edition

This article provides a configuration example for HAProxy Community Edition. If necessary, you can change the settings to suit your needs. This configuration was tested with package version 2.4.24-0ubuntu0.22.04.2.

To configure HAProxy Community Edition:

  1. On the host where you are installing the balancer, start the command line console and install the haproxy package:

    sudo apt update && sudo apt install haproxy -y

  2. Go to the /etc/haproxy directory and edit the haproxy.cfg configuration file as shown in the example below. The order of the sections and parameters in the configuration file is significant and must be the same as in the example given.

    Example of settings in the haproxy.cfg file if a TLS certificate is not used

    Example of settings in the haproxy.cfg file when using a TLS certificate

  3. Save the haproxy.cfg configuration file.
  4. Check the correctness of the haproxy.cfg configuration file using the following command:

    haproxy -f /etc/haproxy/haproxy.cfg -c

    If the check command returns an error, make sure the contents of the haproxy.cfg configuration file matches the example and make changes if necessary. If the check command does not return any errors, proceed to starting the balancer.

  5. Start the balancer:

    sudo systemctl start haproxy

    If the haproxy service needs to be enabled before starting, run the following sequence of commands:

    sudo systemctl enable haproxy

    sudo systemctl start haproxy

The balancer is configured.

Page top