How to Install and Configure HAProxy as a Load Balancer on Ubuntu 24.04
Learn how to install and configure HAProxy as a high-performance load balancer on Ubuntu 24.04, covering setup, routing and SSL.
If you are scaling your infrastructure, routing traffic efficiently is just as critical as the compute resources behind it. HAProxy is a standard choice for high-performance TCP/HTTP load balancing, and it is lightweight enough to run on a modest server.
What is covered in this tutorial
This guide sets up HAProxy as a reverse proxy and load balancer on Ubuntu 24.04 LTS with a simple three-node layout: one HAProxy node and two Nginx backend servers.
Step-by-step overview
- Prepare the backends: install Nginx, create a distinct page on each server so you can see the balancing work, and restrict port 80 with UFW so only the load balancer can reach it.
- Install HAProxy: install it from the Ubuntu repositories (version 2.8 or newer) and verify the version.
- Configure HAProxy: back up the default file, then use a consolidated config with round-robin balancing, HTTP health checks, the
forwardforoption to pass real client IPs, and a 10-second request timeout to help against Slowloris attacks. - Validate and restart: always run a syntax check before restarting so a typo doesn’t cause downtime.
- Test it: use a simple
curlloop and watch responses alternate between the two servers, then check the statistics dashboard on port 8404. - Add SSL/TLS termination: combine your certificate and key into one PEM file, bind port 443, and redirect HTTP to HTTPS.
- Remove the single point of failure: run two HAProxy nodes sharing a virtual IP with Keepalived.
Troubleshooting tips included
- 503 Service Unavailable errors
- Configuration files that fail to load
- Backends stuck in the DOWN state
📖 Read the full tutorial with all commands and config files: https://www.fitservers.com/tutorials/howto/install-configure-haproxy-load-balancer/

Comments
Post a Comment