How to Configure Load Balancing with HAProxy

How to Configure Load Balancing with HAProxy

HAProxy is an open source software that functions as a load balancing and proxy for TCP and HTTP. Load balancing is a method for distributing traffic to multiple servers.

Topologi Load Balancing
Load Balancing Topology

0.Equipment used

Equipment used in this tutorial:

  • OS Ubuntu 18.04 LTS
  • HAProxy
  • Nginx web server
  • PHP-FPM 7.2
  • Node1:
  • Node2:
  • LoadBalancer:
  • Domain:

Node1 and Node2 have already installed Nginx web server and PHP-FPM 7.2. Each node is made index.php file containing the text node1 and node2 as a test page to find out which pages are read from which node.

1.Install HAProxy

Update and install HAProxy.

2.Configure HAProxy

Open configuration file of HAProxy.

Default file configuration haproxy.cfg.

Add a configuration for the HAProxy listener.

Add configuration for web server backend.

Additional configuration for HAProxy statistics.

The final result is HAProxy configuration.

Verify the configuration and restart HAProxy.


Browse the domain, refresh the page repeatedly until it displays the index.php file of Node1 and Node2.

Halaman index.php dari Node1
index.php page from Node1
Halaman index.php dari Node2
index.php page from Node2


Browse to read HAProxy statistics.

Statistik HAProxy
HAProxy statistics page

Leave a Reply

Your email address will not be published. Required fields are marked *