1. acl #
Access control lists for logical tests. Available since version 1.1.
Structure #
The general syntax is:acl <name> <criterion> <values>. The name lets you reuse the test later.is_api #
Uses path_beg to test the beginning of the URL path.
acl is_api path_beg /apiThis line creates a rule named 'is_api' that matches if the URL starts with /api.
is_static #
Uses path_end to identify files by their extensions.
acl is_static path_end .jpg .pngThis command defines the 'is_static' rule to filter requests for image files.
2. balance #
Defines the load balancing algorithm. Available since version 1.0.
Structure #
The syntax is:balance <algorithm>. It usually goes in a backend section.roundrobin #
The default algorithm, for an even distribution.
balance roundrobinEach new client is sent to the next server in the list, in a circular way.
leastconn #
Optimized for long-running processing.
balance leastconnHAProxy picks the server with the fewest open sessions at the time of the request.
3. bind #
Defines the frontend's listening addresses and ports. Available since version 1.0.
Structure #
The syntax is:bind [<address>]:<port_range> [options].Interface and port #
Specifies the network entry point.
bind *:80HAProxy accepts connections on all available network interfaces on port 80.
SSL/TLS #
Enables encryption on the entry point.
bind *:443 ssl crt /etc/ssl/certs/site.pemListens on port 443 using the specified PEM certificate file for SSL termination.
4. http-check #
Advanced configuration of application health checks. Available since version 2.2.
Structure #
Used together withoption httpchk to customize the health check.send #
Defines the request to send to the server.
http-check send meth GET uri /healthHAProxy sends an HTTP GET request to /health to test the application's health.
expect #
Checks the server's response.
http-check expect status 200The server is only considered 'UP' if it responds with a 200 status code.
5. http-request #
Manipulates or filters incoming HTTP requests. Available since version 1.5.
Structure #
The syntax is:http-request <action> [if/unless <condition>].deny #
Blocks access based on a condition.
http-request deny if { src 192.168.1.50 }Immediately rejects the request if the source IP is 192.168.1.50.
set-header #
Adds or modifies HTTP headers.
http-request set-header X-Proxy-By HAProxyInserts the 'X-Proxy-By' header into the request forwarded to the backend server.
6. mode #
Defines the instance's operating protocol. Available since version 1.0.
Structure #
The syntax is simple:mode <http|tcp>.http #
Layer 7 analysis.
mode httpLets HAProxy understand and modify the content of HTTP packets.
tcp #
Layer 4 analysis.
mode tcpHAProxy acts as a binary stream relay without reading the application protocol content.
7. server #
Declares a backend server and its health options. Available since version 1.0.
Structure #
The syntax is:server <name> <address>[:port] [options].Name and address #
Basic server declaration.
server web1 10.0.0.1:80Defines a server named 'web1' located at IP address 10.0.0.1 on port 80.
check #
Enabling monitoring.
server web1 10.0.0.1:80 checkThe 'check' keyword enables regular health checks to make sure the server is operational.
8. stats #
Configures the monitoring interface. Available since version 1.1.
Structure #
Used with several options to define the behavior of the report page.
enable / uri #
Enabling and access point.
stats enable
stats uri /haproxy?statsEnables the statistics page and makes it accessible at the specified URI.
auth #
Password protection.
stats auth admin:rousseltmRestricts access to the statistics to the user 'admin' with the password 'rousseltm'.
9. timeout #
Manages connection timeouts. Available since version 1.2.
Structure #
The syntax is:timeout <type> <duration>. Durations can be in ms, s, m, h.connect #
timeout connect 5sDefines the maximum time HAProxy waits to establish a TCP connection with the backend server.
client #
timeout client 30sDefines the maximum inactivity time allowed on the client side once the connection is established.
server #
timeout server 30sDefines the maximum time to wait for the backend server to process the request and start responding.
10. use_backend #
Dynamically routes to a server group. Available since version 1.1.
Structure #
Defines the backend choice. Syntax:use_backend <name> [if/unless <condition>].if #
Routing based on an ACL.
use_backend api_cluster if is_apiSends the request to the 'api_cluster' server pool if the 'is_api' ACL matches.
11. server-template #
Dynamically generates backend servers without declaring them one by one. Widely used with Docker, DNS and Kubernetes.
Structure #
The syntax is:server-template <base-name> <start-end> <dns-template> [options]. base-name: base name used to generate the servers (e.g. web → web1, web2, web3).
start-end: number of items to select. If it is an integer, it is the number of instances wanted, in the order of the resolution results. If it is a numeric range, it is the wanted range (e.g. 2-5 → 4 servers, from the 2nd to the 5th).
dns-template: DNS name or template resolved dynamically by HAProxy (e.g. web.service.local or backend.internal).
options: additional parameters such as check, resolvers, resolve-prefer to manage health and DNS resolution.
Docker / DNS example #
server-template web 1-5 web.service.local:80 check resolvers dockerLets HAProxy automatically create servers web1 to web5, deriving their names/IPs through DNS resolution.
12. option #
Enables global or specific behaviors in a frontend or backend.
Structure #
The option directive enables additional features in HAProxy.
Common examples #
option forwardfor
option httpchk
option redispatch
option httplog
option dontlognullforwardfor #
Automatically adds the client IP in X-Forwarded-For.
httpchk #
Enables HTTP health checks on backend servers.
11. Other directives #
Global and behavioral settings. Available since version 1.0.
Structure #
A set of system configuration settings and default behaviors.
log #
log globalTells HAProxy to use the logging configuration defined in the 'global' section.
maxconn #
maxconn 4096Limits the total number of simultaneous connections to avoid saturating system resources.
user / group #
user haproxy
group haproxyDefines the system privileges under which the HAProxy process runs once started.
option forwardfor #
option forwardforAdds the 'X-Forwarded-For' HTTP header containing the client's real IP before forwarding the request to the server.
retries #
retries 3Defines the number of reconnection attempts to the backend server when a TCP connection fails.
