Connect HTTP backends with HAProxy: configure frontends, backends, and health checks
In HAProxy, a frontend accepts client connections on an address and port, while a backend defines the server pool that handles requests. For a small HTTP service, configure a distribution method and health checks, validate the configuration, then verify real responses. This guide follows the HAProxy 3.2 LTS docs and shows a basic Linux HTTP backend.
In HAProxy, a frontend accepts client connections on an address and port, while a backend defines the server pool that handles requests. For a small HTTP service, configure a distribution method and health checks, validate the configuration, then verify real responses. This guide follows the HAProxy 3.2 LTS docs and shows a basic Linux HTTP backend.
What the configuration sections do
global contains process-level settings; defaults contains common settings inherited by following proxy sections; frontend accepts incoming connections; backend defines a server pool. mode http enables Layer 7 HTTP processing. mode tcp forwards at Layer 4 without parsing HTTP headers. The frontend and backend in one flow need compatible modes. balance selects a backend algorithm. roundrobin cycles through servers according to weights; it is not automatically best for every workload, such as highly variable request times or sessions requiring persistence.
Distinguish two health-check levels. With only server ... check, HAProxy normally attempts a TCP connection to the backend. That proves the port can accept a connection, not that the application is ready to serve requests. Add option httpchk GET /healthz to send an HTTP check request. By default, 2xx and 3xx responses count as valid; other responses or no response indicate failure. Choose a health URI that represents actual readiness and ensure its response matches the service's criteria.
Minimal example
This illustrative configuration accepts HTTP on 127.0.0.1:8080 and distributes it across two local backends at ports 8001 and 8002. It assumes the backend returns 2xx or 3xx from /healthz when ready. Change addresses, configuration paths, and service procedures for your installation.
global
maxconn 2048
defaults
mode http
timeout connect 5s
timeout client 30s
timeout server 30s
frontend web_in
bind 127.0.0.1:8080
default_backend app_servers
backend app_servers
balance roundrobin
option httpchk GET /healthz
server app1 127.0.0.1:8001 check
server app2 127.0.0.1:8002 checkTimeouts in defaults are example values that prevent idle connections from remaining open indefinitely. A 5-second connection timeout and 30-second client/server inactivity limits are not universal recommendations. Set them for application latency, streaming/long polling, and deployment limits. bind 127.0.0.1:8080 listens only locally. Review firewall and exposure before changing it to a public address.
Validate and verify behavior
Identify the installed HAProxy binary and configuration path; the `-f` path below is an example.
Check the file with `sudo haproxy -c -f /etc/haproxy/haproxy.cfg`. If validation fails, fix the reported line/section first. Do not restart or reload before it passes.
Apply the configuration using the normal deployment procedure. Reload mechanisms vary by package and service manager; use the procedure for your environment.
Run `curl -i http://127.0.0.1:8080/` and inspect status and body. Backend application logs can show which server received it. Distribution can be affected by concurrent connections, weights, persistence, and other conditions; a short series of requests is not guaranteed to alternate one by one.
In a safe test environment, deliberately make one backend's `/healthz` fail, observe its health state and traffic exclusion, then restore the endpoint and confirm the server rejoins. Do not arbitrarily stop a server carrying production traffic.
Enabling HAProxy's statistics page or admin socket requires separate access control, authentication, and network restrictions; this guide does not enable either. Keep a copy of the current config before changing a service and record checks performed on the actual instance. This example was not run or subjected to load/failure testing.
Troubleshoot and recover
**HAProxy will not start:** inspect validation errors, unsupported directives, include files, and file permissions. Syntax can vary by release; compare the installed version with the 3.2 docs.
**Cannot connect to the frontend:** check `bind` address/port, other processes on that port, firewall, and HAProxy's permission to listen. The local-only example is intentionally unreachable from remote hosts.
**Response is 503 or no backend is selected:** test each backend address/port directly and inspect check status. Check the health path, any required Host header, and the app's readiness criteria.
**TCP check passes but the app fails:** TCP only verifies connection reachability. Configure an appropriate HTTP check if application readiness matters and confirm the app's health URL returns an accepted status.
**Checks keep marking a backend DOWN:** compare HAProxy and backend logs by timestamp; verify check interval, connectivity, Host/path, and status. Do not loosen checks blindly; decide what condition they should protect against.
If a change causes trouble, return to the last known-good configuration, then repeat haproxy -c and a real HTTP check. Health checks are availability signals; they do not prove data integrity or that every part of the application works.
Sources and scope
HAProxy 3.2 [Configuration Manual](https://docs.haproxy.org/3.2/configuration.html) — sections, modes, balancing, server checks, HTTP checks
HAProxy [Configuration basics](https://www.haproxy.com/documentation/haproxy-configuration-tutorials/proxying-essentials/configuration-basics/) — roles of `global`, `defaults`, `frontend`, `backend`
HAProxy [Frontends](https://www.haproxy.com/documentation/haproxy-configuration-tutorials/proxying-essentials/configuration-basics/frontends/) — bind and default backend
HAProxy [Backends](https://www.haproxy.com/documentation/haproxy-configuration-tutorials/proxying-essentials/configuration-basics/backends/) — server pools, balancing, TCP health checks
HAProxy [Health checks](https://www.haproxy.com/documentation/haproxy-configuration-tutorials/reliability/health-checks/) — HTTP check requests
Scope: basic HTTP frontend/backend configuration based on HAProxy 3.2 LTS docs. Packages, service procedures, and application readiness contracts vary. The configuration is illustrative; it was not run, validated with an installed package, or tested under injected failure or load.