HAProxy 3.2.0
A high-performance TCP and HTTP load balancer with real health checking, several balancing algorithms, and a statistics interface that tells you what each backend is doing.
Download TAR.GZ Project website ↗Download Mirrors
HAProxy distributes traffic across backend servers. Unlike a web server that also proxies, it does one job, and the health checking and statistics are where that shows.
Health checks are the point
backend app_servers
balance roundrobin
option httpchk GET /health
http-check expect status 200
server app1 10.0.1.10:8080 check inter 5s fall 3 rise 2
server app2 10.0.1.11:8080 check inter 5s fall 3 rise 2
inter 5s checks every five seconds, fall 3 removes a backend after three failures, rise 2 returns it after two successes.
Point checks at a cheap dedicated endpoint. A check hitting your homepage, which queries a database, will fail exactly when the system is busiest, pulling backends out and cascading load onto the rest.
Balancing algorithms
balance roundrobin # even distribution, the default
balance leastconn # fewest active connections
balance source # hash the client IP, sticky
leastconn matters when request durations vary widely, such as WebSockets, because round-robin piles long connections onto one server.
TCP mode
listen postgres
bind *:5432
mode tcp
balance leastconn
server db1 10.0.2.10:5432 check
server db2 10.0.2.11:5432 check backup
mode tcp forwards bytes without parsing them, so you can proxy databases, SSH, and message brokers. backup marks a server used only when the primaries are down.
The statistics page
listen stats
bind *:8404
stats enable
stats uri /
stats auth admin:changeme
Live per-backend status, sessions, errors, and check results. When something is wrong this page usually says what, and it is the best thing about running HAProxy. Do not expose it publicly.
Always validate before reloading
sudo haproxy -c -f /etc/haproxy/haproxy.cfg
sudo systemctl reload haproxy
A syntax error on reload takes the proxy down and everything behind it with it.
HAProxy or nginx
For one backend, nginx or Caddy is simpler and gives you TLS and static file serving. HAProxy earns its place with several backends, real health checking, or non-HTTP protocols.
Our HAProxy guide covers configuration in more depth.
Verify Your Download
Source releases on haproxy.org are published with checksums and GPG signatures.