← All 189 books haproxy, one keyword per page
One keyword per page

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.


Steve Hodgkiss 7 lessons

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

Contents


Part 1 · Before the config
what a keyword is4
Part 2 · Front doors
frontend5
Part 3 · Behind the doors
backend6
Part 4 · Choosing
balance7
Part 5 · Eyes and guards
check8
Part 6 · Rewriting the wire
acl9
Part 7 · Watching it run
one honest hour10

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.

haproxy companion · No. 01
the frame

what a keyword is

the first word of the line is the law

a keyword leads its line, arguments followglobalmaxconn 256frontendwebbackendapislistenstatsfirst word: the keywordthe rest: its argumentsone line, one jobConfiguration file is validthe whole book follows this one rule, twenty-eight times

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.

SPEND ONE HONEST HOUR

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.

haproxy companion · No. 02
the listening side

frontend

the sockets that accept clients

frontend: the sockets that accept client connectionsa clientfrontendwebbind 127.0.0.1:18099the demo doorbackendapisservers live over thereLISTEN 0 256 127.0.0.1:18099 0.0.0.0:*GET #1 -> HTTP 200 | response from backend-oness listed the socket before the first GET answered 200

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.

SPEND ONE HONEST HOUR

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.

haproxy companion · No. 03
the server side

backend

the set of servers behind the door

backend: the set of servers the proxy connects tofrontendwebaccepts the request,hands it to exactlyone backendbackendapissrv1srv2two servers, one turneach, in the runthe captureeight GETs, evenrequests alternate between the two named servers

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.

SPEND ONE HONEST HOUR

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.

haproxy companion · No. 04
the choosing rule

balance

which server gets this request

balance roundrobin: the captured alternation, turn by turnbalanceroundrobinvalues share it:leastconn, sourceGET #1 -> HTTP 200 | response from backend-two on 127.0.0.1:18102GET #2 -> HTTP 200 | response from backend-one on 127.0.0.1:18101GET #7 -> HTTP 200 | response from backend-two on 127.0.0.1:18102GET #8 -> HTTP 200 | response from backend-one on 127.0.0.1:18101two servers, eight GETs: two, one, two, one, all the way

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.

SPEND ONE HONEST HOUR

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.

haproxy companion · No. 05
is it alive

check

the word that notices a dead server

check: the word that noticed when srv1 diedbefore: both live, turns splitinter 1s probes every secondafter: srv1 gonesrv2 carries every GETthe captured sequence$ kill 3745913 # pid of the backend-one toy serverwaiting 5 seconds for inter 1s/ fall 2 health checks to mark srv1GET #6 -> HTTP 200 | response from backend-twofall 2: dead after two failed probes, not one

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.

SPEND ONE HONEST HOUR

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.

haproxy companion · No. 06
the named test

acl

a name you can ask a request

acl: name a test now, ask it by name lateracl invalid_srcsrc 0.0.0.0/7acl local_dsthdr(host) -i localhostthe manual's own examples, quoted;the demo shipped no acl linewho asks the name:use_backend ... ifhttp-request ... ifredirect ... ifan access list is a noun that other keywords build on

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.

SPEND ONE HONEST HOUR

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.

haproxy companion · No. 07
the practice hour

one honest hour

the close: run it all yourself

one honest hour: the demo's own six steps, yours to reruncheckstartgetkillwatchstopcheck with -c, start with -f -D -p, fetch, kill one backend, watch, stop by pid$ kill -TERM 3745922(note: the pid taken from the pidfile)loopback only: one scratch file, four commands, one hourtwenty-eight keywords, then the hour that makes them yours

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.

SPEND ONE HONEST HOUR

Book the hour this week: the config, the four commands, the kill, the CSV.

Index

Index


acl9
backend6
balance7
check8
frontend5
one honest hour10
what a keyword is4