August 29, 2026 · by Alex M.
As your web application grows, a single server can quickly become both a performance bottleneck and a single point of failure. HAProxy (High Availability Proxy) is one of the most battle-tested open-source load balancers and proxies available, trusted by companies like GitHub, Twitter, and Stack Overflow to handle millions of requests per day.
In this guide you'll learn how to install and configure HAProxy on a NVMe VPS running Ubuntu 22.04 LTS — from initial setup to a fully functional load-balanced environment with health checks, SSL termination, and a real-time monitoring dashboard.
HAProxy is a Layer 4 (TCP) and Layer 7 (HTTP) load balancer and proxy server that distributes incoming traffic across multiple backend servers. Key benefits include:
Whether you're running a WordPress site across multiple instances or a distributed Node.js API on a SSD VPS, HAProxy is an excellent choice.
For this tutorial, we'll configure:
Users → HAProxy (192.168.1.10) → app1 (192.168.1.11:80)
→ app2 (192.168.1.12:80)
You can easily extend this setup with more backend nodes as your traffic grows.
SSH into your server and run:
sudo apt update && sudo apt upgrade -y
sudo apt install haproxy -y
Verify the installed version:
haproxy -v
You should see something like HAProxy version 2.4.x. Check that the service is running:
sudo systemctl status haproxy
On each backend server (app1 and app2), install Nginx to simulate a web application:
sudo apt install nginx -y
To tell the servers apart, customise the default page:
On app1:
echo "<h1>Backend: app1</h1>" | sudo tee /var/www/html/index.html
On app2:
echo "<h1>Backend: app2</h1>" | sudo tee /var/www/html/index.html
Enable and start Nginx on both servers:
sudo systemctl enable nginx && sudo systemctl start nginx
The main configuration file is located at /etc/haproxy/haproxy.cfg. Always back it up before making changes:
sudo cp /etc/haproxy/haproxy.cfg /etc/haproxy/haproxy.cfg.bak
Open the file for editing:
sudo nano /etc/haproxy/haproxy.cfg
Replace the contents with the following configuration:
global
log /dev/log local0
log /dev/log local1 notice
chroot /var/lib/haproxy
stats socket /run/haproxy/admin.sock mode 660 level admin expose-fd listeners
stats timeout 30s
user haproxy
group haproxy
daemon
maxconn 50000
defaults
log global
mode http
option httplog
option dontlognull
timeout connect 5s
timeout client 30s
timeout server 30s
errorfile 400 /etc/haproxy/errors/400.http
errorfile 503 /etc/haproxy/errors/503.http
# Frontend — receives incoming traffic
frontend http_front
bind *:80
default_backend http_back
# Backend — application servers
backend http_back
balance roundrobin
option httpchk GET /
server app1 192.168.1.11:80 check
server app2 192.168.1.12:80 check
# Statistics dashboard
listen stats
bind *:8080
stats enable
stats uri /haproxy?stats
stats refresh 10s
stats auth admin:StrongPassword123
Note: Replace
192.168.1.11and192.168.1.12with your actual backend server IP addresses, and changeStrongPassword123to a secure password.
Before applying changes, validate the configuration syntax:
sudo haproxy -c -f /etc/haproxy/haproxy.cfg
If you see Configuration file is valid, you're good to go. Restart the service:
sudo systemctl restart haproxy
sudo systemctl enable haproxy
Open the required ports:
sudo ufw allow 80/tcp
sudo ufw allow 8080/tcp
sudo ufw enable
For more tips on hardening your Linux server, visit the CLIQHOST blog where you'll find in-depth security guides.
Send several requests to your HAProxy server's IP:
curl http://192.168.1.10
curl http://192.168.1.10
curl http://192.168.1.10
The responses should alternate between Backend: app1 and Backend: app2 — Round Robin in action.
Access the statistics dashboard at:
http://192.168.1.10:8080/haproxy?stats
You'll see the status of each backend server, active connections, request rates and much more.
HAProxy supports several algorithms. Change the balance directive in the backend section:
| Algorithm | Description |
|---|---|
roundrobin |
Distributes requests cyclically |
leastconn |
Sends to the server with the fewest active connections |
source |
IP Hash — the same user always hits the same server |
uri |
Based on URI — useful for caching |
random |
Randomly selects a server |
For stateful applications (e.g., shopping carts), use source or configure sticky sessions.
In production, all traffic must be encrypted. HAProxy can handle SSL termination natively. You can obtain a trusted certificate through CLIQHOST SSL certificates.
Combine the certificate and private key into a single .pem file:
cat mydomain.crt mydomain.key > /etc/haproxy/certs/mydomain.pem
Update the frontend section:
frontend https_front
bind *:443 ssl crt /etc/haproxy/certs/mydomain.pem
redirect scheme https if !{ ssl_fc }
default_backend http_back
frontend http_front
bind *:80
redirect scheme https code 301
The check keyword next to each server entry enables health checks. HAProxy periodically sends a GET / request and automatically removes any non-responsive server from rotation.
You can fine-tune the behaviour:
server app1 192.168.1.11:80 check inter 3s rise 2 fall 3
inter 3s — check every 3 secondsrise 2 — mark server healthy after 2 consecutive successesfall 3 — remove from rotation after 3 consecutive failuresIf your application has outgrown a single VPS, consider a managed dedicated server where CLIQHOST handles all administration for you, or an unmanaged dedicated server if you prefer full control. HAProxy scales effortlessly to handle millions of requests per day on powerful hardware.
For high-performance Intel-based infrastructure, check out CLIQHOST Intel dedicated servers.
cp haproxy.cfg haproxy.cfg.bak before edits.stats auth.timeout server to 60s or more.option httpchk — without health checks, HAProxy will forward traffic to downed servers.systemctl enable — HAProxy won't restart automatically after a reboot.HAProxy is a mature, high-performance tool that transforms your infrastructure from a single point of failure into a resilient, scalable system. With the configuration in this guide, you have a functional load balancer with automatic health checks, SSL termination, and a real-time monitoring dashboard.
Ready to get started? Launch a high-performance NVMe VPS and follow this guide — it only takes a few minutes to have HAProxy up and running. Prefer to let the experts handle it? CLIQHOST server management services cover setup, monitoring and ongoing maintenance. Have questions? Contact our team — we're happy to help.
Real reviews from customers who trust CLIQHOST for performance, reliability and expert technical support.
"We moved our online shop from a foreign host and the difference is night and day — pages load instantly and support replies in minutes, in Romanian."
"Migrated 12 client sites to CLIQHOST. Free migration, zero downtime, and the cPanel setup is exactly what my team needed. Highly recommend."
"Our NVMe VPS handles traffic spikes without a sweat. Full root, local datacenter, and billing in MDL — everything we wanted from a provider."