haproxy, one keyword per page
Twenty-eight lessons on the keywords of an HAProxy configuration file: the frame, what a keyword is, reading a config file, global and defaults; the front doors, frontend, bind, mode and timeout client; behind the doors, backend, server, default_backend and use_backend; choosing, balance, weight, hash-type and stick-table; eyes and guards, check, option httpchk, retries and maxconn; rewriting the wire, acl, http-request, redirect and cookie; and watching it run, stats enable, log, timeout connect and one honest hour, every claim traced to the official configuration manual or a loopback run of HAProxy 2.8.30 on this machine.
One keyword, one page, one honest loopback run. That is the shape of this book.
haproxy, one keyword per page
Twenty-eight lessons on the keywords of an HAProxy configuration file: the frame, what a keyword is, reading a config file, global and defaults; the front doors, frontend, bind, mode and timeout client; behind the doors, backend, server, default_backend and use_backend; choosing, balance, weight, hash-type and stick-table; eyes and guards, check, option httpchk, retries and maxconn; rewriting the wire, acl, http-request, redirect and cookie; and watching it run, stats enable, log, timeout connect and one honest hour, every claim traced to the official configuration manual or a loopback run of HAProxy 2.8.30 on this machine.
Set in Space Grotesk, Inter and JetBrains Mono (SIL Open Font License).
An honest book about its demo: HAProxy 2.8.30-0ubuntu0.24.04.2 on Ubuntu 24.04 ran a loopback demo on the machine that built this book: haproxy -c -f printed "Configuration file is valid"; it started with -f, -D and -p; ss listed the four loopback listeners; eight GETs through frontend 127.0.0.1:18099 alternated strictly between two toy Python backends; one kill later, the next six GETs all landed on the survivor; the stats page on 127.0.0.1:18098 returned a CSV marking apis,srv1 DOWN, L4CON, "Connection refused" and apis,srv2 UP, L7OK,200; the run stopped on kill -TERM of the pidfile pid. Every quoted line is captured verbatim in /root/.hermes/cache/web/slot189park/haproxy_demo_log1.txt through haproxy_demo_log7.txt; no output was invented, nothing outside loopback was touched, no real secret anywhere. All other facts trace to the cached HAProxy configuration manual (master text, 2.8 rendering) or the two cached Wikipedia articles; the haproxy(1) man page cache came back empty here, so no page cites a man page: command-line facts quote the captured run. No facts from Reddit, Stack Overflow, vendor blogs or commercial sites; practice exercises carry 'this book's plan'. This book explains what the keywords do; it is not production security advice. Independent, not affiliated with HAProxy Technologies or the Wikimedia Foundation.
Your purchase is for personal use only. You do not have redistribution rights: please do not share, resell, or republish this book or its pages.
© 2026 Steve Hodgkiss. All rights reserved. Personal use only; no redistribution rights.
Edition 1.0 · stevehodgkiss.net
Contents
Per the HAProxy configuration manual, the first word or sequence of words of a line is one of the keywords or keyword sequences listed in this document; all other words are all arguments of the first one; certain keywords delimit a section inside which only a subset of keywords are supported; This section provides a description of each keyword and its usage. Per the Wikipedia article HAProxy, HAProxy is a free and open source software that provides a high availability load balancer and proxy (forward proxy, reverse proxy) for TCP and HTTP-based applications that spreads requests across multiple servers. Per a real run on the build machine captured at dispatch, Configuration file is valid. Per this book's plan, this page is the frame of the whole book: twenty-eight lessons, each one built around a single keyword, read in the order a config reads top to bottom.
what a keyword is
In HAProxy's own words, the first word or sequence of words of a line is one of the keywords, and all other words are all arguments of the first one. One line, one keyword, one job.
The reference chapter provides a description of each keyword and its usage, and certain keywords delimit a section with its own subset of them. That is the whole grammar this book walks.
Per this book's plan: twenty-eight pages, one keyword each, in the order a config reads.
Open any HAProxy config you own: can you circle the first word of every line?
Per the HAProxy configuration manual, A "frontend" section describes a set of listening sockets accepting client connections. Per a real run on the build machine captured at dispatch, frontend web; bind 127.0.0.1:18099; LISTEN 0 256 127.0.0.1:18099 0.0.0.0:*; GET #1 -> HTTP 200 | response from backend-one on 127.0.0.1:18101. Per this book's plan, the front-door part opens here: the frontend is the first section a request meets, and its two helper keywords bind and mode follow.
frontend
The definition, verbatim: A "frontend" section describes a set of listening sockets accepting client connections. The demo named one: frontend web, bound to 127.0.0.1:18099.
The listener was real, quoted from ss: LISTEN 0 256 127.0.0.1:18099 0.0.0.0:*. The first request through it answered GET #1 -> HTTP 200 | response from backend-one on 127.0.0.1:18101.
A frontend accepts. A backend decides. The config keeps them apart on purpose.
Start one frontend on loopback and confirm it with ss before adding a backend.
Per the HAProxy configuration manual, A "backend" section describes a set of servers to which the proxy will connect to forward incoming connections. Per a real run on the build machine captured at dispatch, backend apis; GET #1 -> HTTP 200 | response from backend-two on 127.0.0.1:18102; GET #2 -> HTTP 200 | response from backend-one on 127.0.0.1:18101. Per the Wikipedia article HAProxy, spreads requests across multiple servers. Per this book's plan, backend is the pivot of the book: a frontend ends and a backend begins, and the three following pages hold its three working keywords.
backend
The manual defines it in one line: A "backend" section describes a set of servers to which the proxy will connect. Wikipedia frames the purpose: a proxy for TCP and HTTP that spreads requests across multiple servers.
The demo's backend apis held two servers, and the spread was visible request by request: GET #1 -> HTTP 200 | response from backend-two on 127.0.0.1:18102, then GET #2 -> HTTP 200 | response from backend-one on 127.0.0.1:18101.
Frontends accept. Backends choose. The next three pages are the members and the pointers.
Name every server in one backend you own: which one gets the next request?
Per the HAProxy configuration manual, Define the load balancing algorithm to be used in a backend. Per the HAProxy configuration manual, Each server is used in turns, according to their weights. This is the smoothest and fairest algorithm when the server's processing time remains equally distributed. Per the HAProxy configuration manual, It is limited by design to 4095 active servers per backend. Per the HAProxy configuration manual, The server with the lowest number of connections receives the connection. Per the HAProxy configuration manual, The source IP address is hashed and divided by the total weight. Per the HAProxy configuration manual, This algorithm hashes either the left part of the URI. Per the Wikipedia article Load balancing (computing), In a round-robin algorithm, the first request is sent to the first server, then the next to the second, and so on down to the last. Per a real run on the build machine captured at dispatch, balance roundrobin; GET #1 -> HTTP 200 | response from backend-two on 127.0.0.1:18102; GET #8 -> HTTP 200 | response from backend-one on 127.0.0.1:18101. Per this book's plan, roundrobin, leastconn, source and uri are values of balance, so they share this one page exactly as the manual's balance entry folds them under one keyword.
balance
balance Define the load balancing algorithm to be used in a backend. The demo: balance roundrobin, where Each server is used in turns.
Values share the one keyword: leastconn takes The server with the lowest number of connections; source hashes the client address; uri hashes the path. Wikipedia's round-robin picture: the first request is sent to the first server. Which backend is "first" is the proxy's own bookkeeping.
The run: GET #1 -> HTTP 200 | response from backend-two, eight turns, even.
Swap balance uri into a scratch backend: does the same path keep its server?
Per the HAProxy configuration manual, This option enables health checks on a server. Per the HAProxy configuration manual, when not set, no health checking is performed, and the server is always considered available. Per the HAProxy configuration manual, The "fall" parameter states that a server will be considered as dead after <count> consecutive unsuccessful health checks. This value defaults to 3 if unspecified. Per a real run on the build machine captured at dispatch, server srv1 127.0.0.1:18101 check inter 1s fall 2 rise 2; $ kill 3745913 # pid of the backend-one toy server; (waiting 5 seconds for inter 1s / fall 2 health checks to mark srv1 down); GET #6 -> HTTP 200 | response from backend-two on 127.0.0.1:18102; 0,0,0,0,DOWN,1,1,0,2,1; L4CON,,0,0,5; Connection refused; Layer4 connection problem. Per this book's plan, the kill of backend-one is the whole demo of this word: the check keyword is what noticed.
check
check enables health checks on a server; without it, no health checking is performed. The demo carried check inter 1s fall 2 rise 2: two failed probes, then dead.
Then kill 3745913, and the log waited 5 seconds for inter 1s / fall 2 health checks to mark srv1 down. The CSV wrote the verdict: 0,0,0,0,DOWN,1,1,0,2,1, L4CON, Connection refused.
One word: the difference between an outage and a quiet evening.
Kill one backend on loopback and count the seconds until traffic moves.
Per the HAProxy configuration manual, Declare or complete an access list. Per the HAProxy configuration manual, May be used in sections : defaults | frontend | listen | backend yes(!) | yes | yes | yes. Per the HAProxy configuration manual, acl invalid_src src 0.0.0.0/7 224.0.0.0/3. Per the HAProxy configuration manual, acl local_dst hdr(host) -i localhost. Per the HAProxy configuration manual, See section 7 about ACL usage. Per this book's plan, the demo config shipped no acl line, so this page draws the manual's own example and quotes it instead of pretending a run.
acl
acl Declare or complete an access list: name a test now, and rules ask the name later. The matrix is generous, yes(!) | yes | yes | yes across all four sections.
The manual's examples, quoted: acl invalid_src src 0.0.0.0/7 224.0.0.0/3 tests addresses; acl local_dst hdr(host) -i localhost tests a header, case-insensitive. See section 7 about ACL usage for the algebra.
An acl is a noun. http-request is the verb. Keep them separate.
Write one acl naming a header test; use it in a rule line you own.
Per a real run on the build machine captured at dispatch, $ haproxy -v; Configuration file is valid; $ kill -TERM 3745922; (note: the pid taken from the pidfile); 3745922. Per this book's plan, the honest hour is: copy the demo's twenty-line config, run haproxy -c -f until it prints Configuration file is valid, start it with -f, -D and -p on loopback, fetch the frontend port twenty times and watch balance alternate, kill one backend and watch check and the stats CSV handle the news, then stop the process by the pid in the pidfile. Per this book's plan, nothing outside 127.0.0.1 is bound, and the whole hour costs one scratch file and four commands.
one honest hour
The demo this book quotes took one hour and four commands: haproxy -v to know the version, -c -f to see Configuration file is valid, -f -D -p to run, and kill -TERM on the pid taken from the pidfile to stop.
Per this book's plan, your hour is the same loop with your own copy: alternate, kill, watch the CSV flip DOWN, stop clean. Twenty-four keyword pages were the map; this strip is the walk.
Twenty-eight lessons, one loopback run, one hour that is yours next.
Book the hour this week: the config, the four commands, the kill, the CSV.