Learn how to set up load balancing using HAProxy on AlmaLinux 10 Server.
HAProxy (High Availability Proxy) is an open-source TCP and HTTP load balancer widely used for distributing network traffic across multiple servers. It enhances performance, scalability, and reliability by ensuring no single server becomes overloaded. Known for its speed, stability, and advanced features like health checks, SSL termination, and session persistence, HAProxy is a trusted choice for high-traffic environments and enterprise infrastructure.
In this guide, we’ll set up HAProxy on AlmaLinux 10 and configure it to balance web traffic efficiently across backend servers.
Prerequisites
Before we begin, ensure we have the following:
- An AlmaLinux 10 dedicate server or KVM VPS.
- Basic Linux Command Line Knowledge.
Set Up Load Balancing with HAProxy on AlmaLinux 10
Step 1: Update the Server
First, always make sure our system is up to date.
sudo dnf update -y
sudo dnf upgrade -y
Reboot if the kernel was updated:
sudo reboot
Step 2: Install HAProxy
AlmaLinux 10 already includes HAProxy in its default repo.
sudo dnf install haproxy -y
Check if it’s installed correctly:
haproxy -v
Step 3: Enable and Start the Service
We want HAProxy to run now and also on every reboot.
sudo systemctl enable haproxy
sudo systemctl start haproxy
sudo systemctl status haproxy
If you see active (running), it’s working.
Step 4: Basic Configuration
Edit the main config file:
sudo vi /etc/haproxy/haproxy.cfg
Delete everything from:
#---------------------------------------------------------------------
# main frontend which proxys to the backends
#---------------------------------------------------------------------
And add following content:
frontend web_front
bind *:80
default_backend web_back
backend web_back
balance roundrobin
server web1 192.168.1.101:80 check
server web2 192.168.1.102:80 check
Save and exit (Esc, then type :wq).
Step 5: Check Configuration
Always verify there are no syntax errors before restarting:
sudo haproxy -c -f /etc/haproxy/haproxy.cfg
If it says Configuration file is valid, move ahead.
Restart HAProxy. Apply our new config:
sudo systemctl restart haproxy
Step 6: Open Firewall Port
If the firewall is enabled, allow HTTP traffic.
sudo firewall-cmd --add-port=80/tcp --permanent
sudo firewall-cmd --reload
Step 7: Test the Setup
From any browser or using curl, open our HAProxy server’s IP:
curl http://<HAProxy server IP>
If both backend servers are live, refreshing several times should load them in rotation.
Step 8: Optional – Enable Stats Page
We can also view live HAProxy stats.
Edit config again:
listen stats
bind *:8080
stats enable
stats uri /stats
stats auth admin:password
Then restart HAProxy:
sudo systemctl restart haproxy
If the firewall is enabled, allow HTTP traffic.
sudo firewall-cmd --add-port=8080/tcp --permanent
sudo firewall-cmd --reload
Now open:
http://server-ip:8080/stats
Login with the username and password we just set.
Step 9: Run a test (Optionally)
The haproxy.cfg file you created points to two backend servers, for example:
192.168.1.101:80
192.168.1.102:80
On both backend servers, install and start a tiny web service so HAProxy has something to forward traffic to.
On web1 (192.168.1.101)
sudo dnf install httpd -y
echo "Hello from web1" | sudo tee /var/www/html/index.html
sudo systemctl enable httpd --now
On web2 (192.168.1.102)
sudo dnf install httpd -y
echo "Hello from web2" | sudo tee /var/www/html/index.html
sudo systemctl enable httpd --now
Each server now serves a simple “Hello” message.
Check Backend Reachability from the HAProxy Server
On your HAProxy server, make sure both backend servers respond:
curl http://192.168.1.101
curl http://192.168.1.102
If both return their “Hello” text, HAProxy can talk to them.
Access HAProxy Frontend
Now test HAProxy itself.
From any machine (or from your own HAProxy server), run:
curl http://<haproxy-server-ip>
Example:
curl http://192.168.1.150
You should see:
Hello from web1
Run it again:
curl http://192.168.1.150
You should see:
Hello from web2
That’s load balancing in action. HAProxy is switching between both servers using the round-robin method you configured.
Step 10: Check Logs (Optional but Helpful)
sudo tail -f /var/log/haproxy.log
Conclusion
By following these steps, we’ve built a reliable and scalable load balancing setup with HAProxy on AlmaLinux 10. This setup ensures high availability, improves response time, and enhances redundancy across our backend servers.
In production environments, we can extend this by:
- Using SSL termination for HTTPS traffic
- Implementing sticky sessions for applications needing session persistence
- Adding backend weighting for performance tuning
With HAProxy, our infrastructure gains the stability and flexibility needed for modern web applications. It’s simple, powerful, and ready to handle serious traffic.

