HAProxy spreads traffic across multiple servers, with health checks and centrally terminated TLS. Step-by-step, production-ready setup.
1. Install
sudo apt -y install haproxy
haproxy -v
2. Frontend + backend
# /etc/haproxy/haproxy.cfg — frontend + backend
frontend web
bind *:80
bind *:443 ssl crt /etc/haproxy/certs/site.pem
redirect scheme https if !{ ssl_fc }
default_backend app_servers
backend app_servers
balance roundrobin
option httpchk GET /health
server app1 10.0.0.11:8080 check
server app2 10.0.0.12:8080 check
3. Algorithms + sticky
# algoritmi uzuali:
# balance roundrobin -> pe rand
# balance leastconn -> cel mai putin incarcat (bun pt sesiuni lungi)
# balance source -> sticky pe IP client
# sticky pe cookie:
# cookie SRV insert indirect nocache
4. Stats page
# pagina de statistici (protejata cu user/parola)
listen stats
bind *:8404
stats enable
stats uri /
stats auth admin:parolaAici
5. Verify
sudo haproxy -c -f /etc/haproxy/haproxy.cfg # verifica sintaxa
sudo systemctl reload haproxy
curl -I http://LB_IP/ # trebuie sa raspunda un backend
Conclusion
You now have load balancing with health checks and TLS, no single point of failure on the app. We design and configure it for you.