1001Ferramentas
🔀 Dev

HAProxy Frontend/Backend Generator

Create matching frontend/backend in HAProxy with bind, mode http, balance roundrobin and servers. Minimal working config.

HAProxy frontend and backend, the minimum pair

HAProxy configuration falls into two halves that must exist together: the frontend, which receives connections and listens on a port, and the backend, which lists the real servers and says how to spread load between them. Neither does anything alone — and the link between them is the backend name quoted in the frontend, which is where the configuration usually breaks on a typo.

Fill in the bind address, the servers and the balancing algorithm, and the page assembles both sections wired together. The available algorithms cover the usual cases: plain round robin, the one sending traffic to whichever server has fewest active connections, and the one choosing by source address, keeping the same client on the same server.

It is worth knowing what the minimum pair leaves out. Without health checking configured on the servers, HAProxy keeps sending traffic to a dead backend — the check directive is what makes it pull the server out of rotation on its own. And to serve HTTPS you need the certificate on the bind line, plus handling the HTTP to HTTPS redirect in the frontend itself.

Frequently asked questions

Which balancing algorithm should I pick?
Round robin is the sensible default when requests cost roughly the same. Least connections does better when duration varies a lot, as with WebSocket or downloads. Source-address hashing helps when there is no shared session store — but pinning a client to a server hurts when that server goes down.
How do I set up health checks?
By adding the check directive on each server line, which enables the basic connection test. To genuinely check the application, declare an HTTP health request in the backend, pointing at a route that exercises what matters — checking only that the port is open lets a live-but-stuck process through.
What changes between HTTP and TCP mode?
In HTTP mode HAProxy parses the requests, which allows routing by path or header, rewriting, and per-request logging. In TCP mode it merely forwards bytes, which is what non-HTTP protocols need. The wrong mode is a common cause of a connection that opens and never answers.

Related Tools