Load balancing config without the boilerplate
A working HAProxy setup needs a global block, sane defaults, a frontend that binds and routes, and a backend pool with health checks. This builder writes all of it from a form — pick the mode, list your servers, choose an algorithm, and optionally add SSL and a stats page.
How it works
The config starts with a global block (logging, max connections, dropping privileges to the haproxy user) and a defaults block with HTTP logging, forwardfor, and connection and server timeouts. The frontend binds to your chosen port; when SSL termination is on it adds ssl crt <pem> and sets X-Forwarded-Proto https. The backend applies your chosen balance algorithm and, if health checks are enabled, runs option httpchk GET /health with http-check expect status 200, tagging each server line with check. Each backend you enter as name host:port becomes a server directive. An optional listen stats block exposes the live dashboard on :8404/stats.
Tips and example
- HAProxy wants a single combined PEM (certificate + key + chain) for
ssl crt, unlike Apache which uses separate files. - Use
leastconnrather thanroundrobinwhen request durations vary a lot, such as file uploads or slow reports. - Always set health checks in production so a crashed backend is pulled from rotation automatically instead of returning errors.
- Firewall the stats page or bind it to an internal interface —
stats admin if TRUElets anyone who reaches it disable servers.