HTTP Load Balancing
Cheat sheet · https://pcornel.dk/topic.php?topic=6271
Answer
HTTP (layer 7) load balancing distributes requests across backend servers based on HTTP information, with health checks, persistence and header handling. nginx (upstream) and HAProxy are the common software implementations.
Remember
Open-source nginx has only passive health checks (max_fails/fail_timeout); HAProxy has active checks. Retrying is safe only for idempotent requests. Drain a server before maintenance. Backends see the balancer's IP unless X-Forwarded-For or PROXY protocol is configured and trusted.
First checks
- HAProxy:
echo "show stat" | socat stdio /run/haproxy/admin.sock | cut -d, -f1,2,18,19— backend/server status. - HAProxy:
haproxy -c -f /etc/haproxy/haproxy.cfg— config check. - nginx:
nginx -t; error log 'upstream ... failed' / 'no live upstreams'. curl -sS -o /dev/null -w "%{http_code}\n" http://<backend>:<port>/healthz— health endpoint directly.
Commands
show stat
Verify in this order
client → frontend/listener (TLS) → routing rules (host/path) → backend pool → algorithm + persistence → healthy server → response; health checks update membership
Read-only verification commands unless stated otherwise. Confirm syntax for your platform and release. Full reference: https://pcornel.dk/topic.php?topic=6271