This document covers the configuration language as implemented in the version
specified above. It does not provide any hints, examples, or advice. For such
documentation, please refer to the Reference Manual or the Architecture Manual.
The summary below is meant to help you find sections by name and navigate
through the document.
Note to documentation contributors :
This document is formatted with 80 columns per line, with even number of
spaces for indentation and without tabs. Please follow these rules strictly
so that it remains easily printable everywhere. If a line needs to be
printed verbatim and does not fit, please end each line with a backslash
('\') and continue on next line, indented by two characters. It is also
sometimes useful to prefix all output lines (logs, console outputs) with 3
closing angle brackets ('>>>') in order to emphasize the difference between
inputs and outputs when they may be ambiguous. If you add sections,
please update the summary below for easier searching.
| 1. | Quick reminder about HTTP | |
| 1.1. | ||
| 1.2. | ||
| 1.3. | ||
| 1.3.1. | ||
| 1.3.2. | ||
| 1.4. | ||
| 1.4.1. | ||
| 1.4.2. | ||
2. |
Configuring HAProxy | |
| 2.1. | ||
| 2.2. | ||
| 2.3. | ||
| 2.4. | ||
| 2.5. | ||
| 2.6. | ||
| 2.7. | ||
| 2.8. | ||
| 2.9. | ||
| 2.9.1. | ||
| 2.9.2. | ||
| 2.9.3. | ||
| 2.10. | ||
3. |
Global section | |
| 3.1. | ||
| 3.2. | ||
| 3.3. | ||
| 3.4. | ||
4. |
Proxies | |
| 4.1. | ||
| 4.2. | ||
| 4.3. | ||
| 4.4. | ||
5. |
Bind and server options | |
| 5.1. | ||
| 5.2. | ||
| 5.3. | ||
| 5.3.1. | ||
| 5.3.2. | ||
6. |
Cache | |
| 6.1. | ||
| 6.2. | ||
| 6.2.1. | ||
| 6.2.2. | ||
7. |
Using ACLs and fetching samples | |
| 7.1. | ||
| 7.1.1. | ||
| 7.1.2. | ||
| 7.1.3. | ||
| 7.1.4. | ||
| 7.1.5. | ||
| 7.1.6. | ||
| 7.2. | ||
| 7.3. | ||
| 7.3.1. | ||
| 7.3.2. | ||
| 7.3.3. | ||
| 7.3.4. | ||
| 7.3.5. | ||
| 7.3.6. | ||
| 7.3.7. | ||
| 7.4. | ||
8. |
Logging | |
| 8.1. | ||
| 8.2. | ||
| 8.2.1. | ||
| 8.2.2. | ||
| 8.2.3. | ||
| 8.2.4. | ||
| 8.2.5. | ||
| 8.2.6. | ||
| 8.3. | ||
| 8.3.1. | ||
| 8.3.2. | ||
| 8.3.3. | ||
| 8.3.4. | ||
| 8.3.5. | ||
| 8.4. | ||
| 8.5. | ||
| 8.6. | ||
| 8.7. | ||
| 8.8. | ||
| 8.9. | ||
9. |
Supported filters | |
| 9.1. | ||
| 9.2. | ||
| 9.3. | ||
| 9.4. | ||
| 9.5. | ||
| 9.6. | ||
| 9.7. | ||
10. |
FastCGI applications | |
| 10.1. | ||
| 10.1.1. | ||
| 10.1.2. | ||
| 10.1.3. | ||
| 10.2. | ||
| 10.3. | ||
11. |
Stick-tables and Peers | |
| 11.1. | ||
| 11.2. | ||
12. |
Other sections | |
| 12.1. | ||
| 12.2. | ||
| 12.3. | ||
| 12.4. | ||
| 12.5. | ||
| 12.6. | ||
| 12.7. | ||
| 12.7.1. | ||
| 12.8. | ||
| 12.9. |
When HAProxy is running in HTTP mode, both the request and the response are fully analyzed and indexed, thus it becomes possible to build matching criteria on almost anything found in the contents. However, it is important to understand how HTTP requests and responses are formed, and how HAProxy decomposes them. It will then become easier to write correct rules and to debug existing configurations. First, HTTP is standardized by a series of RFC that HAProxy follows as closely as possible: - RFC 9110: HTTP Semantics (explains the meaning of protocol elements) - RFC 9111: HTTP Caching (explains the rules to follow for an HTTP cache) - RFC 9112: HTTP/1.1 (representation, interoperability rules, security) - RFC 9113: HTTP/2 (representation, interoperability rules, security) - RFC 9114: HTTP/3 (representation, interoperability rules, security) In addition to these, RFC 8999 to 9002 specify the QUIC transport layer used by the HTTP/3 protocol.
The HTTP protocol is transaction-driven. This means that each request will lead
to one and only one response. Originally, with version 1.0 of the protocol,
there was a single request per connection: a TCP connection is established from
the client to the server, a request is sent by the client over the connection,
the server responds, and the connection is closed. A new request then involves
a new connection :
[CON1] [REQ1] ... [RESP1] [CLO1] [CON2] [REQ2] ... [RESP2] [CLO2] ...
In this mode, often called the "HTTP close" mode, there are as many connection
establishments as there are HTTP transactions. Since the connection is closed
by the server after the response, the client does not need to know the content
length, it considers that the response is complete when the connection closes.
This also means that if some responses are truncated due to network errors, the
client could mistakenly think a response was complete, and this used to cause
truncated images to be rendered on screen sometimes.
Due to the transactional nature of the protocol, it was possible to improve it
to avoid closing a connection between two subsequent transactions. In this mode
however, it is mandatory that the server indicates the content length for each
response so that the client does not wait indefinitely. For this, a special
header is used: "Content-length". This mode is called the "keep-alive" mode,
and arrived with HTTP/1.1 (some HTTP/1.0 agents support it), and connections
that are reused between requests are called "persistent connections":
[CON] [REQ1] ... [RESP1] [REQ2] ... [RESP2] [CLO] ...
Its advantages are a reduced latency between transactions, less processing
power required on the server side, and the ability to detect a truncated
response. It is generally faster than the close mode, but not always because
some clients often limit their concurrent connections to a smaller value, and
this compensates less for poor network connectivity. Also, some servers have to
keep the connection alive for a long time waiting for a possible new request
and may experience a high memory usage due to the high number of connections,
and closing too fast may break some requests that arrived at the moment the
connection was closed.
In this mode, the response size needs to be known upfront so that's not always
possible with dynamically generated or compressed contents. For this reason
another mode was implemented, the "chunked mode", where instead of announcing
the size of the whole size at once, the sender only advertises the size of the
next "chunk" of response it already has in a buffer, and can terminate at any
moment with a zero-sized chunk. In this mode, the Content-Length header is not
used.
Another improvement in the communications is the pipelining mode. It still uses
keep-alive, but the client does not wait for the first response to send the
second request. This is useful for fetching large number of images composing a
page :
[CON] [REQ1] [REQ2] ... [RESP1] [RESP2] [CLO] ...
This can obviously have a tremendous benefit on performance because the network
latency is eliminated between subsequent requests. Many HTTP agents do not
correctly support pipelining since there is no way to associate a response with
the corresponding request in HTTP. For this reason, it is mandatory for the
server to reply in the exact same order as the requests were received. In
practice, after several attempts by various clients to deploy it, it has been
totally abandoned for its lack of reliability on certain servers. But it is
mandatory for servers to support it.
The next improvement is the multiplexed mode, as implemented in HTTP/2 and
HTTP/3. In this mode, multiple transactions (i.e. request-response pairs) are
transmitted in parallel over a single connection, and they all progress at
their own speed, independent from each other. With multiplexed protocols, a new
notion of "stream" was introduced, to represent these parallel communications
happening over the same connection. Each stream is generally assigned a unique
identifier for a given connection, that is used by both endpoints to know where
to deliver the data. It is fairly common for clients to start many (up to 100,
sometimes more) streams in parallel over a same connection, and let the server
sort them out and respond in any order depending on what response is available.
The main benefit of the multiplexed mode is that it significantly reduces the
number of round trips, and speeds up page loading time over high latency
networks. It is sometimes visible on sites using many images, where all images
appear to load in parallel.
These protocols have also improved their efficiency by adopting some mechanisms
to compress header fields in order to reduce the number of bytes on the wire,
so that without the appropriate tools, they are not realistically manipulable
by hand nor readable to the naked eye like HTTP/1 was. For this reason, various
examples of HTTP messages continue to be represented in literature (including
this document) using the HTTP/1 syntax even for newer versions of the protocol.
HTTP/2 suffers from some design limitations, such as packet losses affecting
all streams at once, and if a client takes too much time to retrieve an object
(e.g. needs to store it on disk), it may slow down its retrieval and make it
impossible during this time to access the data that is pending behind it. This
is called "head of line blocking" or "HoL blocking" or sometimes just "HoL".
HTTP/3 is implemented over QUIC, itself implemented over UDP. QUIC solves the
head of line blocking at the transport level by means of independently handled
streams. Indeed, when experiencing loss, an impacted stream does not affect the
other streams, and all of them can be accessed in parallel. QUIC also provides
connection migration support but currently haproxy does not support it.
By default HAProxy operates in keep-alive mode with regards to persistent
connections: for each connection it processes each request and response, and
leaves the connection idle on both sides between the end of a response and the
start of a new request. When it receives HTTP/2 connections from a client, it
processes all the requests in parallel and leaves the connection idling,
waiting for new requests, just as if it was a keep-alive HTTP connection.
HAProxy essentially supports 3 connection modes :
- keep alive : all requests and responses are processed, and the client
facing and server facing connections are kept alive for new
requests. This is the default and suits the modern web and
modern protocols (HTTP/2 and HTTP/3).
- server close : the server-facing connection is closed after the response.
- close : the connection is actively closed after end of response on
both sides.
In addition to this, by default, the server-facing connection is reusable by
any request from any client, as mandated by the HTTP protocol specification, so
any information pertaining to a specific client has to be passed along with
each request if needed (e.g. client's source address etc). When HTTP/2 is used
with a server, by default HAProxy will dedicate this connection to the same
client to avoid the risk of head of line blocking between clients.
Inside HAProxy, the terminology has evolved a bit over the ages to follow the
evolutions of the HTTP protocol and its usages. While originally there was no
significant difference between a connection, a session, a stream or a
transaction, these ones clarified over time to match closely what exists in the
modern versions of the HTTP protocol, though some terms remain visible in the
configuration or the command line interface for the purpose of historical
compatibility.
Here are some definitions that apply to the current version of HAProxy:
- connection: a connection is a single, bidiractional communication channel
between a remote agent (client or server) and haproxy, at the lowest level
possible. Usually it corresponds to a TCP socket established between a pair
of IP and ports. On the client-facing side, connections are the very first
entities that are instantiated when a client connects to haproxy, and rules
applying at the connection level are the earliest ones that apply.
- session: a session adds some context information associated with a
connection. This includes and information specific to the transport layer
(e.g. TLS keys etc), or variables. This term has long been used inside
HAProxy to denote end-to-end HTTP/1.0 communications between two ends, and
as such it remains visible in the name of certain CLI commands or
statistics, despite representing streams nowadays, but the help messages
and descriptions try to make this unambiguous. It is still valid when it
comes to network-level terminology (e.g. TCP sessions inside the operating
systems, or TCP sessions across a firewall), or for non-HTTP user-level
applications (e.g. a telnet session or an SSH session). It must not be
confused with "application sessions" that are used to store a full user
context in a cookie and require to be sent to the same server.
- stream: a stream exactly corresponds to an end-to-end bidirectional
communication at the application level, where analysis and transformations
may be applied. In HTTP, it contains a single request and its associated
response, and is instantiated by the arrival of the request and is finished
with the end of delivery of the response. In this context there is a 1:1
relation between such a stream and the stream of a multiplexed protocol. In
TCP communications there is a single stream per connection.
- transaction: a transaction is only a pair of a request and the associated
response. The term was used in conjunction with sessions before the streams
but nowadays there is a 1:1 relation between a transaction and a stream. It
is essentially visible in the variables' scope "txn" which is valid during
the whole transaction, hence the stream.
- request: it designates the traffic flowing from the client to the server.
It is mainly used for HTTP to indicate where operations are performed. This
term also exists for TCP operations to indicate where data are processed.
Requests often appear in counters as a unit of traffic or activity. They do
not always imply a response (e.g. due to errors), but since there is no
spontaneous responses without requests, requests remain a relevant metric
of the overall activity. In TCP there are as many requests as connections.
- response: this designates the traffic flowing from the server to the
client, or sometimes from HAProxy to the client, when HAProxy produces the
response itself (e.g. an HTTP redirect).
- service: this generally indicates some internal processing in HAProxy that
does not require a server, such as the stats page, the cache, or some Lua
code to implement a small application. A service usually reads a request,
performs some operations and produces a response.
First, let's consider this HTTP request :
Line Contents
number
1 GET /serv/login.php?lang=en&profile=2 HTTP/1.1
2 Host: www.mydomain.com
3 User-agent: my small browser
4 Accept: image/jpeg, image/gif
5 Accept: image/png
Line 1 is the "request line". It is always composed of 3 fields :
- a METHOD : GET
- a URI : /serv/login.php?lang=en&profile=2
- a version tag : HTTP/1.1
All of them are delimited by what the standard calls LWS (linear white spaces),
which are commonly spaces, but can also be tabs or line feeds/carriage returns
followed by spaces/tabs. The method itself cannot contain any colon (':') and
is limited to alphabetic letters. All those various combinations make it
desirable that HAProxy performs the splitting itself rather than leaving it to
the user to write a complex or inaccurate regular expression.
The URI itself can have several forms :
- A "relative URI" :
/serv/login.php?lang=en&profile=2
It is a complete URL without the host part. This is generally what is
received by servers, reverse proxies and transparent proxies.
- An "absolute URI", also called a "URL" :
http://192.168.0.12:8080/serv/login.php?lang=en&profile=2
It is composed of a "scheme" (the protocol name followed by '://'), a host
name or address, optionally a colon (':') followed by a port number, then
a relative URI beginning at the first slash ('/') after the address part.
This is generally what proxies receive, but a server supporting HTTP/1.1
must accept this form too.
- a star ('*') : this form is only accepted in association with the OPTIONS
method and is not relayable. It is used to inquiry a next hop's
capabilities.
- an address:port combination : 192.168.0.12:80
This is used with the CONNECT method, which is used to establish TCP
tunnels through HTTP proxies, generally for HTTPS, but sometimes for
other protocols too.
In a relative URI, two sub-parts are identified. The part before the question
mark is called the "path". It is typically the relative path to static objects
on the server. The part after the question mark is called the "query string".
It is mostly used with GET requests sent to dynamic scripts and is very
specific to the language, framework or application in use.
HTTP/2 and HTTP/3 do not convey a version information with the request, so the
version is assumed to be the same as the one of the underlying protocol (i.e.
"HTTP/2"). In addition, these protocols do not send a request line as one part,
but split it into individual fields called "pseudo-headers", whose name start
with a colon, and which are conveniently reassembled by HAProxy into an
equivalent request line. For this reason, request lines found in logs may
slightly differ between HTTP/1.x and HTTP/2 or HTTP/3.
The headers start at the second line. They are composed of a name at the
beginning of the line, immediately followed by a colon (':'). Traditionally,
an LWS is added after the colon but that's not required. Then come the values.
Multiple identical headers may be folded into one single line, delimiting the
values with commas, provided that their order is respected. This is commonly
encountered in the "Cookie:" field. A header may span over multiple lines if
the subsequent lines begin with an LWS. In the example in 1.3, lines 4 and 5
define a total of 3 values for the "Accept:" header. Finally, all LWS at the
beginning or at the end of a header are ignored and are not part of the value,
as per the specification.
Contrary to a common misconception, header names are not case-sensitive, and
their values are not either if they refer to other header names (such as the
"Connection:" header). In HTTP/2 and HTTP/3, header names are always sent in
lower case, as can be seen when running in debug mode. Internally, all header
names are normalized to lower case so that HTTP/1.x and HTTP/2 or HTTP/3 use
the exact same representation, and they are sent as-is on the other side. This
explains why an HTTP/1.x request typed with camel case is delivered in lower
case.
The end of the headers is indicated by the first empty line. People often say
that it's a double line feed, which is not exact, even if a double line feed
is one valid form of empty line.
Fortunately, HAProxy takes care of all these complex combinations when indexing
headers, checking values and counting them, so there is no reason to worry
about the way they could be written, but it is important not to accuse an
application of being buggy if it does unusual, valid things.
Important note:
As suggested by RFC7231, HAProxy normalizes headers by replacing line breaks
in the middle of headers by LWS in order to join multi-line headers. This
is necessary for proper analysis and helps less capable HTTP parsers to work
correctly and not to be fooled by such complex constructs.
An HTTP response looks very much like an HTTP request. Both are called HTTP
messages. Let's consider this HTTP response :
Line Contents
number
1 HTTP/1.1 200 OK
2 Content-length: 350
3 Content-Type: text/html
As a special case, HTTP supports so called "Informational responses" as status
codes 1xx. These messages are special in that they don't convey any part of the
response, they're just used as sort of a signaling message to ask a client to
continue to post its request for instance. In the case of a status 100 response
the requested information will be carried by the next non-100 response message
following the informational one. This implies that multiple responses may be
sent to a single request, and that this only works when keep-alive is enabled
(1xx messages appeared in HTTP/1.1). HAProxy handles these messages and is able
to correctly forward and skip them, and only process the next non-100 response.
As such, these messages are neither logged nor transformed, unless explicitly
state otherwise. Status 101 messages indicate that the protocol is changing
over the same connection and that HAProxy must switch to tunnel mode, just as
if a CONNECT had occurred. Then the Upgrade header would contain additional
information about the type of protocol the connection is switching to.
Line 1 is the "response line". It is always composed of 3 fields :
- a version tag : HTTP/1.1
- a status code : 200
- a reason : OK
The status code is always 3-digit. The first digit indicates a general status :
- 1xx = informational message to be skipped (e.g. 100, 101)
- 2xx = OK, content is following (e.g. 200, 206)
- 3xx = OK, no content following (e.g. 302, 304)
- 4xx = error caused by the client (e.g. 401, 403, 404)
- 5xx = error caused by the server (e.g. 500, 502, 503)
Status codes greater than 599 must not be emitted in communications, though
certain agents may produce them in logs to report their internal statuses.
Please refer to RFC9110 for the detailed meaning of all such codes. HTTP/2 and
above do not have a version tag and use the ":status" pseudo-header to report
the status code.
The "reason" field is just a hint, but is not parsed by clients. Anything can
be found there, but it's a common practice to respect the well-established
messages. It can be composed of one or multiple words, such as "OK", "Found",
or "Authentication Required". It does not exist in HTTP/2 and above and is
not emitted there. When a response from HTTP/2 or above is transmitted to an
HTTP/1 client, HAProxy will produce such a common reason field that matches
the status code.
HAProxy may emit the following status codes by itself :
Code When / reason
200 access to stats page, and when replying to monitoring requests
301 when performing a redirection, depending on the configured code
302 when performing a redirection, depending on the configured code
303 when performing a redirection, depending on the configured code
307 when performing a redirection, depending on the configured code
308 when performing a redirection, depending on the configured code
400 for an invalid or too large request
401 when an authentication is required to perform the action (when
accessing the stats page)
403 when a request is forbidden by a "http-request deny" rule
404 when the requested resource could not be found
408 when the request timeout strikes before the request is complete
410 when the requested resource is no longer available and will not
be available again
413 when a HTTP/1.0 GET/HEAD/DELETE requests has a payload, also see
the "h1-accept-payload-with-any-method" option
500 when HAProxy encounters an unrecoverable internal error, such as a
memory allocation failure, which should never happen
501 when HAProxy is unable to satisfy a client request because of an
unsupported feature
502 when the server returns an empty, invalid or incomplete response, or
when an "http-response deny" rule blocks the response.
503 when no server was available to handle the request, or in response to
monitoring requests which match the "monitor fail" condition
504 when the response timeout strikes before the server responds
The error 4xx and 5xx codes above may be customized (see "errorloc" in section
4.2). Other status codes can be emitted on purpose by specific actions (see the
"deny", "return" and "redirect" actions in section 4.3 for example).
Response headers work exactly like request headers, and as such, HAProxy uses the same parsing function for both. Please refer to paragraph 1.3.2 for more details.
HAProxy's configuration process involves 3 major sources of parameters :
- the arguments from the command-line, which always take precedence
- the configuration file(s), whose format is described here
- the running process's environment, in case some environment variables are
explicitly referenced
The configuration file follows a fairly simple hierarchical format which obey
a few basic rules:
1. a configuration file is an ordered sequence of statements
2. a statement is a single non-empty line before any unprotected "#" (hash)
3. a line is a series of tokens or "words" delimited by unprotected spaces or
tab characters
4. the first word or sequence of words of a line is one of the keywords or
keyword sequences listed in this document
5. all other words are all arguments of the first one, some being well-known
keywords listed in this document, others being values, references to other
parts of the configuration, or expressions
6. certain keywords delimit a section inside which only a subset of keywords
are supported
7. a section ends at the end of a file or on a special keyword starting a new
section
This is all that is needed to know to write a simple but reliable configuration
generator, but this is not enough to reliably parse any configuration nor to
figure how to deal with certain corner cases.
First, there are a few consequences of the rules above. Rule 6 and 7 imply that
the keywords used to define a new section are valid everywhere and cannot have
a different meaning in a specific section. These keywords are always a single
word (as opposed to a sequence of words), and traditionally the section that
follows them is designated using the same name. For example when speaking about
the "global section", it designates the section of configuration that follows
the "global" keyword. This usage is used a lot in error messages to help locate
the parts that need to be addressed.
A number of sections create an internal object or configuration space, which
requires to be distinguished from other ones. In this case they will take an
extra word which will set the name of this particular section. For some of them
the section name is mandatory. For example "frontend foo" will create a new
section of type "frontend" named "foo". Usually a name is specific to its
section and two sections of different types may use the same name, but this is
not recommended as it tends to complexify configuration management.
A direct consequence of rule 7 is that when multiple files are read at once,
each of them must start with a new section, and the end of each file will end
a section. A file cannot contain sub-sections nor end an existing section and
start a new one.
Rule 1 mentioned that ordering matters. Indeed, some keywords create directives
that can be repeated multiple times to create ordered sequences of rules to be
applied in a certain order. For example "tcp-request" can be used to alternate
"accept" and "reject" rules on varying criteria. As such, a configuration file
processor must always preserve a section's ordering when editing a file. The
ordering of sections usually does not matter except for the global section
which must be placed before other sections, but it may be repeated if needed.
In addition, some automatic identifiers may automatically be assigned to some
of the created objects (e.g. proxies), and by reordering sections, their
identifiers will change. These ones appear in the statistics for example. As
such, the configuration below will assign "foo" an ID number smaller than its
"bar" counterpart. This will be swapped if the two sections are reversed:
listen foo
bind :80
listen bar
bind :81
Another important point is that according to rules 2 and 3 above, empty lines,
spaces, tabs, and comments following and unprotected "#" character are not part
of the configuration as they are just used as delimiters. This implies that the
following configurations are strictly equivalent:
global#this is the global section
daemon#daemonize
frontend foo
mode http # or tcp
and:
global
daemon
# this is the public web frontend
frontend foo
mode http
The common practice is to align to the left only the keyword that initiates a
new section, and indent (i.e. prepend a tab character or a few spaces) all
other keywords so that it's instantly visible that they belong to the same
section (as done in the second example above). Placing comments before a new
section helps the reader decide if it's the desired one. Leaving a blank line
at the end of a section also visually helps spotting the end when editing it.
Tabs are very convenient for indent but they do not copy-paste well. If spaces
are used instead, it is recommended to avoid placing too many (2 to 4) so that
editing in field doesn't become a burden with limited editors that do not
support automatic indent.
In the early days it used to be common to see arguments split at fixed tab
positions because most keywords would not take more than two arguments. With
modern versions featuring complex expressions this practice does not stand
anymore, and is not recommended.
In modern configurations, some arguments require the use of some characters
that were previously considered as pure delimiters. In order to make this
possible, HAProxy supports character escaping by prepending a backslash ('\')
in front of the character to be escaped, weak quoting with double quotes ("")
around a piece of text, and strong quoting with single quotes ('') around a
piece of text.
This is pretty similar to what is done in a number of programming languages and
very close to what is commonly encountered in Bourne shell. The principle is
the following: while the configuration parser cuts the lines into words, it
also takes care of quotes and backslashes to decide whether a character is a
delimiter or is the raw representation of this character within the current
word. The escape character is then removed, the quotes are removed, and the
remaining word is used as-is as a keyword or argument for example.
If a backslash is needed in a word, it must either be escaped using itself
(i.e. double backslash) or be strongly quoted.
Escaping outside quotes is achieved by preceding a special character by a
backslash ('\'):
\ to mark a space and differentiate it from a delimiter
\# to mark a hash and differentiate it from a comment
\\ to use a backslash
\' to use a single quote and differentiate it from strong quoting
\" to use a double quote and differentiate it from weak quoting
In addition, a few non-printable characters may be emitted using their usual
C-language representation:
\n to insert a line feed (LF, character \x0a or ASCII 10 decimal)
\r to insert a carriage return (CR, character \x0d or ASCII 13 decimal)
\t to insert a tab (character \x09 or ASCII 9 decimal)
\xNN to insert character having ASCII code hex NN (e.g \x0a for LF).
Weak quoting is achieved by surrounding double quotes ("") around the character
or sequence of characters to protect. Weak quoting prevents the interpretation
of:
space or tab as a word separator
' single quote as a strong quoting delimiter
# hash as a comment start
Weak quoting permits the interpretation of environment variables (which are not
evaluated outside of quotes) by preceding them with a dollar sign ('$'). If a
dollar character is needed inside double quotes, it must be escaped using a
backslash.
Strong quoting is achieved by surrounding single quotes ('') around the
character or sequence of characters to protect. Inside single quotes, nothing
is interpreted, it's the efficient way to quote regular expressions.
As a result, here is the matrix indicating how special characters can be
entered in different contexts (unprintable characters are replaced with their
name within angle brackets). Note that some characters that may only be
represented escaped have no possible representation inside single quotes,
hence its absence there:
| Character | Unquoted | Weakly quoted | Strongly quoted |
|---|---|---|---|
| <TAB> | \<TAB>, \x09 | "<TAB>", "\<TAB>", "\x09" | '<TAB>' |
| <LF> | \n, \x0a | "\n", "\x0a" | |
| <CR> | \r, \x0d | "\r", "\x0d" | |
| <SPC> | \<SPC>, \x20 | "<SPC>", "\<SPC>", "\x20" | '<SPC>' |
| " | \", \x22 | "\"", "\x22" | '"' |
| # | \#, \x23 | "#", "\#", "\x23" | '#' |
| $ | $, \$, \x24 | "\$", "\x24" | '$' |
| ' | \', \x27 | "'", "\'", "\x27" | |
| \ | \\, \x5c | "\\", "\x5c" | '\' |
# those are all strictly equivalent:
log-format %{+Q}o\ %t\ %s\ %{-Q}r
log-format "%{+Q}o %t %s %{-Q}r"
log-format '%{+Q}o %t %s %{-Q}r'
log-format "%{+Q}o %t"' %s %{-Q}r'
log-format "%{+Q}o %t"' %s'\ %{-Q}r
There is one particular case where a second level of quoting or escaping may be necessary. Some keywords take arguments within parenthesis, sometimes delimited by commas. These arguments are commonly integers or predefined words, but when they are arbitrary strings, it may be required to perform a separate level of escaping to disambiguate the characters that belong to the argument from the characters that are used to delimit the arguments themselves. A pretty common case is the "regsub" converter. It takes a regular expression in argument, and if a closing parenthesis is needed inside, this one will require to have its own quotes. The keyword argument parser is exactly the same as the top-level one regarding quotes, except that the \#, \$, and \xNN escapes are not processed. But what is not always obvious is that the delimiters used inside must first be escaped or quoted so that they are not resolved at the top level. Let's take this example making use of the "regsub" converter which takes 3 arguments, one regular expression, one replacement string and one set of flags: # replace all occurrences of "foo" with "blah" in the path: http-request set-path %[path,regsub(foo,blah,g)] Here no special quoting was necessary. But if now we want to replace either "foo" or "bar" with "blah", we'll need the regular expression "(foo|bar)". We cannot write: http-request set-path %[path,regsub((foo|bar),blah,g)] because we would like the string to cut like this: http-request set-path %[path,regsub((foo|bar),blah,g)] |---------|----|-| arg1 _/ / / arg2 __________/ / arg3 ______________/ but actually what is passed is a string between the opening and closing parenthesis then garbage: http-request set-path %[path,regsub((foo|bar),blah,g)] |--------|--------| arg1=(foo|bar _/ / trailing garbage _________/ The obvious solution here seems to be that the closing parenthesis needs to be quoted, but alone this will not work, because as mentioned above, quotes are processed by the top-level parser which will resolve them before processing this word: http-request set-path %[path,regsub("(foo|bar)",blah,g)] ------------ -------- ---------------------------------- word1 word2 word3=%[path,regsub((foo|bar),blah,g)] So we didn't change anything for the argument parser at the second level which still sees a truncated regular expression as the only argument, and garbage at the end of the string. By escaping the quotes they will be passed unmodified to the second level: http-request set-path %[path,regsub(\"(foo|bar)\",blah,g)] ------------ -------- ------------------------------------ word1 word2 word3=%[path,regsub("(foo|bar)",blah,g)] |---------||----|-| arg1=(foo|bar) _/ / / arg2=blah ___________/ / arg3=g _______________/ Another approach consists in using single quotes outside the whole string and double quotes inside (so that the double quotes are not stripped again): http-request set-path '%[path,regsub("(foo|bar)",blah,g)]' ------------ -------- ---------------------------------- word1 word2 word3=%[path,regsub("(foo|bar)",blah,g)] |---------||----|-| arg1=(foo|bar) _/ / / arg2 ___________/ / arg3 _______________/ But in this case it's important to note that delimiters embedded into the higher level string remain pure characters and are not delimiters anymore. It particularly means that spaces and tabs around commas are part of the string. The example below is wrong on multiple points: http-request set-path '%[path, regsub("(foo|bar)", blah, g)]' ------------ -------- -------------------------------------- word1 word2 word3=%[path, regsub("(foo|bar)", blah, g)] |--------|---------||-----|--| converter=" regsub" _/ / / / arg1=(foo|bar) _/ / / arg2=" blah" ___________/ / arg3=" g" ______________/ The single fact of surrounding commas with spaces resulted in the spaces being part of the field itself, hence the converter " regsub" (starting with a space), which won't be found and will trigger an error, but more subtly, the replacement string " blah" will insert a space in the output. A good rule of thumb is to never insert unneeded spaces inside expressions. When using regular expressions, it can happen that the dollar ('$') character appears in the expression or that a backslash ('\') is used in the replacement string. In this case these ones will also be processed inside the double quotes thus single quotes are preferred (or double escaping). Example: http-request set-path '%[path,regsub("^/(here)(/|$)","my/\1",g)]' ------------ -------- ----------------------------------------- word1 word2 word3=%[path,regsub("^/(here)(/|$)","my/\1",g)] |-------------| |-----||-| arg1=(here)(/|$) _/ / / arg2=my/\1 ________________/ / arg3 ______________________/ Remember that backslashes are not escape characters within single quotes and that the whole word above is already protected against them using the single quotes. Conversely, if double quotes had been used around the whole expression, single the dollar character and the backslashes would have been resolved at top level, breaking the argument contents at the second level. Unfortunately, since single quotes can't be escaped inside of strong quoting, if you need to include single quotes in your argument, you will need to escape or quote them twice. There are a few ways to do this: http-request set-var(txn.foo) str("\\'foo\\'") http-request set-var(txn.foo) str(\"\'foo\'\") http-request set-var(txn.foo) str(\\\'foo\\\') When in doubt, simply do not use quotes anywhere, and start to place single or double quotes around arguments that require a comma or a closing parenthesis, and think about escaping these quotes using a backslash if the string contains a dollar or a backslash. Again, this is pretty similar to what is used under a Bourne shell when double-escaping a command passed to "eval". For API writers the best is probably to place escaped quotes around each and every argument, regardless of their contents. Users will probably find that using single quotes around the whole expression and double quotes around each argument provides more readable configurations.
HAProxy's configuration supports environment variables. Those variables are
interpreted only within double quotes. Variables are expanded during the
configuration parsing. Variable names must be preceded by a dollar ("$") and
optionally enclosed with braces ("{}") similarly to what is done in Bourne
shell. Variable names can contain alphanumerical characters or the character
underscore ("_") but should not start with a digit. If the variable contains a
list of several values separated by spaces, it can be expanded as individual
arguments by enclosing the variable with braces and appending the suffix '[*]'
before the closing brace. It is also possible to specify a default value to
use when the variable is not set, by appending that value after a dash '-'
next to the variable name. Note that the default value only replaces non
existing variables, not empty ones.
bind "fd@${FD_APP1}"
log "${LOCAL_SYSLOG-127.0.0.1}:514" local0 notice # send to local server
user "$HAPROXY_USER"
Some variables are defined by HAProxy, they can be used in the configuration
file. These variables are listed in the matrix below, and they are classified
among four categories:
* usable: the variable is accessible from the configuration, either to be
resolved as-is, or used within conditional blocks or predicates to enable
or disable this some configuration fragments, as described in section 2.4
"Conditional blocks".
* modifiable: the variable can be redefined or unset in the configuration via
"setenv"/"unsetenv" keywords.
* listed: the variable is listed in CLI's "show env" command output,
described in section 9.3 "Unix Sockets commands" of the management guide.
There also two subcategories "master" and "worker", respectively marked 'M' and
'W' in the table below, showing the differences between the two processes when
HAProxy is launched in master-worker mode.
* master: the variable is set and accessible from the master process. So, it
will appear in the master CLI's "show env" output and it can be used in
conditional blocks or directives to enable some special settings for the
master (see examples in section 2.4 "Conditional blocks").
* worker: the variable is set and accessible from the worker process. It will
appear in the worker CLI's "show env" (or the master CLI's "@1 show env")
and it may as well condition some worker process parameters (see examples
from section 2.4 "Conditional blocks").
In standalone mode (without "-W" option nor the "master-worker" keyword) the
process behaves like a worker, except for variables "HAPROXY_MASTER_CLI" and
"HAPROXY_MWORKER" which are not defined.
Some variables are marked as not usable and not modifiable:
* HAPROXY_CFGFILES
* HAPROXY_MWORKER
* HAPROXY_CLI
* HAPROXY_MASTER_CLI
* HAPROXY_LOCALPEER
Their values are undefined during configuration parsing, they are set later
during the initialization. So, it's recommended not to use these variables
within conditional blocks and not to reference them in the global section's
"setenv"/"resetenv"/"unsetenv" keywords.
The table below summaries the status of each variable for the different working
modes:
+---------------------------+---------+------------+-----------+
| variable | usable | modifiable | listed |
| +---------+------------+-----------+
| | M | W | M | W | M | W |
+---------------------------+----+----+------+-----+-----+-----+
| HAPROXY_STARTUP_VERSION | X | X | | | X | X |
| HAPROXY_BRANCH | X | X | | | X | X |
| HAPROXY_CFGFILES | | | | | X | X |
| HAPROXY_MWORKER | | | | | X | X |
| HAPROXY_CLI | | | | | | X |
| HAPROXY_MASTER_CLI | | | | | X | |
| HAPROXY_LOCALPEER | | X | | | | X |
| HAPROXY_HTTP_LOG_FMT | | X | | X | | |
| HAPROXY_HTTP_CLF_LOG_FMT | | X | | X | | |
| HAPROXY_HTTPS_LOG_FMT | | X | | X | | |
| HAPROXY_TCP_LOG_FMT | | X | | X | | |
| HAPROXY_TCP_CLF_LOG_FMT | | X | | X | | |
| HAPROXY_KEYLOG_FC_LOG_FMT | | X | | X | | |
| HAPROXY_KEYLOG_BC_LOG_FMT | | X | | X | | |
+---------------------------+----+----+------+-----+-----+-----+
The variables in question are the following:
* HAPROXY_LOCALPEER: defined at the startup of the process which contains the
name of the local peer. (See "-L" in the management guide.)
* HAPROXY_CFGFILES: list of the configuration files loaded by HAProxy,
separated by semicolons. Can be useful in the case you specified a
directory.
* HAPROXY_HTTP_LOG_FMT: contains the value of the default HTTP log format as
defined in section 8.2.3 "HTTP log format". It can be used to override the
default log format without having to copy the whole original definition.
* HAPROXY_HTTP_CLF_LOG_FMT: contains the value of the default HTTP CLF log
format as defined in section 8.2.3 "HTTP log format". It can be used to
override the default log format without having to copy the whole original
definition.
# Add the rule that gave the final verdict to the log
log-format "${HAPROXY_TCP_LOG_FMT} lr=%[last_rule_file]:%[last_rule_line]"
* HAPROXY_HTTPS_LOG_FMT: similar to HAPROXY_HTTP_LOG_FMT but for HTTPS log
format as defined in section 8.2.4 "HTTPS log format".
* HAPROXY_TCP_LOG_FMT: similar to HAPROXY_HTTP_LOG_FMT but for TCP log format
as defined in section 8.2.2 "TCP log format".
* HAPROXY_TCP_CLF_LOG_FMT: similar to HAPROXY_HTTP_CLF_LOG_FMT but for TCP
CLF log format as defined in section 8.2.2 "TCP log format".
* HAPROXY_KEYLOG_FC_LOG_FMT: contains the keylog format for the frontend
(client-facing) TLS connection, with key entries separated by newlines so
it might not be compatible with your syslog server. "tune.ssl.keylog on" is
required.
* HAPROXY_KEYLOG_BC_LOG_FMT: similar to HAPROXY_KEYLOG_FC_LOG_FMT but for the
backend (server-facing) TLS connection. Key entries are separated by
newlines so it might not be compatible with your syslog server.
"tune.ssl.keylog on" is required.
* HAPROXY_MWORKER: In master-worker mode, this variable is set to 1.
* HAPROXY_CLI: configured listeners addresses of the stats socket of every
processe, these addresses are separated by semicolons.
* HAPROXY_MASTER_CLI: In master-worker mode, listeners addresses of the master
CLI, separated by semicolons.
* HAPROXY_STARTUP_VERSION: contains the version used to start, in master-
worker mode this is the version which was used to start the master, even
after updating the binary and reloading.
* HAPROXY_BRANCH: contains the HAProxy branch version (such as "2.8"). It
does not contain the full version number. It can be useful in case of
migration if resources (such as maps or certificates) are in a path
containing the branch number.
In addition, some pseudo-variables are internally resolved and may be used as
regular variables. Pseudo-variables always start with a dot ('.'), and are the
only ones where the dot is permitted. The current list of pseudo-variables is:
* .FILE: the name of the configuration file currently being parsed.
* .LINE: the line number of the configuration file currently being parsed,
starting at one.
* .SECTION: the name of the section currently being parsed, or its type if
the section doesn't have a name (e.g. "global"), or an empty string before
the first section.
These variables are resolved at the location where they are parsed. For example
if a ".LINE" variable is used in a "log-format" directive located in a defaults
section, its line number will be resolved before parsing and compiling the
"log-format" directive, so this same line number will be reused by subsequent
proxies.
This way it is possible to emit information to help locate a rule in variables,
logs, error statuses, health checks, header values, or even to use line numbers
to name some config objects like servers for example.
It may sometimes be convenient to be able to conditionally enable or disable
some arbitrary parts of the configuration, for example to enable/disable SSL or
ciphers, enable or disable some pre-production listeners without modifying the
configuration, or adjust the configuration's syntax to support two distinct
versions of HAProxy during a migration.. HAProxy brings a set of nestable
preprocessor-like directives which allow to integrate or ignore some blocks of
text. These directives must be placed on their own line and they act on the
lines that follow them. Two of them support an expression, the other ones only
switch to an alternate block or end a current level. The 4 following directives
are defined to form conditional blocks:
- .if <condition>
- .elif <condition>
- .else
- .endif
The ".if" directive nests a new level, ".elif" stays at the same level, ".else"
as well, and ".endif" closes a level. Each ".if" must be terminated by a
matching ".endif". The ".elif" may only be placed after ".if" or ".elif", and
there is no limit to the number of ".elif" that may be chained. There may be
only one ".else" per ".if" and it must always be after the ".if" or the last
".elif" of a block.
Comments may be placed on the same line if needed after a '#', they will be
ignored. The directives are tokenized like other configuration directives, and
as such it is possible to use environment variables in conditions.
Conditions can also be evaluated on startup with the -cc parameter.
See "3. Starting HAProxy" in the management doc.
The conditions are either an empty string (which then returns false), or an
expression made of any combination of:
- the integer zero ('0'), always returns "false"
- a non-nul integer (e.g. '1'), always returns "true".
- a predicate optionally followed by argument(s) in parenthesis.
- a condition placed between a pair of parenthesis '(' and ')'
- an exclamation mark ('!') preceding any of the non-empty elements above,
and which will negate its status.
- expressions combined with a logical AND ('&&'), which will be evaluated
from left to right until one returns false
- expressions combined with a logical OR ('||'), which will be evaluated
from right to left until one returns true
The same line tokenizer and argument parser are used as for the rest of the
configuration language. Words are split around consecutive series of one or
more unquoted spaces or tabs, and are reassembled together using a single space
to delimit them before evaluation, in order to save the user from having to
quote the entire line. But this also means that spaces surrounding commas or
parenthesis are definitely part of the value, which is not always expected.
For example, the expression below:
.if defined( HAPROXY_MWORKER )
will test for the existence of variable " HAPROXY_MWORKER " (with spaces),
and this one:
.if streq("$ENABLE_SSL", 1)
will compare the environment variable "ENABLE_SSL" to the value " 1" (with a
single leading space). The reason is the line is first split into words like
this:
.if streq("$ENABLE_SSL", 1)
|---|--------------------| |--|
1 2 3
then the weak quoting is applied and environment variable "$ENABLE_SSL" is
resolved (let's say for example that ENABLE_SSL=0), and finally the words are
reassembled into a single string by placing a single space between the words:
.if streq(0, 1)
|---|-------|--|
1 2 3
and only then it is parsed as a single expression. The space that was inserted
between the comma and "1" is still part of the argument value, making this
argument " 1":
.if streq(0, 1)
|---|-----|-|--|
\ \ \ \_ argument2: " 1"
\ \ \___ argument1: "0"
\ \_______ function: "streq"
\___________ directive: ".if"
It's visible here that even if ENABLE_SSL had been equal to "1", it wouldn't
have matched " 1" since the string would differ by one space.
Note: as explained in section "2.2. Quoting and escaping", a good rule of thumb
is to never insert unneeded spaces inside expressions.
Note that like in other languages, the AND operator has precedence over the OR
operator, so that "A && B || C && D" evalues as "(A && B) || (C && D)".
The list of currently supported predicates is the following:
- awslc_api_atleast(<ver>): returns true if the current awslc API number
is at least as recent as <ver> otherwise false.
awslc_api_atleast(35)
- awslc_api_before(<ver>): returns true if the current awslc API number
is strictly older than <ver> otherwise false.
awslc_api_before(26)
- defined(<name>) : returns true if an environment variable <name>
exists, regardless of its contents
- feature(<name>) : returns true if feature <name> is listed as present
in the features list reported by "haproxy -vv"
(which means a <name> appears after a '+')
- openssl_version_atleast(<ver>) : returns true if the current openssl
version is at least as recent as <ver> otherwise
false.
Libraries like LibreSSL, AWS-LC and WolfSSL also
provide a pseudo OpenSSL version.
ssllib_name_startswith(OpenSSL) && openssl_version_atleast(1.1.1)
- openssl_version_before(<ver>) : returns true if the current openssl
version is strictly older than <ver> otherwise
false.
Libraries like LibreSSL, AWS-LC and WolfSSL also
provide a pseudo OpenSSL version.
openssl_version_before(3.5.0)
- ssllib_name_startswith(<name>) : return true if the SSL library name
HAProxy was linked with, starts with <name>.
ssllib_name_startswith(wolfSSL)
- streq(<str1>,<str2>) : returns true only if the two strings are equal
- strneq(<str1>,<str2>) : returns true only if the two strings differ
- strstr(<str1>,<str2>) : returns true only if the second string is found in
the first one.
- version_atleast(<ver>): returns true if the current haproxy version is
at least as recent as <ver> otherwise false. The
version syntax is the same as shown by "haproxy -v"
and missing components are assumed as being zero.
- version_before(<ver>) : returns true if the current haproxy version is
strictly older than <ver> otherwise false. The
version syntax is the same as shown by "haproxy -v"
and missing components are assumed as being zero.
- enabled(<opt>) : returns true if the option <opt> is enabled at
run-time. Only a subset of options are supported:
POLL, EPOLL, KQUEUE, EVPORTS, SPLICE,
GETADDRINFO, REUSEPORT, FAST-FORWARD,
SERVER-SSL-VERIFY-NONE
# 1. HAPROXY_MWORKER variable is set automatically by HAProxy in master and
# in worker process environments (see HAProxy variables matrix from
# 2.3. Environment variables). Its presence enables an additional listener.
global
master-worker
.if defined(HAPROXY_MWORKER)
listen mwcli_px
bind :1111
...
.endif
# 2. HAPROXY_BRANCH is set automatically by HAProxy in master and in worker
# process environments (see HAProxy variables matrix from 2.3. Environment
# variables). We check HAPROXY_BRANCH value and conditionally enable
# mworker-max-reloads parameter.
global
master-worker
.if streq("$HAPROXY_BRANCH",3.1)
mworker-max-reloads 5
.endif
# 3. Some arbitrary environment variables are set by user in the global
# section. If HAProxy is started in master-worker mode, they are presented in
# master and in worker process environments. We check values of these
# variables and conditionally enable ports 80 and 443. Environment variables
# checks can be mixed with features and version checks.
global
setenv WITH_SSL yes
unsetenv SSL_ONLY
.if strneq("$SSL_ONLY",yes)
bind :80
.endif
.if streq("$WITH_SSL",yes)
.if feature(OPENSSL)
bind :443 ssl crt ...
.endif
.endif
.if feature(OPENSSL) && (streq("$WITH_SSL",yes) || streq("$SSL_ONLY",yes))
bind :443 ssl crt ...
.endif
.if version_atleast(2.4-dev19)
profiling.memory on
.endif
.if !feature(OPENSSL)
.alert "SSL support is mandatory"
.endif
Four other directives are provided to report some status: - .diag "message" : emit this message only when in diagnostic mode (-dD) - .notice "message" : emit this message at level NOTICE - .warning "message" : emit this message at level WARNING - .alert "message" : emit this message at level ALERT Messages emitted at level WARNING may cause the process to fail to start if "zero-warning" is enabled. Messages emitted at level ALERT will always cause a fatal error. These can be used to detect some inappropriate conditions and provide advice to the user.
.if "${A}"
.if "${B}"
.notice "A=1, B=1"
.elif "${C}"
.notice "A=1, B=0, C=1"
.elif "${D}"
.warning "A=1, B=0, C=0, D=1"
.else
.alert "A=1, B=0, C=0, D=0"
.endif
.else
.notice "A=0"
.endif
.diag "WTA/2021-05-07: replace 'redirect' with 'return' after switch to 2.4"
http-request redirect location /goaway if ABUSE
Some parameters involve values representing time, such as timeouts. These values are generally expressed in milliseconds (unless explicitly stated otherwise) but may be expressed in any other unit by suffixing the unit to the numeric value. It is important to consider this because it will not be repeated for every keyword. Supported units are : - us : microseconds. 1 microsecond = 1/1000000 second - ms : milliseconds. 1 millisecond = 1/1000 second. This is the default. - s : seconds. 1s = 1000ms - m : minutes. 1m = 60s = 60000ms - h : hours. 1h = 60m = 3600s = 3600000ms - d : days. 1d = 24h = 1440m = 86400s = 86400000ms
Some parameters involve values representing size, such as bandwidth limits. These values are generally expressed in bytes (unless explicitly stated otherwise) but may be expressed in any other unit by suffixing the unit to the numeric value. It is important to consider this because it will not be repeated for every keyword. Supported units are case insensitive : - k : kilobytes. 1 kilobyte = 1024 bytes - m : megabytes. 1 megabyte = 1048576 bytes - g : gigabytes. 1 gigabyte = 1073741824 bytes Both time and size formats require integers, decimal notation is not allowed.
It is possible to use a list of pattern for maps or ACLs. A list of pattern is
identified by its name and may be used at different places in the
configuration. List of pattern are split on three categories depending on
the name format:
* Lists of pattern based on regular files: It is the default case. The
filename, absolute or relative, is used as name. The file must exist
otherwise an error is triggered. But it may be empty. The "file@" prefix
may also be specified but it is not part of the name identifying the
list. A filename, with or without the prefix, references the same list of
pattern.
* Lists of pattern based on optional files: The filename must be preceded by
"opt@" prefix. The file existence is optional. If the file exists, its
content is loaded but no error is reported if not. The prefix is not part
of the name identifying the list. It means, for a given filename, Optional
files and regular files reference the same list of pattern.
* Lists of pattern based on virtual files: The name is just an identifier. It
is not a reference to any file. "virt@" prefix must be used. It is part of
the name. Thus it cannot be mixed with other kind of lists.
Virtual files are useful when patterns are fully dynamically managed with no
patterns on startup and on reload. Optional files may be used under the same
conditions. But patterns can be dumped in the file, via an external script based
on the "show map" CLI command for instance. This way, it is possible to keep
patterns on reload.
Note: Even if it is unlikely, it means no regular file starting with "file@",
"opt@" or "virt@" can be loaded, except by adding "./" explicitly in
front of the filename (for instance "file@./virt@map").
In HAProxy configuration, variables can be used in sample fetch functions,
converters, log-format strings or TCP/HTTP actions. Process-wide variables can
be defined, globally accessible for the whole life of the process. Some others
have a shorter lifespan. Variables are similar to those found in shell
scripts. It is a symbolic name for a chunk of memory. The variables size is not
limited and is dynamically allocated. So they must be used with caution,
especially for an intensive usage. However, it is possible to limit the maximum
amount of memory used by the variables by setting "tune.vars" global parameters.
Variables must be designated using the format "<scope>.<name>". The <scope> is
a single word indicating the life time of the variable. The <name> part, inside
a scope, may only contain characters 'a-z', 'A-Z', '0-9' and '_'. It is unique
in this scope but the same name in different scopes can be used and refers to
different variables. Supported scopes are:
* proc : for variables known during the whole process lifespan and globally
accessible. "proc" variables can be manipulated from the CLI using
"get var" and "set var" commands. They can also be set from
"global" sections via "set-var" and "set-var-fmt" directives.
* sess : for variables known during the whole lifespan of a session. "sess"
variables are private to a session, not visbile from outside it and
not shared with other sessions.
* txn : for variables known during the whole lifespan of a transaction. "txn"
variables are private to a stream, not visible from outside it and
not shared with other streams.
* req : for variables known during the request processing for a specific
stream. "req" variables are visible from the stream creation and
until the first server connection attempt. They are private to a
stream, not visible from outside it and not shared with other
streams. There is no overlap at all between "req" and "res"
variables.
* res : for variables known during the response processing for a specific
stream. "res" variables are visible from the first server
connection attempt and until the stream destruction. They are
private to a stream, not visible from outside it and not shared
with other streams. There is no overlap at all between "req" and
"res" variables.
* check : for variables known during a health-check execution. "check"
variables are private to a health-check, not visible from outside
it and are not shared with other health-checks. They can be set
using dedicated "tcp-check" or "http-check" directives.
Depending on the context, extra scopes referencing the parent of a current
stream can be used:
* psess : same as "sess" but using the session of the parent stream, if any.
* ptxn : same as "txn" but using the transaction of the parent stream, if
any.
* preq : same as "req" but using the parent stream, if any. "preq"
variables are only accessible during request processing of the
parent stream.
* pres : same as "res" but using the parent stream, if any. "pres"
variables are only accessible during response processing of the
parent stream.
Scopes referencing the parent stream are usable from the moment it is defined.
Most of time, there is no parent stream. But, if applicable, this will be
explicitly specified. For now, it is only possible to retrieve the value of
variables defined in a scope of the parent stream. It is not possible to set
nor unset such variables. Usually a child stream performs some processing for
the parent at a precise moment and prevents it from making progress until the
operation it does is completed. This means that the parent may be stopped in
the middle of a request processing or a response processing for example. As
such, certain scopes will not be available from the child stream. For example
if a request is subject to some analysis performed by a child stream, this
child stream will not find any variable in the "pres" scope since the parent is
not processing a response, hence doesn't have any variables in its "res" scope.
The content of a variable is the result of the evaluation of a sample fetch
expression and it inherits of the output type of this expression. It is
important when the variable is used because its type must be compatible with
its usage. For instance a variable containing a string used in "add()"
converter must be convertible to a valid integer to succeed. It is especially
true when variables are compared to static value. The right matching method
must be used.
Several statements as "bind, "server", "nameserver" and "log" requires an address. This address can be a host name, an IPv4 address, an IPv6 address, or '*'. The '*' is equal to the special address "0.0.0.0" and can be used, in the case of "bind" or "dgram-bind" to listen on all IPv4 of the system.The IPv6 equivalent is '::'. Depending of the statement, a port or port range follows the IP address. This is mandatory on 'bind' statement, optional on 'server'. This address can also begin with a slash '/'. It is considered as the "unix" family, and '/' and following characters must be present the path. Default socket type or transport method "datagram" or "stream" depends on the configuration statement showing the address. Indeed, 'bind' and 'server' will use a "stream" socket type by default whereas 'log', 'nameserver' or 'dgram-bind' will use a "datagram". Optionally, a prefix could be used to force the address family and/or the socket type and the transport method.
'abns@<name>' following <name> is an abstract namespace (Linux only).
'abnsz@<name>' following <name> is a zero-terminated abstract namespace
(Linux only).
'fd@<n>' following address is a file descriptor <n> inherited from the
parent. The fd must be bound and may or may not already be
listening.
'ip@<address>[:port1[-port2]]' following <address> is considered as an IPv4 or
IPv6 address depending on the syntax. Depending
on the statement using this address, a port or
a port range may or must be specified.
'ipv4@<address>[:port1[-port2]]' following <address> is always considered as
an IPv4 address. Depending on the statement
using this address, a port or a port range
may or must be specified.
'ipv6@<address>[:port1[-port2]]' following <address> is always considered as
an IPv6 address. Depending on the statement
using this address, a port or a port range
may or must be specified.
'sockpair@<n>' following address is the file descriptor of a connected unix
socket or of a socketpair. During a connection, the initiator
creates a pair of connected sockets, and passes one of them
over the FD to the other end. The listener waits to receive
the FD from the unix socket and uses it as if it were the FD
of an accept(). Should be used carefully.
Bugs: This protocol is known to be unreliable on macOS because
of an issue in the macOS sendmsg(2) implementation. The
connection might not be accepted correctly.
'unix@<path>' following string is considered as a UNIX socket <path>. this
prefix is useful to declare an UNIX socket path which don't
start by slash '/'.
Previous "Address family prefixes" can also be prefixed to force the socket
type and the transport method. The default depends of the statement using
this address but in some cases the user may force it to a different one.
This is the case for "log" statement where the default is syslog over UDP
but we could force to use syslog over TCP.
Those prefixes were designed for internal purpose and users should instead use
use aliases of the next section "2.9.3 Protocol prefixes". However these can
sometimes be convenient, for example in combination with inherited sockets
known by their file descriptor number, in which case the address family is "fd"
and the socket type must be declared.
If users need one those prefixes to perform what they expect because
they can not configure the same using the protocol prefixes, they should
report this to the maintainers.
'stream+<family>@<address>' forces socket type and transport method
to "stream"
'dgram+<family>@<address>' forces socket type and transport method
to "datagram".
'quic+<family>@<address>' forces socket type to "datagram" and transport
method to "stream".
'quic4@<address>[:port1[-port2]]' following <address> is always considered as
an IPv4 address but socket type is forced to
"datagram" and the transport method is forced
to "stream". Depending on the statement using
this address, a UDP port or port range can or
must be specified. It is equivalent to
"quic+ipv4@".
'quic6@<address>[:port1[-port2]]' following <address> is always considered as
an IPv6 address but socket type is forced to
"datagram" and the transport method is forced
to "stream". Depending on the statement using
this address, a UDP port or port range can or
must be specified. It is equivalent to
"quic+ipv6@".
'tcp@<address>[:port1[-port2]]' following <address> is considered as an IPv4
or IPv6 address depending of the syntax but
socket type and transport method is forced to
"stream". Depending on the statement using
this address, a port or a port range can or
must be specified. It is considered as an alias
of 'stream+ip@'.
'tcp4@<address>[:port1[-port2]]' following <address> is always considered as
an IPv4 address but socket type and transport
method is forced to "stream". Depending on the
statement using this address, a port or port
range can or must be specified.
It is considered as an alias of 'stream+ipv4@'.
'tcp6@<address>[:port1[-port2]]' following <address> is always considered as
an IPv6 address but socket type and transport
method is forced to "stream". Depending on the
statement using this address, a port or port
range can or must be specified.
It is considered as an alias of 'stream+ipv4@'.
'mptcp@<address>[:port1[-port2]]' following <address> is considered as an IPv4
or IPv6 address depending of the syntax but
socket type and transport method is forced to
"stream", with the MPTCP protocol. Depending
on the statement using this address, a port or
a port range can or must be specified.
'mptcp4@<address>[:port1[-port2]]' following <address> is always considered as
an IPv4 address but socket type and transport
method is forced to "stream", with the MPTCP
protocol. Depending on the statement using
this address, a port or port range can or
must be specified.
'mptcp6@<address>[:port1[-port2]]' following <address> is always considered as
an IPv6 address but socket type and transport
method is forced to "stream", with the MPTCP
protocol. Depending on the statement using
this address, a port or port range can or
must be specified.
'udp@<address>[:port1[-port2]]' following <address> is considered as an IPv4
or IPv6 address depending of the syntax but
socket type and transport method is forced to
"datagram". Depending on the statement using
this address, a port or a port range can or
must be specified. It is considered as an alias
of 'dgram+ip@'.
'udp4@<address>[:port1[-port2]]' following <address> is always considered as
an IPv4 address but socket type and transport
method is forced to "datagram". Depending on
the statement using this address, a port or
port range can or must be specified.
It is considered as an alias of 'dgram+ipv4@'.
'udp6@<address>[:port1[-port2]]' following <address> is always considered as
an IPv6 address but socket type and transport
method is forced to "datagram". Depending on
the statement using this address, a port or
port range can or must be specified.
It is considered as an alias of 'dgram+ipv4@'.
'uxdg@<path>' following string is considered as a unix socket <path> but
transport method is forced to "datagram". It is considered as
an alias of 'dgram+unix@'.
'uxst@<path>' following string is considered as a unix socket <path> but
transport method is forced to "stream". It is considered as
an alias of 'stream+unix@'.
In future versions, other prefixes could be used to specify protocols like
QUIC which proposes stream transport based on socket of type "datagram".
# Simple configuration for an HTTP proxy listening on port 80 on all
# interfaces and forwarding requests to a single backend "servers" with a
# single server "server1" listening on 127.0.0.1:8000
global
daemon
maxconn 256
defaults
mode http
timeout connect 5000ms
timeout client 50000ms
timeout server 50000ms
frontend http-in
bind *:80
default_backend servers
backend servers
server server1 127.0.0.1:8000 maxconn 32
# The same configuration defined with a single listen block. Shorter but
# less expressive, especially in HTTP mode.
global
daemon
maxconn 256
defaults
mode http
timeout connect 5000ms
timeout client 50000ms
timeout server 50000ms
listen http-in
bind *:80
server server1 127.0.0.1:8000 maxconn 32
Assuming haproxy is in $PATH, test these configurations in a shell with:
$ sudo haproxy -f configuration.conf -c
Parameters in the "global" section are process-wide and often OS-specific. They are generally set once for all and do not need being changed once correct. Some of them have command-line equivalents. The following keywords are supported in the "global" section : * Process management and security - 51degrees-allow-unmatched - 51degrees-cache-size - 51degrees-data-file - 51degrees-difference - 51degrees-drift - 51degrees-property-name-list - 51degrees-property-separator - 51degrees-use-performance-graph - 51degrees-use-predictive-graph - ca-base - chroot - cluster-secret - cpu-affinity - cpu-map - cpu-policy - cpu-set - crt-base - daemon - default-path - description - deviceatlas-json-file - deviceatlas-log-level - deviceatlas-properties-cookie - deviceatlas-separator - dns-accept-family - expose-deprecated-directives - expose-experimental-directives - external-check - fd-hard-limit - gid - grace - group - h1-accept-payload-with-any-method - h1-case-adjust - h1-case-adjust-file - h1-do-not-close-on-insecure-transfer-encoding - h2-workaround-bogus-websocket-clients - hard-stop-after - harden.reject-privileged-ports.tcp - harden.reject-privileged-ports.quic - insecure-fork-wanted - insecure-setuid-wanted - issuers-chain-path - jwt.decrypt_alg_list - jwt.decrypt_enc_list - key-base - limited-quic - localpeer - log - log-send-hostname - log-tag - lua-load - lua-load-per-thread - lua-prepend-path - max-threads-per-group - mworker-max-reloads - nbthread - node - numa-cpu-mapping - ocsp-update.disable - ocsp-update.maxdelay - ocsp-update.mindelay - ocsp-update.httpproxy - ocsp-update.mode - pidfile - pp2-never-send-local - presetenv - prealloc-fd - resetenv - set-dumpable - set-var - setenv - ssl-default-bind-ciphers - ssl-default-bind-ciphersuites - ssl-default-bind-client-sigalgs - ssl-default-bind-curves - ssl-default-bind-options - ssl-default-bind-sigalgs - ssl-default-server-ciphers - ssl-default-server-ciphersuites - ssl-default-server-client-sigalgs - ssl-default-server-curves - ssl-default-server-options - ssl-default-server-sigalgs - ssl-dh-param-file - ssl-propquery - ssl-provider - ssl-provider-path - ssl-security-level - ssl-server-verify - ssl-skip-self-issued-ca - stats - stats-file - strict-limits - uid - ulimit-n - unix-bind - unsetenv - user - wurfl-cache-size - wurfl-data-file - wurfl-information-list - wurfl-information-list-separator * Performance tuning - busy-polling - max-spread-checks - maxcompcpuusage - maxcomprate - maxconn - maxconnrate - maxpipes - maxsessrate - maxsslconn - maxsslrate - maxzlibmem - no-memory-trimming - noepoll - noevports - nogetaddrinfo - nokqueue - noktls - nopoll - noreuseport - nosplice - profiling.memory - profiling.tasks - server-state-base - server-state-file - spread-checks - ssl-engine - ssl-mode-async - tune.applet.zero-copy-forwarding - tune.buffers.limit - tune.buffers.reserve - tune.bufsize - tune.bufsize.large - tune.bufsize.small - tune.cli.max-payload-size - tune.comp.maxlevel - tune.defaults.purge - tune.disable-fast-forward - tune.disable-zero-copy-forwarding - tune.epoll.mask-events - tune.events.max-events-at-once - tune.fail-alloc - tune.fd.edge-triggered - tune.h1.be.glitches-threshold - tune.h1.fe.glitches-threshold - tune.h1.zero-copy-fwd-recv - tune.h1.zero-copy-fwd-send - tune.h2.be.glitches-threshold - tune.h2.be.initial-window-size - tune.h2.be.max-concurrent-streams - tune.h2.be.max-frames-at-once - tune.h2.be.rxbuf - tune.h2.fe.glitches-threshold - tune.h2.fe.initial-window-size - tune.h2.fe.max-concurrent-streams - tune.h2.fe.max-frames-at-once - tune.h2.fe.max-rst-at-once - tune.h2.fe.max-total-streams - tune.h2.fe.rxbuf - tune.h2.header-table-size - tune.h2.initial-window-size - tune.h2.max-concurrent-streams - tune.h2.max-frame-size - tune.h2.zero-copy-fwd-send - tune.http.cookielen - tune.http.logurilen - tune.http.maxhdr - tune.idle-pool.shared - tune.idletimer - tune.lua.bool-sample-conversion - tune.lua.burst-timeout - tune.lua.forced-yield - tune.lua.log.loggers - tune.lua.log.stderr - tune.lua.maxmem - tune.lua.openlibs - tune.lua.service-timeout - tune.lua.session-timeout - tune.lua.task-timeout - tune.max-checks-per-thread - tune.maxaccept - tune.maxpollevents - tune.maxrewrite - tune.max-rules-at-once - tune.memory.hot-size - tune.pattern.cache-size - tune.peers.max-updates-at-once - tune.pipesize - tune.pool-high-fd-ratio - tune.pool-low-fd-ratio - tune.pt.zero-copy-forwarding - tune.quic.be.cc.cubic-min-losses - tune.quic.be.cc.hystart - tune.quic.be.cc.max-frame-loss - tune.quic.be.cc.max-win-size - tune.quic.be.cc.reorder-ratio - tune.quic.be.max-idle-timeout - tune.quic.be.sec.glitches-threshold - tune.quic.be.stream.data-ratio - tune.quic.be.stream.max-concurrent - tune.quic.be.stream.rxbuf - tune.quic.be.tx.pacing - tune.quic.be.tx.udp-gso - tune.quic.cc.cubic.min-losses (deprecated) - tune.quic.cc-hystart (deprecated) - tune.quic.disable-tx-pacing (deprecated) - tune.quic.disable-udp-gso (deprecated) - tune.quic.fe.cc.cubic-min-losses - tune.quic.fe.cc.hystart - tune.quic.fe.cc.max-frame-loss - tune.quic.fe.cc.max-win-size - tune.quic.fe.cc.reorder-ratio - tune.quic.fe.max-idle-timeout - tune.quic.fe.sec.glitches-threshold - tune.quic.fe.sec.retry-threshold - tune.quic.fe.sock-per-conn - tune.quic.fe.stream.data-ratio - tune.quic.fe.stream.max-concurrent - tune.quic.fe.stream.max-total - tune.quic.fe.stream.rxbuf - tune.quic.fe.tx.pacing - tune.quic.fe.tx.udp-gso - tune.quic.frontend.max-data-size (deprecated) - tune.quic.frontend.max-idle-timeout (deprecated) - tune.quic.frontend.max-streams-bidi (deprecated) - tune.quic.frontend.max-tx-mem (deprecated) - tune.quic.frontend.stream-data-ratio (deprecated) - tune.quic.frontend.default-max-window-size (deprecated) - tune.quic.listen - tune.quic.max-frame-loss (deprecated) - tune.quic.mem.tx-max - tune.quic.reorder-ratio (deprecated) - tune.quic.retry-threshold (deprecated) - tune.quic.socket-owner (deprecated) - tune.quic.zero-copy-fwd-send - tune.renice.runtime - tune.renice.startup - tune.rcvbuf.backend - tune.rcvbuf.client - tune.rcvbuf.frontend - tune.rcvbuf.server - tune.recv_enough - tune.ring.queues - tune.runqueue-depth - tune.sched.low-latency - tune.sndbuf.backend - tune.sndbuf.client - tune.sndbuf.frontend - tune.sndbuf.server - tune.streams-elasticity - tune.stick-counters - tune.ssl.cachesize - tune.ssl.capture-buffer-size - tune.ssl.capture-cipherlist-size (deprecated) - tune.ssl.certificate-compression - tune.ssl.default-dh-param - tune.ssl.force-private-cache - tune.ssl.hard-maxrecord - tune.ssl.keylog - tune.ssl.keyupdate-rate-limit - tune.ssl.lifetime - tune.ssl.maxrecord - tune.ssl.ssl-ctx-cache-size - tune.ssl.ocsp-update.maxdelay (deprecated) - tune.ssl.ocsp-update.mindelay (deprecated) - tune.takeover-other-tg-connections - tune.vars.global-max-size - tune.vars.proc-max-size - tune.vars.reqres-max-size - tune.vars.sess-max-size - tune.vars.txn-max-size - tune.zlib.memlevel - tune.zlib.windowsize * Debugging - anonkey - debug.counters - force-cfg-parser-pause - quiet - warn-blocked-traffic-after - zero-warning * HTTPClient - httpclient.resolvers.disabled - httpclient.resolvers.id - httpclient.resolvers.prefer - httpclient.retries - httpclient.ssl.ca-file - httpclient.ssl.verify - httpclient.timeout.connect
The path of the 51Degrees data file to provide device detection services. The file should be unzipped and accessible by HAProxy with relevant permissions. Please note that this option is only available when HAProxy has been compiled with USE_51DEGREES.
A list of 51Degrees property names to be load from the dataset. A full list of names is available on the 51Degrees website: https://51degrees.com/resources/property-dictionary Please note that this option is only available when HAProxy has been compiled with USE_51DEGREES.
A char that will be appended to every property value in a response header containing 51Degrees results. If not set that will be set as ','. Please note that this option is only available when HAProxy has been compiled with USE_51DEGREES.
Sets the size of the 51Degrees converter cache to <number> entries. This is an LRU cache which reminds previous device detections and their results. By default, this cache is disabled. Please note that this option is only available when HAProxy has been compiled with USE_51DEGREES.
Enables ('on') or disables ('off') the use of the performance graph in
the detection process. The default value depends on 51Degrees library.
Please note that this option is only available when HAProxy has been
compiled with USE_51DEGREES and 51DEGREES_VER=4.
Enables ('on') or disables ('off') the use of the predictive graph in
the detection process. The default value depends on 51Degrees library.
Please note that this option is only available when HAProxy has been
compiled with USE_51DEGREES and 51DEGREES_VER=4.
Sets the drift value that a detection can allow. Please note that this option is only available when HAProxy has been compiled with USE_51DEGREES and 51DEGREES_VER=4.
Sets the difference value that a detection can allow. Please note that this option is only available when HAProxy has been compiled with USE_51DEGREES and 51DEGREES_VER=4.
Enables ('on') or disables ('off') the use of unmatched nodes in the
detection process. The default value depends on 51Degrees library.
Please note that this option is only available when HAProxy has been
compiled with USE_51DEGREES and 51DEGREES_VER=4.
Enable or disable the ACME scheduler. The ACME scheduler starts at HAProxy startup, it will loop over the certificates and start an ACME renewal task when the notAfter value is past curtime + (notAfter - notBefore) / 12, or 7 days if notBefore is not defined. The scheduler will then sleep and wakeup after 12 hours. The default value is "auto".
Assigns a default directory to fetch SSL CA certificates and CRLs from when a relative path is used with "ca-file", "ca-verify-file" or "crl-file" directives. Absolute locations specified in "ca-file", "ca-verify-file" and "crl-file" prevail and ignore "ca-base".
Changes current directory to <jail dir> and performs a chroot() there before dropping privileges. This increases the security level in case an unknown vulnerability would be exploited, since it would make it very hard for the attacker to exploit the system. It is important to ensure that <jail dir> is both empty and non-writable to anyone. When the process is started with superuser privileges, the chroot() is performed directly. On Linux, when started unprivileged, haproxy attempts to perform it from inside a new user namespace created with unshare(CLONE_NEWUSER); if that mechanism is unavailable the chroot() will fail with the usual error. As a special case, <jail dir> may be set to "auto", in which case haproxy creates an anonymous temporary directory, unlinks it, and chroots into it. The resulting jail has no name in the filesystem and is empty and read-only, removing the need to prepare a dedicated jail directory. When starting with superuser privileges, a warning will be displayed if no chroot is used, in order to encourage users to always use the mechanism. If for any reason there is a compelling reason not to use chroot (e.g. access to a server via a UNIX socket with an unconvenient path), it remains possible to silence the warning by adding an explicit "chroot /", which has the benefit of being visible in a configuration.
Define a time window during which idle connections and active connections closing is spread in case of soft-stop. After a SIGUSR1 is received and the grace period is over (if any), the idle connections will all be closed at once if this option is not set, and active HTTP or HTTP2 connections will be ended after the next request is received, either by appending a "Connection: close" line to the HTTP response, or by sending a GOAWAY frame in case of HTTP2. When this option is set, connection closing will be spread over this set <time>. If the close-spread-time is set to "infinite", active connection closing during a soft-stop will be disabled. The "Connection: close" header will not be added to HTTP responses (or GOAWAY for HTTP2) anymore and idle connections will only be closed once their timeout is reached (based on the various timeouts set in the configuration).
<time> is a time window (by default in milliseconds) during which
connection closing will be spread during a soft-stop operation, or
"infinite" if active connection closing should be disabled.
It is recommended to set this setting to a value lower than the one used in the "hard-stop-after" option if this one is used, so that all connections have a chance to gracefully close before the process stops.
Define an ASCII string secret shared between several nodes belonging to the same cluster. It could be used for different usages. It is at least used to derive stateless reset tokens for all the QUIC connections instantiated by this process. This is also the case to derive secrets used to encrypt Retry tokens. If this parameter is not set, a random value will be selected on process startup. This allows to use features which rely on it, albeit with some limitations.
On some operating systems, it is possible to bind a thread group or a thread to a specific CPU set. This means that the designated threads will never run on other CPUs. The "cpu-map" directive specifies CPU sets for individual threads or thread groups. The first argument is a thread group range, optionally followed by a thread set. These ranges have the following format: all | odd | even | number[-[number]] <number> must be a number between 1 and 32 or 64, depending on the machine's word size. Any group IDs above 'thread-groups' and any thread IDs above the machine's word size are ignored. All thread numbers are relative to the group they belong to. It is possible to specify a range with two such number delimited by a dash ('-'). It also is possible to specify all threads at once using "all", only odd numbers using "odd" or even numbers using "even", just like with the "thread" bind directive. The second and forthcoming arguments are CPU sets. Each CPU set is either a unique number starting at 0 for the first CPU or a range with two such numbers delimited by a dash ('-'). These CPU numbers and ranges may be repeated by delimiting them with commas or by passing more ranges as new arguments on the same line. Outside of Linux and BSD operating systems, there may be a limitation on the maximum CPU index to either 31 or 63. Multiple "cpu-map" directives may be specified, but each "cpu-map" directive will replace the previous ones when they overlap. Ranges can be partially defined. The higher bound can be omitted. In such case, it is replaced by the corresponding maximum value, 32 or 64 depending on the machine's word size. The prefix "auto:" can be added before the thread set to let HAProxy automatically bind a set of threads to a CPU by incrementing threads and CPU sets. To be valid, both sets must have the same size. No matter the declaration order of the CPU sets, it will be bound from the lowest to the highest bound. Having both a group and a thread range with the "auto:" prefix is not supported. Only one range is supported, the other one must be a fixed number. Note that group ranges are supported for historical reasons. Nowadays, a lone number designates a thread group and must be 1 if thread-groups are not used, and specifying a thread range or number requires to prepend "1/" in front of it if thread groups are not used. Finally, "1" is strictly equivalent to "1/all" and designates all threads in the group.
cpu-map 1/all 0-3 # bind all threads of the first group on the
# first 4 CPUs
cpu-map 1/1- 0- # will be replaced by "cpu-map 1/1-64 0-63"
# or "cpu-map 1/1-32 0-31" depending on the machine's
# word size.
# all these lines bind thread 1 to the cpu 0, the thread 2 to cpu 1
# and so on.
cpu-map auto:1/1-4 0-3
cpu-map auto:1/1-4 0-1 2-3
cpu-map auto:1/1-4 3 2 1 0
cpu-map auto:1/1-4 3,2,1,0
# bind each thread to exactly one CPU using all/odd/even keyword
cpu-map auto:1/all 0-63
cpu-map auto:1/even 0-31
cpu-map auto:1/odd 32-63
# invalid cpu-map because thread and CPU sets have different sizes.
cpu-map auto:1/1-4 0 # invalid
cpu-map auto:1/1 0-3 # invalid
# map 40 threads of those 4 groups to individual CPUs
cpu-map auto:1/1-10 0-9
cpu-map auto:2/1-10 10-19
cpu-map auto:3/1-10 20-29
cpu-map auto:4/1-10 30-39
# Map 80 threads to one physical socket and 80 others to another socket
# without forcing assignment. These are split into 4 groups since no
# group may have more than 64 threads.
cpu-map 1/1-40 0-39,80-119 # node0, siblings 0 & 1
cpu-map 2/1-40 0-39,80-119
cpu-map 3/1-40 40-79,120-159 # node1, siblings 0 & 1
cpu-map 4/1-40 40-79,120-159
Defines how you want threads to be bound to cpus. It currently accepts the following values : - per-core: each thread will be bound to all the hardware threads of one core. - per-group: each thread will be bound to all the hardware threads of the group. This is the default unless "threads-per-core 1" is used in "cpu-policy". "per-group" accepts an optional argument, to specify how CPUs should be allocated. When a list of CPUs is larger than the maximum allowed number of CPUs per group and has to be split between multiple groups, an extra option allows to choose how the groups will be bound to those CPUs: - auto: each thread group will only be assigned a fair share of contiguous CPU cores that are dedicated to it and not shared with other groups. This is the default as it generally is more optimal. - loose: each group will still be allowed to use any CPU in the list. This generally causes more contention, but may sometimes help deal better with parasitic loads running on the same CPUs. - auto: "per-group" will be used, unless "threads-per-core 1" is used in "cpu-policy", in which case "per-core" will be used. This is the default. - per-thread: that will bind one thread to one hardware thread only. If "threads-per-core 1" is used in "cpu-policy", then each thread will be bound to one hardware thread of a different core. - per-ccx: each thread will be bound to all the hardware threads of a CCX.
Selects the CPU allocation policy to be used. On multi-CPU systems, there can be plenty of reasons for not using all available CPU cores, and/or for grouping them into different thread groups, for performance, latency, cost, or system-wide resource management. The "cpu-set" directive already allows to evict a number of them, but once done, it is necessary to decide how to assign the remaining ones to threads and thread groups. This mapping is normally performed using the "cpu-map" directive, though it can be particularly difficult to maintain on heterogeneous systems. The "cpu-policy" directive chooses between a small number of allocation policies which one to use instead, when "cpu-map" is not used. The following policies are currently supported, with "performance" being the default one: - none no particular post-selection is performed. All enabled CPUs will be usable, and if the number of threads is not set, it will be set to the number of available CPUs but no more than 32 for 32-bit systems or 64 for 64-bit systems, per thread-group. The number of thread-groups, if not set, will be set to 1. - efficiency exactly like "group-by-ccx" below, except that CPU clusters composed of cores whose performance is more than 25% above that of the next less performant one are evicted. These are typically "big" or "performance" cores. This means that if more than one type of CPU cores are detected, only the efficient one will be used. This can make sense for use with moderate loads when the most powerful cores need to be available to the application or a security component. Some modern CPUs have a large number of such efficient CPU cores which can collectively deliver a decent level of performance while using less power. - first-usable-node if the CPUs were not previously restricted at boot (for example using the "taskset" utility), and if the "nbthread" directive was not set, then the first NUMA node with enabled CPUs will be used, and this number of CPUs will be used as the number of threads. A single thread group will be enabled with all of them, within the limit of 32 or 64 depending on the system. - group-by-2-ccx same as "group-by-ccx" below but create a group every two CCX. This can make sense on CPUs having many CCX of few cores each, to avoid creating many groups, or to smooth the distribution a little bit when not all cores are in use. Please note that it can have very bad performance effects when the communication between CCX is slow. This is generally recommended against. - group-by-2-clusters same as "group-by-cluster" but create a group every two clusters. This can make sense on CPUs having many clusters of few cores each, to avoid creating many groups, or to smooth the distribution a little bit when not all cores are in use. Please note that it can have very bad performance effects when the communication between clusters is slow. This is generally recommended against. - group-by-3-ccx same as "group-by-ccx" below but create a group every three CCX. This can make sense on CPUs having many CCX of few cores each, to avoid creating many groups, or to smooth the distribution a little bit when not all cores are in use. Please note that it can have very bad performance effects when the communication between CCX is slow. This is generally recommended against. - group-by-3-clusters same as "group-by-cluster" but create a group every three clusters. This can make sense on CPUs having many clusters of few cores each, to avoid creating many groups, or to smooth the distribution a little bit when not all cores are in use. Please note that it can have very bad performance effects when the communication between clusters is slow. This is generally recommended against. - group-by-4-ccx same as "group-by-ccx" below but create a group every four CCX. This can make sense on CPUs having many CCX of few cores each, to avoid creating many groups, or to smooth the distribution a little bit when not all cores are in use. Please note that it can have very bad performance effects when the communication between CCX is slow. This is generally recommended against. - group-by-4-clusters same as "group-by-cluster" but create a group every four clusters. This can make sense on CPUs having many clusters of few cores each, to avoid creating many groups, or to smooth the distribution a little bit when not all cores are in use. Please note that it can have very bad performance effects when the communication between clusters is slow. This is generally recommended against. - group-by-ccx if neither "nbthread" not "nbtgroups" were set, then one thread group is created for each CPU core complex ("CCX") with available CPUs, each with as many threads as CPUs. A CCX groups CPUs having a similarly fast access to the last level cache ("LLC"), typically the L3 cache. On most modern machines, it is critical for performance not to mix CPUs from distant CCX in the same thread group. All threads of a group are then bound to all CPUs of the CCX so that intra-group communications remain local to the CCX without enforcing too strong a binding. The per-group thread limits and thread-group limits are respected. This is recommended on multi-socket and NUMA systems, as well as CPUs with bad inter-CCX latencies. - group-by-cluster if neither "nbthread" not "nbtgroups" were set, then one thread group is created for each CPU cluster with available CPUs, each with as many threads as CPUs. All threads of a group are bound to all CPUs of the cluster so that intra-group communications remain local to the cluster without enforcing too strong a binding. The per-group thread limits and thread-group limits are respected. This is recommended on multi-socket and NUMA systems, as well as CPUs with bad inter-CCX latencies. On most server machines, clusters and CCX are the same, but on heterogeneous machines ("performance" vs "efficiency" or "big" vs "little"), a cluster will generally be made of only a part of a CCX composed only of very similar CPUs (same type, +/-5% frequency difference max). The difference is visible on modern laptops and desktop machines used by developers and admins to validate setups. - performance exactly like "group-by-ccx" above, except that CPU clusters composed of cores whose performance is less than 80% of those of the next more performant one are evicted. These are typically "little" or "efficient" cores, whose addition generally doesn't bring significant gains and can easily be counter-productive (e.g. TLS handshakes). Often, keeping such cores for other tasks such as network handling is much more effective. On development systems, these can also be used to run auxiliary tools such as load generators and monitoring tools. This is the default policy. - resource this is like "group-by-cluster" above, except that only the smallest and most efficient CPU cluster will be used, while all other ones will be ignored. This can be used to limit the resource usage to the strict minimum that still delivers decent performance, for example to try to further reduce power consumption or minimize the number of cores needed on some rented systems for a sidecar setup, in order to scale the system down more easily. Note that if a single cluster is present, it will still be fully used. An optional keyword can be added, "threads-per-core". It can accept two values, "1" and "auto". If set to 1, then only one thread per core will be created, unrespective of how many hardware threads the core has. If set to auto, then one thread per hardware thread will be created. If no affinity is specified, and threads-per-core 1 is used, then by default the affinity will be per-core.
Allows to symbolically describe what sets of CPUs to run on. The directive
supports the following keyword:
- reset this undoes any previous limitation that could have
been inherited by a service manager or a "taskset"
command for example.
- drop-cpu <set> do not bind to CPUs in this set
- only-cpu <set> do not bind to CPUs not in this set
- drop-node <set> do not bind to CPUs belonging to this NUMA node
- only-node <set> do not bind to CPUs not belonging to this NUMA node
- drop-cluster <set> do not bind to CPUs on this hardware cluster number
- only-cluster <set> do not bind to CPUs on other hardware cluster number
- drop-core <set> do not bind to CPUs on this hardware core number
- only-core <set> do not bind to CPUs on other hardware core number
- drop-thread <set> do not bind to CPUs on this hardware thread number
- only-thread <set> do not bind to CPUs on other hardware thread number
Assigns a default directory to fetch SSL certificates from when a relative path is used with "crtfile" or "crt" directives. Absolute locations specified prevail and ignore "crt-base".
Makes the process fork into background. This is the recommended mode of operation. It is equivalent to the command line "-D" argument. It can be disabled by the command line "-db" argument. This option is ignored in systemd mode.
By default HAProxy loads all files designated by a relative path from the
location the process is started in. In some circumstances it might be
desirable to force all relative paths to start from a different location
just as if the process was started from such locations. This is what this
directive is made for. Technically it will perform a temporary chdir() to
the designated location while processing each configuration file, and will
return to the original directory after processing each file. It takes an
argument indicating the policy to use when loading files whose path does
not start with a slash ('/'):
- "current" indicates that all relative files are to be loaded from the
directory the process is started in ; this is the default.
- "config" indicates that all relative files should be loaded from the
directory containing the configuration file. More specifically, if the
configuration file contains a slash ('/'), the longest part up to the
last slash is used as the directory to change to, otherwise the current
directory is used. This mode is convenient to bundle maps, errorfiles,
certificates and Lua scripts together as relocatable packages. When
multiple configuration files are loaded, the directory is updated for
each of them.
- "parent" indicates that all relative files should be loaded from the
parent of the directory containing the configuration file. More
specifically, if the configuration file contains a slash ('/'), ".."
is appended to the longest part up to the last slash is used as the
directory to change to, otherwise the directory is "..". This mode is
convenient to bundle maps, errorfiles, certificates and Lua scripts
together as relocatable packages, but where each part is located in a
different subdirectory (e.g. "config/", "certs/", "maps/", ...).
- "origin" indicates that all relative files should be loaded from the
designated (mandatory) path. This may be used to ease management of
different HAProxy instances running in parallel on a system, where each
instance uses a different prefix but where the rest of the sections are
made easily relocatable.
Each "default-path" directive instantly replaces any previous one and will
possibly result in switching to a different directory. While this should
always result in the desired behavior, it is really not a good practice to
use multiple default-path directives, and if used, the policy ought to remain
consistent across all configuration files.
Warning: some configuration elements such as maps or certificates are
uniquely identified by their configured path. By using a relocatable layout,
it becomes possible for several of them to end up with the same unique name,
making it difficult to update them at run time, especially when multiple
configuration files are loaded from different directories. It is essential to
observe a strict collision-free file naming scheme before adopting relative
paths. A robust approach could consist in prefixing all files names with
their respective site name, or in doing so at the directory level.
Add a text that describes the instance. Please note that it is required to escape certain characters (# for example) and this text is inserted into a html page so you should avoid using "<" and ">" characters.
Sets the path of the DeviceAtlas JSON data file to be loaded by the API. The path must be a valid JSON data file and accessible by HAProxy process.
Sets the level of information returned by the API. This directive is optional and set to 0 by default if not set.
Sets the client cookie's name used for the detection if the DeviceAtlas Client-side component was used during the request. This directive is optional and set to DAPROPS by default if not set.
Sets the character separator for the API properties results. This directive is optional and set to | by default if not set.
By default, DNS resolvers accept both IPv4 and IPv6 addresses. This can be influenced by the "resolve-prefer" keywords on server lines as well as the family argument to the "do-resolve" action, but that is only a preference, which does not block the other family from being used when it's alone. In some environments where dual-stack is not usable, stumbling on an unreachable IPv6-only DNS record can cause significant trouble as it will replace a previous IPv4 one which would possibly have continued to work till next request. The "dns-accept-family" global option permits to enforce usage of only one (or both) address families. The argument is a comma-delimited list of the following words: - "ipv4": query and accept IPv4 addresses ("A" records) - "ipv6": query and accept IPv6 addresses ("AAAA" records) - "auto": use IPv4, and IPv6 if the system has a default gateway for it. The result of the last check is cached for 30 seconds. When a single family is used, no request will be sent to resolvers for the other family, and any response for the other family will be ignored. The default value since 3.3 is "auto", which effectively enables both families only once IPv6 has been proven to be routable, otherwise sticks to IPv4.
This statement must appear before using some directives tagged as deprecated to silent warnings and make sure the config file will not be rejected. Not all deprecated directives are concerned, only those without any alternative solution.
This statement must appear before using directives tagged as experimental or the config file will be rejected. Please note that features covered by this option are not guaranteed to work well and may break during the maintenance cycle. Developers will maintain them in best effort mode while the next version is being worked on, and will deploy any reasonable effort to avoid breaking them but with no guarantee. For these reasons, these features are not expected to be supported beyond the release of the next LTS release. Users who want to try experimental features are expected to upgrade quickly to benefit from the improvements made to that feature. In order to know if this directive is still needed, it's easy: if it is enabled without being used by any such feature, a warning will be emitted suggesting to turn it off. So without any warning, it means it's still needed.
Allows the use of an external agent to perform health checks. This is disabled by default as a security precaution, and even when enabled, checks may still fail unless "insecure-fork-wanted" is enabled as well. If the program launched makes use of a setuid executable (it should really not), you may also need to set "insecure-setuid-wanted" in the global section. By default, the checks start with a clean environment which only contains variables defined in the "external-check" command in the backend section. It may sometimes be desirable to preserve the environment though, for example when complex scripts retrieve their extra paths or information there. This can be done by appending the "preserve-env" keyword. In this case however it is strongly advised not to run a setuid nor as a privileged user, as this exposes the check program to potential attacks. See "option external-check", and "insecure-fork-wanted", and "insecure-setuid-wanted" for extra details.
Sets an upper bound to the maximum number of file descriptors that the process will use, regardless of system limits. While "ulimit-n" and "maxconn" may be used to enforce a value, when they are not set, the process will be limited to the hard limit of the RLIMIT_NOFILE setting as reported by "ulimit -n -H". But some modern operating systems are now allowing extremely large values here (in the order of 1 billion), which will consume way too much RAM for regular usage. The fd-hard-limit setting is provided to enforce a possibly lower bound to this limit. This means that it will always respect the system-imposed limits when they are below <number> but the specified value will be used if system-imposed limits are higher. By default fd-hard-limit is set to 1048576. This default could be changed via DEFAULT_MAXFD compile-time variable, that could serve as the maximum (kernel) system limit, if RLIMIT_NOFILE hard limit is extremely large. fd-hard-limit set in global section allows to temporarily override the value provided via DEFAULT_MAXFD at the build-time. In the example below, no other setting is specified and the maxconn value will automatically adapt to the lower of "fd-hard-limit" and the RLIMIT_NOFILE limit: global # use as many FDs as possible but no more than 50000 fd-hard-limit 50000
Changes the process's group ID to <number>. It is recommended that the group ID is dedicated to HAProxy or to a small set of similar daemons. HAProxy must be started with a user belonging to this group, or with superuser privileges. Note that if HAProxy is started from a user having supplementary groups, it will only be able to drop these groups if started with superuser privileges. See also "group" and "uid".
Defines a delay between SIGUSR1 and real soft-stop.
<time> is an extra delay (by default in milliseconds) after receipt of the
SIGUSR1 signal that will be waited for before proceeding with the
soft-stop operation.
This is used for compatibility with legacy environments where the haproxy process needs to be stopped but some external components need to detect the status before listeners are unbound. The principle is that the internal "stopping" variable (which is reported by the "stopping" sample fetch function) will be turned to true, but listeners will continue to accept connections undisturbed, until the delay expires, after what the regular soft-stop will proceed. This must not be used with processes that are reloaded, or this will prevent the old process from unbinding, and may prevent the new one from starting, or simply cause trouble.
global
grace 10s
# Returns 200 OK until stopping is set via SIGUSR1
frontend ext-check
bind :9999
monitor-uri /ext-check
monitor fail if { stopping }
Please note that a more flexible and durable approach would instead consist for an orchestration system in setting a global variable from the CLI, use that variable to respond to external checks, then after a delay send the SIGUSR1 signal.
# Returns 200 OK until proc.stopping is set to non-zero. May be done
# from HTTP using set-var(proc.stopping) or from the CLI using:
# > set var proc.stopping int(1)
frontend ext-check
bind :9999
monitor-uri /ext-check
monitor fail if { var(proc.stopping) -m int gt 0 }
Similar to "gid" but uses the GID of group name <group name> from /etc/group. See also "gid" and "user".
Does not reject HTTP/1.0 GET/HEAD/DELETE requests with a payload with a 413 Payload Too Large HTTP response. While It is explicitly allowed in HTTP/1.1, HTTP/1.0 is not clear on this point and some old servers don't expect any payload and never look for body length (via Content-Length or Transfer-Encoding headers). It means that some intermediaries may properly handle the payload for HTTP/1.0 GET/HEAD/DELETE requests, while some others may totally ignore it. That may lead to security issues because a request smuggling attack is possible. Thus, by default, HAProxy rejects HTTP/1.0 GET/HEAD/DELETE requests with a payload. However, it may be an issue with some old clients. In this case, this global option may be set.
As mandated by the HTTP/1.1 specification (RFC9112#6.1), the presence of both a Transfer-Encoding header field and a Content-Length header field in the same message represents a serious risk of conveying a content smuggling attack if there are any HTTP/1.0 agent anywhere in the upstream of downstream chain, and when facing this, an agent must absolutely close the connection after the response so as to prevent any exploitation. But this may have a performance impact on some very old clients, especially if they need to renegotiate a TLS connection for every request. This option is present to ask HAProxy not to enforce this rule, and to just sanitize the message but leave the connection alive after the response. This may only be done when absolutely certain that no HTTP/1.0 agents are present in the chain and that all implementations before HAProxy are fully HTTP/1.1 compliant regarding the rules that apply to these header fields. In any case, HAProxy will continue to ignore and drop the extraneous Content-Length header so as not to confuse the next hop. When enabling this option to work around an old broken client or server, it is important to understand that regardless of the need or not for this option, such an agent violating this rule faces a risk to see its messages truncated by old agents that would consider Content-Length and ignore Transfer-Encoding, since the cumulated size of the encoded chunk sizes are not being accounted for. As such, the rule above is not just a matter of security but also of taking care of getting rid of agents that may face communication trouble due to incompatibilities with older ones.
Defines the case adjustment to apply, when enabled, to the header name <from>, to change it to <to> before sending it to HTTP/1 clients or servers. <from> must be in lower case, and <from> and <to> must not differ except for their case. It may be repeated if several header names need to be adjusted. Duplicate entries are not allowed. If a lot of header names have to be adjusted, it might be more convenient to use "h1-case-adjust-file". Please note that no transformation will be applied unless "option h1-case-adjust-bogus-client" or "option h1-case-adjust-bogus-server" is specified in a proxy. There is no standard case for header names because, as stated in RFC7230, they are case-insensitive. So applications must handle them in a case- insensitive manner. But some bogus applications violate the standards and erroneously rely on the cases most commonly used by browsers. This problem becomes critical with HTTP/2 because all header names must be exchanged in lower case, and HAProxy follows the same convention. All header names are sent in lower case to clients and servers, regardless of the HTTP version. Applications which fail to properly process requests or responses may require to temporarily use such workarounds to adjust header names sent to them for the time it takes the application to be fixed. Please note that an application which requires such workarounds might be vulnerable to content smuggling attacks and must absolutely be fixed.
global
h1-case-adjust content-length Content-Length
See "h1-case-adjust-file", "option h1-case-adjust-bogus-client" and "option h1-case-adjust-bogus-server".
Defines a file containing a list of key/value pairs used to adjust the case of some header names before sending them to HTTP/1 clients or servers. The file <hdrs-file> must contain 2 header names per line. The first one must be in lower case and both must not differ except for their case. Lines which start with '#' are ignored, just like empty lines. Leading and trailing tabs and spaces are stripped. Duplicate entries are not allowed. Please note that no transformation will be applied unless "option h1-case-adjust-bogus-client" or "option h1-case-adjust-bogus-server" is specified in a proxy. If this directive is repeated, only the last one will be processed. It is an alternative to the directive "h1-case-adjust" if a lot of header names need to be adjusted. Please read the risks associated with using this. See "h1-case-adjust", "option h1-case-adjust-bogus-client" and "option h1-case-adjust-bogus-server".
This disables the announcement of the support for h2 websockets to clients. This can be use to overcome clients which have issues when implementing the relatively fresh RFC8441, such as Firefox 88. To allow clients to automatically downgrade to http/1.1 for the websocket tunnel, specify h2 support on the bind line using "alpn" without an explicit "proto" keyword. If this statement was previously activated, this can be disabled by prefixing the keyword with "no".
Defines the maximum time allowed to perform a clean soft-stop.
<time> is the maximum time (by default in milliseconds) for which the
instance will remain alive when a soft-stop is received via the
SIGUSR1 signal.
This may be used to ensure that the instance will quit even if connections remain opened during a soft-stop (for example with long timeouts for a proxy in tcp mode). It applies both in TCP and HTTP mode.
global
hard-stop-after 30s
Toggle per protocol protection which forbid communication with clients which use privileged ports as their source port. This range of ports is defined according to RFC 6335. By default, protection is active for QUIC protocol as this behavior is suspicious and may be used as a spoofing or DNS/NTP amplification attack.
Replace, reduce or extend the list of status codes that define an error as considered by the termination codes and the "http_err_cnt" counter in stick tables. The default range for errors is 400 to 499, but in certain contexts some users prefer to exclude specific codes, especially when tracking client errors (e.g. 404 on systems with dynamically generated contents). See also "http-fail-codes" and "http_err_cnt". A range specified without '+' nor '-' redefines the existing range to the new one. A range starting with '+' extends the existing range to also include the specified one, which may or may not overlap with the existing one. A range starting with '-' removes the specified range from the existing one. A range consists in a number from 100 to 599, optionally followed by "-" followed by another number greater than or equal to the first one to indicate the high boundary of the range. Multiple ranges may be delimited by commas for a same add/del/ replace operation.
http-err-codes 400,402-444,446-480,490 # sets exactly these codes
http-err-codes 400-499 -450 +500 # sets 400 to 500 except 450
http-err-codes -450-459 # removes 450 to 459 from range
http-err-codes +501,505 # adds 501 and 505 to range
Replace, reduce or extend the list of status codes that define a failure as considered by the termination codes and the "http_fail_cnt" counter in stick tables. The default range for failures is 500 to 599 except 501 and 505 which can be triggered by clients, and normally indicate a failure from the server to process the request. Some users prefer to exclude certain codes in certain contexts where it is known they're not relevant, such as 500 in certain SOAP environments as it doesn't translate a server fault there. The syntax is exactly the same as for http-err-codes above. See also "http-err-codes" and "http_fail_cnt".
By default HAProxy tries hard to prevent any thread and process creation after it starts. Doing so is particularly important when using Lua files of uncertain origin, and when experimenting with development versions which may still contain bugs whose exploitability is uncertain. And generally speaking it's good hygiene to make sure that no unexpected background activity can be triggered by traffic. But this prevents external checks from working, and may break some very specific Lua scripts which actively rely on the ability to fork. This option is there to disable this protection. Note that it is a bad idea to disable it, as a vulnerability in a library or within HAProxy itself will be easier to exploit once disabled. In addition, forking from Lua or anywhere else is not reliable as the forked process may randomly embed a lock set by another thread and never manage to finish an operation. As such it is highly recommended that this option is never used and that any workload requiring such a fork be reconsidered and moved to a safer solution (such as agents instead of external checks). This option supports the "no" prefix to disable it. This can also be activated with "-dI" on the haproxy command line.
HAProxy doesn't need to call executables at run time (except when using external checks which are strongly recommended against), and is even expected to isolate itself into an empty chroot. As such, there basically is no valid reason to allow a setuid executable to be called without the user being fully aware of the risks. In a situation where HAProxy would need to call external checks and/or disable chroot, exploiting a vulnerability in a library or in HAProxy itself could lead to the execution of an external program. On Linux it is possible to lock the process so that any setuid bit present on such an executable is ignored. This significantly reduces the risk of privilege escalation in such a situation. This is what HAProxy does by default. In case this causes a problem to an external check (for example one which would need the "ping" command), then it is possible to disable this protection by explicitly adding this directive in the global section. If enabled, it is possible to turn it back off by prefixing it with the "no" keyword.
Assigns a directory to load certificate chain for issuer completion. All files must be in PEM format. For certificates loaded with "crt" or "crt-list", if certificate chain is not included in PEM (also commonly known as intermediate certificate), HAProxy will complete chain if the issuer of the certificate corresponds to the first certificate of the chain loaded with "issuers-chain-path". A "crt" file with PrivateKey+Certificate+IntermediateCA2+IntermediateCA1 could be replaced with PrivateKey+Certificate. HAProxy will complete the chain if a file with IntermediateCA2+IntermediateCA1 is present in "issuers-chain-path" directory. All other certificates with the same issuer will share the chain in memory. The OCSP features are able to use the completed chain when no .issuer was used, or no chain was provided in the PEM.
Set the list of algorithms allowed in the jwt_decrypt_XXX converters. JWT tokens using an unsupported or disabled algorithms will never be decrypted. The specified algorithms must have the same format as in section 4.1 of RFC7518 and must be colon-separated. The special "ALL" name can be used to enable all the supported algorithms (see "jwt_decrypt_jwk" converter for a complete list) and a '!' can be appended to an algorithm name to explicitly disable it. Please note that unless "ALL" is specified, using this option will disable any algorithm that is not explicitly mentioned in the provided list.
# Enable all algorithms but the "ECDH-ES" one
jwt.decrypt_alg_list ALL:!ECDH-ES
# Only enable ECDH-ES algorithms
jwt.decrypt_alg_list ECDH-ES:ECDH-ES+A128KW:ECDH-ES+A192KW:ECDH-ES+A256KW
Set the list of encryption algorithms allowed in the jwt_decrypt_XXX converters. JWT tokens using an unsupported or disabled encryption algorithms will never be decrypted. The specified algorithms must have the same format as in section 5.1 of RFC7518 and must be colon-separated. The special "ALL" name can be used to enable all the supported algorithms (see "jwt_decrypt_jwk" converter for a complete list) and a '!' can be appended to an algorithm name to explicitly disable it. Please note that unless "ALL" is specified, using this option will disable any algorithm that is not explicitly mentioned in the provided list.
# Enable only AES GCM encrypting algorithms
jwt.decrypt_enc_list A128GCM:A192GCM:A256GCM
Assigns a default directory to fetch SSL private keys from when a relative path is used with "key" directives. Absolute locations specified prevail and ignore "key-base". This option only works with a crt-store load line.
This setting must be used to explicitly enable the QUIC listener bindings when haproxy is compiled with a version of OpenSSL without QUIC support. It activates an haproxy internal compatibility layer which must have been selected at build time with USE_QUIC_OPENSSL_COMPAT=1. This compatibility layer supports most of the necessary TLS operations, albeit without QUIC 0-RTT capability. This feature is primarily targeted for OpenSSL prior to version 3.5.2, where QUIC API was not implemented or only partially. The compatibility layer can still be activated for version 3.5.2 and above, but this is probably unnecessary. If limited-quic is set but the compatibility layer was not selected at build time, the option is silently ignored and QUIC TLS operations rely on the TLS library.
Sets the local instance's peer name. It will be ignored if the "-L" command line argument is specified or if used after "peers" section definitions. In such cases, a warning message will be emitted during the configuration parsing. This option will also set the HAPROXY_LOCALPEER environment variable. See also "-L" in the management guide and "peers" section below.
Adds a global syslog server. Several global servers can be defined. They will receive logs for starts and exits, as well as all logs from proxies configured with "log global". See "log" option for proxies for more details.
Sets the hostname field in the syslog header. If optional "string" parameter is set the header is set to the string contents, otherwise uses the hostname of the system. Generally used if one is not relaying logs through an intermediate syslog server or for simply customizing the hostname printed in the logs.
Sets the tag field in the syslog header to this string. It defaults to the
program name as launched from the command line, which usually is "haproxy".
Sometimes it can be useful to differentiate between multiple processes
running on the same host. See also the per-proxy "log-tag" directive.
This global directive loads and executes a Lua file in the shared context that is visible to all threads. Any variable set in such a context is visible from any thread. This is the easiest and recommended way to load Lua programs but it will not scale well if a lot of Lua calls are performed, as only one thread may be running on the global state at a time. A program loaded this way will always see 0 in the "core.thread" variable. This directive can be used multiple times. args are available in the lua file using the code below in the body of the file. Do not forget that Lua arrays start at index 1. A "local" variable declared in a file is available in the entire file and not available on other files. local args = table.pack(...)
This global directive loads and executes a Lua file into each started thread. Any global variable has a thread-local visibility so that each thread could see a different value. As such it is strongly recommended not to use global variables in programs loaded this way. An independent copy is loaded and initialized for each thread, everything is done sequentially and in the thread's numeric order from 1 to nbthread. If some operations need to be performed only once, the program should check the "core.thread" variable to figure what thread is being initialized. Programs loaded this way will run concurrently on all threads and will be highly scalable. This is the recommended way to load simple functions that register sample-fetches, converters, actions or services once it is certain the program doesn't depend on global variables. For the sake of simplicity, the directive is available even if only one thread is used and even if threads are disabled (in which case it will be equivalent to lua-load). This directive can be used multiple times. See lua-load for usage of args.
Prepends the given string followed by a semicolon to Lua's package.<type> variable. <type> must either be "path" or "cpath". If <type> is not given it defaults to "path". Lua's paths are semicolon delimited lists of patterns that specify how the `require` function attempts to find the source file of a library. Question marks (?) within a pattern will be replaced by module name. The path is evaluated left to right. This implies that paths that are prepended later will be checked earlier. As an example by specifying the following path: lua-prepend-path /usr/share/haproxy-lua/?/init.lua lua-prepend-path /usr/share/haproxy-lua/?.lua When `require "example"` is being called Lua will first attempt to load the /usr/share/haproxy-lua/example.lua script, if that does not exist the /usr/share/haproxy-lua/example/init.lua will be attempted and the default paths if that does not exist either. See https://www.lua.org/pil/8.1.html for the details within the Lua documentation.
Master-worker mode. It is equivalent to the command line "-W" argument. This keyword is deprecated, please start in master-worker mode using "-W" or "-Ws". This mode will launch a "master" which will fork a "worker" after reading the configuration to process the traffic. The master is used as a process manager which will monitor the "workers". Using this mode, you can reload HAProxy directly by sending a SIGUSR2 signal to the master. Reloading will ask the master to read the configuration again and fork a new worker. The previous worker will be kept until the end of its jobs. The master-worker mode is compatible either with the foreground or daemon mode. By default, if a worker exits with a bad return code, in the case of a segfault for example, all workers will be killed, and the master will leave. It is convenient to combine this behavior with Restart=on-failure in a systemd unit file in order to relaunch the whole process. If you don't want this behavior, you must use the keyword "no-exit-on-failure". See also "-W" in the management guide.
In master-worker mode, by default, if a worker exits with a bad return code, in the case of a segfault for example, all workers will be killed, and the master will leave. It is convenient to combine this behavior with Restart=on-failure in a systemd unit file in order to relaunch the whole process. This keyword allows to keep the remaining processes alive when a worker crashed instead of killing everything. This need to be used with caution as it is only meant for debugging and could put the master process in an abnormal state.
Defines the maximum number of threads in a thread group. Unless the number of thread groups is fixed with the "thread-groups" directive, haproxy will create as many thread groups as needed to satisfy the requested number of threads. The minimum value is 1, and the maximum value is 64 (on 64-bit systems, or 32 on 32-bit systems). Lower values reduce contention caused by atomic operations on shared states, but can increase the number of sockets needed to create all listeners and to hold idle backend connections. Higher values will reduce these costs, at the expense of higher CPU usage under contented situations, and lower connection rates. The default value is 16, which provides the best tradeoff that was experimentally found on various tested systems, including x86_64 processors from multiple vendors, and large Arm64 systems, both on bare metal and hypervisors.
In master-worker mode, this option limits the number of time a worker can survive to a reload. If the worker did not leave after a reload, once its number of reloads is greater than this number, the worker will receive a SIGTERM. This option helps to keep under control the number of workers. See also "show proc" in the Management Guide. By default this value is set to 50.
This setting is only available when support for threads was built in. It makes HAProxy run on <number> threads. "nbthread" also works when HAProxy is started in foreground. On some platforms supporting CPU affinity, the default "nbthread" value is automatically set to the number of CPUs the process is bound to upon startup. This means that the thread count can easily be adjusted from the calling process using commands like "taskset" or "cpuset". Otherwise, this value defaults to 1. The default value is reported in the output of "haproxy -vv". Note that values set here or automatically detected are subject to the limit set by "thread-hard-limit" (if set).
When running on a NUMA-aware platform, this enables the "cpu-policy" directive to inspect the topology and figure the best set of CPUs to use and the corresponding number of threads. However, if the applied binding is non optimal on a particular architecture, it can be disabled with the statement 'no numa-cpu-mapping'. This automatic binding is also not applied if a 'nbthread' statement is present in the configuration, if the affinity of the process is already specified, for example via the 'cpu-map' directive or the taskset utility, or if the cpu-policy is set to any other value. See also "cpu-map", "cpu-policy", "cpu-set".
Disable completely the ocsp-update in HAProxy. Any ocsp-update configuration will be ignored. Default is "off". See option "ocsp-update" for more information about the auto update mechanism.
Allow to use an HTTP proxy for the OCSP updates. This only works with HTTP, HTTPS is not supported. This option will allow the OCSP updater to send absolute URI in the request to the proxy.
Sets the maximum interval between two automatic updates of the same OCSP response. This time is expressed in seconds and defaults to 3600 (1 hour). It must be set to a higher value than "ocsp-update.mindelay". See option "ocsp-update" for more information about the auto update mechanism.
Sets the minimum interval between two automatic updates of the same OCSP response. This time is expressed in seconds and defaults to 300 (5 minutes). It is particularly useful for OCSP response that do not have explicit expiration times. It must be set to a lower value than "ocsp-update.maxdelay". See option "ocsp-update" for more information about the auto update mechanism.
Sets the default ocsp-update mode for all certificates used in the configuration. This global option can be superseded by the crt-list "ocsp-update" option. This option is set to "off" by default. See option "ocsp-update" for more information about the auto update mechanism.
Writes PIDs of all daemons into file <pidfile> when daemon mode or writes PID of master process into file <pidfile> when master-worker mode. This option is equivalent to the "-p" command line argument. The file must be accessible to the user starting the process. See also "daemon" and "master-worker".
A bug in the PROXY protocol v2 implementation was present in HAProxy up to version 2.1, causing it to emit a PROXY command instead of a LOCAL command for health checks. This is particularly minor but confuses some servers' logs. Sadly, the bug was discovered very late and revealed that some servers which possibly only tested their PROXY protocol implementation against HAProxy fail to properly handle the LOCAL command, and permanently remain in the "down" state when HAProxy checks them. When this happens, it is possible to enable this global option to revert to the older (bogus) behavior for the time it takes to contact the affected components' vendors and get them fixed. This option is disabled by default and acts on all servers having the "send-proxy-v2" statement.
Sets environment variable <name> to value <value>. If the variable exists, it is NOT overwritten. The changes immediately take effect so that the next line in the configuration file sees the new value. See also "setenv", "resetenv", and "unsetenv".
Performs a one-time open of the maximum file descriptor which results in a pre-allocation of the kernel's data structures. This prevents short pauses when nbthread>1 and HAProxy opens a file descriptor which requires the kernel to expand its data structures.
Removes all environment variables except the ones specified in argument. It allows to use a clean controlled environment before setting new values with setenv or unsetenv. Please note that some internal functions may make use of some environment variables, such as time manipulation functions, but also OpenSSL or even external checks. This must be used with extreme care and only after complete validation. The changes immediately take effect so that the next line in the configuration file sees the new environment. See also "setenv", "presetenv", and "unsetenv".
Specifies the directory prefix to be prepended in front of all servers state file names which do not start with a '/'. See also "server-state-file", "load-server-state-from-file" and "server-state-file-name".
Specifies the path to the file containing state of servers. If the path starts
with a slash ('/'), it is considered absolute, otherwise it is considered
relative to the directory specified using "server-state-base" (if set) or to
the current directory. Before reloading HAProxy, it is possible to save the
servers' current state using the stats command "show servers state". The
output of this command must be written in the file pointed by <file>. When
starting up, before handling traffic, HAProxy will read, load and apply state
for each server found in the file and available in its current running
configuration. See also "server-state-base" and "show servers state",
"load-server-state-from-file" and "server-state-file-name"
This option helps choose the core dump behavior in case of process crash.
Available options are:
- on this enables core dumping at the process level if it was
previously disabled.
- off this disables a previously enabled core dumping.
- libs this enables core dumping with an embedded copy of the binaries and
libraries that are required for debugging. This may be requested by
developers. In this case haproxy will try to load the libraries it
depends on into memory and keep them preciously. If the process
crashes, they will be dumped into the core so there is no need for
retrieving them from the file system anymore and no risk that they
do not match the core. This takes a few megabytes to a few tens of
megabytes of additional RAM, so it is better not to use it on small
systems.
This option is better left disabled by default and enabled only upon a
developer's request. By default it is disabled. Without argument, it defaults
to "on". If it has been enabled, it may still be forcibly disabled by prefixing
it with the "no" keyword or by setting it to "off". It has no impact on
performance nor stability but will try hard to re-enable core dumps that were
possibly disabled by file size limitations (ulimit -f), core size limitations
(ulimit -c), or "dumpability" of a process after changing its UID/GID (such
as /proc/sys/fs/suid_dumpable on Linux). Core dumps might still be limited by
the current directory's permissions (check what directory the file is started
from), the chroot directory's permission (it may be needed to temporarily
disable the chroot directive or to move it to a dedicated writable location),
or any other system-specific constraint. For example, some Linux flavours are
notorious for replacing the default core file with a path to an executable
not even installed on the system (check /proc/sys/kernel/core_pattern). Often,
simply writing "core", "core.%p" or "/var/log/core/core.%p" addresses the
issue. When trying to enable this option waiting for a rare issue to
re-appear, it's often a good idea to first try to obtain such a dump by
issuing, for example, "kill -11" to the "haproxy" process and verify that it
leaves a core where expected when dying.
Sets the process-wide variable '<var-name>' to the result of the evaluation of the sample expression <expr>. The variable '<var-name>' may only be a process-wide variable (using the 'proc.' prefix). It works exactly like the 'set-var' action in TCP or HTTP rules except that the expression is evaluated at configuration parsing time and that the variable is instantly set. The sample fetch functions and converters permitted in the expression are only those using internal data, typically 'int(value)' or 'str(value)'. It is possible to reference previously allocated variables as well. These variables will then be readable (and modifiable) from the regular rule sets.
global
set-var proc.current_state str(primary)
set-var proc.prio int(100)
set-var proc.threshold int(200),sub(proc.prio)
Sets the process-wide variable '<var-name>' to the string resulting from the evaluation of the log-format <fmt>. The variable '<var-name>' may only be a process-wide variable (using the 'proc.' prefix). It works exactly like the 'set-var-fmt' action in TCP or HTTP rules except that the expression is evaluated at configuration parsing time and that the variable is instantly set. The sample fetch functions and converters permitted in the expression are only those using internal data, typically 'int(value)' or 'str(value)'. It is possible to reference previously allocated variables as well. These variables will then be readable (and modifiable) from the regular rule sets. Please see section 8.2.6 for details on the Custom log format syntax.
global
set-var-fmt proc.current_state "primary"
set-var-fmt proc.bootid "%pid|%t"
Sets a list of capabilities that must be preserved when starting and running either as a non-root user (uid > 0), or when starting with uid 0 (root) and switching then to a non-root. By default all permissions are lost by the uid switch, but some are often needed when trying to connect to a server from a foreign address during transparent proxying, or when binding to a port below 1024, e.g. when using "tune.quic.fe.sock-per-conn default-on", resulting in setups running entirely under uid 0. Setting capabilities generally is a safer alternative, as only the required capabilities will be preserved. The feature is OS-specific and only enabled on Linux when USE_LINUX_CAP=1 is set at build time. The list of supported capabilities also depends on the OS and is enumerated by the error message displayed when an invalid capability name or an empty one is passed. Multiple capabilities may be passed, delimited by commas. Among those commonly used, "cap_net_raw" allows to transparently bind to a foreign address, and "cap_net_bind_service" allows to bind to a privileged port and may be used by QUIC. If the process is started and run under the same non-root user, needed capabilities should be set on haproxy binary file with setcap along with this keyword. For more details about setting capabilities on haproxy binary, please see chapter 13.1 Linux capabilities support in the Management guide.
global
setcap cap_net_bind_service,cap_net_admin
Sets environment variable <name> to value <value>. If the variable exists, it is overwritten. The changes immediately take effect so that the next line in the configuration file sees the new value. See also "presetenv", "resetenv", and "unsetenv".
When this directive is set, it enables the use of shared memory for storing stats counters. <name> is used as argument to shm_open() to open the shared memory at a unique location. It also means that the directive is only available on systems which support shm_open(). When SHM is used for stats, all shareable counters for frontends, backends, listeners and servers will be stored in the SHM, provided that they have a GUID set. When reloading haproxy, new process will try to scan the SHM for objects that could be associated to objects defined in the configuration based on GUID and type, the goal is to be able to preserve some counters' values upon reload. On the other hand, when haproxy is properly stopped, the SHM objects are released, which means counters are effectively reset. It is also possible to manually remove the file before starting a fresh process to force a reset. See also "guid", "guid-prefix" and "shm-stats-file-max-objects"
This setting defines the maximum number of objects the shared memory used for shared counters will be able to store per thread group. It is directly related to the maximum memory size of the shm and is used to "premap" the shm to a given size in order to avoid runtime re-mapping. It defaults to 2k, which should suit for most setups without risking unsuitable memory usage, but can be easily changed if needed. haproxy will complain during startup if this value is to low to register objects that are expected to be stored in the shared memory. It is only relevant when "shm-stats-file" was defined. See also "thread-groups"
This setting is only available when support for OpenSSL was built in. It sets
the default string describing the list of cipher algorithms ("cipher suite")
that are negotiated during the SSL/TLS handshake up to TLSv1.2 for all
"bind" lines which do not explicitly define theirs. The format of the string
is defined in "man 1 ciphers" from OpenSSL man pages. For background
information and recommendations see e.g.
(https://wiki.mozilla.org/Security/Server_Side_TLS) and
(https://mozilla.github.io/server-side-tls/ssl-config-generator/). For TLSv1.3
cipher configuration, please check the "ssl-default-bind-ciphersuites" keyword.
Please check the "bind" keyword for more information.
This setting is only available when support for OpenSSL was built in and
OpenSSL 1.1.1 or later was used to build HAProxy. It sets the default string
describing the list of cipher algorithms ("cipher suite") that are negotiated
during the TLSv1.3 handshake for all "bind" lines which do not explicitly define
theirs. The format of the string is defined in
"man 1 ciphers" from OpenSSL man pages under the section "ciphersuites". For
cipher configuration for TLSv1.2 and earlier, please check the
"ssl-default-bind-ciphers" keyword. This setting might accept TLSv1.2
ciphersuites however this is an undocumented behavior and not recommended as
it could be inconsistent or buggy.
The default TLSv1.3 ciphersuites of OpenSSL are:
"TLS_AES_256_GCM_SHA384:TLS_CHACHA20_POLY1305_SHA256:TLS_AES_128_GCM_SHA256"
TLSv1.3 only supports 5 ciphersuites:
- TLS_AES_128_GCM_SHA256
- TLS_AES_256_GCM_SHA384
- TLS_CHACHA20_POLY1305_SHA256
- TLS_AES_128_CCM_SHA256
- TLS_AES_128_CCM_8_SHA256
Please check the "bind" keyword for more information.
global
ssl-default-bind-ciphers ECDHE-RSA-AES256-GCM-SHA384:ECDHE-RSA-CHACHA20-POLY1305:ECDHE-RSA-AES128-GCM-SHA256
ssl-default-bind-ciphersuites TLS_AES_256_GCM_SHA384:TLS_CHACHA20_POLY1305_SHA256:TLS_AES_128_GCM_SHA256
This setting is only available when support for OpenSSL was built in. It sets the default string describing the list of signature algorithms related to client authentication for all "bind" lines which do not explicitly define theirs. The format of the string is a colon-delimited list of signature algorithms. Each signature algorithm can use one of two forms: TLS1.3 signature scheme names ("rsa_pss_rsae_sha256") or the public key algorithm + digest form ("ECDSA+SHA256"). A list can contain both forms. For more information on the format, see SSL_CTX_set1_client_sigalgs(3). A list of signature algorithms is also available in RFC8446 section 4.2.3 and in OpenSSL in the ssl/t1_lib.c file. This setting is not applicable to TLSv1.1 and earlier versions of the protocol as the signature algorithms aren't separately negotiated in these versions. It is not recommended to change this setting unless compatibility with a middlebox is required.
This setting is only available when support for OpenSSL was built in. It sets
the default string describing the list of elliptic curves algorithms ("curve
suite") that are negotiated during the SSL/TLS handshake with ECDHE. The format
of the string is a colon-delimited list of curve name.
Please check the "bind" keyword for more information.
This setting is only available when support for OpenSSL was built in. It sets default ssl-options to force on all "bind" lines. Please check the "bind" keyword to see available options.
global
ssl-default-bind-options ssl-min-ver TLSv1.0 no-tls-tickets
This setting is only available when support for OpenSSL was built in. It sets the default string describing the list of signature algorithms that are negotiated during the TLSv1.2 and TLSv1.3 handshake for all "bind" lines which do not explicitly define theirs. The format of the string is a colon-delimited list of signature algorithms. Each signature algorithm can use one of two forms: TLS1.3 signature scheme names ("rsa_pss_rsae_sha256") or the public key algorithm + digest form ("ECDSA+SHA256"). A list can contain both forms. For more information on the format, see SSL_CTX_set1_sigalgs(3). A list of signature algorithms is also available in RFC8446 section 4.2.3 and in OpenSSL in the ssl/t1_lib.c file. This setting is not applicable to TLSv1.1 and earlier versions of the protocol as the signature algorithms aren't separately negotiated in these versions. It is not recommended to change this setting unless compatibility with a middlebox is required.
This setting is only available when support for OpenSSL was built in. It sets the default string describing the list of cipher algorithms that are negotiated during the SSL/TLS handshake up to TLSv1.2 with the server, for all "server" lines which do not explicitly define theirs. The format of the string is defined in "man 1 ciphers" from OpenSSL man pages. For background information and recommendations see e.g. (https://wiki.mozilla.org/Security/Server_Side_TLS) and (https://mozilla.github.io/server-side-tls/ssl-config-generator/). For TLSv1.3 cipher configuration, please check the "ssl-default-server-ciphersuites" keyword. Please check the "server" keyword for more information.
This setting is only available when support for OpenSSL was built in and OpenSSL 1.1.1 or later was used to build HAProxy. It sets the default string describing the list of cipher algorithms that are negotiated during the TLSv1.3 handshake with the server, for all "server" lines which do not explicitly define theirs. The format of the string is defined in "man 1 ciphers" from OpenSSL man pages under the section "ciphersuites". For cipher configuration for TLSv1.2 and earlier, please check the "ssl-default-server-ciphers" keyword. Please check the "server" keyword for more information.
This setting is only available when support for OpenSSL was built in. It sets the default string describing the list of signature algorithms related to client authentication for all "server" lines which do not explicitly define theirs. The format of the string is a colon-delimited list of signature algorithms. Each signature algorithm can use one of two forms: TLS1.3 signature scheme names ("rsa_pss_rsae_sha256") or the public key algorithm + digest form ("ECDSA+SHA256"). A list can contain both forms. For more information on the format, see SSL_CTX_set1_client_sigalgs(3). A list of signature algorithms is also available in RFC8446 section 4.2.3 and in OpenSSL in the ssl/t1_lib.c file. This setting is not applicable to TLSv1.1 and earlier versions of the protocol as the signature algorithms aren't separately negotiated in these versions. It is not recommended to change this setting unless compatibility with a middlebox is required.
This setting is only available when support for OpenSSL was built in. It sets
the default string describing the list of elliptic curves algorithms ("curve
suite") that are negotiated during the SSL/TLS handshake with ECDHE. The format
of the string is a colon-delimited list of curve name.
Please check the "server" keyword for more information.
This setting is only available when support for OpenSSL was built in. It sets default ssl-options to force on all "server" lines. Please check the "server" keyword to see available options.
This setting is only available when support for OpenSSL was built in. It sets the default string describing the list of signature algorithms that are negotiated during the TLSv1.2 and TLSv1.3 handshake for all "server" lines which do not explicitly define theirs. The format of the string is a colon-delimited list of signature algorithms. Each signature algorithm can use one of two forms: TLS1.3 signature scheme names ("rsa_pss_rsae_sha256") or the public key algorithm + digest form ("ECDSA+SHA256"). A list can contain both forms. For more information on the format, see SSL_CTX_set1_sigalgs(3). A list of signature algorithms is also available in RFC8446 section 4.2.3 and in OpenSSL in the ssl/t1_lib.c file. This setting is not applicable to TLSv1.1 and earlier versions of the protocol as the signature algorithms aren't separately negotiated in these versions. It is not recommended to change this setting unless compatibility with a middlebox is required.
This setting is only available when support for OpenSSL was built in. It sets
the default DH parameters that are used during the SSL/TLS handshake when
ephemeral Diffie-Hellman (DHE) key exchange is used, for all "bind" lines
which do not explicitly define theirs. It will be overridden by custom DH
parameters found in a bind certificate file if any. If custom DH parameters
are not specified either by using ssl-dh-param-file or by setting them
directly in the certificate file, DHE ciphers will not be used, unless
tune.ssl.default-dh-param is set. In this latter case, pre-defined DH
parameters of the specified size will be used. Custom parameters are known to
be more secure and therefore their use is recommended.
Custom DH parameters may be generated by using the OpenSSL command
"openssl dhparam <size>", where size should be at least 2048, as 1024-bit DH
parameters should not be considered secure anymore.
This settings is only available when support for OpenSSL was built in. It allows to define a full command line that will be called when an encrypted certificate is loaded during init. The command could be a script or any other program. It will be provided with the encrypted private key path as first parameter and the user-defined "args" parameters then and should dump the passphrase that allows to decode the encrypted private key on the standard output. For every new encrypted private key loaded during init, HAProxy will first try every other already known passphrase to decode the private key and will ultimately call the passphrase command again if none works.
This setting is only available when support for OpenSSL was built in and when OpenSSL's version is at least 3.0. It allows to define a default property string used when fetching algorithms in providers. It behave the same way as the openssl propquery option and it follows the same syntax (described in https://www.openssl.org/docs/man3.0/man7/property.html). For instance, if you have two providers loaded, the foo one and the default one, the propquery "?provider=foo" allows to pick the algorithm implementations provided by the foo provider by default, and to fallback on the default provider's one if it was not found.
This setting is only available when support for OpenSSL was built in and when OpenSSL's version is at least 3.0. It allows to load a provider during init. If loading is successful, any capabilities provided by the loaded provider might be used by HAProxy. Multiple 'ssl-provider' options can be specified in a configuration file. The providers will be loaded in their order of appearance. Please note that loading a provider explicitly prevents OpenSSL from loading the 'default' provider automatically. OpenSSL also allows to define the providers that should be loaded directly in its configuration file (openssl.cnf for instance) so it is not necessary to use this 'ssl-provider' option to load providers. The "show ssl providers" CLI command can be used to show all the providers that were successfully loaded. The default search path of OpenSSL provider can be found in the output of the "openssl version -a" command. If the provider is in another directory, you can set the OPENSSL_MODULES environment variable, which takes the directory where your provider can be found. See also "ssl-propquery" and "ssl-provider-path".
This setting is only available when support for OpenSSL was built in and when OpenSSL's version is at least 3.0. It allows to specify the search path that is to be used by OpenSSL for looking for providers. It behaves the same way as the OPENSSL_MODULES environment variable. It will be used for any following 'ssl-provider' option or until a new 'ssl-provider-path' is defined. See also "ssl-provider".
This setting allows to configure the way HAProxy does the lookup for the extra SSL files. By default HAProxy adds a new extension to the filename. (ex: with "foobar.crt" load "foobar.crt.key"). With this option enabled, HAProxy removes the extension before adding the new one (ex: with "foobar.crt" load "foobar.key"). Your crt file must have a ".crt" extension for this option to work. This option is not compatible with bundle extensions (.ecdsa, .rsa. .dsa) and won't try to remove them. This option is disabled by default. See also "ssl-load-extra-files".
This setting alters the way HAProxy will look for unspecified files during the loading of the SSL certificates. This option applies to certificates associated to "bind" lines as well as "server" lines but some of the extra files will not have any functional impact for "server" line certificates. By default, HAProxy discovers automatically a lot of files not specified in the configuration, and you may want to disable this behavior if you want to optimize the startup time. "none": Only load the files specified in the configuration. Don't try to load a certificate bundle if the file does not exist. In the case of a directory, it won't try to bundle the certificates if they have the same basename. "all": This is the default behavior, it will try to load everything, bundles, sctl, ocsp, issuer, key. "bundle": When a file specified in the configuration does not exist, HAProxy will try to load a "cert bundle". Certificate bundles are only managed on the frontend side and will not work for backend certificates. Starting from HAProxy 2.3, the bundles are not loaded in the same OpenSSL certificate store, instead it will loads each certificate in a separate store which is equivalent to declaring multiple "crt". OpenSSL 1.1.1 is required to achieve this. Which means that bundles are now used only for backward compatibility and are not mandatory anymore to do an hybrid RSA/ECC bind configuration. To associate these PEM files into a "cert bundle" that is recognized by HAProxy, they must be named in the following way: All PEM files that are to be bundled must have the same base name, with a suffix indicating the key type. Currently, three suffixes are supported: rsa, dsa and ecdsa. For example, if www.example.com has two PEM files, an RSA file and an ECDSA file, they must be named: "example.pem.rsa" and "example.pem.ecdsa". The first part of the filename is arbitrary; only the suffix matters. To load this bundle into HAProxy, specify the base name only:
bind :8443 ssl crt example.pem
Note that the suffix is not given to HAProxy; this tells HAProxy to look for a cert bundle. HAProxy will load all PEM files in the bundle as if they were configured separately in several "crt". The bundle loading does not have an impact anymore on the directory loading since files are loading separately. On the CLI, bundles are seen as separate files, and the bundle extension is required to commit them. OCSP files (.ocsp), issuer files (.issuer), Certificate Transparency (.sctl) as well as private keys (.key) are supported with multi-cert bundling. "sctl": Try to load "<basename>.sctl" for each crt keyword. If provided for a backend certificate, it will be loaded but will not have any functional impact. "ocsp": Try to load "<basename>.ocsp" for each crt keyword. If provided for a backend certificate, it will be loaded but will not have any functional impact. "issuer": Try to load "<basename>.issuer" if the issuer of the OCSP file is not provided in the PEM file. If provided for a backend certificate, it will be loaded but will not have any functional impact. "key": If the private key was not provided by the PEM file, try to load a file "<basename>.key" containing a private key. The default behavior is "all".
ssl-load-extra-files bundle sctl
ssl-load-extra-files sctl ocsp issuer
ssl-load-extra-files none
This directive allows to chose the OpenSSL security level as described in https://www.openssl.org/docs/man1.1.1/man3/SSL_CTX_set_security_level.html The security level will be applied to every SSL contextes in HAProxy. Only a value between 0 and 5 is supported. The default value depends on your OpenSSL version, distribution and how was compiled the library. This directive requires at least OpenSSL 1.1.1.
The default behavior for SSL verify on servers side. If specified to 'none', servers certificates are not verified. The default is 'required' except if forced using cmdline option '-dV'.
Self issued CA, aka x509 root CA, is the anchor for chain validation: as a server is useless to send it, client must have it. Standard configuration need to not include such CA in PEM file. This option allows you to keep such CA in PEM file without sending it to the client. Use case is to provide issuer for ocsp without the need for '.issuer' file and be able to share it with 'issuers-chain-path'. This concerns all certificates without intermediate certificates. It's useless for BoringSSL, .issuer is ignored because ocsp bits does not need it. Requires at least OpenSSL 1.0.2.
Activates or deactivates the calculation of stats max counters. If you don't need them, deactivating them may increase performances a bit. The default is on.
By default, the stats socket is limited to 10 concurrent connections. It is possible to change this value with "stats maxconn".
Binds a UNIX socket to <path> or a TCPv4/v6 address to <address:port>. Connections to this socket will return various statistics outputs and even allow some commands to be issued to change some runtime settings. Please consult section 9.3 "Unix Socket commands" of Management Guide for more details. All parameters supported by "bind" lines are supported, for instance to restrict access to some users or their access rights. Please consult section 5.1 for more information.
The default timeout on the stats socket is set to 10 seconds. It is possible to change this value with "stats timeout". The value must be passed in milliseconds, or be suffixed by a time unit among { us, ms, s, m, h, d }.
Path to a generated haproxy stats-file. On startup haproxy will preload the values to its internal counters. Use the CLI command "dump stats-file" to produce such stats-file. See the management manual for more details.
Activate alternative code to stress haproxy binary. Level is an integer from 0 to 9. The default value 0 disable any stressing execution. Levels from 1 to 9 will increase the stress pressure on the haproxy binary. Note that using any positive level can significantly hurt performance. As such it should never be activated unless for debugging purpose and on a developer request.
Makes process fail at startup when a setrlimit fails. HAProxy tries to set the best setrlimit according to what has been calculated. If it fails, it will emit a warning. This option is here to guarantee an explicit failure of HAProxy when those limits fail. It is enabled by default. It may still be forcibly disabled by prefixing it with the "no" keyword.
This setting is only available when support for threads was built in. It enumerates the list of threads that will compose thread group <group>. Thread numbers and group numbers start at 1. Thread ranges are defined either using a single thread number at once, or by specifying the lower and upper bounds delimited by a dash '-' (e.g. "1-16"). Unassigned threads will be automatically assigned to unassigned thread groups, and thread groups defined with this directive will never receive more threads than those defined. Defining the same group multiple times overrides previous definitions with the new one. See also "nbthread" and "thread-groups".
This setting is only available when support for threads was built in. It makes HAProxy split its threads into <number> independent groups. At the moment, the default value is 1. Thread groups make it possible to reduce sharing between threads to limit contention, at the expense of some extra configuration efforts. It is also the only way to use more than 64 threads since up to 64 threads per group may be configured. The maximum number of groups is configured at compile time and defaults to 16. See also "nbthread".
This setting is used to enforce a limit to the number of threads, either detected, or configured. This is particularly useful on operating systems where the number of threads is automatically detected, where a number of threads lower than the number of CPUs is desired in generic and portable configurations. Indeed, while "nbthread" enforces a number of threads that will result in a warning and bad performance if higher than CPUs available, thread-hard-limit will only cap the maximum value and automatically limit the number of threads to no higher than this value, but will not raise lower values. If "nbthread" is forced to a higher value, thread-hard-limit wins, and a warning is emitted in so that the configuration anomaly can be fixed. By default there is no limit. See also "nbthread".
Changes the process's user ID to <number>. It is recommended that the user ID is dedicated to HAProxy or to a small set of similar daemons. HAProxy must be started with superuser privileges in order to be able to switch to another one. See also "gid" and "user".
Sets the maximum number of per-process file-descriptors to <number>. By default, it is automatically computed, so it is recommended not to use this option. If the intent is only to limit the number of file descriptors, better use "fd-hard-limit" instead. Note that the dynamic servers are not taken into account in this automatic resource calculation. If using a large number of them, it may be needed to manually specify this value.
Fixes common settings to UNIX listening sockets declared in "bind" statements. This is mainly used to simplify declaration of those UNIX sockets and reduce the risk of errors, since those settings are most commonly required but are also process-specific. The <prefix> setting can be used to force all socket path to be relative to that directory. This might be needed to access another component's chroot. Note that those paths are resolved before HAProxy chroots itself, so they are absolute. The <mode>, <user>, <uid>, <group> and <gid> all have the same meaning as their homonyms used by the "bind" statement. If both are specified, the "bind" statement has priority, meaning that the "unix-bind" settings may be seen as process-wide default settings.
Removes environment variables specified in arguments. This can be useful to hide some sensitive information that are occasionally inherited from the user's environment during some operations. Variables which did not exist are silently ignored so that after the operation, it is certain that none of these variables remain. The changes immediately take effect so that the next line in the configuration file will not see these variables. See also "setenv", "presetenv", and "resetenv".
Similar to "uid" but uses the UID of user name <user name> from /etc/passwd. See also "uid" and "group".
Only letters, digits, hyphen and underscore are allowed, like in DNS names. This statement is useful in HA configurations where two or more processes or servers share the same IP address. By setting a different node-name on all nodes, it becomes easy to immediately spot what server is handling the traffic.
Sets the WURFL Useragent cache size. For faster lookups, already processed user agents are kept in a LRU cache : - "0" : no cache is used. - <size> : size of lru cache in elements. Please note that this option is only available when HAProxy has been compiled with USE_WURFL=1.
The path of the WURFL data file to provide device detection services. The file should be accessible by HAProxy with relevant permissions. Please note that this option is only available when HAProxy has been compiled with USE_WURFL=1.
A space-delimited list of WURFL capabilities, virtual capabilities, property
names we plan to use in injected headers. A full list of capability and
virtual capability names is available on the Scientiamobile website :
https://www.scientiamobile.com/wurflCapability
Valid WURFL properties are:
- wurfl_id Contains the device ID of the matched device.
- wurfl_root_id Contains the device root ID of the matched
device.
- wurfl_isdevroot Tells if the matched device is a root device.
Possible values are "TRUE" or "FALSE".
- wurfl_useragent The original useragent coming with this
particular web request.
- wurfl_api_version Contains a string representing the currently
used Libwurfl API version.
- wurfl_info A string containing information on the parsed
wurfl.xml and its full path.
- wurfl_last_load_time Contains the UNIX timestamp of the last time
WURFL has been loaded successfully.
- wurfl_normalized_useragent The normalized useragent.
Please note that this option is only available when HAProxy has been compiled
with USE_WURFL=1.
A char that will be used to separate values in a response header containing
WURFL results. If not set that a comma (',') will be used by default.
Please note that this option is only available when HAProxy has been compiled
with USE_WURFL=1.
A list of WURFL patch file paths. Note that patches are loaded during startup thus before the chroot. Please note that this option is only available when HAProxy has been compiled with USE_WURFL=1.
In some situations, especially when dealing with low latency on processors supporting a variable frequency or when running inside virtual machines, each time the process waits for an I/O using the poller, the processor goes back to sleep or is offered to another VM for a long time, and it causes excessively high latencies. This option provides a solution preventing the processor from sleeping by always using a null timeout on the pollers. This results in a significant latency reduction (30 to 100 microseconds observed) at the expense of a risk to overheat the processor. It may even be used with threads, in which case improperly bound threads may heavily conflict, resulting in a worse performance and high values for the CPU stolen fields in "show info" output, indicating which threads are misconfigured. It is important not to let the process run on the same processor as the network interrupts when this option is used. It is also better to avoid using it on multiple CPU threads sharing the same core. This option is disabled by default. If it has been enabled, it may still be forcibly disabled by prefixing it with the "no" keyword. It is ignored by the "select" and "poll" pollers. This option is automatically disabled on old processes in the context of seamless reload; it avoids too much cpu conflicts when multiple processes stay around for some time waiting for the end of their current connections.
By default, HAProxy tries to spread the start of health checks across the smallest health check interval of all the servers in a farm. The principle is to avoid hammering services running on the same server. But when using large check intervals (10 seconds or more), the last servers in the farm take some time before starting to be tested, which can be a problem. This parameter is used to enforce an upper bound on delay between the first and the last check, even if the servers' check intervals are larger. When servers run with shorter intervals, their intervals will be respected though.
Sets the maximum CPU usage HAProxy can reach before stopping the compression for new requests or decreasing the compression level of current requests. It works like 'maxcomprate' but measures CPU usage instead of incoming data bandwidth. The value is expressed in percent of the CPU used by HAProxy. A value of 100 disable the limit. The default value is 100. Setting a lower value will prevent the compression work from slowing the whole process down and from introducing high latencies.
Sets the maximum per-process input compression rate to <number> kilobytes per second. For each stream, if the maximum is reached, the compression level will be decreased during the stream. If the maximum is reached at the beginning of a stream, the stream will not compress at all. If the maximum is not reached, the compression level will be increased up to tune.comp.maxlevel. A value of zero means there is no limit, this is the default value.
Sets the maximum per-process number of concurrent connections to <number>. It is equivalent to the command-line argument "-n". The value provided in command-line argument via "-n" takes the precedence over the maxconn value set in the global section. Haproxy process could be also compiled with SYSTEM_MAXCONN compile-time variable, which is served in this case as the system maxconn maximum. Again, the command-line "-n" argument allows at runtime to bypass SYSTEM_MAXCONN limit, if set. Proxies will stop accepting connections when maxconn is reached. The process soft file descriptor limit (could be obtained with "ulimit -n" command) is automatically adjusted according to provided maxconn. See also "ulimit-n". Note: the "select" poller cannot reliably use more than 1024 file descriptors on some platforms. If your platform only supports select and reports "select FAILED" on startup, you need to reduce the maxconn until it works (slightly below 500 in general). If maxconn value is not set, it will be automatically calculated based on the current file descriptors limits, reported by the "ulimit -nH" command (we take the maximum between the hard and soft values), then automatic value will be possibly reduced by "fd-hard-limit" and by memory limit, if the latter was enforced via "-m" command line option. Automatic value is also dependent from the buffer size, memory allocated to compression, SSL cache size, and the use or not of SSL and the associated maxsslconn (which can also be automatic).
Sets the maximum per-process number of connections per second to <number>. Proxies will stop accepting connections when this limit is reached. It can be used to limit the global capacity regardless of each frontend capacity. It is important to note that this can only be used as a service protection measure, as there will not necessarily be a fair share between frontends when the limit is reached, so it's a good idea to also limit each frontend to some value close to its expected share. Also, lowering tune.maxaccept can improve fairness.
Sets the maximum per-process number of pipes to <number>. Currently, pipes are only used by kernel-based tcp splicing. Since a pipe contains two file descriptors, the "ulimit-n" value will be increased accordingly. The default value is maxconn/4, which seems to be more than enough for most heavy usages. The splice code dynamically allocates and releases pipes, and can fall back to standard copy, so setting this value too low may only impact performance.
Sets the maximum per-process number of sessions per second to <number>. Proxies will stop accepting connections when this limit is reached. It can be used to limit the global capacity regardless of each frontend capacity. It is important to note that this can only be used as a service protection measure, as there will not necessarily be a fair share between frontends when the limit is reached, so it's a good idea to also limit each frontend to some value close to its expected share. Also, lowering tune.maxaccept can improve fairness.
Sets the maximum per-process number of concurrent SSL connections to <number>. By default there is no SSL-specific limit, which means that the global maxconn setting will apply to all connections. Setting this limit avoids having openssl use too much memory and crash when malloc returns NULL (since it unfortunately does not reliably check for such conditions). Note that the limit applies both to incoming and outgoing connections, so one connection which is deciphered then ciphered accounts for 2 SSL connections. If this value is not set, but a memory limit is enforced, this value will be automatically computed based on the memory limit, maxconn, the buffer size, memory allocated to compression, SSL cache size, and use of SSL in either frontends, backends or both. If neither maxconn nor maxsslconn are specified when there is a memory limit, HAProxy will automatically adjust these values so that 100% of the connections can be made over SSL with no risk, and will consider the sides where it is enabled (frontend, backend, both).
Sets the maximum per-process number of SSL sessions per second to <number>. SSL listeners will stop accepting connections when this limit is reached. It can be used to limit the global SSL CPU usage regardless of each frontend capacity. It is important to note that this can only be used as a service protection measure, as there will not necessarily be a fair share between frontends when the limit is reached, so it's a good idea to also limit each frontend to some value close to its expected share. It is also important to note that the sessions are accounted before they enter the SSL stack and not after, which also protects the stack against bad handshakes. Also, lowering tune.maxaccept can improve fairness.
Sets the maximum amount of RAM in megabytes per process usable by the zlib. When the maximum amount is reached, future streams will not compress as long as RAM is unavailable. When sets to 0, there is no limit. The default value is 0. The value is available in bytes on the UNIX socket with "show info" on the line "MaxZlibMemUsage", the memory used by zlib is "ZlibMemUsage" in bytes.
Disables memory trimming ("malloc_trim") at a few moments where attempts are
made to reclaim lots of memory (on memory shortage or on reload). Trimming
memory forces the system's allocator to scan all unused areas and to release
them. This is generally seen as nice action to leave more available memory to
a new process while the old one is unlikely to make significant use of it.
But some systems dealing with tens to hundreds of thousands of concurrent
connections may experience a lot of memory fragmentation, that may render
this release operation extremely long. During this time, no more traffic
passes through the process, new connections are not accepted anymore, some
health checks may even fail, and the watchdog may even trigger and kill the
unresponsive process, leaving a huge core dump. If this ever happens, then it
is suggested to use this option to disable trimming and stop trying to be
nice with the new process. Note that advanced memory allocators usually do
not suffer from such a problem.
Disables the use of the "epoll" event polling system on Linux. It is equivalent to the command-line argument "-de". The next polling system used will generally be "poll". See also "nopoll".
Disables the use of the event ports event polling system on SunOS systems derived from Solaris 10 and later. It is equivalent to the command-line argument "-dv". The next polling system used will generally be "poll". See also "nopoll".
Disables the use of getaddrinfo(3) for name resolving. It is equivalent to the command line argument "-dG". Deprecated gethostbyname(3) will be used.
Disables the use of the "kqueue" event polling system on BSD. It is equivalent to the command-line argument "-dk". The next polling system used will generally be "poll". See also "nopoll".
Disables the use of ktls. It is equivalent to the command line argument "-dT".
Disables the use of the "poll" event polling system. It is equivalent to the command-line argument "-dp". The next polling system used will be "select". It should never be needed to disable "poll" since it's available on all platforms supported by HAProxy. See also "nokqueue", "noepoll" and "noevports".
Disables the use of SO_REUSEPORT - see socket(7). It is equivalent to the command line argument "-dR".
Disables the use of kernel tcp splicing between sockets on Linux. It is equivalent to the command line argument "-dS". Data will then be copied using conventional and more portable recv/send calls. Kernel tcp splicing is limited to some very recent instances of kernel 2.6. Most versions between 2.6.25 and 2.6.28 are buggy and will forward corrupted data, so they must not be used. This option makes it easier to globally disable kernel splicing in case of doubt. See also "option splice-auto", "option splice-request" and "option splice-response".
Enables ('on') or disables ('off') per-function memory profiling. This will
keep usage statistics of malloc/calloc/realloc/free calls anywhere in the
process (including libraries) which will be reported on the CLI using the
"show profiling" command. This is essentially meant to be used when an
abnormal memory usage is observed that cannot be explained by the pools and
other info are required. The performance hit will typically be around 1%,
maybe a bit more on highly threaded machines, so it is normally suitable for
use in production. The same may be achieved at run time on the CLI using the
"set profiling memory" command, please consult the management manual.
Enables ('on') or disables ('off') per-task CPU profiling. When set to 'auto'
the profiling automatically turns on a thread when it starts to suffer from
an average latency of 1000 microseconds or higher as reported in the
"avg_loop_us" activity field, and automatically turns off when the latency
returns below 990 microseconds (this value is an average over the last 1024
loops so it does not vary quickly and tends to significantly smooth short
spikes). It may also spontaneously trigger from time to time on overloaded
systems, containers, or virtual machines, or when the system swaps (which
must absolutely never happen on a load balancer).
When task profiling is enabled, HAProxy can also collect the time each task
spends with a lock held or waiting for a lock, as well as the time spent
waiting for a memory allocation to succeed in case of a pool cache miss. This
can sometimes help understand certain causes of latency. For this, the extra
keywords "lock" (to enable lock time collection), "no-lock" (to disable it),
"memory" (to enable memory allocation time collection) or "no-memory" (to
disable it) may additionally be passed. By default they are not enabled since
they can have a non-negligible CPU impact on highly loaded systems (3-10%).
Note that the overhead is only taken when profiling is effectively running,
so that when running in "auto" mode, it will only appear when HAProxy decides
to turn it on.
CPU profiling per task can be very convenient to report where the time is
spent and which requests have what effect on which other request. Enabling
it will typically affect the overall's performance by less than 1%, thus it
is recommended to leave it to the default 'auto' value so that it only
operates when a problem is identified. This feature requires a system
supporting the clock_gettime(2) syscall with clock identifiers
CLOCK_MONOTONIC and CLOCK_THREAD_CPUTIME_ID, otherwise the reported time will
be zero. This option may be changed at run time using "set profiling" on the
CLI.
Sometimes it is desirable to avoid sending agent and health checks to servers at exact intervals, for instance when many logical servers are located on the same physical server. With the help of this parameter, it becomes possible to add some randomness in the check interval between 0 and +/- 50%. A value between 2 and 5 seems to show good results. The default value remains at 0.
Sets the OpenSSL engine to <name>. List of valid values for <name> may be obtained using the command "openssl engine". This statement may be used multiple times, it will simply enable multiple crypto engines. Referencing an unsupported engine will prevent HAProxy from starting. Note that many engines will lead to lower HTTPS performance than pure software with recent processors. The optional command "algo" sets the default algorithms an ENGINE will supply using the OPENSSL function ENGINE_set_default_string(). A value of "ALL" uses the engine for all cryptographic operations. If no list of algo is specified then the value of "ALL" is used. A comma-separated list of different algorithms may be specified, including: RSA, DSA, DH, EC, RAND, CIPHERS, DIGESTS, PKEY, PKEY_CRYPTO, PKEY_ASN1. This is the same format that openssl configuration file uses: https://www.openssl.org/docs/man1.0.2/apps/config.html HAProxy Version 2.6 disabled the support for engines in the default build. This option is only available when HAProxy has been built with support for it. In case the ssl-engine is required HAProxy can be rebuild with the USE_ENGINE=1 flag.
Adds SSL_MODE_ASYNC mode to the SSL context. This enables asynchronous TLS I/O operations if asynchronous capable SSL engines are used. The current implementation supports a maximum of 32 engines. The Openssl ASYNC API doesn't support moving read/write buffers and is not compliant with HAProxy's buffer management. So the asynchronous mode is disabled on read/write operations (it is only enabled during initial and renegotiation handshakes).
Enables ('on') of disabled ('off') the zero-copy forwarding of data for the
applets. It is enabled by default.
Sets a hard limit on the number of buffers which may be allocated per process. The default value is zero which means unlimited. The limit will automatically be re-adjusted to satisfy the reserved buffers for emergency situations so that the user doesn't have to perform complicated calculations. Forcing this value can be particularly useful to limit the amount of memory a process may take, while retaining a sane behavior. When this limit is reached, a task that requests a buffer waits for another one to be released first. Most of the time the waiting time is very short and not perceptible provided that limits remain reasonable. However, some historical limitations have weakened this mechanism over versions and it is known that in certain situations of sustained shortage, some tasks may freeze until their timeout expires, so it is safer to avoid using this when not strictly necessary.
Sets the number of per-thread buffers which are pre-allocated and reserved for use only during memory shortage conditions resulting in failed memory allocations. The minimum value is 0 and the default is 4. There is no reason a user would want to change this value, unless a core developer suggests to change it for a very specific reason.
Sets the buffer size to this size (in bytes). Lower values allow more streams to coexist in the same amount of RAM, and higher values allow some applications with very large cookies to work. The default value is 16384 and can be changed at build time. It is strongly recommended not to change this from the default value, as very low values will break some services such as statistics, and values larger than default size will increase memory usage, possibly causing the system to run out of memory. At least the global maxconn parameter should be decreased by the same factor as this one is increased. In addition, use of HTTP/2 mandates that this value must be 16384 or more. If an HTTP request is larger than (tune.bufsize - tune.maxrewrite), HAProxy will return HTTP 400 (Bad Request) error. Similarly if an HTTP response is larger than this size, HAProxy will return HTTP 502 (Bad Gateway). Note that the value set using this parameter will automatically be rounded up to the next multiple of 8 on 32-bit machines and 16 on 64-bit machines.
Sets the size in bytes for large buffers. By defaults, support for large buffers is not enabled, it must explicitly be enable by setting this value. These buffers are designed to be used in some specific contexts where more data must be bufferized without changing the size of regular buffers. The large buffers are not implicitly used. Note that when large buffers are configured, three special large buffers will be allocated for each threads during startup for internal usage.
Sets the size in bytes for small buffers. The defaults value is 1024. These buffers are designed to be used in some specific contexts where memory consumption is restrained but it seems unnecessary to allocate a full buffer. If however a small buffer is not sufficient, a reallocation is automatically done to switch to a standard size buffer. For the moment, it is automatically used only by HTTP/3 protocol to emit the response headers. Otherwise, small buffers support can be enabled for specific proxies via the "use-small-buffers" option.
Sets the maximum size allowed for the payload passed to a command on the CLI. On the CLI, a command line is limited by the buffer size. It means all commands and their arguments must fit in a buffer to be processed, excluding the payload that can be passed to the last command of the command line. This payload can be allocated into a dedicated area if necessary. Its size is limited by this parameter. The default value is 128KB. While it should be high enough for most usage, if this value is changed, it must be carefully chosen. A huge value can have impact on the HAProxy performance. Depending on the command, a huge payload can be quite long to process and can possibly trigger the watchdog. Please consult the management manual for details about the CLI.
Sets the maximum compression level. The compression level affects CPU usage during compression. This value affects CPU usage during compression. Each stream using compression initializes the compression algorithm with this value. The default value is 1.
For dynamic backends support, all named defaults sections are now kept in memory after parsing. This is necessary as backend added at runtime must be based on a named defaults for its configuration. This may consume significant memory if the number of defaults instances is important. In this case and if dynamic backend feature is unnecessary, it's possible to use this option to force deletion of defaults section after parsing. It is still mandatory though to keep referenced defaults section which contain settings whose cannot be copied by their referencing proxies. For example, this is the case if the defaults section defines TCP/HTTP rules or a tcpcheck ruleset.
Disables the data fast-forwarding. It is a mechanism to optimize the data forwarding by passing data directly from a side to the other one without waking the stream up. Thanks to this directive, it is possible to disable this optimization. Note it also disable any kernel tcp splicing but also the zero-copy forwarding. This command is not meant for regular use, it will generally only be suggested by developers along complex debugging sessions.
Globally disables the zero-copy forwarding of data. It is a mechanism to optimize the data fast-forwarding by avoiding to use the channel's buffer. Thanks to this directive, it is possible to disable this optimization. Note it also disable any kernel tcp splicing.
Along HAProxy's history, a few complex issues were met that were caused by bugs in the epoll mechanism in the Linux kernel. These ones usually are very rare and unreproducible outside the reporter's environment, and may only be worked around by disabling epoll and switching to poll instead, which is not very satisfying for high performance environments. Each time, issues affect only very specific (and rare) event types, and offering the ability to mask them can constitute a more acceptable work-around. This options offers this possibility by permitting to silently ignore events a few uncommon events and replace them with an input (which reports an unspecified incoming event). The effect is to avoid the fast error processing paths in certain places and only use the common paths. This should never be used unless being invited to do so by an expert in order to diagnose or work around a kernel bug. The option takes a single argument which is a comma-delimited list of words each designating an event to be masked. The currently supported list of events is: - "err": mask the EPOLLERR event - "hup": mask the EPOLLHUP events - "rdhup": mask the EPOLLRDHUP events
# mask all non-traffic epoll events:
tune.epoll.mask-events err,hup,rdhup
Sets the number of events that may be processed at once by an asynchronous task handler (from event_hdl API). <number> should be included between 1 and 10000. Large number could cause thread contention as a result of the task doing heavy work without interruption, and on the other hand, small number could result in the task being constantly rescheduled because it cannot consume enough events per run and is not able to catch up with the event producer. The default value may be forced at build time, otherwise defaults to 100.
If compiled with DEBUG_FAIL_ALLOC or started with "-dMfail", gives the percentage of chances an allocation attempt fails. Must be between 0 (no failure) and 100 (no success). This is useful to debug and make sure memory failures are handled gracefully. When not set, the ratio is 0. However the command-line "-dMfail" option automatically sets it to 1% failure rate so that it is not necessary to change the configuration for testing.
Enables ('on') or disables ('off') the edge-triggered polling mode for FDs
that support it. This is currently only support with epoll. It may noticeably
reduce the number of epoll_ctl() calls and slightly improve performance in
certain scenarios. This is still experimental, it may result in frozen
connections if bugs are still present, and is disabled by default.
Sets the minimum CPU usage between 0 and 100, at which connections showing too many glitches will be killed. This applies to connections that have reached their glitches-threshold limit. In environments where very long connections often behave badly without causing any performance impact, it might be desirable to keep them regardless of their misbehavior as long as they do not hurt, and to only start to kill such connections when the CPU is getting busy. This parameters allows to specify that a connection reaching its glitches threshold will be actively killed when the CPU usage is at this level or above, but never when it's below. Note that the CPU usage is measured per thread, so a single misbehaving connection might be killed. The default is zero, meaning that a connection reaching its glitches-threshold will automatically get killed. A rule of thumb would be to set this value to twice the usually observed CPU usage, or the commonly observed CPU usage plus half the idle one (i.e. if CPU commonly reaches 60%, setting 80 here can make sense). This parameter has no effect without tune.h2.fe.glitches-threshold, tune.quic.fe.sec.glitches-threshold or tune.h1.fe.glitches-threshold. See also the global parameters "tune.h2.fe.glitches-threshold", "tune.h1.fe.glitches-threshold" and "tune.quic.fe.sec.glitches-threshold".
Sets the threshold for the number of glitches on a HTTP/1 backend connection, after which that connection will automatically be killed. This allows to automatically kill misbehaving connections without having to write explicit rules for them. The default value is zero, indicating that no threshold is set so that no event will cause a connection to be closed. Typical events include improperly formatted headers that had been nevertheless accepted by "accept-unsafe-violations-in-http-response". Any non-zero value here should probably be in the hundreds or thousands to be effective without affecting slightly bogus servers. It is also possible to only kill connections when the CPU usage crosses a certain level, by using "tune.glitches.kill.cpu-usage". Note that a graceful close is attempted at 75% of the configured threshold by advertising a GOAWAY for a future stream. This ensures that a slightly faulty connection will stop being used after some time without risking to interrupt ongoing transfers.
Sets the threshold for the number of glitches on a HTTP/1 frontend connection after which that connection will automatically be killed. This allows to automatically kill misbehaving connections without having to write explicit rules for them. The default value is zero, indicating that no threshold is set so that no event will cause a connection to be closed. Typical events include improperly formatted headers that had been nevertheless accepted by "accept-unsafe-violations-in-http-request". Any non-zero value here should probably be in the hundreds or thousands to be effective without affecting slightly bogus clients. It is also possible to only kill connections when the CPU usage crosses a certain level, by using "tune.glitches.kill.cpu-usage". Note that a graceful close is attempted at 75% of the configured threshold by advertising a GOAWAY for a future stream. This ensures that a slightly non- compliant client will have the opportunity to create a new connection and continue to work unaffected without ever triggering the hard close thus risking to interrupt ongoing transfers.
Enables ('on') of disabled ('off') the zero-copy receives of data for the H1
multiplexer. It is enabled by default.
Enables ('on') of disabled ('off') the zero-copy sends of data for the H1
multiplexer. It is enabled by default.
Sets the threshold for the number of glitches on a backend connection, where that connection will automatically be killed. This allows to automatically kill misbehaving connections without having to write explicit rules for them. The default value is zero, indicating that no threshold is set so that no event will cause a connection to be closed. Beware that some H2 servers may occasionally cause a few glitches over long lasting connection, so any non- zero value here should probably be in the hundreds or thousands to be effective without affecting slightly bogus servers. It is also possible to only kill connections when the CPU usage crosses a certain level, by using "tune.glitches.kill.cpu-usage". Note that a graceful close is attempted at 75% of the configured threshold by advertising a GOAWAY for a future stream. This ensures that a slightly faulty connection will stop being used after some time without risking to interrupt ongoing transfers.
Sets the HTTP/2 initial window size for outgoing connections, which is the number of bytes the server can respond before waiting for an acknowledgment from HAProxy. This setting only affects payload contents, not headers. When not set, the common default value set by tune.h2.initial-window-size applies. It can make sense to slightly increase this value to allow faster downloads or to reduce CPU usage on the servers, at the expense of creating unfairness between clients. It is better to use tune.h2.be.rxbuf instead, which does not cause any unfairness. It doesn't affect resource usage.
Sets the HTTP/2 maximum number of concurrent streams per outgoing connection (i.e. the number of outstanding requests on a single connection to a server). When not set, the default set by tune.h2.max-concurrent-streams applies. A smaller value than the default 100 may improve a site's responsiveness at the expense of maintaining more established connections to the servers. When the "http-reuse" setting is set to "always", it is recommended to reduce this value so as not to mix too many different clients over the same connection, because if a client is slower than others, a mechanism known as "head of line blocking" tends to cause cascade effect on download speed for all clients sharing a connection (keep tune.h2.be.initial-window-size low in this case). It is highly recommended not to increase this value; some might find it optimal to run at low values (1..5 typically).
Sets the maximum number of HTTP/2 incoming frames that will be processed at once on a backend connection. It can be useful to set this to a low value (a few tens to a few hundreds) when dealing with very large buffers in order to maintain a low latency and a better fairness between multiple connections. The default value is zero, which means that no limitation is enforced.
Sets the HTTP/2 receive buffer size for outgoing connections, in bytes. This size will be rounded up to the next multiple of tune.bufsize and will be shared between all streams uploading data (both HEADERS and DATA frames). In any case, one buffer will always be granted to each stream, and 7/8 of the unused buffers will be shared between streams downloading payload, allowing to significantly improve upload performance and avoid head-of-line blocking (HoL) on backend connections shared between multiple clients when http-reuse is set to "always". The advertised per-stream window is automatically adjusted to reflect the available space so that in practice it should not be required to touch tune.h2.be.initial-window-size. If less than the size required to deal with all streams is set, this minimum will be used. The default value is about 1600k (100 streams with 16kB buffers each).
Sets the threshold for the number of glitches on a frontend connection, where that connection will automatically be killed. This allows to automatically kill misbehaving connections without having to write explicit rules for them. The default value is zero, indicating that no threshold is set so that no event will cause a connection to be closed. Beware that some H2 clientss may occasionally cause a few glitches over long lasting connection, so any non- zero value here should probably be in the hundreds or thousands to be effective without affecting slightly bogus clients. It is also possible to only kill connections when the CPU usage crosses a certain level, by using "tune.glitches.kill.cpu-usage". Note that a graceful close is attempted at 75% of the configured threshold by advertising a GOAWAY for a future stream. This ensures that a slightly non-compliant client will have the opportunity to create a new connection and continue to work unaffected without ever triggering the hard close thus risking to interrupt ongoing transfers.
Sets the HTTP/2 initial window size for incoming connections, which is the number of bytes the client can upload before waiting for an acknowledgment from HAProxy. This setting only affects payload contents (i.e. the body of POST requests), not headers. When not set, the common default value set by tune.h2.initial-window-size applies. It can make sense to increase this value to allow faster uploads. The default value equals tune.bufsize (16384) and allows at least 1.25 Mbps of bandwidth per stream over a 100 ms ping time, and 125 Mbps for 1 ms ping time. It doesn't affect resource usage. Using too large values may cause clients to experience a lack of responsiveness if pages are accessed in parallel to large uploads. It is better to use tune.h2.fe.rxbuf instead, which does not cause any unfairness.
Sets the HTTP/2 maximum number of concurrent streams per incoming connection
(i.e. the number of outstanding requests on a single connection from a
client). When not set, the default set by tune.h2.max-concurrent-streams
applies. A larger value than the default 100 may sometimes slightly improve
the page load time for complex sites with lots of small objects over high
latency networks but can also result in using more memory by allowing a
client to allocate more resources at once. The default value of 100 is
generally good and it is recommended not to change this value. A larger
concurrency also has an impact on the processing load and latency when
dealing with large numbers of connections which are themselves using many
streams, and it may lower the barrier to denial of service attacks. The
command supports the following optional arguments after the number:
- rq-load { <number> | auto | ignore }:
The optional argument "rq-load" permits to dynamically adjust the
advertised concurrency based on the executing thread's run-queue load:
as long as the thread's load remains below the indicated threshold, the
configured streams limit will be advertised. When the thread's load
increases beyond the configured limit, the advertised streams limit will be
decreased proportionally to the square of the excess ratio. Target load
levels between 50 and 100 generally show very good moderation under heavy
loads. Alternately, instead of specifying an explicit number, the keyword
accepts "ignore", which is the default and means that the thread's
run-queue load will not be considered to moderate the advertised streams
limit, and "auto", which sets the limit to the "tune.runqueue-depth"
value, which generally provides good results without having to tweak
the configuration any further.
- min <number>:
This sets the minimum advertised concurrency level when rq-load is used,
even if this results in a higher load than the configured target. This
allows to maintain a good level of interactivity on a site under very
heavy load. The minimum and default value is 1, but values between 5
and 15 can improve user experience.
tune.h2.fe.max-concurrent-streams 100 rq-load auto min 15
Sets the maximum number of HTTP/2 incoming frames that will be processed at once on a frontend connection. It can be useful to set this to a low value (a few tens to a few hundreds) when dealing with very large buffers in order to maintain a low latency and a better fairness between multiple connections. The default value is zero, which means that no limitation is enforced.
Sets the maximum number of HTTP/2 incoming RST_STREAM that will be processed at once on a frontend connection. Once the specified number of RST_STREAM frames are received, the connection handler will be placed in a low priority queue and be processed after all other tasks. It can be useful to set this to a very low value (1 or a few units) to significantly reduce the impacts of RST_STREAM floods. RST_STREAM do happen when a user clicks on the Stop button in their browser, but the few extra milliseconds caused by this requeuing are generally unnoticeable, however they are generally effective at significantly lowering the load caused from such floods. The default value is zero, which means that no limitation is enforced.
Sets the HTTP/2 maximum number of total streams processed per incoming connection. Once this limit is reached, HAProxy will send a graceful GOAWAY frame informing the client that it will close the connection after all pending streams have been closed. In practice, clients tend to close as fast as possible when receiving this, and to establish a new connection for next requests. Doing this is sometimes useful and desired in situations where clients stay connected for a very long time and cause some imbalance inside a farm. For example, in some highly dynamic environments, it is possible that new load balancers are instantiated on the fly to adapt to a load increase, and that once the load goes down they should be stopped without breaking established connections. By setting a limit here, the connections will have a limited lifetime and will be frequently renewed, with some possibly being established to other nodes, so that existing resources are quickly released. It's important to understand that there is an implicit relation between this limit and "tune.h2.fe.max-concurrent-streams" above. Indeed, HAProxy will always accept to process any possibly pending streams that might be in flight between the client and the frontend, so the advertised limit will always automatically be raised by the value configured in max-concurrent-streams, and this value will serve as a hard limit above which a violation by a non- compliant client will result in the connection being closed. Thus when counting the number of requests per connection from the logs, any number between max-total-streams and (max-total-streams + max-concurrent-streams) may be observed depending on how fast streams are created by the client. The default value is zero, which enforces no limit beyond those implied by the protocol (2^30 ~= 1.07 billion). Values around 1000 may already cause frequent connection renewal without causing any perceptible latency to most clients. Setting it too low may result in an increase of CPU usage due to frequent TLS reconnections, in addition to increased page load time. Please note that some load testing tools do not support reconnections and may report errors with this setting; as such it may be needed to disable it when running performance benchmarks. See also "tune.h2.fe.max-concurrent-streams".
Sets the HTTP/2 receive buffer size for incoming connections, in bytes. This size will be rounded up to the next multiple of tune.bufsize and will be shared between all streams uploading data (both HEADERS and DATA frames). In any case, one buffer will always be granted to each stream, and 7/8 of the unused buffers will be shared between streams uploading payload, allowing to significantly improve upload performance. The advertised per-stream window is automatically adjusted to reflect the available space so that in practice it should not be required to touch tune.h2.fe.initial-window-size. If less than the size required to deal with all streams is set, this minimum will be used. The default value of 1600k (100 streams with 16kB buffers each) permits roughly 130 Mbps of upload speed for a client with a 100ms RTT.
Sets the HTTP/2 dynamic header table size. It defaults to 4096 bytes and cannot be larger than 65536 bytes. A larger value may help certain clients send more compact requests, depending on their capabilities. This amount of memory is consumed for each HTTP/2 connection. It is recommended not to change it.
Sets the default value for the HTTP/2 initial window size, on both incoming and outgoing connections. This value is used for incoming connections when tune.h2.fe.initial-window-size is not set, and by outgoing connections when tune.h2.be.initial-window-size is not set. This setting is used both as the initial value and as a minimum per stream. The default value equals 16384 (tune.bufsize), which for uploads roughly allows at least 1.25 Mbps of bandwidth per stream over a network showing a 100 ms ping time, or 125 Mbps over a 1-ms local network. When less receive buffers than the maximum are in use, within the limits defined by tune.h2.be.rxbuf and tune.h2.fe.rxbuf, unused buffers will be shared between receiving streams. As such there is normally no point in changing this default setting. Given that changing this default value will both increase upload speeds and cause more unfairness between clients on downloads, it is recommended to instead use the side- specific settings tune.h2.fe.initial-window-size and tune.h2.be.initial-window-size.
Sets the level of errors in the H2 demultiplexer that will generate a log. The default is "stream", which means that any decoding error encountered in the demultiplexer will lead to the emission of a log. The "connection" value indicates that only logs that result in invalidating the connection will produce a log. Finally, "none" indicates that no decoding error will produce any log. It is recommended to set at least "connection" in order to detect protocol anomalies, even if this means temporarily switching to "none" during difficult periods.
Sets the default HTTP/2 maximum number of concurrent streams per connection (i.e. the number of outstanding requests on a single connection). This value is used for incoming connections when tune.h2.fe.max-concurrent-streams is not set, and for outgoing connections when tune.h2.be.max-concurrent-streams is not set. The default value is 100. The impact varies depending on the side so please see the two settings above for more details. It is recommended not to use this setting and to switch to the per-side ones instead. A value of zero disables the limit so a single client may create as many streams as allocatable by HAProxy. It is highly recommended not to change this value.
Sets the HTTP/2 maximum frame size that HAProxy announces it is willing to receive to its peers. The default value is the largest between 16384 and the buffer size (tune.bufsize). In any case, HAProxy will not announce support for frame sizes larger than buffers. The main purpose of this setting is to allow to limit the maximum frame size setting when using large buffers. Too large frame sizes might have performance impact or cause some peers to misbehave. It is highly recommended not to change this value.
Enables ('on') of disabled ('off') the zero-copy sends of data for the H2
multiplexer. It is enabled by default.
Sets the maximum length of captured cookies. This is the maximum value that the "capture cookie xxx len yyy" will be allowed to take, and any upper value will automatically be truncated to this one. It is important not to set too high a value because all cookie captures still allocate this size whatever their configured value (they share a same pool). This value is per request per response, so the memory allocated is twice this value per connection. When not specified, the limit is set to 63 characters. It is recommended not to change this value.
Sets the maximum length of request URI in logs. This prevents truncating long request URIs with valuable query strings in log lines. This is not related to syslog limits. If you increase this limit, you may also increase the 'log ... len yyy' parameter. Your syslog daemon may also need specific configuration directives too. The default value is 1024.
Sets the maximum number of headers allowed in received HTTP messages. When a message comes with a number of headers greater than this value (including the first line), it is rejected with a "400 Bad Request" status code for a request, or "502 Bad Gateway" for a response. The default value is 101, which is enough for all usages, considering that the widely deployed Apache server uses the same limit. It can be useful to push this limit further to temporarily allow a buggy application to work by the time it gets fixed. The accepted range is 1..32767. Keep in mind that each new header consumes 32bits of memory for each stream, so don't push this limit too high. Note that HTTP/1.1 is a text protocol, so there is no special limit when the message is sent. The limit during the message parsing is sufficient. HTTP/2 and HTTP/3 are binary protocols and require an encoding step. A limit is set too when headers are encoded to comply to limitation imposed by the protocols. This limit is large enough but not documented on purpose. The same limit is applied on the first steps of the decoding for the same reason.
Controls sharing idle connection pools between threads for a same server.
It can be enabled for all threads in a same thread group ('on'), enabled for
all threads ('full') or disabled ('off'). The default is to share them
between threads in the same thread group ('on'), in order to minimize the
number of persistent connections to a server, and to optimize the connection
reuse rate. Sharing with threads from other thread groups can have a
performance impact, and is not enabled by default, but can be useful if
maximizing connection reuse is a priority. To help with debugging or when
suspecting a bug in HAProxy around connection reuse, it can be convenient to
forcefully disable this idle pool sharing between multiple threads,
and force this option to "off". It is strongly recommended against disabling
this option without setting a conservative value on "pool-low-conn" for all
servers relying on connection reuse to achieve a high performance level,
otherwise connections might be closed very often as the thread count
increases.
Sets the duration after which HAProxy will consider that an empty buffer is probably associated with an idle stream. This is used to optimally adjust some packet sizes while forwarding large and small data alternatively. The decision to use splice() or to send large buffers in SSL is modulated by this parameter. The value is in milliseconds between 0 and 65535. A value of zero means that HAProxy will not try to detect idle streams. The default is 1000, which seems to correctly detect end user pauses (e.g. read a page before clicking). There should be no reason for changing this value. Please check tune.ssl.maxrecord below.
Normally, all "bind" lines will create a single shard, that is, a single socket that all threads of the process will listen to. With many threads, this is not very efficient, and may even induce some important overhead in the kernel for updating the polling state or even distributing events to the various threads. Modern operating systems support balancing of incoming connections, a mechanism that will consist in permitting multiple sockets to be bound to the same address and port, and to evenly distribute all incoming connections to these sockets so that each thread only sees the connections that are waiting in the socket it is bound to. This significantly reduces kernel-side overhead and increases performance in the incoming connection path. This is usually enabled in HAProxy using the "shards" setting on "bind" lines, which defaults to 1, meaning that each listener will be unique in the process. On systems with many processors, it may be more convenient to change the default setting to "by-thread" in order to always create one listening socket per thread, or "by-group" in order to always create one listening socket per thread group. Be careful about the file descriptor usage with "by-thread" as each listener will need as many sockets as there are threads. Also some operating systems (e.g. FreeBSD) are limited to no more than 256 sockets on a same address. Note that "by-group" will remain equivalent to "by-process" for default configurations involving a single thread group, and will fall back to sharing the same socket on systems that do not support this mechanism. The default is "by-group" with a fallback to "by-process" for systems or socket families that do not support multiple bindings.
Enables ('on' / 'fair') or disables ('off') the listener's multi-queue accept
which spreads the incoming traffic to all threads a "bind" line is allowed to
run on instead of taking them for itself. This provides a smoother traffic
distribution and scales much better, especially in environments where threads
may be unevenly loaded due to external activity (network interrupts colliding
with one thread for example). The default mode, "on", optimizes the choice of
a thread by picking in a sample the one with the less connections. It is
often the best choice when connections are long-lived as it manages to keep
all threads busy. A second mode, "fair", instead cycles through all threads
regardless of their instant load level. It can be better suited for short-
lived connections, or on machines with very large numbers of threads where
the probability to find the least loaded thread with the first mode is low.
Finally it is possible to forcefully disable the redistribution mechanism
using "off" for troubleshooting, or for situations where connections are
short-lived and it is estimated that the operating system already provides a
good enough distribution. The default is "on".
Explicitly tell haproxy how haproxy sample objects should be handled when pushed to Lua. Indeed, when leveraging native converters, sample fetches or variables from Lua script (to name a few), haproxy converts the internal smp type to equivalent Lua type. Because of historical implementation, there is an ambiguity around boolean handling: when doing Lua -> haproxy smp conversion, booleans are properly preserved, but when doing haproxy smp -> Lua conversion, booleans were converted to integers by mistake. This means that a sample fetch or converter returning a boolean would return an integer 0 or 1 when leveraged from Lua. Unfortunately, in Lua, booleans and integers are not interchangeable. Thus, to avoid ambiguities, "tune.lua.bool-sample-conversion" must explicitly be set to either "normal" (which means dropping the historical behavior for better consistency) or "pre-3.1-bug" (enforce historical behavior to prevent existing script logic from misbehaving). If the option is not set explicitly and a Lua script is loaded from the configuration, haproxy will emit a warning, and the option will implicitly default to "pre-3.1-bug" to match with the historical behavior. It is recommended to set this option to "normal" after ensuring that in-use Lua scripts are properly handling bool haproxy samples as booleans. This setting must be set before any "lua-load" or "lua-load-per-thread" directive for it to be considered, else it is ignored.
The "burst" execution timeout applies to any Lua handler. If the handler fails to finish or yield before timeout is reached, it will be aborted to prevent thread contention, to prevent traffic from not being served for too long, and ultimately to prevent the process from crashing because of the watchdog kicking in. Unlike other lua timeouts which are yield-cumulative, burst-timeout will ensure that the time spent in a single lua execution window does not exceed the configured timeout. Yielding here means that the lua execution is effectively interrupted either through an explicit call to lua-yielding function such as core.(m)sleep() or core.yield(), or following an automatic forced-yield (see tune.lua.forced-yield) and that it will be resumed later when the related task is set for rescheduling. Not all lua handlers may yield: we have to make a distinction between yieldable handlers and unyieldable handlers. For yieldable handlers (tasks, actions..), reaching the timeout means "tune.lua.forced-yield" might be too high for the system, reducing it could improve the situation, but it could also be a good idea to check if adding manual yields at some key points within the lua function helps or not. It may also indicate that the handler is spending too much time in a specific lua library function that cannot be interrupted. For unyieldable handlers (lua converters, sample fetches), it could simply indicate that the handler is doing too much computation, which could result from an improper design given that such handlers, which often block the request execution flow, are expected to terminate quickly to allow the request processing to go through. A common resolution approach here would be to try to better optimize the lua function for speed since decreasing "tune.lua.forced-yield" won't help. This timeout only counts the pure Lua runtime. If the Lua does a core.sleep, the sleeping time is not taken in account. The default timeout is 1000ms. Note: if a lua GC cycle is initiated from the handler (either explicitly requested or automatically triggered by lua after some time), the GC cycle time will also be accounted for. Indeed, there is no way to deduce the GC cycle time, so this could lead to some false positives on saturated systems (where GC is having hard time to catch up and consumes most of the available execution runtime). If it were to be the case, here are some resolution leads: - checking if the script could be optimized to reduce lua memory footprint - fine-tuning lua GC parameters and / or requesting manual GC cycles (see: https://www.lua.org/manual/5.4/manual.html#pdf-collectgarbage) - increasing tune.lua.burst-timeout Setting value to 0 completely disables this protection.
This directive forces the Lua engine to execute a yield each <number> of instructions executed. This permits interrupting a long script and allows the HAProxy scheduler to process other tasks like accepting connections or forwarding traffic. The default value is 10000 instructions for scripts loaded using "lua-load-per-thread" and MAX(500, 10000 / nbthread) instructions for scripts loaded using "lua-load" (it was found to be an optimal value for performance while taking care of not creating thread contention with multiple threads competing for the global lua lock). If HAProxy often executes some Lua code but more responsiveness is required, this value can be lowered. If the Lua code is quite long and its result is absolutely required to process the data, the <number> can be increased, but the value should be set wisely as in multithreading context it could increase contention.
Enables ('on') or disables ('off') logging the output of LUA scripts via the
loggers applicable to the current proxy, if any.
Defaults to 'on'.
Enables ('on') or disables ('off') logging the output of LUA scripts via
stderr.
When set to 'auto', logging via stderr is conditionally 'on' if any of:
- tune.lua.log.loggers is set to 'off'
- the script is executed in a non-proxy context with no global logger
- the script is executed in a proxy context with no logger attached
Please note that, when enabled, this logging is in addition to the logging
configured via tune.lua.log.loggers.
Defaults to 'auto'.
Sets the maximum amount of RAM in megabytes per process usable by Lua. By default it is zero which means unlimited. It is important to set a limit to ensure that a bug in a script will not result in the system running out of memory.
Selects which Lua standard libraries are loaded when initialising the Lua state. The argument is a comma-separated list of library names taken from the following set: table, io, os, string, math, utf8, package, debug. The special values "all" and "none" may be used instead of a list. "none" cannot be combined with library names. The default value is "all". The base and coroutine libraries are always loaded regardless of this setting: base provides core Lua functions that HAProxy relies on, and coroutine is required because HAProxy overrides coroutine.create() with its own safe implementation. Note that fork() and new thread creation are already blocked by default in HAProxy regardless of this setting, and can only be re-enabled via the "insecure-fork-wanted" global directive. Restricting the set of loaded libraries further reduces the attack surface exposed to Lua scripts. In particular: - omitting "os" prevents os.execute() and os.exit() - omitting "io" prevents io.open() and io.popen() - omitting "package" prevents loading native C modules via require() - omitting "debug" prevents introspection of HAProxy internals via debug.getupvalue(), debug.getmetatable(), or debug.sethook()
tune.lua.openlibs none # only base + coroutine
tune.lua.openlibs string,math,table,utf8 # safe subset, no I/O or OS
tune.lua.openlibs all # default, load everything
This setting must be set before any "lua-load", "lua-load-per-thread" or "lua-prepend-path" directive, otherwise a parse error is returned.
This is the execution timeout for the Lua services. This is useful for preventing infinite loops or spending too much time in Lua. This timeout counts only the pure Lua runtime. If the Lua does a sleep, the sleep is not taken in account. The default timeout is 4s.
This is the execution timeout for the Lua sessions. This is useful for preventing infinite loops or spending too much time in Lua. This timeout counts only the pure Lua runtime. If the Lua does a sleep, the sleep is not taken in account. The default timeout is 4s.
Purpose is the same as "tune.lua.session-timeout", but this timeout is dedicated to the tasks. By default, this timeout isn't set because a task may remain alive during of the lifetime of HAProxy. For example, a task used to check servers.
Sets the number of active checks per thread above which a thread will actively try to search a less loaded thread to run the health check, or queue it until the number of active checks running on it diminishes. The default value is zero, meaning no such limit is set. It may be needed in certain environments running an extremely large number of expensive checks with many threads when the load appears unequal and may make health checks to randomly time out on startup, typically when using OpenSSL 3.0 which is about 20 times more CPU-intensive on health checks than older ones. This will have for result to try to level the health check work across all threads. The vast majority of configurations do not need to touch this parameter. Please note that too low values may significantly slow down the health checking if checks are slow to execute.
Sets the maximum number of consecutive connections a process may accept in a row before switching to other work. In single process mode, higher numbers used to give better performance at high connection rates, though this is not the case anymore with the multi-queue. This value applies individually to each listener, so that the number of processes a listener is bound to is taken into account. This value defaults to 4 which showed best results. If a significantly higher value was inherited from an ancient config, it might be worth removing it as it will both increase performance and lower response time. In multi-process mode, it is divided by twice the number of processes the listener is bound to. Setting this value to -1 completely disables the limitation. It should normally not be needed to tweak this value.
Sets the maximum amount of events that can be processed at once in a call to the polling system. The default value is adapted to the operating system. It has been noticed that reducing it below 200 tends to slightly decrease latency at the expense of network bandwidth, and increasing it above 200 tends to trade latency for slightly increased bandwidth. The configured value must be lower than or equal to 1000000.
Sets the reserved buffer space to this size in bytes. The reserved space is used for header rewriting or appending. The first reads on sockets will never fill more than bufsize-maxrewrite. Historically it has defaulted to half of bufsize, though that does not make much sense since there are rarely large numbers of headers to add. Setting it too high prevents processing of large requests or responses. Setting it too low prevents addition of new headers to already large requests or to POST requests. It is generally wise to set it to about 1024. It is automatically readjusted to half of bufsize if it is larger than that. This means you don't have to worry about it when changing bufsize.
Sets the maximum number of rules that can be evaluated at once in ruleset evaluating functions, provided that they support yielding. Indeed, it is not rare to see configurations with a large number of "tcp-request content" or "http-request" rules for instance. A large number of rules combined with cpu-demanding actions (e.g.: actions that work on content) may create thread contention as all the rules from a given ruleset are evaluated under the same polling loop if the evaluation is not interrupted. This option ensures that no more than <number> number of rules may be executed under the same polling loop for content-oriented rulesets (those that already support yielding due to content inspection). What it does is that it forces the evaluating function to yield, so that it comes back on the next polling loop to continues the evaluation. Affected rulesets are: - "tcp-request content" - "tcp-response content" - "http-request" - "http-response" The default value is 50.
Sets the per-thread amount of memory that will be kept hot in the local cache and will never be recoverable by other threads. Access to this memory is very fast (lockless), and having enough is critical to maintain a good performance level under extreme thread contention. The value is expressed in bytes, and the default value is configured at build time via CONFIG_HAP_POOL_CACHE_SIZE which defaults to 524288 (512 kB). A larger value may increase performance in some usage scenarios, especially when performance profiles show that memory allocation is stressed a lot. Experience shows that a good value sits between once to twice the per CPU core L2 cache size. Too large values will have a negative impact on performance by making inefficient use of the L3 caches in the CPUs, and will consume larger amounts of memory. It is recommended not to change this value, or to proceed in small increments. In order to completely disable the per-thread CPU caches, using a very small value could work, but it is better to use "-dMno-cache" on the command-line.
Adjusts the kernel's per-socket buffering so as to report that the sending side of a socket is full once the amount of buffered data equals this value plus the measured window size. The principle is to let the strict minimum needed amount of bytes in socket buffers, plus a small margin corresponding to what would be sent by the time haproxy tries to send again. Setting this to a low value (typically around tune.bufsize) allows to significantly reduce the memory consumption in system buffers, and reduce the application level latency incurred by flushing buffered data. This generally represents a more effective and more accurate setting than tune.sndbuf.client and tune.sndbuf.client for systems supporting it. This applies per connection (connection from a client or connection to a server depending on the setting) and is only used by TCP connections. The default is zero, which means unlimited. This is only available on Linux.
Sets the size of the pattern lookup cache to <number> entries. This is an LRU cache which reminds previous lookups and their results. It is used by ACLs and maps on slow pattern lookups, namely the ones using the "sub", "reg", "dir", "dom", "end", "bin" match methods as well as the case-insensitive strings. It applies to pattern expressions which means that it will be able to memorize the result of a lookup among all the patterns specified on a configuration line (including all those loaded from files). It automatically invalidates entries which are updated using HTTP actions or on the CLI. The default cache size is set to 10000 entries, which limits its footprint to about 5 MB per process/thread on 32-bit systems and 8 MB per process/thread on 64-bit systems, as caches are thread/process local. There is a very low risk of collision in this cache, which is in the order of the size of the cache divided by 2^64. Typically, at 10000 requests per second with the default cache size of 10000 entries, there's 1% chance that a brute force attack could cause a single collision after 60 years, or 0.1% after 6 years. This is considered much lower than the risk of a memory corruption caused by aging components. If this is not acceptable, the cache can be disabled by setting this parameter to 0.
Sets the maximum number of stick-table updates that haproxy will try to process at once when sending messages. Retrieving the data for these updates requires some locking operations which can be CPU intensive on highly threaded machines if unbound, and may also increase the traffic latency during the initial batched transfer between an older and a newer process. Conversely low values may also incur higher CPU overhead, and take longer to complete. The default value is 200 and it is suggested not to change it.
Sets the kernel pipe buffer size to this size (in bytes). By default, pipes are the default size for the system. But sometimes when using TCP splicing, it can improve performance to increase pipe sizes, especially if it is suspected that pipes are not filled and that many calls to splice() are performed. This has an impact on the kernel's memory footprint, so this must not be changed if impacts are not understood.
This setting sets the max number of file descriptors (in percentage) used by HAProxy globally against the maximum number of file descriptors HAProxy can use before we start killing idle connections when we can't reuse a connection and we have to create a new one. The default is 25 (one quarter of the file descriptor will mean that roughly half of the maximum front connections can keep an idle connection behind, anything beyond this probably doesn't make much sense in the general case when targeting connection reuse).
This setting sets the max number of file descriptors (in percentage) used by HAProxy globally against the maximum number of file descriptors HAProxy can use before we stop putting connection into the idle pool for reuse. The default is 20.
Enables ('on') of disabled ('off') the zero-copy forwarding of data for the
pass-through multiplexer. To be used, the kernel splicing must also be
configured. It is enabled by default.
Defines how many lost packets are needed for the Cubic congestion control algorithm to really consider a loss event. Normally, any loss event is considered as the result of a congestion and is sufficient for Cubic to restart from a smaller window. But experiments show that there can be a variety of causes for losses that are not at all caused by congestion and that can simply be qualified of spurious losses, and for which adjusting the window will have no effect, except slowing communication down. Poor radio signal, out-of-order delivery, high CPU usage on a client causing random delays, as well as system timer imprecision can be among the common causes for this. This setting allows to make Cubic a bit more tolerant to spurious losses, by changing the minimum number of cumulated losses between two ACKs to be considered as a loss event, which defaults to 1. Some significant gains have been observed experimentally, but always accompanied with an aggravation of the bandwidth wasted on retransmits, and an increased risk of saturation of congested links. The value 2 may be used for short periods of time to compare some metrics. Never go beyond 2 without an expert's prior analysis of the situation. The default and minimum value is 1. Always use 1.
This keyword has been deprecated in 3.3 and will be removed in 3.5. It is part of the streamlining process apply on QUIC configuration. If used, this setting will only be applied on frontend connections.
Enables ('on') or disabled ('off') the HyStart++ (RFC 9406) algorithm for
QUIC connections used as a replacement for the slow start phase of congestion
control algorithms which may cause high packet loss. It is disabled by default.
This keyword has been deprecated in 3.3 and will be removed in 3.5. It is part of the streamlining process apply on QUIC configuration. If used, this setting will only be applied on frontend connections.
Sets the limit for which a single QUIC frame can be marked as lost. If exceeded, the connection is considered as failing and is closed immediately. The default value is 10.
This keyword has been deprecated in 3.3 and will be removed in 3.5. It is part of the streamlining process apply on QUIC configuration. If used, this setting will only be applied on frontend connections.
Sets the default maximum window size for the congestion controller of a
single QUIC connection either on frontend or backend side. The value must be
written as an integer with an optional suffix 'k', 'm' or 'g'. It must be
between 10k and 4g.
QUIC multiplexer also uses the current congestion window size to determine if
it can allocate new stream buffers on data emission. As such, the maximum
congestion window size also serves as a limit on this allocator.
The default value is 480k.
See also the "quic-cc-algo" bind and server options.
This keyword has been deprecated in 3.3 and will be removed in 3.5. It is part of the streamlining process apply on QUIC configuration. If used, this setting will only be applied on frontend connections.
The ratio applied to the packet reordering threshold calculated. It may trigger a high packet loss detection when too small. The default value is 50.
This keyword has been deprecated in 3.3 and will be removed in 3.5. It is part of the streamlining process apply on QUIC configuration. If used, this setting will only be applied on frontend connections.
Sets the QUIC max_idle_timeout transport parameters on either frontend or backend side. It follows the HAProxy time format and is expressed in milliseconds. This determines the period of time after which a connection is silently closed if it has remained inactive during an effective period of time. Both endpoints relies on the same negotiated value : - the minimum of the two parameters if both are not null, - the maximum if only one of them is not null, - if both parameters are null, this feature is disabled. The default value is 30s.
This keyword has been deprecated in 3.3 and will be removed in 3.5. It is part of the streamlining process apply on QUIC configuration. If used, this setting will only be applied on frontend connections.
Sets the threshold for the number of glitches per connection either on frontend or backend side, where that connection will automatically be killed. This allows to automatically kill misbehaving connections without having to write explicit rules for them. The default value is zero, indicating that no threshold is set so that no event will cause a connection to be closed. Beware that some QUIC clients may occasionally cause a few glitches over long lasting connection, so any non- zero value here should probably be in the hundreds or thousands to be effective without affecting slightly bogus clients. It is also possible to only kill connections when the CPU usage crosses a certain level, by using "tune.glitches.kill.cpu-usage".
This keyword has been deprecated in 3.3 and will be removed in 3.5. It is part of the streamlining process apply on QUIC configuration. If used, this setting will only be applied on frontend connections.
Dynamically enables the Retry feature for all the configured QUIC listeners as soon as this number of half open connections is reached. A half open connection is a connection whose handshake has not already successfully completed or failed. To be functional this setting needs a cluster secret to be set, if not it will be silently ignored (see "cluster-secret" setting). This setting will be also silently ignored if the use of QUIC Retry was forced (see "quic-force-retry"). The default value is 100. See https://www.rfc-editor.org/rfc/rfc9000.html#section-8.1.2 for more information about QUIC retry.
This keyword has been deprecated in 3.3 and will be removed in 3.5. It is part of the streamlining process apply on QUIC configuration. If used, this setting will only be applied on frontend connections.
Specifies globally how QUIC frontend connections will use socket for receive/send operations. Connections can share listener socket or each connection can allocate its own socket. The default value is "default-on". This is used to allocate a dedicated socket for every QUIC connections. This option is the preferred one to achieve the best performance with a large QUIC traffic. This is also the only way to ensure soft-stop is conducted properly without data loss for QUIC connections and cases of transient errors during sendto() operation are handled efficiently. However, this relies on some advanced features from the UDP network stack. If your platform is deemed not compatible, haproxy will automatically switch to "force-off" mode on startup. Please note that QUIC listeners running on privileged ports may require to run as uid 0, or some OS-specific tuning to permit the target uid to bind such ports, such as system capabilities. See also the "setcap" global directive. The "force-off" value indicates that QUIC transfers will occur on the shared listener socket. This option can be a good compromise for small traffic as it allows to reduce FD consumption. However, performance won't be optimal due to a higher CPU usage if listeners are shared across a lot of threads or a large number of QUIC connections can be used simultaneously. This setting is applied in conjunction with each "quic-socket" bind options. If "default-on" mode is used on global tuning, it will be activated for each listener, except for the ones with "quic-socket listener". However, if "force-off" is used globally, it will be applied on every listener instance, regardless of their individual configuration.
This keyword has been deprecated in 3.3 and will be removed in 3.5. It is part of the streamlining process apply on QUIC configuration. The newer option is named "tune.quic.fe.sock-per-conn", with legacy value "connection" corresponding to "default-on" and "listener" to "force-off".
This setting allows to configure the hard limit of the number of data bytes in flight over each stream. It is expressed as a percentage relative to the QUIC stream rxbuf connection setting, with the result rounded up to bufsize. The default value is 90. This is suitable with the most frequent web scenario, where uploads is performed only for one or a few streams, whereas the rest are used for download only. If the stream rxbuf connection limit remains at a reasonable level, it ensures that only a portion of opened streams can allocate to their maximum capacity. In the case of an application using many uploading streams in parallel and suffering from unfairness between these streams, it can make sense to reduce this ratio, to increase fairness and reduce the per-stream bandwidth.
This keyword has been deprecated in 3.3 and will be removed in 3.5. It is part of the streamlining process apply on QUIC configuration. If used, this setting will only be applied on frontend connections.
On frontend side, this is used as the value for the advertised initial_max_streams_bidi transport parameter. This is enforced as the maximum number of bidirectional streams that the remote peer will be authorized to open concurrently during the connection lifetime. This effectively limits the number of concurrent HTTP/3 client requests. The default value is 100. Note that if you reduces it, it can restrict the buffering capabilities of streams on receive, which would result in poor upload throughput. It can be corrected by increasing the QUIC stream rxbuf connection setting. On backend side, this is enforced locally by haproxy to limit the number of concurrent requests multiplexed over a single connection. This may be further restricted by the peer flow control. It may be necessary to reduce the default value of 100 to improve a site's responsiveness at the expense of a higher number of opened backend connections. Similarly to the frontend side, this setting also directly impacts the Rx buffering capability, this time though limiting the HTTP download capacity. QUIC stream rxbuf setting can be increased when dealing mostly with HTTP responses larger than "tune.bufsize".
Sets the maximum number of requests that can be handled by a single QUIC connection. Once this total is reached, the connection will be gracefully shutdown. In HTTP/3, this translates to a GOAWAY frame. The connection is finally closed when all remaining transfers are completed. This setting is applied as a hard limit on the connection via the QUIC flow control mechanism. If a peer violates it, the connection will be immediately closed. This setting can be used to force clients to open new connections once in a while to continue the emission of requests and avoid maintaining connections for too many times. However, low values will increase latency on the client side, as well as CPU consumption on both sides due to TLS handshakes. The default value is 0 which implies no specific limit outside of the QUIC protocol encoding limitation (2^60, more than a billion billion).
This keyword has been deprecated in 3.3 and will be removed in 3.5. It is part of the streamlining process apply on QUIC configuration. If used, this setting will only be applied on frontend connections.
This setting is the hard limit for the number of data bytes in flight over a QUIC frontend connection. It is reused as the value for the initial_max_data transport parameter. It directly impacts the upload bandwidth for the peer depending on the latency and the per-connection memory consumption in haproxy. By default, the value is set to 0, which indicates that it must be automatically generated as the product between max-concurrent and bufsize. This can be increased for example if a backend application relies on massive uploads over high latency networks.
This keyword has been deprecated in 3.3 and will be removed in 3.5. It is part of the streamlining process apply on QUIC configuration. If used, this setting will only be applied on frontend connections.
Enables ('on') or disables ('off') pacing support for QUIC emission. By
default, it is active. The purpose of pacing is to smooth emission of data to
reduce network losses. In most scenario, it will significantly improve
network throughput by avoiding retransmissions. However, it can be useful to
deactivate it for networks with very high bandwidth/low latency
characteristics to prevent unwanted delay and reduce CPU consumption.
See also the "quic-cc-algo" bind and server options.
This keyword has been deprecated in 3.3 and will be removed in 3.5. It is part of the streamlining process apply on QUIC configuration. If used, this setting will only be applied on frontend connections.
Enables ('on') or disables ('off') UDP GSO support for QUIC emission. By
default, it is active. This kernel feature allows to emit multiple datagrams
via a single system call which is more efficient for large transfer. It may
be useful to disable it on developers suggestion when suspecting an issue on
emission.
This keyword has been deprecated in 3.3 and will be removed in 3.5. It is part of the streamlining process apply on QUIC configuration. If used, this setting will only be applied on frontend connections.
Disable QUIC transport protocol on the frontend side. All the QUIC listeners will still be created, but they won't listen for incoming datagrams. Hence, no QUIC traffic will be processed by haproxy on the frontend side. The default value is "on". If an issue is suspected with QUIC traffic, this option can be used to easily toggle QUIC listeners without messing with each individual config lines. See also "quic_enabled" sample fetch.
Sets the maximum amount of memory usable by QUIC stack at the transport layer for emission. This serves both as a limit of in flight bytes and multiplexer output buffers. Note that to prevent threads contention this limit is not strictly enforced so it can be exceeded on some occasions. Also, each connection will always be able to use a window of at least 2 datagrams, so a proper maxconn should be used in conjunction.
This keyword has been deprecated in 3.3 and will be removed in 3.5. It is part of the streamlining process apply on QUIC configuration. If used, this setting will only be applied on frontend connections.
Enables ('on') of disabled ('off') the zero-copy sends of data for the QUIC
multiplexer. It is enabled by default.
This configuration option takes a value between -20 and 19. It applies a scheduling priority as documented in man 2 setpriority. This priority is applied after the configuration parsing, which means only the worker or the standalone process will apply it. It is usually configured to set a higher priority than a process doing configuration parsing (tune.renice.startup).
This configuration option takes a value between -20 and 19. It applies a scheduling priority as documented in man 2 setpriority. This priority is applied before applying the rest of the configuration which can be useful if you want to lower the priority for configuration parsing. This is applied on the standalone process or the worker before configuration parsing. Once the configuration is parsed, the previous priority is restored unless tune.renice.runtime is used.
For the kernel socket receive buffer size on non-connected sockets to this size. This can be used QUIC in listener mode and log-forward on the frontend. The default system buffers might sometimes be too small for sockets receiving lots of aggregated traffic, causing some losses and possibly retransmits (in case of QUIC), possibly slowing down connection establishment under heavy traffic. The value is expressed in bytes, applied to each socket. In listener mode, sockets are shared between all connections, and the total number of sockets depends on the "shards" value of the "bind" line. There's no good value, a good one corresponds to an expected size per connection multiplied by the expected number of connections. The kernel may trim large values. See also "tune.rcvbuf.client" and "tune.rcvbuf.server" for their connected socket counter parts, as well as "tune.sndbuf.backend" and "tune.sndbuf.frontend" for the send setting.
Forces the kernel socket receive buffer size on the client or the server side to the specified value in bytes. This value applies to all TCP/HTTP frontends and backends. It should normally never be set, and the default size (0) lets the kernel auto-tune this value depending on the amount of available memory. However it can sometimes help to set it to very low values (e.g. 4096) in order to save kernel memory by preventing it from buffering too large amounts of received data. Lower values will significantly increase CPU usage though.
HAProxy uses some hints to detect that a short read indicates the end of the socket buffers. One of them is that a read returns more than <recv_enough> bytes, which defaults to 10136 (7 segments of 1448 each). This default value may be changed by this setting to better deal with workloads involving lots of short messages such as telnet or SSH sessions.
Sets the number of write queues in front of ring buffers. This can have an effect on the CPU usage of traces during debugging sessions, and both too low or too large a value can have an important effect. The good value was determined experimentally by developers and there should be no reason to try to change it unless instructed to do so in order to try to address specific issues. Such a setting should not be left in the configuration across version upgrades because its optimal value may evolve over time.
Sets the maximum amount of task that can be processed at once when running tasks. The default value depends on the number of threads but sits between 35 and 280, which tend to show the highest request rates and lowest latencies. Increasing it may incur latency when dealing with I/Os, making it too small can incur extra overhead. Higher thread counts benefit from lower values. When experimenting with much larger values, it may be useful to also enable tune.sched.low-latency and possibly tune.fd.edge-triggered to limit the maximum latency to the lowest possible.
Enables ('on') or disables ('off') the low-latency task scheduler. By default
HAProxy processes tasks from several classes one class at a time as this is
the most efficient. But when running with large values of tune.runqueue-depth
this can have a measurable effect on request or connection latency. When this
low-latency setting is enabled, tasks of lower priority classes will always
be executed before other ones if they exist. This will permit to lower the
maximum latency experienced by new requests or connections in the middle of
massive traffic, at the expense of a higher impact on this large traffic.
For regular usage it is better to leave this off. The default value is off.
For the kernel socket send buffer size on non-connected sockets to this size. This can be used for UNIX socket and UDP logging on the backend side, and for QUIC in listener mode on the frontend. The default system buffers might sometimes be too small for sockets shared between many connections (or log senders), causing some losses and possibly retransmits, slowing down new connection establishment under high traffic. The value is expressed in bytes, applied to each socket. In listener mode, sockets are shared between all connections, and the total number of sockets depends on the "shards" value of the "bind" line. There's no good value, a good one corresponds to an expected size per connection multiplied by the expected number of connections. The kernel may trim large values. See also "tune.sndbuf.client" and "tune.sndbuf.server" for their connected socket counter parts, as well as "tune.rcvbuf.backend" and "tune.rcvbuf.frontend" for the receive setting.
Forces the kernel socket send buffer size on the client or the server side to the specified value in bytes. This value applies to all TCP/HTTP frontends and backends. It should normally never be set, and the default size (0) lets the kernel auto-tune this value depending on the amount of available memory. However it can sometimes help to set it to very low values (e.g. 4096) in order to save kernel memory by preventing it from buffering too large amounts of received data. Lower values will significantly increase CPU usage though. Another use case is to prevent write timeouts with extremely slow clients due to the kernel waiting for a large part of the buffer to be read before notifying HAProxy again. See also tune.notsent-lowat.client and tune.notsent-lowat.server for more effective settings to more finely control memory usage and responsiveness on Linux without hurting performance.
Sets the size of the global SSL session cache, in a number of blocks. A block is large enough to contain an encoded session without peer certificate. An encoded session with peer certificate is stored in multiple blocks depending on the size of the peer certificate. A block uses approximately 200 bytes of memory (based on `sizeof(struct sh_ssl_sess_hdr) + SHSESS_BLOCK_MIN_SIZE` calculation used for `shctx_init` function). The default value may be forced at build time, otherwise defaults to 20000. When the cache is full, the most idle entries are purged and reassigned. Higher values reduce the occurrence of such a purge, hence the number of CPU-intensive SSL handshakes by ensuring that all users keep their session as long as possible. All entries are pre-allocated upon startup. Setting this value to 0 disables the SSL session cache.
Sets the maximum size of the buffer used for capturing client hello cipher list, extensions list, elliptic curves list and elliptic curve point formats. If the value is 0 (default value) the capture is disabled, otherwise a buffer is allocated for each SSL/TLS connection.
This setting allows to configure the certificate compression support which is an extension (RFC 8879) to TLS 1.3. When set to "auto" it uses the default value of the TLS library. With "off" it tries to explicitly disable the support of the feature. HAProxy won't try to send compressed certificates anymore nor accept compressed certificates. Configures both backend and frontend sides. This keyword is supported by OpenSSL >= 3.2.0. The default value is auto.
Sets the maximum size of the Diffie-Hellman parameters used for generating the ephemeral/temporary Diffie-Hellman key in case of DHE key exchange. The final size will try to match the size of the server's RSA (or DSA) key (e.g, a 2048 bits temporary DH key for a 2048 bits RSA key), but will not exceed this maximum value. Only 1024 or higher values are allowed. Higher values will increase the CPU load, and values greater than 1024 bits are not supported by Java 7 and earlier clients. This value is not used if static Diffie-Hellman parameters are supplied either directly in the certificate file or by using the ssl-dh-param-file parameter. If there is neither a default-dh-param nor a ssl-dh-param-file defined, and if the server's PEM file of a given frontend does not specify its own DH parameters, then DHE ciphers will be unavailable for this frontend.
This option disables SSL session cache sharing between all processes. It should normally not be used since it will force many renegotiations due to clients hitting a random process. But it may be required on some operating systems where none of the SSL cache synchronization method may be used. In this case, adding a first layer of hash-based load balancing before the SSL layer might limit the impact of the lack of session sharing.
Sets the maximum amount of bytes passed to SSL_write() at any time. Default value 0 means there is no limit. In contrast to tune.ssl.maxrecord this settings will not be adjusted dynamically. Smaller records may decrease throughput, but may be required when dealing with low-footprint clients.
This option activates the logging of the TLS keys. It should be used with
care as it will consume more memory per SSL session and could decrease
performances. This is disabled by default.
These sample fetches should be used to generate the SSLKEYLOGFILE that is
required to decipher traffic with wireshark.
https://tlswg.org/sslkeylogfile/draft-ietf-tls-keylogfile.html
The SSLKEYLOG is a series of lines which are formatted this way:
<Label> <space> <ClientRandom> <space> <Secret>
The ClientRandom is provided by the %[ssl_fc_client_random,hex] sample
fetch, the secret and the Label could be find in the array below. You need
to generate a SSLKEYLOGFILE with all the labels in this array.
The following sample fetches are hexadecimal strings and does not need to be
converted.
SSLKEYLOGFILE Label | Sample fetches for the Secrets
--------------------------------|-----------------------------------------
CLIENT_EARLY_TRAFFIC_SECRET | %[ssl_xx_client_early_traffic_secret]
CLIENT_HANDSHAKE_TRAFFIC_SECRET | %[ssl_xx_client_handshake_traffic_secret]
SERVER_HANDSHAKE_TRAFFIC_SECRET | %[ssl_xx_server_handshake_traffic_secret]
CLIENT_TRAFFIC_SECRET_0 | %[ssl_xx_client_traffic_secret_0]
SERVER_TRAFFIC_SECRET_0 | %[ssl_xx_server_traffic_secret_0]
EXPORTER_SECRET | %[ssl_xx_exporter_secret]
EARLY_EXPORTER_SECRET | %[ssl_xx_early_exporter_secret]
These fetches exists for frontend (fc) or backend (bc) sides, replace "xx" by
"fc" or "bc" to use the right side.
This is only available with OpenSSL 1.1.1, and useful with TLS1.3 session.
If you want to generate the content of a SSLKEYLOGFILE with TLS < 1.3, you
only need this line:
"CLIENT_RANDOM %[ssl_fc_client_random,hex] %[ssl_fc_session_key,hex]"
A complete keylog could be generate with a log-format these way, even though
this is not ideal for syslog:
log-format "CLIENT_EARLY_TRAFFIC_SECRET %[ssl_bc_client_random,hex] %[ssl_bc_client_early_traffic_secret]\n
CLIENT_HANDSHAKE_TRAFFIC_SECRET %[ssl_bc_client_random,hex] %[ssl_bc_client_handshake_traffic_secret]\n
SERVER_HANDSHAKE_TRAFFIC_SECRET %[ssl_bc_client_random,hex] %[ssl_bc_server_handshake_traffic_secret]\n
CLIENT_TRAFFIC_SECRET_0 %[ssl_bc_client_random,hex] %[ssl_bc_client_traffic_secret_0]\n
SERVER_TRAFFIC_SECRET_0 %[ssl_bc_client_random,hex] %[ssl_bc_server_traffic_secret_0]\n
EXPORTER_SECRET %[ssl_bc_client_random,hex] %[ssl_bc_exporter_secret]\n
EARLY_EXPORTER_SECRET %[ssl_bc_client_random,hex] %[ssl_bc_early_exporter_secret]"
HAProxy also provides the above formats as predefined environment variables
that can be used directly in a "log-format" directive:
$HAPROXY_KEYLOG_FC_LOG_FMT frontend (client-facing) connection keys
$HAPROXY_KEYLOG_BC_LOG_FMT backend (server-facing) connection keys
Limit the amount of KeyUpdate per second we're willing to accept to <limit> before considering it flood, and killing the connection. Dealing with KeyUpdate is cpu-expensive, and there is little reason to receive a lot of them. Using a value of "0" disables the rate limiting. The default value is 100.
Sets how long a cached SSL session may remain valid. This time is expressed in seconds and defaults to 300 (5 min). It is important to understand that it does not guarantee that sessions will last that long, because if the cache is full, the longest idle sessions will be purged despite their configured lifetime. The real usefulness of this setting is to prevent sessions from being used for too long.
Sets the maximum amount of bytes passed to SSL_write() at the beginning of the data transfer. Default value 0 means there is no limit. Over SSL/TLS, the client can decipher the data only once it has received a full record. With large records, it means that clients might have to download up to 16kB of data before starting to process them. Limiting the value can improve page load times on browsers located over high latency or low bandwidth networks. It is suggested to find optimal values which fit into 1 or 2 TCP segments (generally 1448 bytes over Ethernet with TCP timestamps enabled, or 1460 when timestamps are disabled), keeping in mind that SSL/TLS add some overhead. Typical values of 1419 and 2859 gave good results during tests. Use "strace -e trace=write" to find the best value. HAProxy will automatically switch to this setting after an idle stream has been detected (see tune.idletimer above). See also tune.ssl.hard-maxrecord.
Sets the size of the cache used to store generated certificates to <number> entries. This is a LRU cache. Because generating a SSL certificate dynamically is expensive, they are cached. The default cache size is set to 1000 entries.
Defines a target percentage of streams per frontend connection relative to the maximum number of concurrent connections (maxconn) when all connections are established. This metric applies to multiplexed protocols like HTTP/2 or QUIC, where each connection may receive multiple streams. At least one is always guaranteed, so the percentage must be at least 100%. During connection setup, HAProxy dynamically advertises additional streams up to the configured limit, maintaining the target ratio. At connection establishment, every frontend connection receives at least one stream; extra streams are assigned based on the target percentage and configured stream limits. This ensures efficient stream allocation under varying load conditions (more streams at low loads, fewer at high loads). Highly dynamic sites with many objects per page benefit from high ratios, enabling many streams per connection. Sites using fewer streams on average (WebSocket, application code) may prefer small ratios closer to 120 or 150 (20 to 50% more streams than connections) preventing excessive stream counts under sustained loads. The default value is 0, meaning no enforcement at this level, so only H2 and QUIC configurations apply (with the default setting of 100 streams per connection, this corresponds to 10000%). This remains the recommended setting for small deployments (maxconn around a thousand). Moderately sized setups (few thousands to tens of thousands connections) typically set the ratio between 1000 and 5000, allowing 10 to 50 streams per connection at full load. Large-scale deployments (hundreds of thousands to millions connections) might use lower values (120 to 200) to support 1.2 to 2 streams per connection on average at full load. Contrary to HTTP/2, QUIC is capable to dynamically adjust the number of concurrent streams during the connection lifetime. However, QUIC flow control is stricter than HTTP/2, thus it is preferable when using it to specify values big enough to prevent extra latency on the connection. There is also a limitation for QUIC listeners with enabled 0-RTT. In this case, the initial value advertised to the peer will ignore stream elasticity and instead rely solely on the "tune.quic.fe.stream.max-concurrent" setting. However, the stream elasticity principle will still be effective past this initial annoucement during the connection lifetime. Monitoring the total number of active streams on backends, including queues, provides a practical indicator of a sustainable target load and helps avoid over-provisioning.
Sets the number of stick-counters that may be tracked at the same time by a connection or a request via "track-sc*" actions in "tcp-request" or "http-request" rules. The default value is set at build time by the macro MAX_SESS_STK_CTR, and defaults to 3. With this setting it is possible to change the value and ignore the one passed at build time, but it cannot be set to a value greater than 100. Increasing this value may be needed when porting complex configurations to haproxy, but users are warned against the costs: each entry takes 16 bytes per connection and 16 bytes per request, all of which need to be allocated and zeroed for all requests even when not used. As such a value of 10 will inflate the memory consumption per request by 320 bytes and will cause this memory to be erased for each request, which does have measurable CPU impacts. Conversely, when no "track-sc" rules are used, the value may be lowered (0 being valid to entirely disable stick-counters).
By default, we won't attempt to use idle connections from other thread groups. This can however be changed. Valid values for <value> are : "none", the default, if used, no attempt will be made to use idle connections from other thread groups, "restricted" where we will only attempt to get an idle connection from another thread if we're using protocols that can't create new connections, such as reverse http, as well as when using strict-maxconn, and "full" where we will always look in other thread groups for idle connections. Note that using connections from other thread groups can occur performance penalties, so it should not be used unless really needed. Note that this behavior is now controlled by tune.idle-pool.shared, and this keyword is just there for compatibility with older configurations, and will be deprecated.
These five tunes help to manage the maximum amount of memory used by the variables system. "global" limits the overall amount of memory available for all scopes. "proc" limits the memory for the process scope, "sess" limits the memory for the session scope, "txn" for the transaction scope, and "reqres" limits the memory for each request or response processing. Memory accounting is hierarchical, meaning more coarse grained limits include the finer grained ones: "proc" includes "sess", "sess" includes "txn", and "txn" includes "reqres". For example, when "tune.vars.sess-max-size" is limited to 100, "tune.vars.txn-max-size" and "tune.vars.reqres-max-size" cannot exceed 100 either. If we create a variable "txn.var" that contains 100 bytes, all available space is consumed. Notice that exceeding the limits at runtime will not result in an error message, but values might be cut off or corrupted. So make sure to accurately plan for the amount of space needed to store all your variables.
Sets the memLevel parameter in zlib initialization for each stream. It defines how much memory should be allocated for the internal compression state. A value of 1 uses minimum memory but is slow and reduces compression ratio, a value of 9 uses maximum memory for optimal speed. Can be a value between 1 and 9. The default value is 8.
Sets the window size (the size of the history buffer) as a parameter of the zlib initialization for each stream. Larger values of this parameter result in better compression at the expense of memory usage. Can be a value between 8 and 15. The default value is 15.
This sets the global anonymizing key to <key>, which must be a 32-bit number between 0 and 4294967295. This is the key that will be used by default by CLI commands when anonymized mode is enabled. This key may also be set at runtime from the CLI command "set anon global-key". See also command line argument "-dC" in the management manual.
Enables ('on') or disables ('off') the updating of event counters in the
code. These are the counters reported under the type "CNT" in the CLI command
"debug counters". These counters are only available when the code was build
with DEBUG_COUNTERS set to a value 1 or above. With the value 1, the counters
are not updated by default ("debug.counters off"), and with value 2, they are
updated by default ("debug.counters on"). There is normally no reason to
change this setting unless a developer requests it, or unless it is suspected
to consume abnormal amounts of CPU (in which case a report to developers is
necessary with a dump of the counters). It is also possible to change this
status at run time using the "debug counters" CLI command. Please consult the
management manual.
This command is pausing the configuration parser for <timeout> milliseconds.
This is useful for development or for testing timeouts of init scripts,
particularly to simulate a very long reload.
It requires the expose-experimental-directives to be set.
<timeout> is the timeout value specified in milliseconds by default, but
can be in any other unit if the number is suffixed by the unit,
as explained at the top of this document.
global
expose-experimental-directives
force-cfg-parser-pause 10s
This speeds up the old process exit upon reload by skipping the releasing of memory objects and listeners, since all of these are reclaimed by the operating system at the process' death. The gains are only marginal (in the order of a few hundred milliseconds for huge configurations at most). The main target usage in fact is when a bug is spotted in the deinit() code, as this allows to bypass it. It is better not to use this unless instructed to do so by developers.
Do not display any message during startup. It is equivalent to the command- line argument "-q".
This allows to adjust the delay after which a stuck task blocking the traffic will trigger the emission of a warning on the standard error output. The delay is expressed in milliseconds and defaults to 100 ms. Permitted values must be comprised between 1 ms and 1000 ms included. Lower values will trigger warnings frequently and higher ones will rarely. The watchdog will kill a runaway task that fails to respond twice for one second anyway, so a 1000 ms warning delay will normally not trigger any warning. It is recommended to stay with values between 10 and 100ms to detect configuration anomalies that may degrade the user's experience, causing long response times or jerkiness on interactive sessions. For example, a poorly designed Lua sample-fetch function doing heavy computations, or a very large map_reg or map_regm map file with a very high evaluation cost may cause such trouble. For comparison a TLS handshake can eat between one and two milliseconds, and compressing a 16kB HTTP response buffer is around one millisecond. The output contains a thread dump of the offending task with a backtrace and some context that helps figure where the time is being spent.
When this option is set, HAProxy will refuse to start if any warning was emitted while processing the configuration and applying it. It means that warnings about bad combinations of parameters, warnings about very high limits that couldn't be set, and so on, make the process exit with an error during startup. A few late startup warnings cannot be caught by this option, such as the failure to drop supplementary groups when changing the group ID in "daemon" or "master-worker" modes, or the failure to mark the process dumpable after the fork(). This option does not catch warnings emitted at runtime. It is highly recommended to set this option on configurations that are not changed often, as it helps to detect subtle mistakes and keep the configuration clean and forward-compatible. Note that "haproxy -c" will also report errors in such a case. This option is equivalent to command line argument "-dW".
HTTPClient is an internal HTTP library, it can be used by various subsystems, for example in LUA scripts. HTTPClient is not used in the data path, in other words it has nothing with HTTP traffic passing through HAProxy.
Disable the DNS resolution of the httpclient. Prevent the creation of the "default" resolvers section. Default value is off.
This option defines the resolvers section with which the httpclient will try to resolve. Default option is the "default" resolvers ID. By default, if this option is not used, it will simply disable the resolving if the section is not found. However, when this option is explicitly enabled it will trigger a configuration error if it fails to load.
This option allows to chose which family of IP you want when resolving, which is convenient when IPv6 is not available on your network. Default option is "ipv6".
This option allows to configure the number of retries attempt of the httpclient when a request failed. This does the same as the "retries" keyword in a backend. Default value is 3.
This option defines the ca-file which should be used to verify the server
certificate. It takes the same parameters as the "ca-file" option on the
server line.
By default and when this option is not used, the value is
"@system-ca" which tries to load the CA of the system. If it fails the SSL
will be disabled for the httpclient.
However, when this option is explicitly enabled it will trigger a
configuration error if it fails.
Works the same way as the verify option on server lines. If specified to 'none', servers certificates are not verified. Default option is "required". By default and when this option is not used, the value is "required". If it fails the SSL will be disabled for the httpclient. However, when this option is explicitly enabled it will trigger a configuration error if it fails.
Set the maximum time to wait for a connection attempt by default for the httpclient.
<timeout> is the timeout value specified in milliseconds by default, but
can be in any other unit if the number is suffixed by the unit,
as explained at the top of this document.
The default value is 5000ms.
Proxy configuration can be located in a set of sections :
- defaults [<name>] [ from <defaults_name> ]
- frontend <name> [ from <defaults_name> ]
- backend <name> [ from <defaults_name> ]
- listen <name> [ from <defaults_name> ]
A "frontend" section describes a set of listening sockets accepting client
connections.
A "backend" section describes a set of servers to which the proxy will connect
to forward incoming connections.
A "listen" section defines a complete proxy with its frontend and backend
parts combined in one section. It is generally useful for TCP-only traffic.
A "defaults" section resets all settings to the documented ones and presets new
ones for use by subsequent sections. All of "frontend", "backend" and "listen"
sections always take their initial settings from a defaults section, by default
the latest one that appears before the newly created section. It is possible to
explicitly designate a specific "defaults" section to load the initial settings
from by indicating its name on the section line after the optional keyword
"from". While "defaults" section do not impose a name, this use is encouraged
for better readability. It is also the only way to designate a specific section
to use instead of the default previous one. Since "defaults" section names are
optional, by default a very permissive check is applied on their name and these
are even permitted to overlap. However if a "defaults" section is referenced by
any other section, its name must comply with the syntax imposed on all proxy
names, and this name must be unique among the defaults sections. Please note
that regardless of what is currently permitted, it is recommended to avoid
duplicate section names in general and to respect the same syntax as for proxy
names. This rule might be enforced in a future version. In addition, a warning
is emitted if a defaults section is explicitly used by a proxy while it is also
implicitly used by another one because it is the last one defined. It is highly
encouraged to not mix both usages by always using explicit references or by
adding a last common defaults section reserved for all implicit uses.
Note that it is even possible for a defaults section to take its initial
settings from another one, and as such, inherit settings across multiple levels
of defaults sections. This can be convenient to establish certain configuration
profiles to carry groups of default settings (e.g. TCP vs HTTP or short vs long
timeouts) but can quickly become confusing to follow.
All proxy names must be formed from upper and lower case letters, digits,
'-' (dash), '_' (underscore) , '.' (dot) and ':' (colon). ACL names are
case-sensitive, which means that "www" and "WWW" are two different proxies.
Historically, all proxy names could overlap when certain conditions were met
(e.g. when not having the same frontend/backend capabilities), but it used to
cause too many problems in the logs as well as confusion on CLI operations,
stick-tables naming and stats retrieval. It is now mandatory that two proxies
have different names, regardless of their respective capabilities.
Right now, two major proxy modes are supported : "tcp", also known as layer 4,
and "http", also known as layer 7. In layer 4 mode, HAProxy simply forwards
bidirectional traffic between two sides. In layer 7 mode, HAProxy analyzes the
protocol, and can interact with it by allowing, blocking, switching, adding,
modifying, or removing arbitrary contents in requests or responses, based on
arbitrary criteria.
In HTTP mode, the processing applied to requests and responses flowing over
a connection depends in the combination of the frontend's HTTP options and
the backend's. HAProxy supports 3 connection modes :
- KAL : keep alive ("option http-keep-alive") which is the default mode : all
requests and responses are processed, and connections remain open but idle
between responses and new requests.
- SCL: server close ("option http-server-close") : the server-facing
connection is closed after the end of the response is received, but the
client-facing connection remains open.
- CLO: close ("option httpclose"): the connection is closed after the end of
the response and "Connection: close" appended in both directions.
The effective mode that will be applied to a connection passing through a
frontend and a backend can be determined by both proxy modes according to the
following matrix, but in short, the modes are symmetric, keep-alive is the
weakest option and close is the strongest.
Backend mode
| KAL | SCL | CLO
----+-----+-----+----
KAL | KAL | SCL | CLO
----+-----+-----+----
mode SCL | SCL | SCL | CLO
----+-----+-----+----
CLO | CLO | CLO | CLO
It is possible to chain a TCP frontend to an HTTP backend. It is pointless if
only HTTP traffic is handled. But it may be used to handle several protocols
within the same frontend. In this case, the client's connection is first handled
as a raw tcp connection before being upgraded to HTTP. Before the upgrade, the
content processings are performed on raw data. Once upgraded, data is parsed
and stored using an internal representation called HTX and it is no longer
possible to rely on raw representation. There is no way to go back.
There are two kind of upgrades, in-place upgrades and destructive upgrades. The
first ones involves a TCP to HTTP/1 upgrade. In HTTP/1, the request
processings are serialized, thus the applicative stream can be preserved. The
second one involves a TCP to HTTP/2 upgrade. Because it is a multiplexed
protocol, the applicative stream cannot be associated to any HTTP/2 stream and
is destroyed. New applicative streams are then created when HAProxy receives
new HTTP/2 streams at the lower level, in the H2 multiplexer. It is important
to understand this difference because that drastically changes the way to
process data. When an HTTP/1 upgrade is performed, the content processings
already performed on raw data are neither lost nor reexecuted while for an
HTTP/2 upgrade, applicative streams are distinct and all frontend rules are
evaluated systematically on each one. And as said, the first stream, the TCP
one, is destroyed, but only after the frontend rules were evaluated.
There is another important point to understand when HTTP processings are
performed from a TCP proxy. While HAProxy is able to parse HTTP/1 in-fly from
tcp-request content rules, it is not possible for HTTP/2. Only the HTTP/2
preface can be parsed. This is a huge limitation regarding the HTTP content
analysis in TCP. Concretely it is only possible to know if received data are
HTTP. For instance, it is not possible to choose a backend based on the Host
header value while it is trivial in HTTP/1. Hopefully, there is a solution to
mitigate this drawback.
There are two ways to perform an HTTP upgrade. The first one, the historical
method, is to select an HTTP backend. The upgrade happens when the backend is
set. Thus, for in-place upgrades, only the backend configuration is considered
in the HTTP data processing. For destructive upgrades, the applicative stream
is destroyed, thus its processing is stopped. With this method, possibilities
to choose a backend with an HTTP/2 connection are really limited, as mentioned
above, and a bit useless because the stream is destroyed. The second method is
to upgrade during the tcp-request content rules evaluation, thanks to the
"switch-mode http" action. In this case, the upgrade is performed in the
frontend context and it is possible to define HTTP directives in this
frontend. For in-place upgrades, it offers all the power of the HTTP analysis
as soon as possible. It is not that far from an HTTP frontend. For destructive
upgrades, it does not change anything except it is useless to choose a backend
on limited information. It is of course the recommended method. Thus, testing
the request protocol from the tcp-request content rules to perform an HTTP
upgrade is enough. All the remaining HTTP manipulation may be moved to the
frontend http-request ruleset. But keep in mind that tcp-request content rules
remains evaluated on each streams, that can't be changed.
The following list of keywords is supported. Most of them may only be used in a
limited set of section types. Some of them are marked as "deprecated" because
they are inherited from an old syntax which may be confusing or functionally
limited, and there are new recommended keywords to replace them. Keywords
marked with "(*)" can be optionally inverted using the "no" prefix, e.g. "no
option contstats". This makes sense when the option has been enabled by default
and must be disabled for a specific instance. Such options may also be prefixed
with "default" in order to restore default settings regardless of what has been
specified in a previous "defaults" section. Keywords supported in defaults
sections marked with "(!)" are only supported in named defaults sections, not
anonymous ones.
Note: Some dangerous and not recommended directives are intentionnaly not
listed in the following matrix. It is on purpose. These directives are
documentated. But by not listing them below is one more way to discourage
anyone to use it.
This section provides a description of each keyword and its usage.
Declare or complete an access list. May be used in the following contexts: tcp, http
May be used in sections :
| defaults | frontend | listen | backend |
|---|---|---|---|
yes(!)![]() | yes![]() | yes![]() | yes![]() |
This directive is only available from named defaults sections, not anonymous ones. ACLs defined in a defaults section are not visible from other sections using it.
acl invalid_src src 0.0.0.0/7 224.0.0.0/3
acl invalid_src src_port 0:1023
acl local_dst hdr(host) -i localhost
See section 7 about ACL usage.
Give hints to the system about the approximate listen backlog desired size May be used in the following contexts: tcp, http
May be used in sections :
| defaults | frontend | listen | backend |
|---|---|---|---|
yes![]() | yes![]() | yes![]() | no![]() |
<conns> is the number of pending connections. Depending on the operating
system, it may represent the number of already acknowledged
connections, of non-acknowledged ones, or both.
This option is only meaningful for stream listeners, including QUIC ones. Its behavior however is not identical with QUIC instances. For all listeners but QUIC, in order to protect against SYN flood attacks, one solution is to increase the system's SYN backlog size. Depending on the system, sometimes it is just tunable via a system parameter, sometimes it is not adjustable at all, and sometimes the system relies on hints given by the application at the time of the listen() syscall. By default, HAProxy passes the frontend's maxconn value to the listen() syscall. On systems which can make use of this value, it can sometimes be useful to be able to specify a different value, hence this backlog parameter. On Linux 2.4, the parameter is ignored by the system. On Linux 2.6, it is used as a hint and the system accepts up to the smallest greater power of two, and never more than some limits (usually 32768). For QUIC listeners, backlog sets a shared limits for both the maximum count of active handshakes and connections waiting to be accepted. The handshake phase relies primarily of the network latency with the remote peer, whereas the second phase depends solely on haproxy load. When either one of this limit is reached, haproxy starts to drop reception of INITIAL packets, preventing any new connection allocation, until the connection excess starts to decrease. This situation may cause browsers to silently downgrade the HTTP versions and switching to TCP.
Define the load balancing algorithm to be used in a backend. May be used in the following contexts: tcp, http, log
May be used in sections :
| defaults | frontend | listen | backend |
|---|---|---|---|
yes![]() | no![]() | yes![]() | yes![]() |
<algorithm> is the algorithm used to select a server when doing load
balancing. This only applies when no persistence information
is available, or when a connection is redispatched to another
server. <algorithm> may be one of the following :
roundrobin 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. This algorithm
is dynamic, which means that server weights may be adjusted
on the fly for slow starts for instance. It is limited by
design to 4095 active servers per backend. Note that in some
large farms, when a server becomes up after having been down
for a very short time, it may sometimes take a few hundreds
requests for it to be re-integrated into the farm and start
receiving traffic. This is normal, though very rare. It is
indicated here in case you would have the chance to observe
it, so that you don't worry. Note: weights are ignored for
backends in LOG mode.
static-rr Each server is used in turns, according to their weights.
This algorithm is as similar to roundrobin except that it is
static, which means that changing a server's weight on the
fly will have no effect. On the other hand, it has no design
limitation on the number of servers, and when a server goes
up, it is always immediately reintroduced into the farm, once
the full map is recomputed. It also uses slightly less CPU to
run (around -1%). This algorithm is not usable in LOG mode.
leastconn The server with the lowest number of connections receives the
connection. Round-robin is performed within groups of servers
of the same load to ensure that all servers will be used. Use
of this algorithm is recommended where very long sessions are
expected, such as LDAP, SQL, TSE, etc... but is not very well
suited for protocols using short sessions such as HTTP. This
algorithm is dynamic, which means that server weights may be
adjusted on the fly for slow starts for instance. It will
also consider the number of queued connections in addition to
the established ones in order to minimize queuing. This
algorithm is not usable in LOG mode.
first The first server with available connection slots receives the
connection. The servers are chosen from the lowest numeric
identifier to the highest (see server parameter "id"), which
defaults to the server's position in the farm. Once a server
reaches its maxconn value, the next server is used. It does
not make sense to use this algorithm without setting maxconn.
The purpose of this algorithm is to always use the smallest
number of servers so that extra servers can be powered off
during non-intensive hours. This algorithm ignores the server
weight, and brings more benefit to long session such as RDP
or IMAP than HTTP, though it can be useful there too. In
order to use this algorithm efficiently, it is recommended
that a cloud controller regularly checks server usage to turn
them off when unused, and regularly checks backend queue to
turn new servers on when the queue inflates. Alternatively,
using "http-check send-state" may inform servers on the load.
This algorithm is not usable in LOG mode.
hash Takes a regular sample expression in argument. The expression
is evaluated for each request and hashed according to the
configured hash-type. The result of the hash is divided by
the total weight of the running servers to designate which
server will receive the request. This can be used in place of
"source", "uri", "hdr()", "url_param()", "rdp-cookie" to make
use of a converter, refine the evaluation, or be used to
extract data from local variables for example. When the data
is not available, round robin will apply. This algorithm is
static by default, which means that changing a server's
weight on the fly will have no effect, but this can be
changed using "hash-type". This algorithm is not usable for
backends in LOG mode, please use "log-hash" instead.
source The source IP address is hashed and divided by the total
weight of the running servers to designate which server will
receive the request. This ensures that the same client IP
address will always reach the same server as long as no
server goes down or up. If the hash result changes due to the
number of running servers changing, many clients will be
directed to a different server. This algorithm is generally
used in TCP mode where no cookie may be inserted. It may also
be used on the Internet to provide a best-effort stickiness
to clients which refuse session cookies. This algorithm is
static by default, which means that changing a server's
weight on the fly will have no effect, but this can be
changed using "hash-type". See also the "hash" option above.
This algorithm is not usable for backends in LOG mode.
uri This algorithm hashes either the left part of the URI (before
the question mark) or the whole URI (if the "whole" parameter
is present) and divides the hash value by the total weight of
the running servers. The result designates which server will
receive the request. This ensures that the same URI will
always be directed to the same server as long as no server
goes up or down. This is used with proxy caches and
anti-virus proxies in order to maximize the cache hit rate.
Note that this algorithm may only be used in an HTTP backend.
This algorithm is static by default, which means that
changing a server's weight on the fly will have no effect,
but this can be changed using "hash-type".
This algorithm supports two optional parameters "len" and
"depth", both followed by a positive integer number. These
options may be helpful when it is needed to balance servers
based on the beginning of the URI only. The "len" parameter
indicates that the algorithm should only consider that many
characters at the beginning of the URI to compute the hash.
Note that having "len" set to 1 rarely makes sense since most
URIs start with a leading "/".
The "depth" parameter indicates the maximum directory depth
to be used to compute the hash. One level is counted for each
slash in the request. If both parameters are specified, the
evaluation stops when either is reached.
A "path-only" parameter indicates that the hashing key starts
at the first '/' of the path. This can be used to ignore the
authority part of absolute URIs, and to make sure that HTTP/1
and HTTP/2 URIs will provide the same hash. See also the
"hash" option above.
url_param The URL parameter specified in argument will be looked up in
the query string of each HTTP GET request.
If the modifier "check_post" is used, then an HTTP POST
request entity will be searched for the parameter argument,
when it is not found in a query string after a question mark
('?') in the URL. The message body will only start to be
analyzed once either the advertised amount of data has been
received or the request buffer is full. In the unlikely event
that chunked encoding is used, only the first chunk is
scanned. Parameter values separated by a chunk boundary, may
be randomly balanced if at all. This keyword used to support
an optional <max_wait> parameter which is now ignored.
If the parameter is found followed by an equal sign ('=') and
a value, then the value is hashed and divided by the total
weight of the running servers. The result designates which
server will receive the request.
This is used to track user identifiers in requests and ensure
that a same user ID will always be sent to the same server as
long as no server goes up or down. If no value is found or if
the parameter is not found, then a round robin algorithm is
applied. Note that this algorithm may only be used in an HTTP
backend. This algorithm is static by default, which means
that changing a server's weight on the fly will have no
effect, but this can be changed using "hash-type". See also
the "hash" option above.
hdr(<name>) The HTTP header <name> will be looked up in each HTTP
request. Just as with the equivalent ACL 'hdr()' function,
the header name in parenthesis is not case sensitive. If the
header is absent or if it does not contain any value, the
roundrobin algorithm is applied instead.
An optional 'use_domain_only' parameter is available, for
reducing the hash algorithm to the main domain part with some
specific headers such as 'Host'. For instance, in the Host
value "haproxy.1wt.eu", only "1wt" will be considered.
This algorithm is static by default, which means that
changing a server's weight on the fly will have no effect,
but this can be changed using "hash-type". See also the
"hash" option above.
random
random(<draws>)
A random number will be used as the key for the consistent
hashing function. This means that the servers' weights are
respected, dynamic weight changes immediately take effect, as
well as new server additions. Random load balancing can be
useful with large farms or when servers are frequently added
or removed as it may avoid the hammering effect that could
result from roundrobin or leastconn in this situation. The
hash-balance-factor directive can be used to further improve
fairness of the load balancing, especially in situations
where servers show highly variable response times. When an
argument <draws> is present, it must be an integer value one
or greater, indicating the number of draws before selecting
the least loaded of these servers. It was indeed demonstrated
that picking the least loaded of two servers is enough to
significantly improve the fairness of the algorithm, by
always avoiding to pick the most loaded server within a farm
and getting rid of any bias that could be induced by the
unfair distribution of the consistent list. Higher values N
will take away N-1 of the highest loaded servers at the
expense of performance. With very high values, the algorithm
will converge towards the leastconn's result but much slower.
In addition, for large server farms with very low loads (or
perfect balance), comparing loads will often lead to a tie,
so in case of equal loads between all measured servers, their
request rate over the last second are compared, which allows
to better balance server usage over time in the same spirit
as roundrobin does, and smooth consistent hash unfairness.
The default value is 2, which generally shows very good
distribution and performance. For large farms with low loads
(less than a few requests per second per server), it may help
to raise it to 3 or even 4. This algorithm is also known as
the Power of Two Random Choices and is described here :
http://www.eecs.harvard.edu/~michaelm/postscripts/handbook2001.pdf
For backends in LOG mode, the number of draws is ignored and
a single random is picked since there is no notion of server
load. Random log balancing can be useful with large farms or
when servers are frequently added or removed from the pool of
available servers as it may avoid the hammering effect that
could result from roundrobin in this situation.
rdp-cookie
rdp-cookie(<name>)
The RDP cookie <name> (or "mstshash" if omitted) will be
looked up and hashed for each incoming TCP request. Just as
with the equivalent ACL 'req.rdp_cookie()' function, the name
is not case-sensitive. This mechanism is useful as a degraded
persistence mode, as it makes it possible to always send the
same user (or the same session ID) to the same server. If the
cookie is not found, the normal roundrobin algorithm is
used instead.
Note that for this to work, the frontend must ensure that an
RDP cookie is already present in the request buffer. For this
you must use 'tcp-request content accept' rule combined with
a 'req.rdp_cookie_cnt' ACL.
This algorithm is static by default, which means that
changing a server's weight on the fly will have no effect,
but this can be changed using "hash-type". See also the
"hash" option above.
log-hash Takes a comma-delimited list of converters in argument. These
converters are applied in sequence to the input log message,
and the result will be cast as a string then hashed according
to the configured hash-type. The resulting hash will be used
to select the destination server among the ones declared in
the log backend. The goal of this algorithm is to be able to
extract a key within the final log message using string
converters and then be able to stick to the same server thanks
to the hash. Only "map-based" hashes are supported for now.
This algorithm is only usable for backends in LOG mode, for
others, please use "hash" instead.
sticky Tries to stick to the same server as much as possible. The
first server in the list of available servers receives all
the log messages. When the server goes DOWN, the next server
in the list takes its place. When a previously DOWN server
goes back UP it is added at the end of the list so that the
sticky server doesn't change until it becomes DOWN.
<arguments> is an optional list of arguments which may be needed by some
algorithms. Right now, only "url_param", "uri" and "log-hash"
support an optional argument.
The load balancing algorithm of a backend is set to "random" when no other
algorithm, mode nor option have been set. The algorithm may only be set once
for each backend.
With authentication schemes that require the same connection like NTLM, URI
based algorithms must not be used, as they would cause subsequent requests
to be routed to different backend servers, breaking the invalid assumptions
NTLM relies on.
TCP/HTTP Examples :
balance roundrobin
balance url_param userid
balance url_param session_id check_post 64
balance hdr(User-Agent)
balance hdr(host)
balance hdr(Host) use_domain_only
balance hash req.cookie(clientid)
balance hash var(req.client_id)
balance hash req.hdr_ip(x-forwarded-for,-1),ipmask(24)
LOG backend examples:
global
log backend@mylog-rrb local0 # send all logs to mylog-rrb backend
log backend@mylog-hash local0 # send all logs to mylog-hash backend
backend mylog-rrb
mode log
balance roundrobin
server s1 udp@127.0.0.1:514 # will receive 50% of log messages
server s2 udp@127.0.0.1:514
backend mylog-hash
mode log
# extract "METHOD URL PROTO" at the end of the log message,
# and let haproxy hash it so that log messages generated from
# similar requests get sent to the same syslog server:
balance log-hash 'field(-2,\")'
# server list here
server s1 127.0.0.1:514
#...
Note: the following caveats and limitations on using the "check_post"
extension with "url_param" must be considered :
- all POST requests are eligible for consideration, because there is no way
to determine if the parameters will be found in the body or entity which
may contain binary data. Therefore another method may be required to
restrict consideration of POST requests that have no URL parameters in
the body. (see acl http_end)
- using a <max_wait> value larger than the request buffer size does not
make sense and is useless. The buffer size is set at build time, and
defaults to 16 kB.
- Content-Encoding is not supported, the parameter search will probably
fail; and load balancing will fall back to Round Robin.
- Expect: 100-continue is not supported, load balancing will fall back to
Round Robin.
- Transfer-Encoding (RFC7230 3.3.1) is only supported in the first chunk.
If the entire parameter value is not present in the first chunk, the
selection of server is undefined (actually, defined by how little
actually appeared in the first chunk).
- This feature does not support generation of a 100, 411 or 501 response.
- In some cases, requesting "check_post" MAY attempt to scan the entire
contents of a message body. Scanning normally terminates when linear
white space or control characters are found, indicating the end of what
might be a URL parameter list. This is probably not a concern with SGML
type message bodies.
Define one or several listening addresses and/or ports in a frontend. May be used in the following contexts: tcp, http
May be used in sections :
| defaults | frontend | listen | backend |
|---|---|---|---|
no![]() | yes![]() | yes![]() | no![]() |
<address> is optional and can be a host name, an IPv4 address, an IPv6
address, or '*'. It designates the address the frontend will
listen on. If unset, all IPv4 addresses of the system will be
listened on. The same will apply for '*' or the system's
special address "0.0.0.0". The IPv6 equivalent is '::'. Note
that for UDP, specific OS features are required when binding
on multiple addresses to ensure the correct network interface
and source address will be used on response. In other way,
for QUIC listeners only bind on multiple addresses if running
with a modern enough systems.
Optionally, an address family prefix may be used before the
address to force the family regardless of the address format,
which can be useful to specify a path to a unix socket with
no slash ('/'). Currently supported prefixes are :
- 'ipv4@' -> address is always IPv4
- 'ipv6@' -> address is always IPv6
- 'udp@' -> address is resolved as IPv4 or IPv6 and
protocol UDP is used. Currently those listeners are
supported only in log-forward sections.
- 'udp4@' -> address is always IPv4 and protocol UDP
is used. Currently those listeners are supported
only in log-forward sections.
- 'udp6@' -> address is always IPv6 and protocol UDP
is used. Currently those listeners are supported
only in log-forward sections.
- 'unix@' -> address is a path to a local unix socket
- 'abns@' -> address is in abstract namespace (Linux only).
- 'abnsz@' -> address is in abstract namespace (Linux only)
but it is explicitly zero-terminated. This means no \0
padding is used to complete sun_path. It is useful to
interconnect with programs that don't implement the
default abns naming logic that haproxy uses.
- 'fd@<n>' -> use file descriptor <n> inherited from the
parent. The fd must be bound and may or may not already
be listening.
- 'sockpair@<n>'-> like fd@ but you must use the fd of a
connected unix socket or of a socketpair. The bind waits
to receive a FD over the unix socket and uses it as if it
was the FD of an accept(). Should be used carefully.
- 'quic4@' -> address is resolved as IPv4 and protocol UDP
is used. Note that to achieve the best performance with a
large traffic you should keep "tune.quic.fe.sock-per-conn
default-on". Else QUIC connections will be multiplexed
over the listener socket. Another alternative would be to
duplicate QUIC listener instances over several threads,
for example using "shards" keyword to at least reduce
thread contention.
- 'quic6@' -> address is resolved as IPv6 and protocol UDP
is used. The performance note for QUIC over IPv4 applies
as well.
- 'rhttp@' [ EXPERIMENTAL ] -> used for reverse HTTP.
Address must be a server with the format
'<backend>/<server>'. The server will be used to
instantiate connections to a remote address. The listener
will try to maintain "nbconn" connections. This is an
experimental features which requires
"expose-experimental-directives" on a line before this
bind.
You may want to reference some environment variables in the
address parameter, see section 2.3 about environment
variables.
<port_range> is either a unique TCP port, or a port range for which the
proxy will accept connections for the IP address specified
above. The port is mandatory for TCP listeners. Note that in
the case of an IPv6 address, the port is always the number
after the last colon (':'). A range can either be :
- a numerical port (ex: '80')
- a dash-delimited ports range explicitly stating the lower
and upper bounds (ex: '2000-2100') which are included in
the range.
Particular care must be taken against port ranges, because
every <address:port> couple consumes one socket (= a file
descriptor), so it's easy to consume lots of descriptors
with a simple range, and to run out of sockets. Also, each
<address:port> couple must be used only once among all
instances running on a same system. Please note that binding
to ports lower than 1024 generally require particular
privileges to start the program, which are independent of
the 'uid' parameter.
<path> is a UNIX socket path beginning with a slash ('/'). This is
alternative to the TCP listening port. HAProxy will then
receive UNIX connections on the socket located at this place.
The path must begin with a slash and by default is absolute.
It can be relative to the prefix defined by "unix-bind" in
the global section. Note that the total length of the prefix
followed by the socket path cannot exceed some system limits
for UNIX sockets, which commonly are set to 107 characters.
<param*> is a list of parameters common to all sockets declared on the
same line. These numerous parameters depend on OS and build
options and have a complete section dedicated to them. Please
refer to section 5 to for more details.
It is possible to specify a list of address:port combinations delimited by
commas. The frontend will then listen on all of these addresses. There is no
fixed limit to the number of addresses and ports which can be listened on in
a frontend, as well as there is no limit to the number of "bind" statements
in a frontend.
listen http_proxy
bind :80,:443
bind 10.0.0.1:10080,10.0.0.1:10443
bind /var/run/ssl-frontend.sock user root mode 600 accept-proxy
listen http_https_proxy
bind :80
bind :443 ssl crt /etc/haproxy/site.pem
listen http_https_proxy_explicit
bind ipv6@:80
bind ipv4@public_ssl:443 ssl crt /etc/haproxy/site.pem
bind unix@ssl-frontend.sock user root mode 600 accept-proxy
listen external_bind_app1
bind "fd@${FD_APP1}"
listen h3_quic_proxy
bind quic4@10.0.0.1:8888 ssl crt /etc/mycrt
Note: regarding Linux's abstract namespace sockets, "abns" HAProxy sockets
uses the whole sun_path length is used for the address length. Some
other programs such as socat use the string length only by default.
Pass the option ",unix-tightsocklen=0" to any abstract socket
definition in socat to make it compatible with HAProxy's, or use the
"abnsz" HAProxy socket family instead.
Capture and log a cookie in the request and in the response. May be used in the following contexts: http
May be used in sections :
| defaults | frontend | listen | backend |
|---|---|---|---|
no![]() | yes![]() | yes![]() | no![]() |
<name> is the beginning of the name of the cookie to capture. In order
to match the exact name, simply suffix the name with an equal
sign ('='). The full name will appear in the logs, which is
useful with application servers which adjust both the cookie name
and value (e.g. ASPSESSIONXXX).
<length> is the maximum number of characters to report in the logs, which
include the cookie name, the equal sign and the value, all in the
standard "name=value" form. The string will be truncated on the
right if it exceeds <length>.
Only the first cookie is captured. Both the "cookie" request headers and the "set-cookie" response headers are monitored. This is particularly useful to check for application bugs causing session crossing or stealing between users, because generally the user's cookies can only change on a login page. When the cookie was not presented by the client, the associated log column will report "-". When a request does not cause a cookie to be assigned by the server, a "-" is reported in the response column. The capture is performed in the frontend only because it is necessary that the log format does not change for a given frontend depending on the backends. This may change in the future. Note that there can be only one "capture cookie" statement in a frontend. The maximum capture length is set by the global "tune.http.cookielen" setting and defaults to 63 characters. It is not possible to specify a capture in a "defaults" section.
capture cookie ASPSESSION len 32
Capture and log the last occurrence of the specified request header. May be used in the following contexts: http
May be used in sections :
| defaults | frontend | listen | backend |
|---|---|---|---|
no![]() | yes![]() | yes![]() | no![]() |
<name> is the name of the header to capture. The header names are not
case-sensitive, but it is a common practice to write them as they
appear in the requests, with the first letter of each word in
upper case. The header name will not appear in the logs, only the
value is reported, but the position in the logs is respected.
<length> is the maximum number of characters to extract from the value and
report in the logs. The string will be truncated on the right if
it exceeds <length>.
The complete value of the last occurrence of the header is captured. The
value will be added to the logs between braces ('{}'). If multiple headers
are captured, they will be delimited by a vertical bar ('|') and will appear
in the same order they were declared in the configuration. Non-existent
headers will be logged just as an empty string. Common uses for request
header captures include the "Host" field in virtual hosting environments, the
"Content-length" when uploads are supported, "User-agent" to quickly
differentiate between real users and robots, and "X-Forwarded-For" in proxied
environments to find where the request came from.
Note that when capturing headers such as "User-agent", some spaces may be
logged, making the log analysis more difficult. Thus be careful about what
you log if you know your log parser is not smart enough to rely on the
braces.
There is no limit to the number of captured request headers nor to their
length, though it is wise to keep them low to limit memory usage per stream.
In order to keep log format consistent for a same frontend, header captures
can only be declared in a frontend. It is not possible to specify a capture
in a "defaults" section.
capture request header Host len 15
capture request header X-Forwarded-For len 15
capture request header Referer len 15
Capture and log the last occurrence of the specified response header. May be used in the following contexts: http
May be used in sections :
| defaults | frontend | listen | backend |
|---|---|---|---|
no![]() | yes![]() | yes![]() | no![]() |
<name> is the name of the header to capture. The header names are not
case-sensitive, but it is a common practice to write them as they
appear in the response, with the first letter of each word in
upper case. The header name will not appear in the logs, only the
value is reported, but the position in the logs is respected.
<length> is the maximum number of characters to extract from the value and
report in the logs. The string will be truncated on the right if
it exceeds <length>.
The complete value of the last occurrence of the header is captured. The
result will be added to the logs between braces ('{}') after the captured
request headers. If multiple headers are captured, they will be delimited by
a vertical bar ('|') and will appear in the same order they were declared in
the configuration. Non-existent headers will be logged just as an empty
string. Common uses for response header captures include the "Content-length"
header which indicates how many bytes are expected to be returned, the
"Location" header to track redirections.
There is no limit to the number of captured response headers nor to their
length, though it is wise to keep them low to limit memory usage per stream.
In order to keep log format consistent for a same frontend, header captures
can only be declared in a frontend. It is not possible to specify a capture
in a "defaults" section.
capture response header Content-length len 9
capture response header Location len 15
Sets the maximum number of keepalive probes TCP should send before dropping the connection on the client side. May be used in the following contexts: tcp, http, log
May be used in sections :
| defaults | frontend | listen | backend |
|---|---|---|---|
yes![]() | yes![]() | yes![]() | no![]() |
<count> is the maximum number of keepalive probes.
This keyword corresponds to the socket option TCP_KEEPCNT. If this keyword is not specified, system-wide TCP parameter (tcp_keepalive_probes) is used. The availability of this setting depends on the operating system. It is known to work on Linux.
Sets the time the connection needs to remain idle before TCP starts sending keepalive probes, if enabled the sending of TCP keepalive packets on the client side. May be used in the following contexts: tcp, http
May be used in sections :
| defaults | frontend | listen | backend |
|---|---|---|---|
yes![]() | yes![]() | yes![]() | no![]() |
<timeout> is the time the connection needs to remain idle before TCP starts
sending keepalive probes. It is specified in seconds by default,
but can be in any other unit if the number is suffixed by the
unit, as explained at the top of this document.
This keyword corresponds to the socket option TCP_KEEPIDLE. If this keyword is not specified, system-wide TCP parameter (tcp_keepalive_time) is used. The availability of this setting depends on the operating system. It is known to work on Linux.
Sets the time between individual keepalive probes on the client side. May be used in the following contexts: tcp, http
May be used in sections :
| defaults | frontend | listen | backend |
|---|---|---|---|
yes![]() | yes![]() | yes![]() | no![]() |
<timeout> is the time between individual keepalive probes. It is specified
in seconds by default, but can be in any other unit if the number
is suffixed by the unit, as explained at the top of this
document.
This keyword corresponds to the socket option TCP_KEEPINTVL. If this keyword is not specified, system-wide TCP parameter (tcp_keepalive_intvl) is used. The availability of this setting depends on the operating system. It is known to work on Linux.
Enable HTTP compression. May be used in the following contexts: http
May be used in sections :
| defaults | frontend | listen | backend |
|---|---|---|---|
yes![]() | yes![]() | yes![]() | yes![]() |
algo is followed by the list of supported compression algorithms for
responses (legacy keyword)
algo-req is followed by compression algorithm for request (only one is
provided).
algo-res is followed by the list of supported compression algorithms for
responses.
type is followed by the list of MIME types that will be compressed for
responses (legacy keyword).
type-req is followed by the list of MIME types that will be compressed for
requests.
type-res is followed by the list of MIME types that will be compressed for
responses.
The currently supported algorithms are :
identity this is mostly for debugging, and it was useful for developing
the compression feature. Identity does not apply any change on
data.
gzip applies gzip compression. This setting is only available when
support for zlib or libslz was built in.
deflate same as "gzip", but with deflate algorithm and zlib format.
Note that this algorithm has ambiguous support on many
browsers and no support at all from recent ones. It is
strongly recommended not to use it for anything else than
experimentation. This setting is only available when support
for zlib or libslz was built in.
raw-deflate same as "deflate" without the zlib wrapper, and used as an
alternative when the browser wants "deflate". All major
browsers understand it and despite violating the standards,
it is known to work better than "deflate", at least on MSIE
and some versions of Safari. Do not use it in conjunction
with "deflate", use either one or the other since both react
to the same Accept-Encoding token. This setting is only
available when support for zlib or libslz was built in.
Compression will be activated depending on the Accept-Encoding request
header. With identity, it does not take care of that header.
If backend servers support HTTP compression, these directives
will be no-op: HAProxy will see the compressed response and will not
compress again. If backend servers do not support HTTP compression and
there is Accept-Encoding header in request, HAProxy will compress the
matching response.
Compression is disabled when:
* the request does not advertise a supported compression algorithm in the
"Accept-Encoding" header
* the response message is not HTTP/1.1 or above
* HTTP status code is not one of 200, 201, 202, or 203
* response contain neither a "Content-Length" header nor a
"Transfer-Encoding" whose last value is "chunked"
* response contains a "Content-Type" header whose first value starts with
"multipart"
* the response contains the "no-transform" value in the "Cache-control"
header
* User-Agent matches "Mozilla/4" unless it is MSIE 6 with XP SP2, or MSIE 7
and later
* The response contains a "Content-Encoding" header, indicating that the
response is already compressed (see compression offload)
* The response contains an invalid "ETag" header or multiple ETag headers
* The payload size is smaller than the minimum size
(see compression minsize-res)
Note: The compression does not emit the Warning header.
compression algo gzip
compression type text/html text/plain
Sets the minimum payload size in bytes for compression to be applied. May be used in the following contexts: http
May be used in sections :
| defaults | frontend | listen | backend |
|---|---|---|---|
yes![]() | yes![]() | yes![]() | yes![]() |
Payloads smaller than this size will not be compressed, avoiding unnecessary CPU overhead for data that would not significantly benefit from compression. "minsize-req" applies on requests and "minsize-res" on responses. The default value is 0.
Makes HAProxy work as a compression offloader only. May be used in the following contexts: http
May be used in sections :
| defaults | frontend | listen | backend |
|---|---|---|---|
no![]() | yes![]() | yes![]() | yes![]() |
The "offload" setting makes HAProxy remove the Accept-Encoding header to prevent backend servers from compressing responses. It is strongly recommended not to do this because this means that all the compression work will be done on the single point where HAProxy is located. However in some deployment scenarios, HAProxy may be installed in front of a buggy gateway with broken HTTP compression implementation which can't be turned off. In that case HAProxy can be used to prevent that gateway from emitting invalid payloads. In this case, simply removing the header in the configuration does not work because it applies before the header is parsed, so that prevents HAProxy from compressing. The "offload" setting should then be used for such scenarios. If this setting is used in a defaults section, a warning is emitted and the option is ignored.
Makes haproxy able to compress both requests and responses. Valid values are "request", to compress only requests, "response", to compress only responses, or "both", when you want to compress both. The default value is "response". This directive is only relevant when legacy "filter compression" was enabled, as with explicit comp-req and comp-res filters compression direction is redundant. May be used in the following contexts: http
Enable cookie-based persistence in a backend. May be used in the following contexts: http
May be used in sections :
| defaults | frontend | listen | backend |
|---|---|---|---|
yes![]() | no![]() | yes![]() | yes![]() |
<name> is the name of the cookie which will be monitored, modified or
inserted in order to bring persistence. This cookie is sent to
the client via a "Set-Cookie" header in the response, and is
brought back by the client in a "Cookie" header in all requests.
Special care should be taken to choose a name which does not
conflict with any likely application cookie. Also, if the same
backends are subject to be used by the same clients (e.g.
HTTP/HTTPS), care should be taken to use different cookie names
between all backends if persistence between them is not desired.
rewrite This keyword indicates that the cookie will be provided by the
server and that HAProxy will have to modify its value to set the
server's identifier in it. This mode is handy when the management
of complex combinations of "Set-cookie" and "Cache-control"
headers is left to the application. The application can then
decide whether or not it is appropriate to emit a persistence
cookie. Since all responses should be monitored, this mode
doesn't work in HTTP tunnel mode. Unless the application
behavior is very complex and/or broken, it is advised not to
start with this mode for new deployments. This keyword is
incompatible with "insert" and "prefix".
insert This keyword indicates that the persistence cookie will have to
be inserted by HAProxy in server responses if the client did not
already have a cookie that would have permitted it to access this
server. When used without the "preserve" option, if the server
emits a cookie with the same name, it will be removed before
processing. For this reason, this mode can be used to upgrade
existing configurations running in the "rewrite" mode. The cookie
will only be a session cookie and will not be stored on the
client's disk. By default, unless the "indirect" option is added,
the server will see the cookies emitted by the client. Due to
caching effects, it is generally wise to add the "nocache" or
"postonly" keywords (see below). The "insert" keyword is not
compatible with "rewrite" and "prefix".
prefix This keyword indicates that instead of relying on a dedicated
cookie for the persistence, an existing one will be completed.
This may be needed in some specific environments where the client
does not support more than one single cookie and the application
already needs it. In this case, whenever the server sets a cookie
named <name>, it will be prefixed with the server's identifier
and a delimiter. The prefix will be removed from all client
requests so that the server still finds the cookie it emitted.
Since all requests and responses are subject to being modified,
this mode doesn't work with tunnel mode. The "prefix" keyword is
not compatible with "rewrite" and "insert". Note: it is highly
recommended not to use "indirect" with "prefix", otherwise server
cookie updates would not be sent to clients.
indirect When this option is specified, no cookie will be emitted to a
client which already has a valid one for the server which has
processed the request. If the server sets such a cookie itself,
it will be removed, unless the "preserve" option is also set. In
"insert" mode, this will additionally remove cookies from the
requests transmitted to the server, making the persistence
mechanism totally transparent from an application point of view.
Note: it is highly recommended not to use "indirect" with
"prefix", otherwise server cookie updates would not be sent to
clients.
nocache This option is recommended in conjunction with the insert mode
when there is a cache between the client and HAProxy, as it
ensures that a cacheable response will be tagged non-cacheable if
a cookie needs to be inserted. This is important because if all
persistence cookies are added on a cacheable home page for
instance, then all customers will then fetch the page from an
outer cache and will all share the same persistence cookie,
leading to one server receiving much more traffic than others.
See also the "insert" and "postonly" options.
postonly This option ensures that cookie insertion will only be performed
on responses to POST requests. It is an alternative to the
"nocache" option, because POST responses are not cacheable, so
this ensures that the persistence cookie will never get cached.
Since most sites do not need any sort of persistence before the
first POST which generally is a login request, this is a very
efficient method to optimize caching without risking to find a
persistence cookie in the cache.
See also the "insert" and "nocache" options.
preserve This option may only be used with "insert" and/or "indirect". It
allows the server to emit the persistence cookie itself. In this
case, if a cookie is found in the response, HAProxy will leave it
untouched. This is useful in order to end persistence after a
logout request for instance. For this, the server just has to
emit a cookie with an invalid value (e.g. empty) or with a date in
the past. By combining this mechanism with the "disable-on-404"
check option, it is possible to perform a completely graceful
shutdown because users will definitely leave the server after
they logout.
httponly This option tells HAProxy to add an "HttpOnly" cookie attribute
when a cookie is inserted. This attribute is used so that a
user agent doesn't share the cookie with non-HTTP components.
Please check RFC6265 for more information on this attribute.
secure This option tells HAProxy to add a "Secure" cookie attribute when
a cookie is inserted. This attribute is used so that a user agent
never emits this cookie over non-secure channels, which means
that a cookie learned with this flag will be presented only over
SSL/TLS connections. Please check RFC6265 for more information on
this attribute.
domain This option allows to specify the domain at which a cookie is
inserted. It requires exactly one parameter: a valid domain
name. If the domain begins with a dot, the browser is allowed to
use it for any host ending with that name. It is also possible to
specify several domain names by invoking this option multiple
times. Some browsers might have small limits on the number of
domains, so be careful when doing that. For the record, sending
10 domains to MSIE 6 or Firefox 2 works as expected.
maxidle This option allows inserted cookies to be ignored after some idle
time. It only works with insert-mode cookies. When a cookie is
sent to the client, the date this cookie was emitted is sent too.
Upon further presentations of this cookie, if the date is older
than the delay indicated by the parameter (in seconds), it will
be ignored. Otherwise, it will be refreshed if needed when the
response is sent to the client. This is particularly useful to
prevent users who never close their browsers from remaining for
too long on the same server (e.g. after a farm size change). When
this option is set and a cookie has no date, it is always
accepted, but gets refreshed in the response. This maintains the
ability for admins to access their sites. Cookies that have a
date in the future further than 24 hours are ignored. Doing so
lets admins fix timezone issues without risking kicking users off
the site.
maxlife This option allows inserted cookies to be ignored after some life
time, whether they're in use or not. It only works with insert
mode cookies. When a cookie is first sent to the client, the date
this cookie was emitted is sent too. Upon further presentations
of this cookie, if the date is older than the delay indicated by
the parameter (in seconds), it will be ignored. If the cookie in
the request has no date, it is accepted and a date will be set.
Cookies that have a date in the future further than 24 hours are
ignored. Doing so lets admins fix timezone issues without risking
kicking users off the site. Contrary to maxidle, this value is
not refreshed, only the first visit date counts. Both maxidle and
maxlife may be used at the time. This is particularly useful to
prevent users who never close their browsers from remaining for
too long on the same server (e.g. after a farm size change). This
is stronger than the maxidle method in that it forces a
redispatch after some absolute delay.
dynamic Activate dynamic cookies. When used, a session cookie is
dynamically created for each server, based on the IP and port
of the server, and a secret key, specified in the
"dynamic-cookie-key" backend directive.
The cookie will be regenerated each time the IP address change,
and is only generated for IPv4/IPv6.
attr This option tells HAProxy to add an extra attribute when a
cookie is inserted. The attribute value can contain any
characters except control ones or ";". This option may be
repeated.
There can be only one persistence cookie per HTTP backend, and it can be declared in a defaults section. The value of the cookie will be the value indicated after the "cookie" keyword in a "server" statement. If no cookie is declared for a given server, the cookie is not set.
cookie JSESSIONID prefix
cookie SRV insert indirect nocache
cookie SRV insert postonly indirect
cookie SRV insert indirect nocache maxidle 30m maxlife 8h
Declares a capture slot. May be used in the following contexts: tcp, http
May be used in sections :
| defaults | frontend | listen | backend |
|---|---|---|---|
no![]() | yes![]() | yes![]() | no![]() |
<length> is the length allowed for the capture.
This declaration is only available in the frontend or listen section, but the reserved slot can be used in the backends. The "request" keyword allocates a capture slot for use in the request, and "response" allocates a capture slot for use in the response.
Change default options for a server in a backend May be used in the following contexts: tcp, http
May be used in sections :
| defaults | frontend | listen | backend |
|---|---|---|---|
yes![]() | no![]() | yes![]() | yes![]() |
<param*> is a list of parameters for this server. The "default-server" keyword accepts an important number of options and has a complete section dedicated to it. Please refer to section 5 for more details.
default-server inter 1000 weight 13
Specify the backend to use when no "use_backend" rule has been matched. May be used in the following contexts: tcp, http
May be used in sections :
| defaults | frontend | listen | backend |
|---|---|---|---|
yes![]() | yes![]() | yes![]() | no![]() |
<backend> is the name of the backend to use.
When doing content-switching between frontend and backends using the "use_backend" keyword, it is often useful to indicate which backend will be used when no rule has matched. It generally is the dynamic backend which will catch all undetermined requests. If a backend is disabled or unpublished, default_backend rules targeting it will be ignored and stream processing will remain on the original proxy.
use_backend dynamic if url_dyn
use_backend static if url_css url_img extension_img
default_backend dynamic
Describe a listen, frontend or backend. May be used in the following contexts: tcp, http, log
May be used in sections :
| defaults | frontend | listen | backend |
|---|---|---|---|
no![]() | yes![]() | yes![]() | yes![]() |
Allows to add a sentence to describe the related object in the HAProxy HTML stats page. The description will be printed on the right of the object name it describes. No need to backslash spaces in the <string> arguments.
Disable a proxy, frontend or backend. May be used in the following contexts: tcp, http, log
May be used in sections :
| defaults | frontend | listen | backend |
|---|---|---|---|
yes![]() | yes![]() | yes![]() | yes![]() |
The "disabled" keyword is used to disable an instance, mainly in order to liberate a listening port or to temporarily disable a service. The instance will still be created and its configuration will be checked, but it will be created in the "stopped" state and will appear as such in the statistics. It will not receive any traffic nor will it send any health-checks or logs. It is possible to disable many instances at once by adding the "disabled" keyword in a "defaults" section. By default, a disabled backend cannot be selected for content-switching. However, a portion of the traffic can ignore this when "force-be-switch" is used.
Set a default server address May be used in the following contexts: tcp, http
May be used in sections :
| defaults | frontend | listen | backend |
|---|---|---|---|
no![]() | no![]() | yes![]() | yes![]() |
<address> is the IPv4 address of the default server. Alternatively, a
resolvable hostname is supported, but this name will be resolved
during start-up.
<ports> is a mandatory port specification. All connections will be sent
to this port, and it is not permitted to use port offsets as is
possible with normal servers.
The "dispatch" keyword designates a default server for use when no other server can take the connection. In the past it was used to forward non persistent connections to an auxiliary load balancer. Due to its simple syntax, it has also been used for simple TCP relays. It is recommended not to use it for more clarity, and to use the "server" directive instead. This keyword has been deprecated in 3.3 and will be removed in 3.5 due to some internal limitations (no support for SSL nor idle connections etc). Using it will emit a warning that may be silenced by enabling directive "expose-deprecated-directives" in the global section. The correct way to proceed without this directive is to simply declare a server with the same address and port. If the "dispatch" directive was mixed with other servers, then these servers should be configured with a weight of zero in order never to be elected by the load balancing algorithm.
backend deprecated_setup
dispatch 192.168.100.100:80 # external load balancer's address
server s1 192.168.100.1:80 cookie S1 check
server s2 192.168.100.2:80 cookie S2 check
backend modern_setup
server external_lb 192.168.100.100:80
server s1 192.168.100.1:80 cookie S1 check weight 0
server s2 192.168.100.2:80 cookie S2 check weight 0
Set the dynamic cookie secret key for a backend. May be used in the following contexts: http
May be used in sections :
| defaults | frontend | listen | backend |
|---|---|---|---|
yes![]() | no![]() | yes![]() | yes![]() |
When dynamic cookies are enabled (see the "dynamic" directive for cookie),
a dynamic cookie is created for each server (unless one is explicitly
specified on the "server" line), using a hash of the IP address of the
server, the TCP port, and the secret key.
That way, we can ensure session persistence across multiple load-balancers,
even if servers are dynamically added or removed.
Enable a proxy, frontend or backend. May be used in the following contexts: tcp, http, log
May be used in sections :
| defaults | frontend | listen | backend |
|---|---|---|---|
yes![]() | yes![]() | yes![]() | yes![]() |
The "enabled" keyword is used to explicitly enable an instance, when the defaults has been set to "disabled". This is very rarely used.
Return a file contents instead of errors generated by HAProxy May be used in the following contexts: http
May be used in sections :
| defaults | frontend | listen | backend |
|---|---|---|---|
yes![]() | yes![]() | yes![]() | yes![]() |
<code> is the HTTP status code. Currently, HAProxy is capable of
generating codes 200, 400, 401, 403, 404, 405, 407, 408, 410,
413, 414, 425, 429, 431, 500, 501, 502, 503, and 504.
<file> designates a file containing the full HTTP response. It is
recommended to follow the common practice of appending ".http" to
the filename so that people do not confuse the response with HTML
error pages, and to use absolute paths, since files are read
before any chroot is performed.
It is important to understand that this keyword is not meant to rewrite errors returned by the server, but errors detected and returned by HAProxy. This is why the list of supported errors is limited to a small set. Code 200 is emitted in response to requests matching a "monitor-uri" rule. The files are parsed when HAProxy starts and must be valid according to the HTTP specification. They should not exceed the configured buffer size (BUFSIZE), which generally is 16 kB, otherwise an internal error will be returned. It is also wise not to put any reference to local contents (e.g. images) in order to avoid loops between the client and HAProxy when all servers are down, causing an error to be returned instead of an image. Finally, The response cannot exceed (tune.bufsize - tune.maxrewrite) so that "http-after-response" rules still have room to operate (see "tune.maxrewrite"). The files are read at the same time as the configuration and kept in memory. For this reason, the errors continue to be returned even when the process is chrooted, and no file change is considered while the process is running. A simple method for developing those files consists in associating them to the 403 status code and interrogating a blocked URL.
errorfile 400 /etc/haproxy/errorfiles/400badreq.http
errorfile 408 /dev/null # work around Chrome pre-connect bug
errorfile 403 /etc/haproxy/errorfiles/403forbid.http
errorfile 503 /etc/haproxy/errorfiles/503sorry.http
Import, fully or partially, the error files defined in the <name> http-errors section. May be used in the following contexts: http
May be used in sections :
| defaults | frontend | listen | backend |
|---|---|---|---|
yes![]() | yes![]() | yes![]() | yes![]() |
<name> is the name of an existing http-errors section.
<code> is a HTTP status code. Several status code may be listed.
Currently, HAProxy is capable of generating codes 200, 400, 401,
403, 404, 405, 407, 408, 410, 413, 414, 425, 429, 431, 500, 501,
502, 503, and 504.
Errors defined in the http-errors section with the name <name> are imported
in the current proxy. If no status code is specified, all error files of the
http-errors section are imported. Otherwise, only error files associated to
the listed status code are imported. Those error files override the already
defined custom errors for the proxy. And they may be overridden by following
ones. Functionally, it is exactly the same as declaring all error files by
hand using "errorfile" directives.
errorfiles generic
errorfiles site-1 403 404
Return an HTTP redirection to a URL instead of errors generated by HAProxy May be used in the following contexts: http
May be used in sections :
| defaults | frontend | listen | backend |
|---|---|---|---|
yes![]() | yes![]() | yes![]() | yes![]() |
<code> is the HTTP status code. Currently, HAProxy is capable of
generating codes 200, 400, 401, 403, 404, 405, 407, 408, 410,
413, 414, 425, 429, 431, 500, 501, 502, 503, and 504.
<url> it is the exact contents of the "Location" header. It may contain
either a relative URI to an error page hosted on the same site,
or an absolute URI designating an error page on another site.
Special care should be given to relative URIs to avoid redirect
loops if the URI itself may generate the same error (e.g. 500).
It is important to understand that this keyword is not meant to rewrite errors returned by the server, but errors detected and returned by HAProxy. This is why the list of supported errors is limited to a small set. Code 200 is emitted in response to requests matching a "monitor-uri" rule. Note that both keyword return the HTTP 302 status code, which tells the client to fetch the designated URL using the same HTTP method. This can be quite problematic in case of non-GET methods such as POST, because the URL sent to the client might not be allowed for something other than GET. To work around this problem, please use "errorloc303" which send the HTTP 303 status code, indicating to the client that the URL must be fetched with a GET request.
Return an HTTP redirection to a URL instead of errors generated by HAProxy May be used in the following contexts: http
May be used in sections :
| defaults | frontend | listen | backend |
|---|---|---|---|
yes![]() | yes![]() | yes![]() | yes![]() |
<code> is the HTTP status code. Currently, HAProxy is capable of
generating codes 200, 400, 401, 403, 404, 405, 407, 408, 410,
413, 414, 425, 429, 431, 500, 501, 502, 503, and 504.
<url> it is the exact contents of the "Location" header. It may contain
either a relative URI to an error page hosted on the same site,
or an absolute URI designating an error page on another site.
Special care should be given to relative URIs to avoid redirect
loops if the URI itself may generate the same error (e.g. 500).
It is important to understand that this keyword is not meant to rewrite errors returned by the server, but errors detected and returned by HAProxy. This is why the list of supported errors is limited to a small set. Code 200 is emitted in response to requests matching a "monitor-uri" rule. Note that both keyword return the HTTP 303 status code, which tells the client to fetch the designated URL using the same HTTP GET method. This solves the usual problems associated with "errorloc" and the 302 code. It is possible that some very old browsers designed before HTTP/1.1 do not support it, but no such problem has been reported till now.
Declare the from email address to be used in both the envelope and header of email alerts. This is the address that email alerts are sent from. May be used in the following contexts: tcp, http, log
May be used in sections :
| defaults | frontend | listen | backend |
|---|---|---|---|
yes![]() | yes![]() | yes![]() | yes![]() |
<emailaddr> is the from email address to use when sending email alerts
Also requires "email-alert mailers" and "email-alert to" to be set and if so sending email alerts is enabled for the proxy.
Declare the maximum log level of messages for which email alerts will be sent. This acts as a filter on the sending of email alerts. May be used in the following contexts: tcp, http, log
May be used in sections :
| defaults | frontend | listen | backend |
|---|---|---|---|
yes![]() | yes![]() | yes![]() | yes![]() |
<level> One of the 8 syslog levels:
emerg alert crit err warning notice info debug
The above syslog levels are ordered from lowest to highest.
By default level is alert Also requires "email-alert from", "email-alert mailers" and "email-alert to" to be set and if so sending email alerts is enabled for the proxy. Alerts are sent when : * An un-paused server is marked as down and <level> is alert or lower * A paused server is marked as down and <level> is notice or lower * A server is marked as up or enters the drain state and <level> is notice or lower * "option log-health-checks" is enabled, <level> is info or lower, and a health check status update occurs
Declare the mailers to be used when sending email alerts May be used in the following contexts: tcp, http, log
May be used in sections :
| defaults | frontend | listen | backend |
|---|---|---|---|
yes![]() | yes![]() | yes![]() | yes![]() |
<mailersect> is the name of the mailers section to send email alerts.
Also requires "email-alert from" and "email-alert to" to be set and if so sending email alerts is enabled for the proxy.
Declare the to hostname address to be used when communicating with mailers. May be used in the following contexts: tcp, http, log
May be used in sections :
| defaults | frontend | listen | backend |
|---|---|---|---|
yes![]() | yes![]() | yes![]() | yes![]() |
<hostname> is the hostname to use when communicating with mailers
By default the systems hostname is used. Also requires "email-alert from", "email-alert mailers" and "email-alert to" to be set and if so sending email alerts is enabled for the proxy.
Declare both the recipient address in the envelope and to address in the header of email alerts. This is the address that email alerts are sent to. May be used in the following contexts: tcp, http, log
May be used in sections :
| defaults | frontend | listen | backend |
|---|---|---|---|
yes![]() | yes![]() | yes![]() | yes![]() |
<emailaddr> is the to email address to use when sending email alerts
Also requires "email-alert mailers" and "email-alert to" to be set and if so sending email alerts is enabled for the proxy.
Specifies the log format string to use in case of connection error on the frontend side. May be used in the following contexts: tcp, http
May be used in sections :
| defaults | frontend | listen | backend |
|---|---|---|---|
yes![]() | yes![]() | yes![]() | no![]() |
This directive specifies the log format string that will be used for logs containing information related to errors, timeouts, retries redispatches or HTTP status code 5xx. This format will in short be used for every log line that would be concerned by the "log-separate-errors" option, including connection errors described in section 8.2.5. If the directive is used in a defaults section, all subsequent frontends will use the same log format. Please see section 8.2.6 which covers the custom log format string in depth. "error-log-format" directive overrides previous "error-log-format" directives.
Declare a condition to force persistence on down servers May be used in the following contexts: tcp, http
May be used in sections :
| defaults | frontend | listen | backend |
|---|---|---|---|
no![]() | no![]() | yes![]() | yes![]() |
By default, requests are not dispatched to down servers. It is possible to force this using "option persist", but it is unconditional and redispatches to a valid server if "option redispatch" is set. That leaves with very little possibilities to force some requests to reach a server which is artificially marked down for maintenance operations. The "force-persist" statement allows one to declare various ACL-based conditions which, when met, will cause a request to ignore the down status of a server and still try to connect to it. That makes it possible to start a server, still replying an error to the health checks, and run a specially configured browser to test the service. Among the handy methods, one could use a specific source IP address, or a specific cookie. The cookie also has the advantage that it can easily be added/removed on the browser from a test page. Once the service is validated, it is then possible to open the service to the world by returning a valid response to health checks. The forced persistence is enabled when an "if" condition is met, or unless an "unless" condition is met. The final redispatch is always disabled when this is used.
Executable to run when performing an external-check May be used in the following contexts: tcp, http, log
May be used in sections :
| defaults | frontend | listen | backend |
|---|---|---|---|
yes![]() | no![]() | yes![]() | yes![]() |
<command> is the external command to run
The arguments passed to the command are:
<proxy_address> <proxy_port> <server_address> <server_port>
The <proxy_address> and <proxy_port> are derived from the first listener
that is either IPv4, IPv6 or a UNIX socket. In the case of a UNIX socket
listener the proxy_address will be the path of the socket and the
<proxy_port> will be the string "NOT_USED". In a backend section, it's not
possible to determine a listener, and both <proxy_address> and <proxy_port>
will have the string value "NOT_USED".
Some values are also provided through environment variables.
Environment variables :
HAPROXY_PROXY_ADDR The first bind address if available (or empty if not
applicable, for example in a "backend" section).
HAPROXY_PROXY_ID The backend id.
HAPROXY_PROXY_NAME The backend name.
HAPROXY_PROXY_PORT The first bind port if available (or empty if not
applicable, for example in a "backend" section or
for a UNIX socket).
HAPROXY_SERVER_ADDR The server address.
HAPROXY_SERVER_CURCONN The current number of connections on the server.
HAPROXY_SERVER_ID The server id.
HAPROXY_SERVER_MAXCONN The server max connections.
HAPROXY_SERVER_NAME The server name.
HAPROXY_SERVER_PORT The server port if available (or empty for a UNIX
socket).
HAPROXY_SERVER_SSL "0" when SSL is not used, "1" when it is used
HAPROXY_SERVER_PROTO The protocol used by this server, which can be one
of "cli" (the haproxy CLI), "syslog" (syslog TCP
server), "peers" (peers TCP server), "h1" (HTTP/1.x
server), "h2" (HTTP/2 server), or "tcp" (any other
TCP server).
PATH The PATH environment variable used when executing
the command may be set using "external-check path".
If the command executed and exits with a zero status then the check is
considered to have passed, otherwise the check is considered to have
failed.
external-check command /bin/true
The value of the PATH environment variable used when running an external-check May be used in the following contexts: tcp, http, log
May be used in sections :
| defaults | frontend | listen | backend |
|---|---|---|---|
yes![]() | no![]() | yes![]() | yes![]() |
<path> is the path used when executing external command to run
The default path is "".
external-check path "/usr/bin:/bin"
Allow content switching to select a backend instance even if it is disabled or unpublished. This rule can be used by admins to test traffic to services prior to expose them to the outside world. May be used in the following contexts: tcp, http
May be used in sections :
| defaults | frontend | listen | backend |
|---|---|---|---|
no![]() | yes![]() | yes![]() | no![]() |
Add the filter <name> in the filter list attached to the proxy. May be used in the following contexts: tcp, http
May be used in sections :
| defaults | frontend | listen | backend |
|---|---|---|---|
no![]() | yes![]() | yes![]() | yes![]() |
<name> is the name of the filter. Officially supported filters are
referenced in section 9.
<param*> is a list of parameters accepted by the filter <name>. The
parsing of these parameters are the responsibility of the
filter. Please refer to the documentation of the corresponding
filter (section 9) for all details on the supported parameters.
Multiple occurrences of the filter line can be used for the same proxy. The same filter can be referenced many times if needed.
listen
bind *:80
filter trace name BEFORE-HTTP-COMP
filter compression
filter trace name AFTER-HTTP-COMP
compression algo gzip
compression offload
server srv1 192.168.0.1:80
Specifies in which order filters declared on the proxy should be executed. May be used in the following contexts: tcp, http
May be used in sections :
| defaults | frontend | listen | backend |
|---|---|---|---|
no![]() | yes![]() | yes![]() | yes![]() |
Comma-separated list of filter names (<filter_list>) to specify in which order filters declared on the proxy should be executed, for request or response path, respectively. When filter-sequence is not specified for a given path (ie: request vs response), the order in which filters are declared on the proxy is used. If filter-sequence omits some filters that were declared on the proxy, they will not be executed. This is an effective way of temporarily disabling a filter without removing it from the configuration.
global
lua-load my-filter.lua # defines custom "lua.my-filter"
frontend myfront
filter comp-req
filter comp-res
filter lua.my-filter
filter-sequence request lua.my-filter,comp-req
filter-sequence response lua.my-filter,comp-res
Specify at what backend load the servers will reach their maxconn May be used in the following contexts: tcp, http
May be used in sections :
| defaults | frontend | listen | backend |
|---|---|---|---|
yes![]() | no![]() | yes![]() | yes![]() |
<conns> is the number of connections on the backend which will make the
servers use the maximal number of connections.
When a server has a "maxconn" parameter specified, it means that its number of concurrent connections will never go higher. Additionally, if it has a "minconn" parameter, it indicates a dynamic limit following the backend's load. The server will then always accept at least <minconn> connections, never more than <maxconn>, and the limit will be on the ramp between both values when the backend has less than <conns> concurrent connections. This makes it possible to limit the load on the servers during normal loads, but push it further for important loads without overloading the servers during exceptional loads. Since it's hard to get this value right, HAProxy automatically sets it to 10% of the sum of the maxconns of all frontends that may branch to this backend (based on "use_backend" and "default_backend" rules). That way it's safe to leave it unset. However, "use_backend" involving dynamic names are not counted since there is no way to know if they could match or not.
# The servers will accept between 100 and 1000 concurrent connections each
# and the maximum of 1000 will be reached when the backend reaches 10000
# connections.
backend dynamic
fullconn 10000
server srv1 dyn1:80 minconn 100 maxconn 1000
server srv2 dyn2:80 minconn 100 maxconn 1000
Specify a case-sensitive global unique ID for this proxy. May be used in the following contexts: tcp, http, log
May be used in sections :
| defaults | frontend | listen | backend |
|---|---|---|---|
no![]() | yes![]() | yes![]() | yes![]() |
<string> must be unique across all haproxy configuration on every object types. Format is left unspecified to allow the user to select its naming policy. The only restriction is its length which cannot be greater than 127 characters. All alphanumerical values and '.', ':', '-' and '_' characters are valid. See also "shm-stats-file".
Specify the balancing factor for bounded-load consistent hashing May be used in the following contexts: tcp, http
May be used in sections :
| defaults | frontend | listen | backend |
|---|---|---|---|
yes![]() | no![]() | no![]() | yes![]() |
<factor> is the control for the maximum number of concurrent requests to
send to a server, expressed as a percentage of the average number
of concurrent requests across all of the active servers.
Specifying a "hash-balance-factor" for a server with "hash-type consistent" enables an algorithm that prevents any one server from getting too many requests at once, even if some hash buckets receive many more requests than others. Setting <factor> to 0 (the default) disables the feature. Otherwise, <factor> is a percentage greater than 100. For example, if <factor> is 150, then no server will be allowed to have a load more than 1.5 times the average. If server weights are used, they will be respected. If the first-choice server is disqualified, the algorithm will choose another server based on the request hash, until a server with additional capacity is found. A higher <factor> allows more imbalance between the servers, while a lower <factor> means that more servers will be checked on average, affecting performance. Reasonable values are from 125 to 200. This setting is also used by "balance random" which internally relies on the consistent hashing mechanism.
Specify a method for assigning streams to servers with hash load balancing when servers are satured or have a full queue. May be used in the following contexts: http
May be used in sections :
| defaults | frontend | listen | backend |
|---|---|---|---|
yes![]() | no![]() | yes![]() | yes![]() |
The following values can be specified:
- "always" : this is the default strategy. A stream is assigned to a
server based on hashing irrespective of whether the server
is currently saturated.
- "maxconn" : when selected, servers that have "maxconn" set and are
currently saturated will be skipped. Another server will be
picked by following the hashing ring. This has no effect on
servers that do not set "maxconn". If all servers are
saturated, the request is enqueued to the last server in the
hash ring before the initially selected server.
- "maxqueue" : when selected, servers that have "maxconn" set, "maxqueue"
set to a non-zero value (limited queue size) and currently
have a full queue will be skipped. Another server will be
picked by following the hashing ring. This has no effect on
servers that do not set both "maxconn" and "maxqueue".
Specify a method to use for mapping hashes to servers May be used in the following contexts: tcp, http, log
May be used in sections :
| defaults | frontend | listen | backend |
|---|---|---|---|
yes![]() | no![]() | yes![]() | yes![]() |
<method> is the method used to select a server from the hash computed by
the <function> :
map-based the hash table is a static array containing all alive servers.
The hashes will be very smooth, will consider weights, but
will be static in that weight changes while a server is up
will be ignored. This means that there will be no slow start.
Also, since a server is selected by its position in the array,
most mappings are changed when the server count changes. This
means that when a server goes up or down, or when a server is
added to a farm, most connections will be redistributed to
different servers. This can be inconvenient with caches for
instance.
consistent the hash table is a tree filled with many occurrences of each
server. The hash key is looked up in the tree and the closest
server is chosen. This hash is dynamic, it supports changing
weights while the servers are up, so it is compatible with the
slow start feature. It has the advantage that when a server
goes up or down, only its associations are moved. When a
server is added to the farm, only a few part of the mappings
are redistributed, making it an ideal method for caches.
However, due to its principle, the distribution will never be
very smooth and it may sometimes be necessary to adjust a
server's weight or its ID to get a more balanced distribution.
In order to get the same distribution on multiple load
balancers, it is important that all servers have the exact
same IDs. Note: consistent hash uses sdbm and avalanche if no
hash function is specified.
<function> is the hash function to be used :
sdbm this function was created initially for sdbm (a public-domain
reimplementation of ndbm) database library. It was found to do
well in scrambling bits, causing better distribution of the keys
and fewer splits. It also happens to be a good general hashing
function with good distribution, unless the total server weight
is a multiple of 64, in which case applying the avalanche
modifier may help.
djb2 this function was first proposed by Dan Bernstein many years ago
on comp.lang.c. Studies have shown that for certain workload this
function provides a better distribution than sdbm. It generally
works well with text-based inputs though it can perform extremely
poorly with numeric-only input or when the total server weight is
a multiple of 33, unless the avalanche modifier is also used.
wt6 this function was designed for HAProxy while testing other
functions in the past. It is not as smooth as the other ones, but
is much less sensible to the input data set or to the number of
servers. It can make sense as an alternative to sdbm+avalanche or
djb2+avalanche for consistent hashing or when hashing on numeric
data such as a source IP address or a visitor identifier in a URL
parameter.
crc32 this is the most common CRC32 implementation as used in Ethernet,
gzip, PNG, etc. It is slower than the other ones but may provide
a better distribution or less predictable results especially when
used on strings.
none don't hash the key, the key will be used as a hash, this can be
useful to manually hash the key using a converter for that purpose
and let haproxy use the result directly. The operation will
convert the key to a string if it is not already, and parse it as
an integer whose value will be used as the key. Some input key
types might not be relevant here (e.g. IP addresses).
<modifier> indicates an optional method applied after hashing the key :
avalanche This directive indicates that the result from the hash
function above should not be used in its raw form but that
a 4-byte full avalanche hash must be applied first. The
purpose of this step is to mix the resulting bits from the
previous hash in order to avoid any undesired effect when
the input contains some limited values or when the number of
servers is a multiple of one of the hash's components (64
for SDBM, 33 for DJB2). Enabling avalanche tends to make the
result less predictable, but it's also not as smooth as when
using the original function. Some testing might be needed
with some workloads. This hash is one of the many proposed
by Bob Jenkins.
The default hash type is "map-based" and is recommended for most usages. The default function is "sdbm", the selection of a function should be based on the range of the values being hashed.
Access control for all Layer 7 responses (server, applet/service and internal ones). May be used in the following contexts: http
May be used in sections :
| defaults | frontend | listen | backend |
|---|---|---|---|
yes(!)![]() | yes![]() | yes![]() | yes![]() |
The http-after-response statement defines a set of rules which apply to layer 7 processing. The rules are evaluated in their declaration order when they are met in a frontend, listen or backend section. Since these rules apply on responses, the backend rules are applied first, followed by the frontend's rules. Any rule may optionally be followed by an ACL-based condition, in which case it will only be evaluated if the condition evaluates true. Unlike http-response rules, these ones are applied on all responses, the server ones but also to all responses generated by HAProxy. These rules are evaluated at the end of the responses analysis, before the data forwarding phase. The condition is evaluated just before the action is executed, and the action is performed exactly once. As such, there is no problem if an action changes an element which is checked as part of the condition. This also means that multiple actions may rely on the same condition so that the first action that changes the condition's evaluation is sufficient to implicitly disable the remaining actions. This is used for example when trying to assign a value to a variable from various sources when it's empty. There is no limit to the number of "http-after-response" statements per instance. The first keyword after "http-after-response" in the syntax is the rule's action, optionally followed by a varying number of arguments for the action. The supported actions and their respective syntaxes are enumerated in section 4.3 "Actions" (look for actions which tick "HTTP Aft"). This directive is only available from named defaults sections, not anonymous ones. Rules defined in the defaults section are evaluated before ones in the associated proxy section. To avoid ambiguities, in this case the same defaults section cannot be used by proxies with the frontend capability and by proxies with the backend capability. It means a listen section cannot use a defaults section defining such rules. Note: Errors emitted in early stage of the request parsing are handled by the multiplexer at a lower level, before any http analysis. Thus no http-after-response ruleset is evaluated on these errors.
http-after-response set-header Strict-Transport-Security "max-age=31536000"
http-after-response set-header Cache-Control "no-store,no-cache,private"
http-after-response set-header Pragma "no-cache"
Defines a comment for the following the http-check rule, reported in logs if it fails. May be used in the following contexts: tcp, http
May be used in sections :
| defaults | frontend | listen | backend |
|---|---|---|---|
yes![]() | no![]() | yes![]() | yes![]() |
<string> is the comment message to add in logs if the following http-check
rule fails.
It only works for connect, send and expect rules. It is useful to make user-friendly error reporting.
Opens a new connection to perform an HTTP health check May be used in the following contexts: tcp, http
May be used in sections :
| defaults | frontend | listen | backend |
|---|---|---|---|
yes![]() | no![]() | yes![]() | yes![]() |
comment <msg> defines a message to report if the rule evaluation fails.
default Use default options of the server line to do the health
checks. The server options are used only if not redefined.
port <expr> if not set, check port or server port is used.
It tells HAProxy where to open the connection to.
<port> must be a valid TCP port source integer, from 1 to
65535 or an sample-fetch expression.
addr <ip> defines the IP address to do the health check.
send-proxy send a PROXY protocol string
via-socks4 enables outgoing health checks using upstream socks4 proxy.
ssl opens a ciphered connection
sni <sni> specifies the SNI to use to do health checks over SSL.
alpn <alpn> defines which protocols to advertise with ALPN. The protocol
list consists in a comma-delimited list of protocol names,
for instance: "h2,http/1.1". If it is not set, the server ALPN
is used.
proto <name> forces the multiplexer's protocol to use for this connection.
It must be an HTTP mux protocol and it must be usable on the
backend side. The list of available protocols is reported in
haproxy -vv.
linger cleanly close the connection instead of using a single RST.
Just like tcp-check health checks, it is possible to configure the connection
to use to perform HTTP health check. This directive should also be used to
describe a scenario involving several request/response exchanges, possibly on
different ports or with different servers.
When there are no TCP port configured on the server line neither server port
directive, then the first step of the http-check sequence must be to specify
the port with a "http-check connect".
In an http-check ruleset a 'connect' is required, it is also mandatory to start
the ruleset with a 'connect' rule. Purpose is to ensure admin know what they
do.
When a connect must start the ruleset, if may still be preceded by set-var,
unset-var or comment rules.
# check HTTP and HTTPs services on a server.
# first open port 80 thanks to server line port directive, then
# tcp-check opens port 443, ciphered and run a request on it:
option httpchk
http-check connect
http-check send meth GET uri / ver HTTP/1.1 hdr host haproxy.1wt.eu
http-check expect status 200-399
http-check connect port 443 ssl sni haproxy.1wt.eu
http-check send meth GET uri / ver HTTP/1.1 hdr host haproxy.1wt.eu
http-check expect status 200-399
server www 10.0.0.1 check port 80
Enable a maintenance mode upon HTTP/404 response to health-checks May be used in the following contexts: tcp, http
May be used in sections :
| defaults | frontend | listen | backend |
|---|---|---|---|
yes![]() | no![]() | yes![]() | yes![]() |
When this option is set, a server which returns an HTTP code 404 will be excluded from further load-balancing, but will still receive persistent connections. This provides a very convenient method for Web administrators to perform a graceful shutdown of their servers. It is also important to note that a server which is detected as failed while it was in this mode will not generate an alert, just a notice. If the server responds 2xx or 3xx again, it will immediately be reinserted into the farm. The status on the stats page reports "NOLB" for a server in this mode. It is important to note that this option only works in conjunction with the "httpchk" option. If this option is used with "http-check expect", then it has precedence over it so that 404 responses will still be considered as soft-stop. Note also that a stopped server will stay stopped even if it replies 404s. This option is only evaluated for running servers.
Make HTTP health checks consider response contents or specific status codes May be used in the following contexts: tcp, http
May be used in sections :
| defaults | frontend | listen | backend |
|---|---|---|---|
yes![]() | no![]() | yes![]() | yes![]() |
comment <msg> defines a message to report if the rule evaluation fails.
min-recv is optional and can define the minimum amount of data required to
evaluate the current expect rule. If the number of received bytes
is under this limit, the check will wait for more data. This
option can be used to resolve some ambiguous matching rules or to
avoid executing costly regex matches on content known to be still
incomplete. If an exact string is used, the minimum between the
string length and this parameter is used. This parameter is
ignored if it is set to -1. If the expect rule does not match,
the check will wait for more data. If set to 0, the evaluation
result is always conclusive.
ok-status <st> is optional and can be used to set the check status if
the expect rule is successfully evaluated and if it is
the last rule in the tcp-check ruleset. "L7OK", "L7OKC",
"L6OK" and "L4OK" are supported :
- L7OK : check passed on layer 7
- L7OKC : check conditionally passed on layer 7, set
server to NOLB state.
- L6OK : check passed on layer 6
- L4OK : check passed on layer 4
By default "L7OK" is used.
error-status <st> is optional and can be used to set the check status if
an error occurred during the expect rule evaluation.
"L7OKC", "L7RSP", "L7STS", "L6RSP" and "L4CON" are
supported :
- L7OKC : check conditionally passed on layer 7, set
server to NOLB state.
- L7RSP : layer 7 invalid response - protocol error
- L7STS : layer 7 response error, for example HTTP 5xx
- L6RSP : layer 6 invalid response - protocol error
- L4CON : layer 1-4 connection problem
By default "L7RSP" is used.
tout-status <st> is optional and can be used to set the check status if
a timeout occurred during the expect rule evaluation.
"L7TOUT", "L6TOUT", and "L4TOUT" are supported :
- L7TOUT : layer 7 (HTTP/SMTP) timeout
- L6TOUT : layer 6 (SSL) timeout
- L4TOUT : layer 1-4 timeout
By default "L7TOUT" is used.
on-success <fmt> is optional and can be used to customize the
informational message reported in logs if the expect
rule is successfully evaluated and if it is the last rule
in the tcp-check ruleset. <fmt> is a Custom log format
string (see section 8.2.6).
on-error <fmt> is optional and can be used to customize the
informational message reported in logs if an error
occurred during the expect rule evaluation. <fmt> is a
Custom log format string (see section 8.2.6).
status-code <expr> is optional and can be used to set the check status code
reported in logs, on success or on error. <expr> is a
standard HAProxy expression formed by a sample-fetch
followed by some converters.
<match> is a keyword indicating how to look for a specific pattern in the
response. The keyword may be one of "status", "rstatus", "hdr",
"fhdr", "string", or "rstring". The keyword may be preceded by an
exclamation mark ("!") to negate the match. Spaces are allowed
between the exclamation mark and the keyword. See below for more
details on the supported keywords.
<pattern> is the pattern to look for. It may be a string, a regular
expression or a more complex pattern with several arguments. If
the string pattern contains spaces, they must be escaped with the
usual backslash ('\').
By default, "option httpchk" considers that response statuses 2xx and 3xx are valid, and that others are invalid. When "http-check expect" is used, it defines what is considered valid or invalid. Only one "http-check" statement is supported in a backend. If a server fails to respond or times out, the check obviously fails. The available matches are : status <codes> : test the status codes found parsing <codes> string. it must be a comma-separated list of status codes or range codes. A health check response will be considered as valid if the response's status code matches any status code or is inside any range of the list. If the "status" keyword is prefixed with "!", then the response will be considered invalid if the status code matches. rstatus <regex> : test a regular expression for the HTTP status code. A health check response will be considered valid if the response's status code matches the expression. If the "rstatus" keyword is prefixed with "!", then the response will be considered invalid if the status code matches. This is mostly used to check for multiple codes. hdr { name | name-lf } [ -m <meth> ] <name> [ { value | value-lf } [ -m <meth> ] <value> : test the specified header pattern on the HTTP response headers. The name pattern is mandatory but the value pattern is optional. If not specified, only the header presence is verified. <meth> is the matching method, applied on the header name or the header value. Supported matching methods are "str" (exact match), "beg" (prefix match), "end" (suffix match), "sub" (substring match) or "reg" (regex match). If not specified, exact matching method is used. If the "name-lf" parameter is used, <name> is evaluated as a Custom log format string (see section 8.2.6). If "value-lf" parameter is used, <value> is evaluated as a log-format string. These parameters cannot be used with the regex matching method. Finally, the header value is considered as comma-separated list. Note that matchings are case insensitive on the header names. fhdr { name | name-lf } [ -m <meth> ] <name> [ { value | value-lf } [ -m <meth> ] <value> : test the specified full header pattern on the HTTP response headers. It does exactly the same as the "hdr" keyword, except the full header value is tested, commas are not considered as delimiters. string <string> : test the exact string match in the HTTP response body. A health check response will be considered valid if the response's body contains this exact string. If the "string" keyword is prefixed with "!", then the response will be considered invalid if the body contains this string. This can be used to look for a mandatory word at the end of a dynamic page, or to detect a failure when a specific error appears on the check page (e.g. a stack trace). rstring <regex> : test a regular expression on the HTTP response body. A health check response will be considered valid if the response's body matches this expression. If the "rstring" keyword is prefixed with "!", then the response will be considered invalid if the body matches the expression. This can be used to look for a mandatory word at the end of a dynamic page, or to detect a failure when a specific error appears on the check page (e.g. a stack trace). string-lf <fmt> : test a Custom log format string (see section 8.2.6) match in the HTTP response body. A health check response will be considered valid if the response's body contains the string resulting of the evaluation of <fmt>, which follows the log-format rules. If prefixed with "!", then the response will be considered invalid if the body contains the string. It is important to note that the responses will be limited to a certain size defined by the global "tune.bufsize" option, which defaults to 16384 bytes. Thus, too large responses may not contain the mandatory pattern when using "string" or "rstring". If a large response is absolutely required, it is possible to change the default max size by setting the global variable. However, it is worth keeping in mind that parsing very large responses can waste some CPU cycles, especially when regular expressions are used, and that it is always better to focus the checks on smaller resources. In an http-check ruleset, the last expect rule may be implicit. If no expect rule is specified after the last "http-check send", an implicit expect rule is defined to match on 2xx or 3xx status codes. It means this rule is also defined if there is no "http-check" rule at all, when only "option httpchk" is set. Last, if "http-check expect" is combined with "http-check disable-on-404", then this last one has precedence when the server responds with 404.
# only accept status 200 as valid
http-check expect status 200,201,300-310
# be sure a sessid coookie is set
http-check expect hdr name "set-cookie" value -m beg "sessid="
# consider SQL errors as errors
http-check expect ! string SQL\ Error
# consider status 5xx only as errors
http-check expect ! rstatus ^5
# check that we have a correct hexadecimal tag before /html
http-check expect rstring <!--tag:[0-9a-f]*--></html>
Add a possible list of headers and/or a body to the request sent during HTTP health checks. May be used in the following contexts: tcp, http
May be used in sections :
| defaults | frontend | listen | backend |
|---|---|---|---|
yes![]() | no![]() | yes![]() | yes![]() |
comment <msg> defines a message to report if the rule evaluation fails.
meth <method> is the optional HTTP method used with the requests. When not
set, the "OPTIONS" method is used, as it generally requires
low server processing and is easy to filter out from the
logs. Any method may be used, though it is not recommended
to invent non-standard ones.
uri <uri> is optional and set the URI referenced in the HTTP requests
to the string <uri>. It defaults to "/" which is accessible
by default on almost any server, but may be changed to any
other URI. Query strings are permitted.
uri-lf <fmt> is optional and set the URI referenced in the HTTP requests
using the Custom log format <fmt> (see section 8.2.6). It
defaults to "/" which is accessible by default on almost any
server, but may be changed to any other URI. Query strings
are permitted.
ver <version> is the optional HTTP version string. It defaults to
"HTTP/1.0" but some servers might behave incorrectly in HTTP
1.0, so turning it to HTTP/1.1 may sometimes help. Note that
the Host field is mandatory in HTTP/1.1, use "hdr" argument
to add it.
hdr <name> <fmt> adds the HTTP header field whose name is specified in
<name> and whose value is defined by <fmt>, which follows
the Custom log format rules described in section 8.2.6.
body <string> add the body defined by <string> to the request sent during
HTTP health checks. If defined, the "Content-Length" header
is thus automatically added to the request.
body-lf <fmt> add the body defined by the Custom log format <fmt> (see
section 8.2.6) to the request sent during HTTP health
checks. If defined, the "Content-Length" header is thus
automatically added to the request.
In addition to the request line defined by the "option httpchk" directive, this one is the valid way to add some headers and optionally a body to the request sent during HTTP health checks. If a body is defined, the associate "Content-Length" header is automatically added. Thus, this header or "Transfer-encoding" header should not be present in the request provided by "http-check send". If so, it will be ignored. The old trick consisting to add headers after the version string on the "option httpchk" line is now deprecated. Also "http-check send" doesn't support HTTP keep-alive. Keep in mind that it will automatically append a "Connection: close" header, unless a Connection header has already already been configured via a hdr entry. Note that the Host header and the request authority, when both defined, are automatically synchronized. It means when the HTTP request is sent, when a Host is inserted in the request, the request authority is accordingly updated. Thus, don't be surprised if the Host header value overwrites the configured request authority. Note also for now, no Host header is automatically added in HTTP/1.1 or above requests. You should add it explicitly.
Enable emission of a state header with HTTP health checks May be used in the following contexts: tcp, http
May be used in sections :
| defaults | frontend | listen | backend |
|---|---|---|---|
yes![]() | no![]() | yes![]() | yes![]() |
When this option is set, HAProxy will systematically send a special header
"X-Haproxy-Server-State" with a list of parameters indicating to each server
how they are seen by HAProxy. This can be used for instance when a server is
manipulated without access to HAProxy and the operator needs to know whether
HAProxy still sees it up or not, or if the server is the last one in a farm.
The header is composed of fields delimited by semi-colons, the first of which
is a word ("UP", "DOWN", "NOLB"), possibly followed by a number of valid
checks on the total number before transition, just as appears in the stats
interface. Next headers are in the form "<variable>=<value>", indicating in
no specific order some values available in the stats interface :
- a variable "address", containing the address of the backend server.
This corresponds to the <address> field in the server declaration. For
unix domain sockets, it will read "unix".
- a variable "port", containing the port of the backend server. This
corresponds to the <port> field in the server declaration. For unix
domain sockets, it will read "unix".
- a variable "name", containing the name of the backend followed by a slash
("/") then the name of the server. This can be used when a server is
checked in multiple backends.
- a variable "node" containing the name of the HAProxy node, as set in the
global "node" variable, otherwise the system's hostname if unspecified.
- a variable "weight" indicating the weight of the server, a slash ("/")
and the total weight of the farm (just counting usable servers). This
helps to know if other servers are available to handle the load when this
one fails.
- a variable "scur" indicating the current number of concurrent connections
on the server, followed by a slash ("/") then the total number of
connections on all servers of the same backend.
- a variable "qcur" indicating the current number of requests in the
server's queue.
Example of a header received by the application server :
>>> X-Haproxy-Server-State: UP 2/3; name=bck/srv2; node=lb1; weight=1/2; \
scur=13/22; qcur=0
This operation sets the content of a variable. The variable is declared inline. May be used in the following contexts: tcp, http
May be used in sections :
| defaults | frontend | listen | backend |
|---|---|---|---|
yes![]() | no![]() | yes![]() | yes![]() |
<var-name> The name of the variable. Only "proc", "sess" and "check" scopes can be used. See section 2.8 about variables for details. <cond> A set of conditions that must all be true for the variable to actually be set (such as "ifnotempty", "ifgt" ...). See the set-var converter's description for a full list of possible conditions. <expr> Is a sample-fetch expression potentially followed by converters. <fmt> This is the value expressed using Custom log format (see Custom Log Format in section 8.2.6).
http-check set-var(check.port) int(1234)
http-check set-var-fmt(check.port) "name=%H"
Free a reference to a variable within its scope. May be used in the following contexts: tcp, http
May be used in sections :
| defaults | frontend | listen | backend |
|---|---|---|---|
yes![]() | no![]() | yes![]() | yes![]() |
<var-name> The name of the variable. Only "proc", "sess" and "check" scopes can be used. See section 2.8 about variables for details.
http-check unset-var(check.port)
Defines a custom error message to use instead of errors generated by HAProxy. May be used in the following contexts: http
May be used in sections :
| defaults | frontend | listen | backend |
|---|---|---|---|
yes![]() | yes![]() | yes![]() | yes![]() |
status <code> is the HTTP status code. It must be specified.
Currently, HAProxy is capable of generating codes
200, 400, 401, 403, 404, 405, 407, 408, 410, 413,
414, 425, 429, 431, 500, 501, 502, 503, and 504.
content-type <type> is the response content type, for instance
"text/plain". This parameter is ignored and should be
omitted when an errorfile is configured or when the
payload is empty. Otherwise, it must be defined.
default-errorfiles Reset the previously defined error message for current
proxy for the status <code>. If used on a backend, the
frontend error message is used, if defined. If used on
a frontend, the default error message is used.
errorfile <file> designates a file containing the full HTTP response.
It is recommended to follow the common practice of
appending ".http" to the filename so that people do
not confuse the response with HTML error pages, and to
use absolute paths, since files are read before any
chroot is performed.
errorfiles <name> designates the http-errors section to use to import
the error message with the status code <code>. If no
such message is found, the proxy's error messages are
considered.
file <file> specifies the file to use as response payload. If the
file is not empty, its content-type must be set as
argument to "content-type", otherwise, any
"content-type" argument is ignored. <file> is
considered as a raw string.
string <str> specifies the raw string to use as response payload.
The content-type must always be set as argument to
"content-type".
lf-file <file> specifies the file to use as response payload. If the
file is not empty, its content-type must be set as
argument to "content-type", otherwise, any
"content-type" argument is ignored. <file> is
evaluated as a Custom log format (see section 8.2.6).
lf-string <str> specifies the log-format string to use as response
payload. The content-type must always be set as
argument to "content-type".
hdr <name> <fmt> adds to the response the HTTP header field whose name
is specified in <name> and whose value is defined by
<fmt>, which follows the Custom log format rules (see
section 8.2.6). This parameter is ignored if an
errorfile is used.
This directive may be used instead of "errorfile", to define a custom error message. As "errorfile" directive, it is used for errors detected and returned by HAProxy. If an errorfile is defined, it is parsed when HAProxy starts and must be valid according to the HTTP standards. The generated response must not exceed the configured buffer size (BUFFSIZE), otherwise an internal error will be returned. Finally, if you consider to use some http-after-response rules to rewrite these errors, the reserved buffer space should be available (see "tune.maxrewrite"). The files are read at the same time as the configuration and kept in memory. For this reason, the errors continue to be returned even when the process is chrooted, and no file change is considered while the process is running. Note: 400/408/500 errors emitted in early stage of the request parsing are handled by the multiplexer at a lower level. No custom formatting is supported at this level. Thus only static error messages, defined with "errorfile" directive, are supported. However, this limitation only exists during the request headers parsing or between two transactions.
Access control for Layer 7 requests May be used in the following contexts: http
May be used in sections :
| defaults | frontend | listen | backend |
|---|---|---|---|
yes(!)![]() | yes![]() | yes![]() | yes![]() |
The http-request statement defines a set of rules which apply to layer 7 processing. The rules are evaluated in their declaration order when they are met in a frontend, listen or backend section. Any rule may optionally be followed by an ACL-based condition, in which case it will only be evaluated if the condition evaluates to true. The condition is evaluated just before the action is executed, and the action is performed exactly once. As such, there is no problem if an action changes an element which is checked as part of the condition. This also means that multiple actions may rely on the same condition so that the first action that changes the condition's evaluation is sufficient to implicitly disable the remaining actions. This is used for example when trying to assign a value to a variable from various sources when it's empty. There is no limit to the number of "http-request" statements per instance. The first keyword after "http-request" in the syntax is the rule's action, optionally followed by a varying number of arguments for the action. The supported actions and their respective syntaxes are enumerated in section 4.3 "Actions" (look for actions which tick "HTTP Req"). This directive is only available from named defaults sections, not anonymous ones. Rules defined in the defaults section are evaluated before ones in the associated proxy section. To avoid ambiguities, in this case the same defaults section cannot be used by proxies with the frontend capability and by proxies with the backend capability. It means a listen section cannot use a defaults section defining such rules.
acl nagios src 192.168.129.3
acl local_net src 192.168.0.0/16
acl auth_ok http_auth(L1)
http-request allow if nagios
http-request allow if local_net auth_ok
http-request auth realm Gimme if local_net auth_ok
http-request deny
acl key req.hdr(X-Add-Acl-Key) -m found
acl add path /addacl
acl del path /delacl
acl myhost hdr(Host) -f myhost.lst
http-request add-acl(myhost.lst) %[req.hdr(X-Add-Acl-Key)] if key add
http-request del-acl(myhost.lst) %[req.hdr(X-Add-Acl-Key)] if key del
acl value req.hdr(X-Value) -m found
acl setmap path /setmap
acl delmap path /delmap
use_backend bk_appli if { hdr(Host),map_str(map.lst) -m found }
http-request set-map(map.lst) %[src] %[req.hdr(X-Value)] if setmap value
http-request del-map(map.lst) %[src] if delmap
Access control for Layer 7 responses May be used in the following contexts: http
May be used in sections :
| defaults | frontend | listen | backend |
|---|---|---|---|
yes(!)![]() | yes![]() | yes![]() | yes![]() |
The http-response statement defines a set of rules which apply to layer 7 processing. The rules are evaluated in their declaration order when they are met in a frontend, listen or backend section. Since these rules apply on responses, the backend rules are applied first, followed by the frontend's rules. Any rule may optionally be followed by an ACL-based condition, in which case it will only be evaluated if the condition evaluates to true. The condition is evaluated just before the action is executed, and the action is performed exactly once. As such, there is no problem if an action changes an element which is checked as part of the condition. This also means that multiple actions may rely on the same condition so that the first action that changes the condition's evaluation is sufficient to implicitly disable the remaining actions. This is used for example when trying to assign a value to a variable from various sources when it's empty. There is no limit to the number of "http-response" statements per instance. The first keyword after "http-response" in the syntax is the rule's action, optionally followed by a varying number of arguments for the action. The supported actions and their respective syntaxes are enumerated in section 4.3 "Actions" (look for actions which tick "HTTP Res"). This directive is only available from named defaults sections, not anonymous ones. Rules defined in the defaults section are evaluated before ones in the associated proxy section. To avoid ambiguities, in this case the same defaults section cannot be used by proxies with the frontend capability and by proxies with the backend capability. It means a listen section cannot use a defaults section defining such rules.
acl key_acl res.hdr(X-Acl-Key) -m found
acl myhost hdr(Host) -f myhost.lst
http-response add-acl(myhost.lst) %[res.hdr(X-Acl-Key)] if key_acl
http-response del-acl(myhost.lst) %[res.hdr(X-Acl-Key)] if key_acl
acl value res.hdr(X-Value) -m found
use_backend bk_appli if { hdr(Host),map_str(map.lst) -m found }
http-response set-map(map.lst) %[src] %[res.hdr(X-Value)] if value
http-response del-map(map.lst) %[src] if ! value
Declare how idle HTTP connections may be shared between requests May be used in the following contexts: http
May be used in sections :
| defaults | frontend | listen | backend |
|---|---|---|---|
yes![]() | no![]() | yes![]() | yes![]() |
In order to avoid the cost of setting up new connections to backend servers for each HTTP request, HAProxy tries to keep such idle connections opened after being used. These connections are specific to a server and are stored in a list called a pool, and are grouped together by a set of common key properties. Subsequent HTTP requests will cause a lookup of a compatible connection sharing identical properties in the associated pool and result in this connection being reused instead of establishing a new one. A limit on the number of idle connections to keep on a server can be specified via the "pool-max-conn" server keyword. Unused connections are periodically purged according to the "pool-purge-delay" interval. The following connection properties are used to determine if an idle connection is eligible for reuse on a given request: - source and destination addresses - proxy protocol - TOS and mark socket options - connection name, determined either by the result of the evaluation of the "pool-conn-name" expression if present, otherwise by the "sni" expression, which defaults to "req.hdr(host),field(1,:)", i.e. uses the incoming request's "Host" header field without the colon nor the port number. In some occasions, connection lookup or reuse is not performed due to extra restrictions. This is determined by the reuse strategy specified via the keyword argument: - "never" : idle connections are never shared between sessions. This mode may be enforced to cancel a different strategy inherited from a defaults section or for troubleshooting. For example, if an old bogus application considers that multiple requests over the same connection come from the same client and it is not possible to fix the application, it may be desirable to disable connection sharing in a single backend. An example of such an application could be an old HAProxy using cookie insertion in tunnel mode and not checking any request past the first one. - "safe" : this is the default and the recommended strategy. The first request of a session is always sent over its own connection, and only subsequent requests may be dispatched over other existing connections. This ensures that in case the server closes the connection when the request is being sent, the browser can decide to silently retry it. Since it is exactly equivalent to regular keep-alive, there should be no side effects. There is also a special handling for the connections using protocols subject to Head-of-line blocking (backend with h2 or fcgi). In this case, when at least one stream is processed, the used connection is reserved to handle streams of the same session. When no more streams are processed, the connection is released and can be reused. - "aggressive" : this mode may be useful in webservices environments where all servers are not necessarily known and where it would be appreciable to deliver most first requests over existing connections. In this case, first requests are only delivered over existing connections that have been reused at least once, proving that the server correctly supports connection reuse. It should only be used when it's sure that the client can retry a failed request once in a while and where the benefit of aggressive connection reuse significantly outweighs the downsides of rare connection failures. - "always" : this mode is only recommended when the path to the server is known for never breaking existing connections quickly after releasing them. It allows the first request of a session to be sent to an existing connection. This can provide a significant performance increase over the "safe" strategy when the backend is a cache farm, since such components tend to show a consistent behavior and will benefit from the connection sharing. It is recommended that the "http-keep-alive" timeout remains low in this mode so that no dead connections remain usable. In most cases, this will lead to the same performance gains as "aggressive" but with more risks. It should only be used when it improves the situation over "aggressive". Also note that connections with certain bogus authentication schemes (relying on the connection) like NTLM are marked private if possible and never shared. This won't be the case however when using a protocol with multiplexing abilities and using reuse mode level value greater than the default "safe" strategy as in this case nothing prevents the connection from being already shared. The rules to decide to keep an idle connection opened or to close it after processing are also governed by the "tune.pool-low-fd-ratio" (default: 20%) and "tune.pool-high-fd-ratio" (default: 25%). These correspond to the percentage of total file descriptors spent in idle connections above which haproxy will respectively refrain from keeping a connection opened after a response, and actively kill idle connections. Some setups using a very high ratio of idle connections, either because of too low a global "maxconn", or due to a lot of HTTP/2 or HTTP/3 traffic on the frontend (few connections) but HTTP/1 connections on the backend, may observe a lower reuse rate because too few connections are kept open. It may be desirable in this case to adjust such thresholds or simply to increase the global "maxconn" value. In some rare cases, when the host name is used to distinguish outgoing TLS connections (e.g. forward proxy), where most request target different hosts, the reuse rate will be very low, and the automatic eviction of rarely used connections will kick in before connections have a chance to be reused, because the mechanism continuously measures the average number of connections needed to deliver the service without exhausting resources. In such situations, setting "pool-low-conn" to a value close to the average expected number of idle connections may help preserve more connections by encouraging threads to setup their own instead of trying to pick other threads' and shrinking the pool of available connections. If a locally hosted server uses a single certificate (with multiple host names or wildcards) and operates multiple sites, it may be more effective to just use "no-sni-auto" on the "server" line to avoid reserving a connection to a single Host name. This will significantly increase the reuse rate. Some servers might perform excessive checks between Host and SNI though, resulting in rejecting subsequent requests, so this option requires preliminary validation. The default behavior ("sni-auto") is to be safe even with such servers. When thread groups are explicitly enabled, it is important to understand that idle connections are only usable between threads from a same group. As such it may happen that unfair load between groups leads to more idle connections being needed, causing a lower reuse rate. The same solution may then be applied (increase global "maxconn" or increase pool ratios).
Add the server name to a request. Use the header string given by <header> May be used in the following contexts: http
May be used in sections :
| defaults | frontend | listen | backend |
|---|---|---|---|
yes![]() | no![]() | yes![]() | yes![]() |
<header> The header string to use to send the server name
The "http-send-name-header" statement causes the header field named <header> to be set to the name of the target server at the moment the request is about to be sent on the wire. Any existing occurrences of this header are removed. Upon retries and redispatches, the header field is updated to always reflect the server being attempted to connect to. Given that this header is modified very late in the connection setup, it may have unexpected effects on already modified headers. For example using it with transport-level header such as connection, content-length, transfer-encoding and so on will likely result in invalid requests being sent to the server. This is why following header names are forbidden: host, content-length, transfer-encoding and connection.
Set a persistent ID to a proxy. May be used in the following contexts: tcp, http, log
May be used in sections :
| defaults | frontend | listen | backend |
|---|---|---|---|
no![]() | yes![]() | yes![]() | yes![]() |
Set a persistent ID for the proxy. This ID must be unique and positive. An unused ID will automatically be assigned if unset. Due to an historical behavior, value 1 is not used unless explicitly set. Thus, the lowest value automatically assigned will be 2. This ID is currently only returned in statistics.
Declare a condition to ignore persistence May be used in the following contexts: tcp, http
May be used in sections :
| defaults | frontend | listen | backend |
|---|---|---|---|
no![]() | no![]() | yes![]() | yes![]() |
By default, when cookie persistence is enabled, every requests containing the cookie are unconditionally persistent (assuming the target server is up and running). The "ignore-persist" statement allows one to declare various ACL-based conditions which, when met, will cause a request to ignore persistence. This is sometimes useful to load balance requests for static files, which often don't require persistence. This can also be used to fully disable persistence for a specific User-Agent (for example, some web crawler bots). The persistence is ignored when an "if" condition is met, or unless an "unless" condition is met.
acl url_static path_beg /static /images /img /css
acl url_static path_end .gif .png .jpg .css .js
ignore-persist if url_static
Allow seamless reload of HAProxy May be used in the following contexts: tcp, http, log
May be used in sections :
| defaults | frontend | listen | backend |
|---|---|---|---|
yes![]() | no![]() | yes![]() | yes![]() |
This directive points HAProxy to a file where server state from previous running process has been saved. That way, when starting up, before handling traffic, the new process can apply old states to servers exactly has if no reload occurred. The purpose of the "load-server-state-from-file" directive is to tell HAProxy which file to use. For now, only 2 arguments to either prevent loading state or load states from a file containing all backends and servers. The state file can be generated by running the command "show servers state" over the stats socket and redirect output. The format of the file is versioned and is very specific. To understand it, please read the documentation of the "show servers state" command (chapter 9.3 of Management Guide).
global load the content of the file pointed by the global directive
named "server-state-file".
local load the content of the file pointed by the directive
"server-state-file-name" if set. If not set, then the backend
name is used as a file name.
none don't load any stat for this backend
Notes:
- server's IP address is preserved across reloads by default, but the
order can be changed thanks to the server's "init-addr" setting. This
means that an IP address change performed on the CLI at run time will
be preserved, and that any change to the local resolver (e.g. /etc/hosts)
will possibly not have any effect if the state file is in use.
- server's weight is applied from previous running process unless it has
has changed between previous and new configuration files.
Minimal configurationglobal stats socket /tmp/socket server-state-file /tmp/server_state defaults load-server-state-from-file global backend bk server s1 127.0.0.1:22 check weight 11 server s2 127.0.0.1:22 check weight 12
Then one can run : socat /tmp/socket - <<< "show servers state" > /tmp/server_state Content of the file /tmp/server_state would be like this: 1 # <field names skipped for the doc example> 1 bk 1 s1 127.0.0.1 2 0 11 11 4 6 3 4 6 0 0 1 bk 2 s2 127.0.0.1 2 0 12 12 4 6 3 4 6 0 0
Minimal configurationglobal stats socket /tmp/socket server-state-base /etc/haproxy/states defaults load-server-state-from-file local backend bk server s1 127.0.0.1:22 check weight 11 server s2 127.0.0.1:22 check weight 12
Then one can run : socat /tmp/socket - <<< "show servers state bk" > /etc/haproxy/states/bk Content of the file /etc/haproxy/states/bk would be like this: 1 # <field names skipped for the doc example> 1 bk 1 s1 127.0.0.1 2 0 11 11 4 6 3 4 6 0 0 1 bk 2 s2 127.0.0.1 2 0 12 12 4 6 3 4 6 0 0
Enable per-instance logging of events and traffic. May be used in the following contexts: tcp, http, log
May be used in sections :
| defaults | frontend | listen | backend |
|---|---|---|---|
yes![]() | yes![]() | yes![]() | yes![]() |
Prefix :
no should be used when the logger list must be flushed. For example,
if you don't want to inherit from the default logger list. This
prefix does not allow arguments.
global should be used when the instance's logging parameters are the
same as the global ones. This is the most common usage. "global"
replaces all log arguments with those of the log entries found
in the "global" section. Only one "log global" statement may be
used per instance, and this form takes no other parameter.
<target> indicates where to send the logs. It takes the same format as
for the "global" section's logs, and can be one of :
- An IPv4 address optionally followed by a colon (':') and a UDP
port. If no port is specified, 514 is used by default (the
standard syslog port).
- An IPv6 address followed by a colon (':') and optionally a UDP
port. If no port is specified, 514 is used by default (the
standard syslog port).
- A filesystem path to a UNIX domain socket, keeping in mind
considerations for chroot (be sure the path is accessible
inside the chroot) and uid/gid (be sure the path is
appropriately writable).
- A file descriptor number in the form "fd@<number>", which may
point to a pipe, terminal, or socket. In this case unbuffered
logs are used and one writev() call per log is performed. This
is a bit expensive but acceptable for most workloads. Messages
sent this way will not be truncated but may be dropped, in
which case the DroppedLogs counter will be incremented. The
writev() call is atomic even on pipes for messages up to
PIPE_BUF size, which POSIX recommends to be at least 512 and
which is 4096 bytes on most modern operating systems. Any
larger message may be interleaved with messages from other
processes. Exceptionally for debugging purposes the file
descriptor may also be directed to a file, but doing so will
significantly slow HAProxy down as non-blocking calls will be
ignored. Also there will be no way to purge nor rotate this
file without restarting the process. Note that the configured
syslog format is preserved, so the output is suitable for use
with a TCP syslog server. See also the "short" and "raw"
formats below.
- "stdout" / "stderr", which are respectively aliases for "fd@1"
and "fd@2", see above.
- A ring buffer in the form "ring@<name>", which will correspond
to an in-memory ring buffer accessible over the CLI using the
"show events" command, which will also list existing rings and
their sizes. Such buffers are lost on reload or restart but
when used as a complement this can help troubleshooting by
having the logs instantly available. See section 12.5 about
rings.
- A log backend in the form "backend@<name>", which will send
log messages to the corresponding log backend responsible for
sending the message to the proper server according to the
backend's lb settings. A log backend is a backend section with
"mode log" set (see "mode" for more information).
- An explicit stream address prefix such as "tcp@","tcp6@",
"tcp4@" or "uxst@" will allocate an implicit ring buffer with
a stream forward server targeting the given address.
You may want to reference some environment variables in the
address parameter, see section 2.3 about environment variables.
<length> is an optional maximum line length. Log lines larger than this
value will be truncated before being sent. The reason is that
syslog servers act differently on log line length. All servers
support the default value of 1024, but some servers simply drop
larger lines while others do log them. If a server supports long
lines, it may make sense to set this value here in order to avoid
truncating long lines. Similarly, if a server drops long lines,
it is preferable to truncate them before sending them. Accepted
values are 80 to 65535 inclusive. The default value of 1024 is
generally fine for all standard usages. Some specific cases of
long captures or JSON-formatted logs may require larger values.
You may also need to increase "tune.http.logurilen" if your
request URIs are truncated.
<ranges> A list of comma-separated ranges to identify the logs to sample.
This is used to balance the load of the logs to send to the log
server. The limits of the ranges cannot be null. They are numbered
from 1. The size or period (in number of logs) of the sample must
be set with <sample_size> parameter.
<sample_size>
The size of the sample in number of logs to consider when balancing
their logging loads. It is used to balance the load of the logs to
send to the syslog server. This size must be greater or equal to the
maximum of the high limits of the ranges.
(see also <ranges> parameter).
<format> is the log format used when generating syslog messages. It may be
one of the following :
local Analog to rfc3164 syslog message format except that hostname
field is stripped. This is the default.
Note: option "log-send-hostname" switches the default to
rfc3164.
rfc3164 The RFC3164 syslog message format.
(https://tools.ietf.org/html/rfc3164)
rfc5424 The RFC5424 syslog message format.
(https://tools.ietf.org/html/rfc5424)
priority A message containing only a level plus syslog facility between
angle brackets such as '<63>', followed by the text. The PID,
date, time, process name and system name are omitted. This is
designed to be used with a local log server.
short A message containing only a level between angle brackets such as
'<3>', followed by the text. The PID, date, time, process name
and system name are omitted. This is designed to be used with a
local log server. This format is compatible with what the
systemd logger consumes.
timed A message containing only a level between angle brackets such as
'<3>', followed by ISO date and by the text. The PID, process
name and system name are omitted. This is designed to be
used with a local log server.
iso A message containing only the ISO date, followed by the text.
The PID, process name and system name are omitted. This is
designed to be used with a local log server.
raw A message containing only the text. The level, PID, date, time,
process name and system name are omitted. This is designed to
be used in containers or during development, where the severity
only depends on the file descriptor used (stdout/stderr).
<prof> name of the optional "log-profile" section that will be
considered during the log building process to override some
log options. Check out "8.3.5. Log profiles" for more info.
<facility> must be one of the 24 standard syslog facilities :
kern user mail daemon auth syslog lpr news
uucp cron auth2 ftp ntp audit alert cron2
local0 local1 local2 local3 local4 local5 local6 local7
Note that the facility is ignored for the "short" and "raw"
formats, but still required as a positional field. It is
recommended to use "daemon" in this case to make it clear that
it's only supposed to be used locally.
<level> is optional and can be specified to filter outgoing messages. By
default, all messages are sent. If a level is specified, only
messages with a severity at least as important as this level
will be sent. An optional minimum level can be specified. If it
is set, logs emitted with a more severe level than this one will
be capped to this level. This is used to avoid sending "emerg"
messages on all terminals on some default syslog configurations.
Eight levels are known :
emerg alert crit err warning notice info debug
It is important to keep in mind that it is the frontend which decides what to
log from a connection, and that in case of content switching, the log entries
from the backend will be ignored. Connections are logged at level "info".
However, backend log declaration define how and where servers status changes
will be logged. Level "notice" will be used to indicate a server going up,
"warning" will be used for termination signals and definitive service
termination, and "alert" will be used for when a server goes down.
Note : According to RFC3164, messages are truncated to 1024 bytes before
being emitted.
log global
log stdout format short daemon # send log to systemd
log stdout format raw daemon # send everything to stdout
log stderr format raw daemon notice # send important events to stderr
log 127.0.0.1:514 local0 notice # only send important events
log tcp@127.0.0.1:514 local0 notice notice # same but limit output
# level and send in tcp
log "${LOCAL_SYSLOG}:514" local0 notice # send to local server
Specifies the custom log format string to use for traffic logs May be used in the following contexts: tcp, http
May be used in sections :
| defaults | frontend | listen | backend |
|---|---|---|---|
yes![]() | yes![]() | yes![]() | no![]() |
This directive specifies the log format string that will be used for all logs resulting from traffic passing through the frontend using this line. If the directive is used in a defaults section, all subsequent frontends will use the same log format. Please see section 8.2.6 which covers the custom log format string in depth. A specific log-format used only in case of connection error can also be defined, see the "error-log-format" option. "log-format" directive overrides previous "option tcplog", "log-format", "option httplog" and "option httpslog" directives.
Specifies the Custom log format string used to produce RFC5424 structured-data May be used in the following contexts: tcp, http
May be used in sections :
| defaults | frontend | listen | backend |
|---|---|---|---|
yes![]() | yes![]() | yes![]() | no![]() |
This directive specifies the RFC5424 structured-data log format string that will be used for all logs resulting from traffic passing through the frontend using this line. If the directive is used in a defaults section, all subsequent frontends will use the same log format. Please see section 8.2.6 which covers the log format string in depth. See https://tools.ietf.org/html/rfc5424#section-6.3 for more information about the RFC5424 structured-data part. Note : This log format string will be used only for loggers that have set log format to "rfc5424".
log-format-sd [exampleSDID@1234\ bytes=\"%B\"\ status=\"%ST\"]
Specifies at which steps during transaction processing logs should be generated. May be used in the following contexts: tcp, http
May be used in sections :
| defaults | frontend | listen | backend |
|---|---|---|---|
yes![]() | yes![]() | yes![]() | no![]() |
During tcp/http transaction processing, haproxy may produce logs at different steps during the processing (ie: accept, connect, request, response, close). By default, HAProxy emits a single log per transaction, once all of the items used in the logformat expression could be satisfied, which means that in practice the log is usually emitted at the end of the transaction (after the end of the response for HTTP or end of connection for TCP), unless "option logasap" is used. The "log-steps" directive allows to refine the precise instants where logs will be emitted, and even permits to emit multiple logs for a same transaction. Special value 'all' may be used to enable all available log origins, making it possible to track a transaction from accept to close. Individual log origins may also be specified using their names separated by commas to selectively enable when logs should be produced. Common log origins are: accept, connect, request, response, close.
frontend myfront
option httplog
log-steps accept,close #only log accept and close for the txn
Log origins specified as "logging steps" (such as accept, close) can be used as-is in log-profiles (after 'on' directive). Combining "log-steps" with log-profiles is really interesting to have fine-grained control over logs automatically generated by haproxy during transaction processing. This setting is only relevant on frontends, it is ignored on backends.
Specifies the log tag to use for all outgoing logs May be used in the following contexts: tcp, http, log
May be used in sections :
| defaults | frontend | listen | backend |
|---|---|---|---|
yes![]() | yes![]() | yes![]() | yes![]() |
Sets the tag field in the syslog header to this string. It defaults to the
log-tag set in the global section, otherwise the program name as launched
from the command line, which usually is "HAProxy". Sometimes it can be useful
to differentiate between multiple processes running on the same host, or to
differentiate customer instances running in the same process. In the backend,
logs about servers up/down will use this tag. As a hint, it can be convenient
to set a log-tag related to a hosted customer in a defaults section then put
all the frontends and backends for that customer, then start another customer
in a new defaults section. See also the global "log-tag" directive.
Set the maximum server queue size for maintaining keep-alive connections May be used in the following contexts: http
May be used in sections :
| defaults | frontend | listen | backend |
|---|---|---|---|
yes![]() | no![]() | yes![]() | yes![]() |
HTTP keep-alive tries to reuse the same server connection whenever possible, but sometimes it can be counter-productive, for example if a server has a lot of connections while other ones are idle. This is especially true for static servers. The purpose of this setting is to set a threshold on the number of queued connections at which HAProxy stops trying to reuse the same server and prefers to find another one. The default value, -1, means there is no limit. A value of zero means that keep-alive requests will never be queued. For very close servers which can be reached with a low latency and which are not sensible to breaking keep-alive, a low value is recommended (e.g. local static server can use a value of 10 or less). For remote servers suffering from a high latency, higher values might be needed to cover for the latency and/or the cost of picking a different server. Note that this has no impact on responses which are maintained to the same server consecutively to a 401 response. They will still go to the same server even if they have to be queued.
Set the maximum number of outgoing connections we can keep idling for a given client session. The default is 5 (it precisely equals MAX_SRV_LIST which is defined at build time). May be used in the following contexts: tcp, http
May be used in sections :
| defaults | frontend | listen | backend |
|---|---|---|---|
yes![]() | yes![]() | yes![]() | no![]() |
Fix the maximum number of concurrent connections on a frontend May be used in the following contexts: tcp, http
May be used in sections :
| defaults | frontend | listen | backend |
|---|---|---|---|
yes![]() | yes![]() | yes![]() | no![]() |
<conns> is the maximum number of concurrent connections the frontend will
accept to serve. Excess connections will be queued by the system
in the socket's listen queue and will be served once a connection
closes.
If the system supports it, it can be useful on big sites to raise this limit
very high so that HAProxy manages connection queues, instead of leaving the
clients with unanswered connection attempts. This value should not exceed the
global maxconn. Also, keep in mind that a connection contains two buffers
of tune.bufsize (16kB by default) each, as well as some other data resulting
in about 33 kB of RAM being consumed per established connection. That means
that a medium system equipped with 1GB of RAM can withstand around
20000-25000 concurrent connections if properly tuned.
Also, when <conns> is set to large values, it is possible that the servers
are not sized to accept such loads, and for this reason it is generally wise
to assign them some reasonable connection limits.
When this value is set to zero, which is the default, the global "maxconn"
value is used.
Set the running mode or protocol of the instance
May be used in sections :
| defaults | frontend | listen | backend |
|---|---|---|---|
yes![]() | yes![]() | yes![]() | yes![]() |
tcp The instance will work in pure TCP mode. A full-duplex connection
will be established between clients and servers, and no layer 7
examination will be performed. This is the default mode. It
should be used for SSL, SSH, SMTP, ...
http The instance will work in HTTP mode. The client request will be
analyzed in depth before connecting to any server. Any request
which is not RFC-compliant will be rejected. Layer 7 filtering,
processing and switching will be possible. This is the mode which
brings HAProxy most of its value.
haterm The frontend will work in haterm HTTP benchmark mode. This is
not supported by backends. See doc/haterm.txt for details.
log When used in a backend section, it will turn the backend into a
log backend. Such backend can be used as a log destination for
any "log" directive by using the "backend@<name>" syntax. Log
messages will be distributed to the servers from the backend
according to the lb settings which can be configured using the
"balance" keyword. Log backends support UDP servers by prefixing
the server's address with the "udp@" prefix. Common backend and
server features are supported, but not TCP or HTTP specific ones.
spop When used in a backend section, it will turn the backend into a
spop backend. This mode is mandatory if the backend contains
SPOA servers, but when mode is tcp, it will automatically be
converted to mode spop if such servers are detected.
When doing content switching, it is mandatory that the frontend and the backend are in the same mode (generally HTTP), otherwise the configuration will be refused.
defaults http_instances
mode http
Add a condition to report a failure to a monitor HTTP request. May be used in the following contexts: http
May be used in sections :
| defaults | frontend | listen | backend |
|---|---|---|---|
no![]() | yes![]() | yes![]() | no![]() |
if <cond> the monitor request will fail if the condition is satisfied,
and will succeed otherwise. The condition should describe a
combined test which must induce a failure if all conditions
are met, for instance a low number of servers both in a
backend and its backup.
unless <cond> the monitor request will succeed only if the condition is
satisfied, and will fail otherwise. Such a condition may be
based on a test on the presence of a minimum number of active
servers in a list of backends.
This statement adds a condition which can force the response to a monitor request to report a failure. By default, when an external component queries the URI dedicated to monitoring, a 200 response is returned. When one of the conditions above is met, HAProxy will return 503 instead of 200. This is very useful to report a site failure to an external component which may base routing advertisements between multiple sites on the availability reported by HAProxy. In this case, one would rely on an ACL involving the "nbsrv" criterion. Note that "monitor fail" only works in HTTP mode. Both status messages may be tweaked using "errorfile" or "errorloc" if needed.
frontend www
mode http
acl site_dead nbsrv(dynamic) lt 2
acl site_dead nbsrv(static) lt 2
monitor-uri /site_alive
monitor fail if site_dead
Intercept a URI used by external components' monitor requests May be used in the following contexts: http
May be used in sections :
| defaults | frontend | listen | backend |
|---|---|---|---|
yes![]() | yes![]() | yes![]() | no![]() |
<uri> is the exact URI which we want to intercept to return HAProxy's
health status instead of forwarding the request.
When an HTTP request referencing <uri> will be received on a frontend, HAProxy will not forward it nor log it, but instead will return either "HTTP/1.0 200 OK" or "HTTP/1.0 503 Service unavailable", depending on failure conditions defined with "monitor fail". This is normally enough for any front-end HTTP probe to detect that the service is UP and running without forwarding the request to a backend server. Note that the HTTP method, the version and all headers are ignored, but the request must at least be valid at the HTTP level. This keyword may only be used with an HTTP-mode frontend. Monitor requests are processed very early, just after the request is parsed and even before any "http-request". The only rulesets applied before are the tcp-request ones. They cannot be logged either, and it is the intended purpose. Only one URI may be configured for monitoring; when multiple "monitor-uri" statements are present, the last one will define the URI to be used. They are only used to report HAProxy's health to an upper component, nothing more. However, it is possible to add any number of conditions using "monitor fail" and ACLs so that the result can be adjusted to whatever check can be imagined (most often the number of available servers in a backend). Note: if <uri> starts by a slash ('/'), the matching is performed against the request's path instead of the request's uri. It is a workaround to let the HTTP/2 requests match the monitor-uri. Indeed, in HTTP/2, clients are encouraged to send absolute URIs only.
# Use /haproxy_test to report HAProxy's status
frontend www
mode http
monitor-uri /haproxy_test
Enable or disable early abortion of not started processing when client closes May be used in the following contexts: tcp, http
May be used in sections :
| defaults | frontend | listen | backend |
|---|---|---|---|
yes![]() | yes![]() | yes![]() | yes![]() |
TCP connections support being closed independently in each direction, and a connection with only one direction closed is often said to be "half-closed". Originally when the HTTP ecosystem was mostly made of the "close mode", with only one request and one response per connection before closing, it was pretty frequent to see scripted clients send their request, close the sending side, wait for the response, receive the close indication and be done with this. But with the arrival of keep-alive and more advanced protocols, this practice has practically disappeared and the only cases where a client closes before receiving its response is essentially when the user wants to abort a transfer, or when a timeout strikes and the connection is closed. These two situations (half-closed vs abort) are undistinguishable from the server side (here the HAProxy listener). This is a problem because leaving the connection alive and continuing to process a request when clients abort can cost a lot of resources, particularly if the closure is the result of a user hitting the "reload" button, as it means new requests are queued without the previous ones being aborted. And conversely, systematically aborting when facing such a half-close situation would break a number of TCP applications and even some HTTP ones on internal networks interacting with legacy agents. The "abortonclose" option permits to choose the desired behavior: - when present in a frontend, it will avoid processing TLS handshakes which are pending on a half-closed connection. This can be the result of a user hitting "reload" during an HTTPS request under high load such as a VRRP fail-over between an active HAProxy node and the backup one: all clients reconnect at the same time to the new node, and all have to perform a costly, full TLS handshake. If it takes more than a few seconds, it's likely that some users will give up, and it's pointless to waste CPU cycles on their handshakes. Given the CPU cost of TLS handshakes, it is recommended to leave this option enabled on internet-facing frontends. This is the default for incoming TLS connections. - when present in a backend, it will cause half-closed connections to try to abort a request that was not yet sent to a server (i.e. when it's pending in the queue or when trying to connect). If the request is already being served by a server, then the connection to the server is in turn switched to half-close to indicate the same condition to the server, which will then decide how to proceed. This is the default for HTTP-mode backends. The recommendation is to enable this option on internet-facing TLS endpoints and HTTP services, and to disable it for pure TCP ones as well as unexposed legacy environments. It is enabled by default in HTTP backends, and may be forcefully disabled by prepending the "no" keyword before it, either in the backend section itself, or in the "defaults" section it inherits from. It is also enabled by default for TLS listeners and may be forcefully disabled as well by specifying "no option abortonclose" in the frontend or in the "defaults" section it inherits from. If this option has been enabled in a "defaults" section, it can be disabled in a specific instance by prepending the "no" keyword before it.
Enable or disable relaxing of HTTP request parsing The "accept-invalid-http-request" keyword is deprecated, use "option accept-unsafe-violations-in-http-request" instead.
Enable or disable relaxing of HTTP response parsing The "accept-invalid-http-response" keyword is deprecated, use "option accept-unsafe-violations-in-http-response" instead.
Enable or disable relaxing of HTTP request parsing May be used in the following contexts: http
May be used in sections :
| defaults | frontend | listen | backend |
|---|---|---|---|
yes![]() | yes![]() | yes![]() | no![]() |
By default, HAProxy complies with the different HTTP RFCs in terms of message
parsing. This means the message parsing is quite strict and causes an error
to be returned to the client for malformed messages. This is the desired
behavior as such malformed messages are essentially used to build attacks
exploiting server weaknesses, and bypass security filtering. Sometimes, a
buggy browser will not respect these RCFs for whatever reason (configuration,
implementation...) and the issue will not be immediately fixed. In such case,
it is possible to relax HAProxy's parser to accept some invalid requests by
specifying this option. Most of rules concern the H1 parsing for historical
reason. Newer HTTP versions tends to be cleaner and applications follow more
stickly these protocols.
When this option is set, the following rules are observed:
* In H1 only, invalid characters, including NULL character, in header name
will not be rejected; however the header will be dropped.
* In H1 only, NULL character in header value will be accepted;
* In H1 only, characters above 127 in the URI will be accepted. The list of
characters allowed to appear in a URI is well defined by RFC3986, and
chars 0-31, 32 (space), 34 ('"'), 60 ('<'), 62 ('>'), 92 ('\'), 94 ('^'),
96 ('`'), 123 ('{'), 124 ('|'), 125 ('}'), 127 (delete) and anything
above are normally not allowed. In H1, all character between (0..32) and
127 will always be blocked. All characters above 127 (excluded) will also
be blocked, except when this option is enabled. Other characters
(33..126) will not be checked at all.
* In H1 and H2, URLs containing fragment references ('#' after the path)
will be accepted;
* In H1 only, no check will be performed on the authority for CONNECT
requests;
* In H1 only, no check will be performed against the authority and the Host
header value.
* In H1 only, tests on the HTTP version will be relaxed. It will allow
HTTP/0.9 GET requests to pass through (no version specified), as well as
different protocol names (e.g. RTSP), and multiple digits for both the
major and the minor version.
* In H1 only, WebSocket (RFC6455) requests failing to present a valid
"Sec-Websocket-Key" header field will be accepted.
This option should never be enabled by default as it hides application bugs
and open security breaches. It should only be deployed after a problem has
been confirmed.
When this option is enabled, invalid but accepted H1 requests will be
captured in order to permit later analysis using the "show errors" request on
the UNIX stats socket.Doing this also helps confirming that the issue has
been solved.
If this option has been enabled in a "defaults" section, it can be disabled
in a specific instance by prepending the "no" keyword before it.
Enable or disable relaxing of HTTP response parsing May be used in the following contexts: http
May be used in sections :
| defaults | frontend | listen | backend |
|---|---|---|---|
yes![]() | no![]() | yes![]() | yes![]() |
Similarly to "option accept-unsafe-violations-in-http-request", this option may be used to relax parsing rules of HTTP responses. It should only be enabled for trusted legacy servers to accept some invalid responses. Most of rules concern the H1 parsing for historical reason. Newer HTTP versions tends to be cleaner and applications follow more stickly these protocols. When this option is set, the following rules are observed: * In H1 only, status codes longer than 3 digits but whose value fits in 16 bits are not rejected. * In H1 only, invalid characters, including NULL character, in header name will not be rejected; however the header will be dropped. * In H1 only, NULL character in header value will be accepted; * In H1 only, empty values or several "chunked" value occurrences for Transfer-Encoding header will be accepted; * In H1 only, no check will be performed against the authority and the Host header value. * In H1 only, tests on the HTTP version will be relaxed. It will allow different protocol names (e.g. RTSP), and multiple digits for both the major and the minor version. * In H1 only, WebSocket (RFC6455) responses failing to present a valid "Sec-Websocket-Accept" header field will be accepted. This option should never be enabled by default as it hides application bugs and open security breaches. It should only be deployed after a problem has been confirmed. When this option is enabled, erroneous header names will still be accepted in responses, but the complete response will be captured in order to permit later analysis using the "show errors" request on the UNIX stats socket. Doing this also helps confirming that the issue has been solved. If this option has been enabled in a "defaults" section, it can be disabled in a specific instance by prepending the "no" keyword before it.
Use either all backup servers at a time or only the first one May be used in the following contexts: tcp, http, log
May be used in sections :
| defaults | frontend | listen | backend |
|---|---|---|---|
yes![]() | no![]() | yes![]() | yes![]() |
By default, the first operational backup server gets all traffic when normal servers are all down. Sometimes, it may be preferred to use multiple backups at once, because one will not be enough. When "option allbackups" is enabled, the load balancing will be performed among all backup servers when all normal ones are unavailable. The same load balancing algorithm will be used and the servers' weights will be respected. Thus, there will not be any priority order between the backup servers anymore. This option is mostly used with static server farms dedicated to return a "sorry" page when an application is completely offline. If this option has been enabled in a "defaults" section, it can be disabled in a specific instance by prepending the "no" keyword before it.
Analyze all server responses and block responses with cacheable cookies May be used in the following contexts: http
May be used in sections :
| defaults | frontend | listen | backend |
|---|---|---|---|
yes![]() | no![]() | yes![]() | yes![]() |
Some high-level frameworks set application cookies everywhere and do not always let enough control to the developer to manage how the responses should be cached. When a session cookie is returned on a cacheable object, there is a high risk of session crossing or stealing between users traversing the same caches. In some situations, it is better to block the response than to let some sensitive session information go in the wild. The option "checkcache" enables deep inspection of all server responses for strict compliance with HTTP specification in terms of cacheability. It carefully checks "Cache-control", "Pragma" and "Set-cookie" headers in server response to check if there's a risk of caching a cookie on a client-side proxy. When this option is enabled, the only responses which can be delivered to the client are : - all those without "Set-Cookie" header; - all those with a return code other than 200, 203, 204, 206, 300, 301, 404, 405, 410, 414, 501, provided that the server has not set a "Cache-control: public" header field; - all those that result from a request using a method other than GET, HEAD, OPTIONS, TRACE, provided that the server has not set a 'Cache-Control: public' header field; - those with a 'Pragma: no-cache' header - those with a 'Cache-control: private' header - those with a 'Cache-control: no-store' header - those with a 'Cache-control: max-age=0' header - those with a 'Cache-control: s-maxage=0' header - those with a 'Cache-control: no-cache' header - those with a 'Cache-control: no-cache="set-cookie"' header - those with a 'Cache-control: no-cache="set-cookie,' header (allowing other fields after set-cookie) If a response doesn't respect these requirements, then it will be blocked just as if it was from an "http-response deny" rule, with an "HTTP 502 bad gateway". The session state shows "PH--" meaning that the proxy blocked the response during headers processing. Additionally, an alert will be sent in the logs so that admins are informed that there's something to be fixed. Due to the high impact on the application, the application should be tested in depth with the option enabled before going to production. It is also a good practice to always activate it during tests, even if it is not used in production, as it will report potentially dangerous application behaviors. If this option has been enabled in a "defaults" section, it can be disabled in a specific instance by prepending the "no" keyword before it.
Enable or disable the sending of TCP keepalive packets on the client side May be used in the following contexts: tcp, http
May be used in sections :
| defaults | frontend | listen | backend |
|---|---|---|---|
yes![]() | yes![]() | yes![]() | no![]() |
When there is a firewall or any session-aware component between a client and a server, and when the protocol involves very long sessions with long idle periods (e.g. remote desktops), there is a risk that one of the intermediate components decides to expire a session which has remained idle for too long. Enabling socket-level TCP keep-alives makes the system regularly send packets to the other end of the connection, leaving it active. The delay between keep-alive probes is controlled by the system only and depends both on the operating system and its tuning parameters. It is important to understand that keep-alive packets are neither emitted nor received at the application level. It is only the network stacks which sees them. For this reason, even if one side of the proxy already uses keep-alives to maintain its connection alive, those keep-alive packets will not be forwarded to the other side of the proxy. Please note that this has nothing to do with HTTP keep-alive. Using option "clitcpka" enables the emission of TCP keep-alive probes on the client side of a connection, which should help when session expirations are noticed between HAProxy and a client. If this option has been enabled in a "defaults" section, it can be disabled in a specific instance by prepending the "no" keyword before it.
Enable continuous traffic statistics updates May be used in the following contexts: tcp, http
May be used in sections :
| defaults | frontend | listen | backend |
|---|---|---|---|
yes![]() | yes![]() | yes![]() | no![]() |
By default, counters used for statistics calculation are incremented only when a stream finishes. It works quite well when serving small objects, but with big ones (for example large images or archives) or with A/V streaming, a graph generated from HAProxy counters looks like a hedgehog. With this option enabled counters get incremented frequently along the stream, typically every 5 seconds, which is often enough to produce clean graphs. Recounting touches a hotpath directly so it is not not enabled by default, as it can cause a lot of wakeups for very large session counts and cause a small performance drop.
Enable or disable the implicit HTTP/2 upgrade from an HTTP/1.x client connection. May be used in the following contexts: http
May be used in sections :
| defaults | frontend | listen | backend |
|---|---|---|---|
yes![]() | yes![]() | yes![]() | no![]() |
By default, HAProxy is able to implicitly upgrade an HTTP/1.x client connection to an HTTP/2 connection if the first request it receives from a given HTTP connection matches the HTTP/2 connection preface (i.e. the string "PRI * HTTP/2.0\r\n\r\nSM\r\n\r\n"). This way, it is possible to support HTTP/1.x and HTTP/2 clients on a non-SSL connections. This option must be used to disable the implicit upgrade. Note this implicit upgrade is only supported for HTTP proxies, thus this option too. Note also it is possible to force the HTTP/2 on clear connections by specifying "proto h2" on the bind line. Finally, this option is applied on all bind lines. To disable implicit HTTP/2 upgrades for a specific bind line, it is possible to use "proto h1". If this option has been enabled in a "defaults" section, it can be disabled in a specific instance by prepending the "no" keyword before it.
Enable or disable logging of normal, successful connections May be used in the following contexts: tcp, http
May be used in sections :
| defaults | frontend | listen | backend |
|---|---|---|---|
yes![]() | yes![]() | yes![]() | no![]() |
There are large sites dealing with several thousand connections per second and for which logging is a major pain. Some of them are even forced to turn logs off and cannot debug production issues. Setting this option ensures that normal connections, those which experience no error, no timeout, no retry nor redispatch, will not be logged. This leaves disk space for anomalies. In HTTP mode, the response status code is checked and return codes 5xx will still be logged. It is strongly discouraged to use this option as most of the time, the key to complex issues is in the normal logs which will not be logged here. If you need to separate logs, see the "log-separate-errors" option instead.
Enable or disable logging of null connections May be used in the following contexts: tcp, http
May be used in sections :
| defaults | frontend | listen | backend |
|---|---|---|---|
yes![]() | yes![]() | yes![]() | no![]() |
In certain environments, there are components which will regularly connect to various systems to ensure that they are still alive. It can be the case from another load balancer as well as from monitoring systems. By default, even a simple port probe or scan will produce a log. If those connections pollute the logs too much, it is possible to enable option "dontlognull" to indicate that a connection on which no data has been transferred will not be logged, which typically corresponds to those probes. Note that errors will still be returned to the client and accounted for in the stats. If this is not what is desired, option http-ignore-probes can be used instead. It is generally recommended not to use this option in uncontrolled environments (e.g. internet), otherwise scans and other malicious activities would not be logged. If this option has been enabled in a "defaults" section, it can be disabled in a specific instance by prepending the "no" keyword before it.
Use external processes for server health checks May be used in the following contexts: tcp, http, log
May be used in sections :
| defaults | frontend | listen | backend |
|---|---|---|---|
yes![]() | no![]() | yes![]() | yes![]() |
It is possible to test the health of a server using an external command.
This is achieved by running the executable set using "external-check
command".
Requires the "external-check" global to be set.
Enable insertion of the rfc 7239 forwarded header in requests sent to servers May be used in the following contexts: http
May be used in sections :
| defaults | frontend | listen | backend |
|---|---|---|---|
yes![]() | no![]() | yes![]() | yes![]() |
<host_expr> optional argument to specify a custom sample expression
those result will be used as 'host' parameter value
<by_expr> optional argument to specify a custom sample expression
those result will be used as 'by' parameter nodename value
<for_expr> optional argument to specify a custom sample expression
those result will be used as 'for' parameter nodename value
<by_port_expr> optional argument to specify a custom sample expression
those result will be used as 'by' parameter nodeport value
<for_port_expr> optional argument to specify a custom sample expression
those result will be used as 'for' parameter nodeport value
Since HAProxy works in reverse-proxy mode, servers are losing some request
context (request origin: client ip address, protocol used...)
A common way to address this limitation is to use the well known
x-forward-for and x-forward-* friends to expose some of this context to the
underlying servers/applications.
While this use to work and is widely deployed, it is not officially supported
by the IETF and can be the root of some interoperability as well as security
issues.
To solve this, a new HTTP extension has been described by the IETF:
forwarded header (RFC7239).
More information here: https://www.rfc-editor.org/rfc/rfc7239.html
The use of this single header allow to convey numerous details
within the same header, and most importantly, fixes the proxy chaining
issue. (the rfc allows for multiple chained proxies to append their own
values to an already existing header).
This option may be specified in defaults, listen or backend section, but it
will be ignored for frontend sections.
Setting option forwarded without arguments results in using default implicit
behavior.
Default behavior enables proto parameter and injects original client ip.
The equivalent explicit/manual configuration would be:
option forwarded proto for
The keyword 'by' is used to enable 'by' parameter ("nodename") in
forwarded header. It allows to embed request proxy information.
'by' value will be set to proxy ip (destination address)
If not available (ie: UNIX listener), 'by' will be set to
"unknown".
The keyword 'by-expr' is used to enable 'by' parameter ("nodename") in
forwarded header. It allows to embed request proxy information.
'by' value will be set to the result of the sample expression
<by_expr>, if valid, otherwise it will be set to "unknown".
The keyword 'for' is used to enable 'for' parameter ("nodename") in
forwarded header. It allows to embed request client information.
'for' value will be set to client ip (source address)
If not available (ie: UNIX listener), 'for' will be set to
"unknown".
The keyword 'for-expr' is used to enable 'for' parameter ("nodename") in
forwarded header. It allows to embed request client information.
'for' value will be set to the result of the sample expression
<for_expr>, if valid, otherwise it will be set to "unknown".
The keyword 'by_port' is used to provide "nodeport" info to
'by' parameter. 'by_port' requires 'by' or 'by-expr' to be set or
it will be ignored.
"nodeport" will be set to proxy (destination) port if available,
otherwise it will be ignored.
The keyword 'by_port-expr' is used to provide "nodeport" info to
'by' parameter. 'by_port-expr' requires 'by' or 'by-expr' to be set or
it will be ignored.
"nodeport" will be set to the result of the sample expression
<by_port_expr>, if valid, otherwise it will be ignored.
The keyword 'for_port' is used to provide "nodeport" info to
'for' parameter. 'for_port' requires 'for' or 'for-expr' to be set or
it will be ignored.
"nodeport" will be set to client (source) port if available,
otherwise it will be ignored.
The keyword 'for_port-expr' is used to provide "nodeport" info to
'for' parameter. 'for_port-expr' requires 'for' or 'for-expr' to be set or
it will be ignored.
"nodeport" will be set to the result of the sample expression
<for_port_expr>, if valid, otherwise it will be ignored.
# Those servers want the ip address and protocol of the client request
# Resulting header would look like this:
# forwarded: proto=http;for=127.0.0.1
backend www_default
mode http
option forwarded
#equivalent to: option forwarded proto for
# Those servers want the requested host and hashed client ip address
# as well as client source port (you should use seed for xxh32 if ensuring
# ip privacy is a concern)
# Resulting header would look like this:
# forwarded: host="haproxy.org";for="_000000007F2F367E:60138"
backend www_host
mode http
option forwarded host for-expr src,xxh32,hex for_port
# Those servers want custom data in host, for and by parameters
# Resulting header would look like this:
# forwarded: host="host.com";by=_haproxy;for="[::1]:10"
backend www_custom
mode http
option forwarded host-expr str(host.com) by-expr str(_haproxy) for for_port-expr int(10)
# Those servers want random 'for' obfuscated identifiers for request
# tracing purposes while protecting sensitive IP information
# Resulting header would look like this:
# forwarded: for=_000000002B1F4D63
backend www_for_hide
mode http
option forwarded for-expr rand,hex
Enable insertion of the X-Forwarded-For header to requests sent to servers May be used in the following contexts: http
May be used in sections :
| defaults | frontend | listen | backend |
|---|---|---|---|
yes![]() | yes![]() | yes![]() | yes![]() |
<network> is an optional argument used to disable this option for sources
matching <network>
<name> an optional argument to specify a different "X-Forwarded-For"
header name.
Since HAProxy works in reverse-proxy mode, the servers see its IP address as their client address. This is sometimes annoying when the client's IP address is expected in server logs. To solve this problem, the well-known HTTP header "X-Forwarded-For" may be added by HAProxy to all requests sent to the server. This header contains a value representing the client's IP address. Since this header is always appended at the end of the existing header list, the server must be configured to always use the last occurrence of this header only. See the server's manual to find how to enable use of this standard header. Note that only the last occurrence of the header must be used, since it is really possible that the client has already brought one. The keyword "header" may be used to supply a different header name to replace the default "X-Forwarded-For". This can be useful where you might already have a "X-Forwarded-For" header from a different application (e.g. stunnel), and you need preserve it. Also if your backend server doesn't use the "X-Forwarded-For" header and requires different one (e.g. Zeus Web Servers require "X-Cluster-Client-IP"). Sometimes, a same HAProxy instance may be shared between a direct client access and a reverse-proxy access (for instance when an SSL reverse-proxy is used to decrypt HTTPS traffic). It is possible to disable the addition of the header for a known source address or network by adding the "except" keyword followed by the network address. In this case, any source IP matching the network will not cause an addition of this header. Most common uses are with private networks or 127.0.0.1. IPv4 and IPv6 are both supported. Alternatively, the keyword "if-none" states that the header will only be added if it is not present. This should only be used in perfectly trusted environment, as this might cause a security issue if headers reaching HAProxy are under the control of the end-user. This option may be specified either in the frontend or in the backend. If at least one of them uses it, the header will be added. Note that the backend's setting of the header subargument takes precedence over the frontend's if both are defined. In the case of the "if-none" argument, if at least one of the frontend or the backend does not specify it, it wants the addition to be mandatory, so it wins.
# Public HTTP address also used by stunnel on the same machine
frontend www
mode http
option forwardfor except 127.0.0.1 # stunnel already adds the header
# Those servers want the IP Address in X-Client
backend www
mode http
option forwardfor header X-Client
Enable or disable the case adjustment of HTTP/1 headers sent to bogus clients May be used in the following contexts: http
May be used in sections :
| defaults | frontend | listen | backend |
|---|---|---|---|
yes![]() | yes![]() | yes![]() | no![]() |
There is no standard case for header names because, as stated in RFC7230, they are case-insensitive. So applications must handle them in a case- insensitive manner. But some bogus applications violate the standards and erroneously rely on the cases most commonly used by browsers. This problem becomes critical with HTTP/2 because all header names must be exchanged in lower case, and HAProxy follows the same convention. All header names are sent in lower case to clients and servers, regardless of the HTTP version. When HAProxy receives an HTTP/1 response, its header names are converted to lower case and manipulated and sent this way to the clients. If a client is known to violate the HTTP standards and to fail to process a response coming from HAProxy, it is possible to transform the lower case header names to a different format when the response is formatted and sent to the client, by enabling this option and specifying the list of headers to be reformatted using the global directives "h1-case-adjust" or "h1-case-adjust-file". This must only be a temporary workaround for the time it takes the client to be fixed, because clients which require such workarounds might be vulnerable to content smuggling attacks and must absolutely be fixed. Please note that this option will not affect standards-compliant clients. If this option has been enabled in a "defaults" section, it can be disabled in a specific instance by prepending the "no" keyword before it.
Enable or disable the case adjustment of HTTP/1 headers sent to bogus servers May be used in the following contexts: http
May be used in sections :
| defaults | frontend | listen | backend |
|---|---|---|---|
yes![]() | no![]() | yes![]() | yes![]() |
There is no standard case for header names because, as stated in RFC7230, they are case-insensitive. So applications must handle them in a case- insensitive manner. But some bogus applications violate the standards and erroneously rely on the cases most commonly used by browsers. This problem becomes critical with HTTP/2 because all header names must be exchanged in lower case, and HAProxy follows the same convention. All header names are sent in lower case to clients and servers, regardless of the HTTP version. When HAProxy receives an HTTP/1 request, its header names are converted to lower case and manipulated and sent this way to the servers. If a server is known to violate the HTTP standards and to fail to process a request coming from HAProxy, it is possible to transform the lower case header names to a different format when the request is formatted and sent to the server, by enabling this option and specifying the list of headers to be reformatted using the global directives "h1-case-adjust" or "h1-case-adjust-file". This must only be a temporary workaround for the time it takes the server to be fixed, because servers which require such workarounds might be vulnerable to content smuggling attacks and must absolutely be fixed. Please note that this option will not affect standards-compliant servers. If this option has been enabled in a "defaults" section, it can be disabled in a specific instance by prepending the "no" keyword before it.
Enable or disable waiting for whole HTTP request body before proceeding May be used in the following contexts: http
May be used in sections :
| defaults | frontend | listen | backend |
|---|---|---|---|
yes![]() | yes![]() | yes![]() | yes![]() |
It is sometimes desirable to wait for the body of an HTTP request before taking a decision. This is what is being done by "balance url_param" for example. The first use case is to buffer requests from slow clients before connecting to the server. Another use case consists in taking the routing decision based on the request body's contents. This option placed in a frontend or backend forces the HTTP processing to wait until either the whole body is received or the request buffer is full. It can have undesired side effects with some applications abusing HTTP by expecting unbuffered transmissions between the frontend and the backend, so this should definitely not be used by default.
Drop the HTTP trailers from the request when sent to the server May be used in the following contexts: http
May be used in sections :
| defaults | frontend | listen | backend |
|---|---|---|---|
yes![]() | no![]() | no![]() | yes![]() |
When this option is enabled, any HTTP trailers found in a request will be dropped before sending it to the server. RFC9110#section-6.5.1 stated that trailer fields could be merged into the header fields. It should be done on purpose, but it may be a problem for some applications, especially if malicious clients hide sensitive header fields in the trailers part and some intermediaries merge them with headers with no specific checks. In that case, this option can be enabled on the backend to drop any trailer fields found in requests before sending them to the server. If this option has been enabled in a "defaults" section, it can be disabled in a specific instance by prepending the "no" keyword before it.
Drop the HTTP trailers from the response when sent to the client May be used in the following contexts: http
May be used in sections :
| defaults | frontend | listen | backend |
|---|---|---|---|
yes![]() | yes![]() | yes![]() | no![]() |
This option is similar to "option http-drop-request-trailers" but it must be used to drop trailer fields from responses before sending them to clients. If this option has been enabled in a "defaults" section, it can be disabled in a specific instance by prepending the "no" keyword before it.
Enable or disable logging of null connections and request timeouts May be used in the following contexts: http
May be used in sections :
| defaults | frontend | listen | backend |
|---|---|---|---|
yes![]() | yes![]() | yes![]() | no![]() |
Recently some browsers started to implement a "pre-connect" feature consisting in speculatively connecting to some recently visited web sites just in case the user would like to visit them. This results in many connections being established to web sites, which end up in 408 Request Timeout if the timeout strikes first, or 400 Bad Request when the browser decides to close them first. These ones pollute the log and feed the error counters. There was already "option dontlognull" but it's insufficient in this case. Instead, this option does the following things : - prevent any 400/408 message from being sent to the client if nothing was received over a connection before it was closed; - prevent any log from being emitted in this situation; - prevent any error counter from being incremented That way the empty connection is silently ignored. Note that it is better not to use this unless it is clear that it is needed, because it will hide real problems. The most common reason for not receiving a request and seeing a 408 is due to an MTU inconsistency between the client and an intermediary element such as a VPN, which blocks too large packets. These issues are generally seen with POST requests as well as GET with large cookies. The logs are often the only way to detect them. If this option has been enabled in a "defaults" section, it can be disabled in a specific instance by prepending the "no" keyword before it.
Enable or disable HTTP keep-alive from client to server for HTTP/1.x connections May be used in the following contexts: http
May be used in sections :
| defaults | frontend | listen | backend |
|---|---|---|---|
yes![]() | yes![]() | yes![]() | yes![]() |
By default HAProxy operates in keep-alive mode with regards to persistent HTTP/1.x connections: for each connection it processes each request and response, and leaves the connection idle on both sides. This mode may be changed by several options such as "option http-server-close" or "option httpclose". This option allows to set back the keep-alive mode, which can be useful when another mode was used in a defaults section. Setting "option http-keep-alive" enables HTTP keep-alive mode on the client- and server- sides. This provides the lowest latency on the client side (slow network) and the fastest session reuse on the server side at the expense of maintaining idle connections to the servers. In general, it is possible with this option to achieve approximately twice the request rate that the "http-server-close" option achieves on small objects. There are mainly two situations where this option may be useful : - when the server is non-HTTP compliant and authenticates the connection instead of requests (e.g. NTLM authentication) - when the cost of establishing the connection to the server is significant compared to the cost of retrieving the associated object from the server. This last case can happen when the server is a fast static server of cache. At the moment, logs will not indicate whether requests came from the same session or not. The accept date reported in the logs corresponds to the end of the previous request, and the request time corresponds to the time spent waiting for a new request. The keep-alive request time is still bound to the timeout defined by "timeout http-keep-alive" or "timeout http-request" if not set. This option disables and replaces any previous "option httpclose" or "option http-server-close".
Instruct the system to favor low interactive delays over performance in HTTP May be used in the following contexts: http
May be used in sections :
| defaults | frontend | listen | backend |
|---|---|---|---|
yes![]() | yes![]() | yes![]() | yes![]() |
In HTTP, each payload is unidirectional and has no notion of interactivity. Any agent is expected to queue data somewhat for a reasonably low delay. There are some very rare server-to-server applications that abuse the HTTP protocol and expect the payload phase to be highly interactive, with many interleaved data chunks in both directions within a single request. This is absolutely not supported by the HTTP specification and will not work across most proxies or servers. When such applications attempt to do this through HAProxy, it works but they will experience high delays due to the network optimizations which favor performance by instructing the system to wait for enough data to be available in order to only send full packets. Typical delays are around 200 ms per round trip. Note that this only happens with abnormal uses. Normal uses such as CONNECT requests nor WebSockets are not affected. When "option http-no-delay" is present in either the frontend or the backend used by a connection, all such optimizations will be disabled in order to make the exchanges as fast as possible. Of course this offers no guarantee on the functionality, as it may break at any other place. But if it works via HAProxy, it will work as fast as possible. This option should never be used by default, and should never be used at all unless such a buggy application is discovered. The impact of using this option is an increase of bandwidth usage and CPU usage, which may significantly lower performance in high latency environments.
Define whether HAProxy will announce keepalive for HTTP/1.x connection to the server or not May be used in the following contexts: http
May be used in sections :
| defaults | frontend | listen | backend |
|---|---|---|---|
yes![]() | no![]() | yes![]() | yes![]() |
When running with "option http-server-close" or "option httpclose", HAProxy adds a "Connection: close" header to the HTTP/1.x request forwarded to the server. Unfortunately, when some servers see this header, they automatically refrain from using the chunked encoding for responses of unknown length, while this is totally unrelated. The effect is that a client or a cache could receive an incomplete response without being aware of it, and consider the response complete. By setting "option http-pretend-keepalive", HAProxy will make the server believe it will keep the connection alive. The server will then not fall back to the abnormal undesired above. When HAProxy gets the whole response, it will close the connection with the server just as it would do with the "option httpclose". That way the client gets a normal response and the connection is correctly closed on the server side. It is recommended not to enable this option by default, because most servers will more efficiently close the connection themselves after the last packet, and release its buffers slightly earlier. Also, the added packet on the network could slightly reduce the overall peak performance. However it is worth noting that when this option is enabled, HAProxy will have slightly less work to do. So if HAProxy is the bottleneck on the whole architecture, enabling this option might save a few CPU cycles. This option may be set in backend and listen sections. Using it in a frontend section will be ignored and a warning will be reported during startup. It is a backend related option, so there is no real reason to set it on a frontend. If this option has been enabled in a "defaults" section, it can be disabled in a specific instance by prepending the "no" keyword before it.
Set HAProxy policy about HTTP request header names containing characters outside the "[a-zA-Z0-9-]" charset May be used in the following contexts: http
May be used in sections :
| defaults | frontend | listen | backend |
|---|---|---|---|
yes![]() | yes![]() | yes![]() | yes![]() |
preserve disable the filtering. It is the default mode for HTTP proxies
with no FastCGI application configured.
delete remove request headers with a name containing a character
outside the "[a-zA-Z0-9-]" charset. It is the default mode for
HTTP backends with a configured FastCGI application.
reject reject the request with a 403-Forbidden response if it contains a
header name with a character outside the "[a-zA-Z0-9-]" charset.
This option may be used to restrict the request header names to alphanumeric
and hyphen characters ([A-Za-z0-9-]). This may be mandatory to interoperate
with non-HTTP compliant servers that fail to handle some characters in header
names. It may also be mandatory for FastCGI applications because all
non-alphanumeric characters in header names are replaced by an underscore
('_'). Thus, it is easily possible to mix up header names and bypass some
rules. For instance, "X-Forwarded-For" and "X_Forwarded-For" headers are both
converted to "HTTP_X_FORWARDED_FOR" in FastCGI.
Note this option is evaluated per proxy and after the http-request rules
evaluation.
Enable or disable HTTP/1.x connection closing on the server side May be used in the following contexts: http
May be used in sections :
| defaults | frontend | listen | backend |
|---|---|---|---|
yes![]() | yes![]() | yes![]() | yes![]() |
By default HAProxy operates in keep-alive mode with regards to persistent HTTP/1.x connections: for each connection it processes each request and response, and leaves the connection idle on both sides. This mode may be changed by several options such as "option http-server-close" or "option httpclose". Setting "option http-server-close" enables HTTP connection-close mode on the server side while keeping the ability to support HTTP keep-alive and pipelining on the client side. This provides the lowest latency on the client side (slow network) and the fastest session reuse on the server side to save server resources, similarly to "option httpclose". It also permits non-keepalive capable servers to be served in keep-alive mode to the clients if they conform to the requirements of RFC7230. Please note that some servers do not always conform to those requirements when they see "Connection: close" in the request. The effect will be that keep-alive will never be used. A workaround consists in enabling "option http-pretend-keepalive". At the moment, logs will not indicate whether requests came from the same session or not. The accept date reported in the logs corresponds to the end of the previous request, and the request time corresponds to the time spent waiting for a new request. The keep-alive request time is still bound to the timeout defined by "timeout http-keep-alive" or "timeout http-request" if not set. This option may be set both in a frontend and in a backend. It is enabled if at least one of the frontend or backend holding a connection has it enabled. It disables and replaces any previous "option httpclose" or "option http-keep-alive". Please check section 4 ("Proxies") to see how this option combines with others when frontend and backend options differ. If this option has been enabled in a "defaults" section, it can be disabled in a specific instance by prepending the "no" keyword before it.
Make use of non-standard Proxy-Connection header instead of Connection May be used in the following contexts: http
May be used in sections :
| defaults | frontend | listen | backend |
|---|---|---|---|
yes![]() | yes![]() | yes![]() | no![]() |
While RFC7230 explicitly states that HTTP/1.1 agents must use the Connection header to indicate their wish of persistent or non-persistent connections, both browsers and proxies ignore this header for proxied connections and make use of the undocumented, non-standard Proxy-Connection header instead. The issue begins when trying to put a load balancer between browsers and such proxies, because there will be a difference between what HAProxy understands and what the client and the proxy agree on. By setting this option in a frontend, HAProxy can automatically switch to use that non-standard header if it sees proxied requests. A proxied request is defined here as one where the URI begins with neither a '/' nor a '*'. This is incompatible with the HTTP tunnel mode. Note that this option can only be specified in a frontend and will affect the request along its whole life. Also, when this option is set, a request which requires authentication will automatically switch to use proxy authentication headers if it is itself a proxied request. That makes it possible to check or enforce authentication in front of an existing proxy. This option should normally never be used, except in front of a proxy.
Enables HTTP protocol to check on the servers health May be used in the following contexts: tcp, http
May be used in sections :
| defaults | frontend | listen | backend |
|---|---|---|---|
yes![]() | no![]() | yes![]() | yes![]() |
<method> is the optional HTTP method used with the requests. When not set,
the "OPTIONS" method is used, as it generally requires low server
processing and is easy to filter out from the logs. Any method
may be used, though it is not recommended to invent non-standard
ones.
<uri> is the URI referenced in the HTTP requests. It defaults to " / "
which is accessible by default on almost any server, but may be
changed to any other URI. Query strings are permitted.
<version> is the optional HTTP version string. It defaults to "HTTP/1.0"
but some servers might behave incorrectly in HTTP 1.0, so turning
it to HTTP/1.1 may sometimes help. Note that the Host field is
mandatory in HTTP/1.1.
<host> is the optional HTTP Host header value. It is not set by default.
It is a log-format string.
By default, server health checks only consist in trying to establish a TCP connection. When "option httpchk" is specified, a complete HTTP request is sent once the TCP connection is established, and responses 2xx and 3xx are considered valid, while all other ones indicate a server failure, including the lack of any response. Combined with "http-check" directives, it is possible to customize the request sent during the HTTP health checks or the matching rules on the response. It is also possible to configure a send/expect sequence, just like with the directive "tcp-check" for TCP health checks. The server configuration is used by default to open connections to perform HTTP health checks. By it is also possible to overwrite server parameters using "http-check connect" rules. "httpchk" option does not necessarily require an HTTP backend, it also works with plain TCP backends. This is particularly useful to check simple scripts bound to some dedicated ports using the inetd daemon. However, it will always internally relies on an HTX multiplexer. Thus, it means the request formatting and the response parsing will be strict.
# Relay HTTPS traffic to Apache instance and check service availability
# using HTTP request "OPTIONS * HTTP/1.1" on port 80.
backend https_relay
mode tcp
option httpchk OPTIONS * HTTP/1.1
http-check send hdr Host www
server apache1 192.168.1.1:443 check port 80
Enable or disable HTTP/1.x connection closing May be used in the following contexts: http
May be used in sections :
| defaults | frontend | listen | backend |
|---|---|---|---|
yes![]() | yes![]() | yes![]() | yes![]() |
By default HAProxy operates in keep-alive mode with regards to persistent HTTP/1.x connections: for each connection it processes each request and response, and leaves the connection idle on both sides. This mode may be changed by several options such as "option http-server-close" or "option httpclose". If "option httpclose" is set, HAProxy will close the client or the server connection, depending where the option is set. The frontend is considered for client connections while the backend is considered for server ones. If the option is set on a listener, it is applied both on client and server connections. It will check if a "Connection: close" header is already set in each direction, and will add one if missing. This option may also be combined with "option http-pretend-keepalive", which will disable sending of the "Connection: close" request header, but will still cause the connection to be closed once the whole response is received. It disables and replaces any previous "option http-server-close" or "option http-keep-alive". If this option has been enabled in a "defaults" section, it can be disabled in a specific instance by prepending the "no" keyword before it.
Enable logging of HTTP request, stream state and timers May be used in the following contexts: http
May be used in sections :
| defaults | frontend | listen | backend |
|---|---|---|---|
yes![]() | yes![]() | yes![]() | no![]() |
clf if the "clf" argument is added, then the output format will be
the CLF format instead of HAProxy's default HTTP format. You can
use this when you need to feed HAProxy's logs through a specific
log analyzer which only support the CLF format and which is not
extensible.
By default, the log output format is very poor, as it only contains the source and destination addresses, and the instance name. By specifying "option httplog", each log line turns into a much richer format including, but not limited to, the HTTP request, the connection timers, the stream status, the connections numbers, the captured headers and cookies, the frontend, backend and server name, and of course the source address and ports. Specifying only "option httplog" will automatically clear the 'clf' mode if it was set by default. "option httplog" overrides any previous "log-format" directive.
Enable logging of HTTPS request, stream state and timers May be used in the following contexts: http
May be used in sections :
| defaults | frontend | listen | backend |
|---|---|---|---|
yes![]() | yes![]() | yes![]() | no![]() |
By default, the log output format is very poor, as it only contains the source and destination addresses, and the instance name. By specifying "option httpslog", each log line turns into a much richer format including, but not limited to, the HTTP request, the connection timers, the stream status, the connections numbers, the captured headers and cookies, the frontend, backend and server name, the SSL certificate verification and SSL handshake statuses, and of course the source address and ports. "option httpslog" overrides any previous "log-format" directive.
Avoid closing idle frontend connections if a soft stop is in progress May be used in the following contexts: http
May be used in sections :
| defaults | frontend | listen | backend |
|---|---|---|---|
yes![]() | yes![]() | yes![]() | no![]() |
By default, idle connections will be closed during a soft stop. In some environments, a client talking to the proxy may have prepared some idle connections in order to send requests later. If there is no proper retry on write errors, this can result in errors while haproxy is reloading. Even though a proper implementation should retry on connection/write errors, this option was introduced to support backwards compatibility with haproxy prior to version 2.4. Indeed before v2.4, haproxy used to wait for a last request and response to add a "connection: close" header before closing, thus notifying the client that the connection would not be reusable. In a real life example, this behavior was seen in AWS using the ALB in front of a haproxy. The end result was ALB sending 502 during haproxy reloads. Users are warned that using this option may increase the number of old processes if connections remain idle for too long. Adjusting the client timeouts and/or the "hard-stop-after" parameter accordingly might be needed in case of frequent reloads.
Enable or disable independent timeout processing for both directions May be used in the following contexts: tcp, http
May be used in sections :
| defaults | frontend | listen | backend |
|---|---|---|---|
yes![]() | yes![]() | yes![]() | yes![]() |
By default, when data is sent over a socket, both the write timeout and the read timeout for that socket are refreshed, because we consider that there is activity on that socket, and we have no other means of guessing if we should receive data or not. While this default behavior is desirable for almost all applications, there exists a situation where it is desirable to disable it, and only refresh the read timeout if there are incoming data. This happens on streams with large timeouts and low amounts of exchanged data such as telnet session. If the server suddenly disappears, the output data accumulates in the system's socket buffers, both timeouts are correctly refreshed, and there is no way to know the server does not receive them, so we don't timeout. However, when the underlying protocol always echoes sent data, it would be enough by itself to detect the issue using the read timeout. Note that this problem does not happen with more verbose protocols because data won't accumulate long in the socket buffers. When this option is set on the frontend, it will disable read timeout updates on data sent to the client. There probably is little use of this case. When the option is set on the backend, it will disable read timeout updates on data sent to the server. Doing so will typically break large HTTP posts from slow lines, so use it with caution.
Use LDAPv3 health checks for server testing May be used in the following contexts: tcp
May be used in sections :
| defaults | frontend | listen | backend |
|---|---|---|---|
yes![]() | no![]() | yes![]() | yes![]() |
It is possible to test that the server correctly talks LDAPv3 instead of just testing that it accepts the TCP connection. When this option is set, an LDAPv3 anonymous simple bind message is sent to the server, and the response is analyzed to find an LDAPv3 bind response message. The server is considered valid only when the LDAP response contains success resultCode (http://tools.ietf.org/html/rfc4511#section-4.1.9). Logging of bind requests is server dependent see your documentation how to configure it.
option ldap-check
Enable or disable logging of health checks status updates May be used in the following contexts: tcp, http, log
May be used in sections :
| defaults | frontend | listen | backend |
|---|---|---|---|
yes![]() | no![]() | yes![]() | yes![]() |
By default, failed health check are logged if server is UP and successful health checks are logged if server is DOWN, so the amount of additional information is limited. When this option is enabled, any change of the health check status or to the server's health will be logged, so that it becomes possible to know that a server was failing occasional checks before crashing, or exactly when it failed to respond a valid HTTP status, then when the port started to reject connections, then when the server stopped responding at all. Note that status changes not caused by health checks (e.g. enable/disable on the CLI) are intentionally not logged by this option.
Change log level for non-completely successful connections May be used in the following contexts: tcp, http
May be used in sections :
| defaults | frontend | listen | backend |
|---|---|---|---|
yes![]() | yes![]() | yes![]() | no![]() |
Sometimes looking for errors in logs is not easy. This option makes HAProxy raise the level of logs containing potentially interesting information such as errors, timeouts, retries, redispatches, or HTTP status codes 5xx. The level changes from "info" to "err". This makes it possible to log them separately to a different file with most syslog daemons. Be careful not to remove them from the original file, otherwise you would lose ordering which provides very important information. Using this option, large sites dealing with several thousand connections per second may log normal traffic to a rotating buffer and only archive smaller error logs.
Enable or disable early logging. May be used in the following contexts: tcp, http
May be used in sections :
| defaults | frontend | listen | backend |
|---|---|---|---|
yes![]() | yes![]() | yes![]() | no![]() |
By default, logs are emitted when all the log format aliases and sample fetches used in the definition of the log-format string return a value, or when the stream is terminated. This allows the built in log-format strings to account for the transfer time, or the number of bytes in log messages. When handling long lived connections such as large file transfers or RDP, it may take a while for the request or connection to appear in the logs. Using "option logasap", the log message is created as soon as the server connection is established in mode tcp, or as soon as the server sends the complete headers in mode http. Missing information in the logs will be the total number of bytes which will only indicate the amount of data transferred before the message was created and the total time which will not take the remainder of the connection life or transfer time into account. For the case of HTTP, it is good practice to capture the Content-Length response header so that the logs at least indicate how many bytes are expected to be transferred.
listen http_proxy 0.0.0.0:80
mode http
option httplog
option logasap
log 192.168.2.200 local3
>>> Feb 6 12:14:14 localhost \
haproxy[14389]: 10.0.1.2:33317 [06/Feb/2009:12:14:14.655] http-in \
static/srv1 9/10/7/14/+30 200 +243 - - ---- 3/1/1/1/0 1/0 \
"GET /image.iso HTTP/1.0"
Use MySQL health checks for server testing May be used in the following contexts: tcp
May be used in sections :
| defaults | frontend | listen | backend |
|---|---|---|---|
yes![]() | no![]() | yes![]() | yes![]() |
<username> This is the username which will be used when connecting to MySQL
server.
post-41 Send post v4.1 client compatible checks (the default)
pre-41 Send pre v4.1 client compatible checks
post-80 Send post v8.0 client compatible checks with CLIENT_PLUGIN_AUTH
capability set and mysql_native_password as the authentication
plugin. Use this option when connecting to MySQL 8.0+ servers
where the health check user is created with mysql_native_password
authentication. Example:
CREATE USER 'haproxy'@'%' IDENTIFIED WITH mysql_native_password BY '';
If you specify a username, the check consists of sending two MySQL packet,
one Client Authentication packet, and one QUIT packet, to correctly close
MySQL session. We then parse the MySQL Handshake Initialization packet and/or
Error packet. It is a basic but useful test which does not produce error nor
aborted connect on the server. However, it requires an unlocked authorised
user without a password. To create a basic limited user in MySQL with
optional resource limits:
CREATE USER '<username>'@'<ip_of_haproxy|network_of_haproxy/netmask>'
/*!50701 WITH MAX_QUERIES_PER_HOUR 1 MAX_UPDATES_PER_HOUR 0 */
/*M!100201 MAX_STATEMENT_TIME 0.0001 */;
If you don't specify a username (it is deprecated and not recommended), the
check only consists in parsing the Mysql Handshake Initialization packet or
Error packet, we don't send anything in this mode. It was reported that it
can generate lockout if check is too frequent and/or if there is not enough
traffic. In fact, you need in this case to check MySQL "max_connect_errors"
value as if a connection is established successfully within fewer than MySQL
"max_connect_errors" attempts after a previous connection was interrupted,
the error count for the host is cleared to zero. If HAProxy's server get
blocked, the "FLUSH HOSTS" statement is the only way to unblock it.
Remember that this does not check database presence nor database consistency.
To do this, you can use an external check with xinetd for example.
The check requires MySQL >=3.22, for older version, please use TCP check.
Most often, an incoming MySQL server needs to see the client's IP address for
various purposes, including IP privilege matching and connection logging.
When possible, it is often wise to masquerade the client's IP address when
connecting to the server using the "usesrc" argument of the "source" keyword,
which requires the transparent proxy feature to be compiled in, and the MySQL
server to route the client via the machine hosting HAProxy.
Enable or disable immediate session resource cleaning after close May be used in the following contexts: tcp, http, log
May be used in sections :
| defaults | frontend | listen | backend |
|---|---|---|---|
yes![]() | yes![]() | yes![]() | yes![]() |
When clients or servers abort connections in a dirty way (e.g. they are physically disconnected), the session timeouts triggers and the session is closed. But it will remain in FIN_WAIT1 state for some time in the system, using some resources and possibly limiting the ability to establish newer connections. When this happens, it is possible to activate "option nolinger" which forces the system to immediately remove any socket's pending data on close. Thus, a TCP RST is emitted, any pending data are truncated, and the session is instantly purged from the system's tables. The generally visible effect for a client is that responses are truncated if the close happens with a last block of data (e.g. on a redirect or error response). On the server side, it may help release the source ports immediately when forwarding a client aborts in tunnels. In both cases, TCP resets are emitted and given that the session is instantly destroyed, there will be no retransmit. On a lossy network this can increase problems, especially when there is a firewall on the lossy side, because the firewall might see and process the reset (hence purge its session) and block any further traffic for this session,, including retransmits from the other side. So if the other side doesn't receive it, it will never receive any RST again, and the firewall might log many blocked packets. For all these reasons, it is strongly recommended NOT to use this option, unless absolutely needed as a last resort. In most situations, using the "client-fin" or "server-fin" timeouts achieves similar results with a more reliable behavior. On Linux it's also possible to use the "tcp-ut" bind or server setting. This option may be used both on frontends and backends, depending on the side where it is required. Use it on the frontend for clients, and on the backend for servers. While this option is technically supported in "defaults" sections, it must really not be used there as it risks to accidentally propagate to sections that must no use it and to cause problems there. If this option has been enabled in a "defaults" section, it can be disabled in a specific instance by prepending the "no" keyword before it.
Enable insertion of the X-Original-To header to requests sent to servers May be used in the following contexts: http
May be used in sections :
| defaults | frontend | listen | backend |
|---|---|---|---|
yes![]() | yes![]() | yes![]() | yes![]() |
<network> is an optional argument used to disable this option for sources
matching <network>
<name> an optional argument to specify a different "X-Original-To"
header name.
Since HAProxy can work in transparent mode, every request from a client can be redirected to the proxy and HAProxy itself can proxy every request to a complex SQUID environment and the destination host from SO_ORIGINAL_DST will be lost. This is annoying when you want access rules based on destination ip addresses. To solve this problem, a new HTTP header "X-Original-To" may be added by HAProxy to all requests sent to the server. This header contains a value representing the original destination IP address. Since this must be configured to always use the last occurrence of this header only. Note that only the last occurrence of the header must be used, since it is really possible that the client has already brought one. The keyword "header" may be used to supply a different header name to replace the default "X-Original-To". This can be useful where you might already have a "X-Original-To" header from a different application, and you need preserve it. Also if your backend server doesn't use the "X-Original-To" header and requires different one. Sometimes, a same HAProxy instance may be shared between a direct client access and a reverse-proxy access (for instance when an SSL reverse-proxy is used to decrypt HTTPS traffic). It is possible to disable the addition of the header for a known destination address or network by adding the "except" keyword followed by the network address. In this case, any destination IP matching the network will not cause an addition of this header. Most common uses are with private networks or 127.0.0.1. IPv4 and IPv6 are both supported. This option may be specified either in the frontend or in the backend. If at least one of them uses it, the header will be added. Note that the backend's setting of the header subargument takes precedence over the frontend's if both are defined.
# Original Destination address
frontend www
mode http
option originalto except 127.0.0.1
# Those servers want the IP Address in X-Client-Dst
backend www
mode http
option originalto header X-Client-Dst
Enable or disable forced persistence on down servers May be used in the following contexts: tcp, http
May be used in sections :
| defaults | frontend | listen | backend |
|---|---|---|---|
yes![]() | no![]() | yes![]() | yes![]() |
When an HTTP request reaches a backend with a cookie which references a dead server, by default it is redispatched to another server. It is possible to force the request to be sent to the dead server first using "option persist" if absolutely needed. A common use case is when servers are under extreme load and spend their time flapping. In this case, the users would still be directed to the server they opened the session on, in the hope they would be correctly served. It is recommended to use "option redispatch" in conjunction with this option so that in the event it would not be possible to connect to the server at all (server definitely dead), the client would finally be redirected to another valid server. If this option has been enabled in a "defaults" section, it can be disabled in a specific instance by prepending the "no" keyword before it.
Use PostgreSQL health checks for server testing May be used in the following contexts: tcp
May be used in sections :
| defaults | frontend | listen | backend |
|---|---|---|---|
yes![]() | no![]() | yes![]() | yes![]() |
<username> This is the username which will be used when connecting to
PostgreSQL server.
The check sends a PostgreSQL StartupMessage and waits for either Authentication request or ErrorResponse message. It is a basic but useful test which does not produce error nor aborted connect on the server. This check is identical with the "mysql-check".
Allow multiple load balanced requests to remain on the same server May be used in the following contexts: tcp, http
May be used in sections :
| defaults | frontend | listen | backend |
|---|---|---|---|
yes![]() | no![]() | yes![]() | yes![]() |
When the load balancing algorithm in use is not deterministic, and a previous request was sent to a server to which HAProxy still holds a connection, it is sometimes desirable that subsequent requests on a same session go to the same server as much as possible. Note that this is different from persistence, as we only indicate a preference which HAProxy tries to apply without any form of warranty. The real use is for keep-alive connections sent to servers. When this option is used, HAProxy will try to reuse the same connection that is attached to the server instead of rebalancing to another server, causing a close of the connection. This can make sense for static file servers. It does not make much sense to use this in combination with hashing algorithms. Note, HAProxy already automatically tries to stick to a server which sends a 401 or to a proxy which sends a 407 (authentication required), when the load balancing algorithm is not deterministic. This is mandatory for use with the broken NTLM authentication challenge, and significantly helps in troubleshooting some faulty applications. Option prefer-last-server might be desirable in these environments as well, to avoid redistributing the traffic after every other response. It may be useful to precise here, which load balancing algorithms are considered deterministic. Deterministic algorithms will always select the same server for a given client data, assuming the set of available servers has not changed. In general, deterministic algorithms involve hashing or lookups on the incoming requests to choose the target server. However, this is not always the case; "static-rr", for example, can be also considered as deterministic because the server choice is based on the server's static weight, making the selection predictable. "sticky" algorithm provides deterministic routing for the returning clients. As for non-deterministic algorithms, these algorithms select a server based on dynamic server state or simple rotation, so two consecutive requests are not guaranteed to land on the same server. option prefer-last-server is designed specifically for these. roundrobin, leastconn are examples of such algorithms. If this option has been enabled in a "defaults" section, it can be disabled in a specific instance by prepending the "no" keyword before it.
Enable or disable session redistribution in case of connection failure May be used in the following contexts: tcp, http
May be used in sections :
| defaults | frontend | listen | backend |
|---|---|---|---|
yes![]() | no![]() | yes![]() | yes![]() |
<interval> The optional integer value that controls how often redispatches
occur when retrying connections. Positive value P indicates a
redispatch is desired on every Pth retry, and negative value
N indicate a redispatch is desired on the Nth retry prior to the
last retry. For example, the default of -1 preserves the
historical behavior of redispatching on the last retry, a
positive value of 1 would indicate a redispatch on every retry,
and a positive value of 3 would indicate a redispatch on every
third retry. You can disable redispatches with a value of 0.
In HTTP mode, if a server designated by a cookie is down, clients may definitely stick to it, for example when using "option persist" or "force-persist", because they cannot flush the cookie, so they will not be able to access the service anymore. Specifying "option redispatch" will allow the proxy to break cookie or consistent hash based persistence and redistribute them to a working server. Active servers are selected from a subset of the list of available servers. Active servers that are not down or in maintenance (i.e., whose health is not checked or that have been checked as "up"), are selected in the following order: 1. Any active, non-backup server, if any, or, 2. If the "allbackups" option is not set, the first backup server in the list, or 3. If the "allbackups" option is set, any backup server. When a retry occurs, HAProxy tries to select another server than the last one. The new server is selected from the current list of servers. Sometimes, if the list is updated between retries (e.g., if numerous retries occur and last longer than the time needed to check that a server is down, remove it from the list and fall back on the list of backup servers), connections may be redirected to a backup server, though. It also allows to retry connections to another server in case of multiple connection failures. Of course, it requires having "retries" set to a nonzero value. If this option has been enabled in a "defaults" section, it can be disabled in a specific instance by prepending the "no" keyword before it.
Use redis health checks for server testing May be used in the following contexts: tcp
May be used in sections :
| defaults | frontend | listen | backend |
|---|---|---|---|
yes![]() | no![]() | yes![]() | yes![]() |
It is possible to test that the server correctly talks REDIS protocol instead of just testing that it accepts the TCP connection. When this option is set, a PING redis command is sent to the server, and the response is analyzed to find the "+PONG" response message.
option redis-check
Use SMTP health checks for server testing May be used in the following contexts: tcp
May be used in sections :
| defaults | frontend | listen | backend |
|---|---|---|---|
yes![]() | no![]() | yes![]() | yes![]() |
<hello> is an optional argument. It is the "hello" command to use. It can
be either "HELO" (for SMTP) or "EHLO" (for ESMTP). All other
values will be turned into the default command ("HELO").
<domain> is the domain name to present to the server. It may only be
specified (and is mandatory) if the hello command has been
specified. By default, "localhost" is used.
When "option smtpchk" is set, the health checks will consist in TCP connections followed by an SMTP command. By default, this command is "HELO localhost". The server's return code is analyzed and only return codes starting with a "2" will be considered as valid. All other responses, including a lack of response will constitute an error and will indicate a dead server. This test is meant to be used with SMTP servers or relays. Depending on the request, it is possible that some servers do not log each connection attempt, so you may want to experiment to improve the behavior. Using telnet on port 25 is often easier than adjusting the configuration. Most often, an incoming SMTP server needs to see the client's IP address for various purposes, including spam filtering, anti-spoofing and logging. When possible, it is often wise to masquerade the client's IP address when connecting to the server using the "usesrc" argument of the "source" keyword, which requires the transparent proxy feature to be compiled in.
option smtpchk HELO mydomain.org
Enable or disable collecting & providing separate statistics for each socket. May be used in the following contexts: tcp, http
May be used in sections :
| defaults | frontend | listen | backend |
|---|---|---|---|
yes![]() | yes![]() | yes![]() | no![]() |
Enable or disable automatic kernel acceleration on sockets in both directions May be used in the following contexts: tcp, http
May be used in sections :
| defaults | frontend | listen | backend |
|---|---|---|---|
yes![]() | yes![]() | yes![]() | yes![]() |
When this option is enabled either on a frontend or on a backend, HAProxy will automatically evaluate the opportunity to use kernel tcp splicing to forward data between the client and the server, in either direction. HAProxy uses heuristics to estimate if kernel splicing might improve performance or not. Both directions are handled independently. Note that the heuristics used are not much aggressive in order to limit excessive use of splicing. This option requires splicing to be enabled at compile time, and may be globally disabled with the global option "nosplice". Since splice uses pipes, using it requires that there are enough spare pipes. Important note: kernel-based TCP splicing is a Linux-specific feature which first appeared in kernel 2.6.25. It offers kernel-based acceleration to transfer data between sockets without copying these data to user-space, thus providing noticeable performance gains and CPU cycles savings. Since many early implementations are buggy, corrupt data and/or are inefficient, this feature is not enabled by default, and it should be used with extreme care. While it is not possible to detect the correctness of an implementation, 2.6.29 is the first version offering a properly working implementation. In case of doubt, splicing may be globally disabled using the global "nosplice" keyword.
option splice-auto
If this option has been enabled in a "defaults" section, it can be disabled in a specific instance by prepending the "no" keyword before it.
Enable or disable automatic kernel acceleration on sockets for requests May be used in the following contexts: tcp, http
May be used in sections :
| defaults | frontend | listen | backend |
|---|---|---|---|
yes![]() | yes![]() | yes![]() | yes![]() |
When this option is enabled either on a frontend or on a backend, HAProxy will use kernel tcp splicing whenever possible to forward data going from the client to the server. It might still use the recv/send scheme if there are no spare pipes left. This option requires splicing to be enabled at compile time, and may be globally disabled with the global option "nosplice". Since splice uses pipes, using it requires that there are enough spare pipes. Important note: see "option splice-auto" for usage limitations.
option splice-request
If this option has been enabled in a "defaults" section, it can be disabled in a specific instance by prepending the "no" keyword before it.
Enable or disable automatic kernel acceleration on sockets for responses May be used in the following contexts: tcp, http
May be used in sections :
| defaults | frontend | listen | backend |
|---|---|---|---|
yes![]() | yes![]() | yes![]() | yes![]() |
When this option is enabled either on a frontend or on a backend, HAProxy will use kernel tcp splicing whenever possible to forward data going from the server to the client. It might still use the recv/send scheme if there are no spare pipes left. This option requires splicing to be enabled at compile time, and may be globally disabled with the global option "nosplice". Since splice uses pipes, using it requires that there are enough spare pipes. Important note: see "option splice-auto" for usage limitations.
option splice-response
If this option has been enabled in a "defaults" section, it can be disabled in a specific instance by prepending the "no" keyword before it.
Use SPOP health checks for server testing May be used in the following contexts: tcp
May be used in sections :
| defaults | frontend | listen | backend |
|---|---|---|---|
yes![]() | no![]() | yes![]() | yes![]() |
It is possible to test that the server correctly talks SPOP protocol instead of just testing that it accepts the TCP connection. When this option is set, a HELLO handshake is performed between HAProxy and the server, and the response is analyzed to check no error is reported.
option spop-check
Enable or disable the sending of TCP keepalive packets on the server side May be used in the following contexts: tcp, http, log
May be used in sections :
| defaults | frontend | listen | backend |
|---|---|---|---|
yes![]() | no![]() | yes![]() | yes![]() |
When there is a firewall or any session-aware component between a client and a server, and when the protocol involves very long sessions with long idle periods (e.g. remote desktops), there is a risk that one of the intermediate components decides to expire a session which has remained idle for too long. Enabling socket-level TCP keep-alives makes the system regularly send packets to the other end of the connection, leaving it active. The delay between keep-alive probes is controlled by the system only and depends both on the operating system and its tuning parameters. It is important to understand that keep-alive packets are neither emitted nor received at the application level. It is only the network stacks which sees them. For this reason, even if one side of the proxy already uses keep-alives to maintain its connection alive, those keep-alive packets will not be forwarded to the other side of the proxy. Please note that this has nothing to do with HTTP keep-alive. Using option "srvtcpka" enables the emission of TCP keep-alive probes on the server side of a connection, which should help when session expirations are noticed between HAProxy and a server. If this option has been enabled in a "defaults" section, it can be disabled in a specific instance by prepending the "no" keyword before it.
Use SSLv3 client hello health checks for server testing May be used in the following contexts: tcp, http
May be used in sections :
| defaults | frontend | listen | backend |
|---|---|---|---|
yes![]() | no![]() | yes![]() | yes![]() |
When some SSL-based protocols are relayed in TCP mode through HAProxy, it is possible to test that the server correctly talks SSL instead of just testing that it accepts the TCP connection. When "option ssl-hello-chk" is set, pure SSLv3 client hello messages are sent once the connection is established to the server, and the response is analyzed to find an SSL server hello message. The server is considered valid only when the response contains this server hello message. All servers tested till there correctly reply to SSLv3 client hello messages, and most servers tested do not even log the requests containing only hello messages, which is appreciable. Note that this check works even when SSL support was not built into HAProxy because it forges the SSL message. When SSL support is available, it is best to use native SSL health checks instead of this one.
Perform health checks using tcp-check send/expect sequences May be used in the following contexts: tcp, http, log
May be used in sections :
| defaults | frontend | listen | backend |
|---|---|---|---|
yes![]() | no![]() | yes![]() | yes![]() |
This health check method is intended to be combined with "tcp-check" command lists in order to support send/expect types of health check sequences. TCP checks currently support 4 modes of operations : - no "tcp-check" directive : the health check only consists in a connection attempt, which remains the default mode. - "tcp-check send" or "tcp-check send-binary" only is mentioned : this is used to send a string along with a connection opening. With some protocols, it helps sending a "QUIT" message for example that prevents the server from logging a connection error for each health check. The check result will still be based on the ability to open the connection only. - "tcp-check expect" only is mentioned : this is used to test a banner. The connection is opened and HAProxy waits for the server to present some contents which must validate some rules. The check result will be based on the matching between the contents and the rules. This is suited for POP, IMAP, SMTP, FTP, SSH, TELNET. - both "tcp-check send" and "tcp-check expect" are mentioned : this is used to test a hello-type protocol. HAProxy sends a message, the server responds and its response is analyzed. the check result will be based on the matching between the response contents and the rules. This is often suited for protocols which require a binding or a request/response model. LDAP, MySQL, Redis and SSL are example of such protocols, though they already all have their dedicated checks with a deeper understanding of the respective protocols. In this mode, many questions may be sent and many answers may be analyzed. A fifth mode can be used to insert comments in different steps of the script. For each tcp-check rule you create, you can add a "comment" directive, followed by a string. This string will be reported in the log and stderr in debug mode. It is useful to make user-friendly error reporting. The "comment" is of course optional. During the execution of a health check, a variable scope is made available to store data samples, using the "tcp-check set-var" operation. Freeing those variable is possible using "tcp-check unset-var".
# perform a POP check (analyze only server's banner)
option tcp-check
tcp-check expect string +OK\ POP3\ ready comment POP\ protocol
# perform an IMAP check (analyze only server's banner)
option tcp-check
tcp-check expect string *\ OK\ IMAP4\ ready comment IMAP\ protocol
# look for the redis master server after ensuring it speaks well
# redis protocol, then it exits properly.
# (send a command then analyze the response 3 times)
option tcp-check
tcp-check comment PING\ phase
tcp-check send PING\r\n
tcp-check expect string +PONG
tcp-check comment role\ check
tcp-check send info\ replication\r\n
tcp-check expect string role:master
tcp-check comment QUIT\ phase
tcp-check send QUIT\r\n
tcp-check expect string +OK
forge a HTTP request, then analyze the response
(send many headers before analyzing)
option tcp-check
tcp-check comment forge\ and\ send\ HTTP\ request
tcp-check send HEAD\ /\ HTTP/1.1\r\n
tcp-check send Host:\ www.mydomain.com\r\n
tcp-check send User-Agent:\ HAProxy\ tcpcheck\r\n
tcp-check send \r\n
tcp-check expect rstring HTTP/1\..\ (2..|3..) comment check\ HTTP\ response
Enable or disable the saving of one ACK packet during the accept sequence May be used in the following contexts: tcp, http
May be used in sections :
| defaults | frontend | listen | backend |
|---|---|---|---|
yes![]() | yes![]() | yes![]() | no![]() |
When an HTTP connection request comes in, the system acknowledges it on behalf of HAProxy, then the client immediately sends its request, and the system acknowledges it too while it is notifying HAProxy about the new connection. HAProxy then reads the request and responds. This means that we have one TCP ACK sent by the system for nothing, because the request could very well be acknowledged by HAProxy when it sends its response. For this reason, in HTTP mode, HAProxy automatically asks the system to avoid sending this useless ACK on platforms which support it (currently at least Linux). It must not cause any problem, because the system will send it anyway after 40 ms if the response takes more time than expected to come. During complex network debugging sessions, it may be desirable to disable this optimization because delayed ACKs can make troubleshooting more complex when trying to identify where packets are delayed. It is then possible to fall back to normal behavior by specifying "no option tcp-smart-accept". It is also possible to force it for non-HTTP proxies by simply specifying "option tcp-smart-accept". For instance, it can make sense with some services such as SMTP where the server speaks first. It is recommended to avoid forcing this option in a defaults section. In case of doubt, consider setting it back to automatic values by prepending the "default" keyword before it, or disabling it using the "no" keyword.
Enable or disable the saving of one ACK packet during the connect sequence May be used in the following contexts: tcp, http
May be used in sections :
| defaults | frontend | listen | backend |
|---|---|---|---|
yes![]() | no![]() | yes![]() | yes![]() |
On certain systems (at least Linux), HAProxy can ask the kernel not to immediately send an empty ACK upon a connection request, but to directly send the buffer request instead. This saves one packet on the network and thus boosts performance. It can also be useful for some servers, because they immediately get the request along with the incoming connection. This feature is enabled when "option tcp-smart-connect" is set in a backend. It is not enabled by default because it makes network troubleshooting more complex. It only makes sense to enable it with protocols where the client speaks first such as HTTP. In other situations, if there is no data to send in place of the ACK, a normal ACK is sent. If this option has been enabled in a "defaults" section, it can be disabled in a specific instance by prepending the "no" keyword before it.
Enable or disable the sending of TCP keepalive packets on both sides May be used in the following contexts: tcp, http, log
May be used in sections :
| defaults | frontend | listen | backend |
|---|---|---|---|
yes![]() | yes![]() | yes![]() | yes![]() |
When there is a firewall or any session-aware component between a client and a server, and when the protocol involves very long sessions with long idle periods (e.g. remote desktops), there is a risk that one of the intermediate components decides to expire a session which has remained idle for too long. Enabling socket-level TCP keep-alives makes the system regularly send packets to the other end of the connection, leaving it active. The delay between keep-alive probes is controlled by the system only and depends both on the operating system and its tuning parameters. It is important to understand that keep-alive packets are neither emitted nor received at the application level. It is only the network stacks which sees them. For this reason, even if one side of the proxy already uses keep-alives to maintain its connection alive, those keep-alive packets will not be forwarded to the other side of the proxy. Please note that this has nothing to do with HTTP keep-alive. Using option "tcpka" enables the emission of TCP keep-alive probes on both the client and server sides of a connection. Note that this is meaningful only in "defaults" or "listen" sections. If this option is used in a frontend, only the client side will get keep-alives, and if this option is used in a backend, only the server side will get keep-alives. For this reason, it is strongly recommended to explicitly use "option clitcpka" and "option srvtcpka" when the configuration is split between frontends and backends.
Enable advanced logging of TCP connections with stream state and timers May be used in the following contexts: tcp, http
May be used in sections :
| defaults | frontend | listen | backend |
|---|---|---|---|
yes![]() | yes![]() | yes![]() | no![]() |
clf if the "clf" argument is added, then the output format will be
the CLF format instead of HAProxy's default TCP format. You can
use this when you need to feed HAProxy's logs through a specific
log analyzer which only support the CLF format and which is not
extensible. Since this expects an HTTP format some of the
values have been pre set. The http request will show as TCP and
the response code will show as 000.
By default, the log output format is very poor, as it only contains the source and destination addresses, and the instance name. By specifying "option tcplog", each log line turns into a much richer format including, but not limited to, the connection timers, the stream status, the connections numbers, the frontend, backend and server name, and of course the source address and ports. This option is useful for pure TCP proxies in order to find which of the client or server disconnects or times out. For normal HTTP proxies, it's better to use "option httplog" which is even more complete. "option tcplog" overrides any previous "log-format" directive.
Enable client-side transparent proxying May be used in the following contexts: tcp, http
May be used in sections :
| defaults | frontend | listen | backend |
|---|---|---|---|
yes![]() | no![]() | yes![]() | yes![]() |
This option was introduced in order to provide layer 7 persistence to layer 3 load balancers. The idea is to use the OS's ability to redirect an incoming connection for a remote address to a local process (here HAProxy), and let this process know what address was initially requested. When this option is used, sessions without cookies will be forwarded to the original destination IP address of the incoming request (which should match that of another equipment), while requests with cookies will still be forwarded to the appropriate server. Note that contrary to a common belief, this option does NOT make HAProxy present the client's IP to the server when establishing the connection. As of 3.3, this option is now deprecated because it used to suffer from a number of internal technical limitations. Using it will emit a warning, which can be avoided if really needed via the "expose-deprecated-directives" global keyword. The correct approach is to declare a server on address 0.0.0.0, which will take care of connecting to the expected destination address. A server will also properly handle idle connections to the target servers.
# option transparent ## before 3.3
server transparent 0.0.0.0
Enable support for small buffers for the given categories. May be used in the following contexts: tcp, http
May be used in sections :
| defaults | frontend | listen | backend |
|---|---|---|---|
yes![]() | no![]() | yes![]() | yes![]() |
This option can be used to enable the small buffers support at different places
to save memory. By default, with no parameter, small buffers are used as far
as possible at all possible places. Otherwise, it is possible to limit it to
following the places:
- queue: When set, small buffers will be used to store the requests, if
small enough, when the connection is queued.
- l7-retries: When set, small buffers will be used to save the requests
when L7 retries are enabled.
- check: When set, small buffers will be used for the health-checks
requests.
When enabled, small buffers are used, but only if it is possible. Otherwise,
when data are too large, a regular buffer is automatically used. The size of
small buffers is configurable via the "tune.bufsize.small" global setting.
If this option has been enabled in a "defaults" section, it can be disabled
in a specific instance by prepending the "no" keyword before it.
Enable RDP cookie-based persistence May be used in the following contexts: tcp
May be used in sections :
| defaults | frontend | listen | backend |
|---|---|---|---|
yes![]() | no![]() | yes![]() | yes![]() |
<name> is the optional name of the RDP cookie to check. If omitted, the
default cookie name "msts" will be used. There currently is no
valid reason to change this name.
This statement enables persistence based on an RDP cookie. The RDP cookie contains all information required to find the server in the list of known servers. So when this option is set in the backend, the request is analyzed and if an RDP cookie is found, it is decoded. If it matches a known server which is still UP (or if "option persist" is set), then the connection is forwarded to this server. Note that this only makes sense in a TCP backend, but for this to work, the frontend must have waited long enough to ensure that an RDP cookie is present in the request buffer. This is the same requirement as with the "rdp-cookie" load-balancing method. Thus it is highly recommended to put all statements in a single "listen" section. Also, it is important to understand that the terminal server will emit this RDP cookie only if it is configured for "token redirection mode", which means that the "IP address redirection" option is disabled.
listen tse-farm
bind :3389
# wait up to 5s for an RDP cookie in the request
tcp-request inspect-delay 5s
tcp-request content accept if RDP_COOKIE
# apply RDP cookie persistence
persist rdp-cookie
# if server is unknown, let's balance on the same cookie.
# alternatively, "balance leastconn" may be useful too.
balance rdp-cookie
server srv1 1.1.1.1:3389
server srv2 1.1.1.2:3389
Perform an action on an incoming QUIC Initial packet. Contrary to "tcp-request connection", this is executed prior to any connection element instantiation and starting and completion of the SSL handshake, which is more efficient when wanting to reject connections attempts. May be used in the following contexts: http
May be used in sections :
| defaults | frontend | listen | backend |
|---|---|---|---|
yes(!)![]() | yes![]() | yes![]() | no![]() |
<action> defines the action to perform if the condition applies. See
below.
<condition> is a standard layer4-only ACL-based condition (see section 7).
However, QUIC initial rules are executed too early even for
some layer4 sample fetch methods despite no configuration
warning and may result in unspecified runtime behavior,
although they will not crash. Consider that only internal
samples and layer4 "src*" and "dst*" are considered as
supported for now.
This action is executed early during QUIC packet parsing. As such, only a minimal list of actions is supported : - accept - dgram-drop - reject - send-retry
Set a limit on the number of new sessions accepted per second on a frontend May be used in the following contexts: tcp, http
May be used in sections :
| defaults | frontend | listen | backend |
|---|---|---|---|
yes![]() | yes![]() | yes![]() | no![]() |
<rate> The <rate> parameter is an integer designating the maximum number
of new sessions per second to accept on the frontend.
When the frontend reaches the specified number of new sessions per second, it
stops accepting new connections until the rate drops below the limit again.
During this time, the pending sessions will be kept in the socket's backlog
(in system buffers) and HAProxy will not even be aware that sessions are
pending. When applying very low limit on a highly loaded service, it may make
sense to increase the socket's backlog using the "backlog" keyword.
This feature is particularly efficient at blocking connection-based attacks
or service abuse on fragile servers. Since the session rate is measured every
millisecond, it is extremely accurate. Also, the limit applies immediately,
no delay is needed at all to detect the threshold.
Limit the connection rate on SMTP to 10 per second maxlisten smtp mode tcp bind :25 rate-limit sessions 10 server smtp1 127.0.0.1:1025
Note : when the maximum rate is reached, the frontend's status is not changed
but its sockets appear as "WAITING" in the statistics if the
"socket-stats" option is enabled.
Return an HTTP redirection if/unless a condition is matched May be used in the following contexts: http
May be used in sections :
| defaults | frontend | listen | backend |
|---|---|---|---|
no![]() | yes![]() | yes![]() | yes![]() |
If/unless the condition is matched, the HTTP request will lead to a redirect response. If no condition is specified, the redirect applies unconditionally.
<loc> With "redirect location", the exact value in <loc> is placed into the HTTP "Location" header. When used in an "http-request" rule, <loc> value follows the Custom log format rules and can include some dynamic values (see Custom log format in section 8.2.6). <pfx> With "redirect prefix", the "Location" header is built from the concatenation of <pfx> and the complete URI path, including the query string, unless the "drop-query" option is specified (see below). As a special case, if <pfx> equals exactly "/", then nothing is inserted before the original URI. It allows one to redirect to the same URL (for instance, to insert a cookie). When used in an "http-request" rule, <pfx> value follows the Custom Log Format rules and can include some dynamic values (see Custom Log Format in section 8.2.6). <sch> With "redirect scheme", then the "Location" header is built by concatenating <sch> with "://" then the first occurrence of the "Host" header, and then the URI path, including the query string unless the "drop-query" option is specified (see below). If no path is found or if the path is "*", then "/" is used instead. If no "Host" header is found, then an empty host component will be returned, which most recent browsers interpret as redirecting to the same host. This directive is mostly used to redirect HTTP to HTTPS. When used in an "http-request" rule, <sch> value follows the Custom log format rules and can include some dynamic values (see Custom log format in section 8.2.6). <code> The code is optional. It indicates which type of HTTP redirection is desired. Only codes 301, 302, 303, 307 and 308 are supported, with 302 used by default if no code is specified. 301 means "Moved permanently", and a browser may cache the Location. 302 means "Moved temporarily" and means that the browser should not cache the redirection. 303 is equivalent to 302 except that the browser will fetch the location with a GET method. 307 is just like 302 but makes it clear that the same method must be reused. Likewise, 308 replaces 301 if the same method must be used. <option> There are several options which can be specified to adjust the expected behavior of a redirection : - "drop-query" When this keyword is used in a prefix-based redirection, then the location will be set without any possible query-string, which is useful for directing users to a non-secure page for instance. It has no effect with a location-type redirect. - "append-slash" This keyword may be used in conjunction with "drop-query" to redirect users who use a URL not ending with a '/' to the same one with the '/'. It can be useful to ensure that search engines will only see one URL. For this, a return code 301 is preferred. - "ignore-empty" This keyword only has effect when a location is produced using a log format expression (i.e. when used in http-request or http-response). It indicates that if the result of the expression is empty, the rule should silently be skipped. The main use is to allow mass-redirects of known paths using a simple map. - "set-cookie NAME[=value]" A "Set-Cookie" header will be added with NAME (and optionally "=value") to the response. This is sometimes used to indicate that a user has been seen, for instance to protect against some types of DoS. No other cookie option is added, so the cookie will be a session cookie. Note that for a browser, a sole cookie name without an equal sign is different from a cookie with an equal sign. - "set-cookie-fmt <fmt>" It is equivaliant to the option above, except the "Set-Cookie" header will be filled with the result of the log-format string <fmt> evaluation. Be careful to respect the "NAME[=value]" format because no special check are performed during the configuration parsing. - "clear-cookie NAME[=]" A "Set-Cookie" header will be added with NAME (and optionally "="), but with the "Max-Age" attribute set to zero. This will tell the browser to delete this cookie. It is useful for instance on logout pages. It is important to note that clearing the cookie "NAME" will not remove a cookie set with "NAME=value". You have to clear the cookie "NAME=" for that, because the browser makes the difference. - "keep-query" When this keyword is used in a location-based redirection, then the query-string of the original URI, if any, will be appended to the location. If no query-string is found, nothing is added. If the location already contains a query-string, the original one will be appended with the '&' delimiter.
Move the login URL only to HTTPS.acl clear dst_port 80 acl secure dst_port 8080 acl login_page url_beg /login acl logout url_beg /logout acl uid_given url_reg /login?userid=[^&]+ acl cookie_set hdr_sub(cookie) SEEN=1 redirect prefix https://mysite.com set-cookie SEEN=1 if !cookie_set redirect prefix https://mysite.com if login_page !secure redirect prefix http://mysite.com drop-query if login_page !uid_given redirect location http://mysite.com/ if !login_page secure redirect location / clear-cookie USERID= if logout
Send redirects for request for articles without a '/'.acl missing_slash path_reg ^/article/[^/]*$ redirect code 301 prefix / drop-query append-slash if missing_slash
Redirect all HTTP traffic to HTTPS when SSL is handled by HAProxy.redirect scheme https if !{ ssl_fc }
Append 'www.' prefix in front of all hosts not having ithttp-request redirect code 301 location \ http://www.%[hdr(host)]%[capture.req.uri] \ unless { hdr_beg(host) -i www }
Permanently redirect only old URLs to new oneshttp-request redirect code 301 location \ %[path,map_str(old-blog-articles.map)] ignore-empty
See section 7 about ACL usage.
Set the number of retries to perform on a server after a failure May be used in the following contexts: tcp, http
May be used in sections :
| defaults | frontend | listen | backend |
|---|---|---|---|
yes![]() | no![]() | yes![]() | yes![]() |
<value> is the number of times a request or connection attempt should be
retried on a server after a failure.
By default, retries apply only to new connection attempts. However, when the "retry-on" directive is used, other conditions might trigger a retry (e.g. empty response, undesired status code), and each of them will count one attempt, and when the total number attempts reaches the value here, an error will be returned. In order to avoid immediate reconnections to a server which is restarting, a turn-around timer of min("timeout connect", one second) is applied before a retry occurs on the same server. When "option redispatch" is set, some retries may be performed on another server even if a cookie references a different server. By default this will only be the last retry unless an argument is passed to "option redispatch".
Specify when to attempt to automatically retry a failed request.
This setting is only valid when "mode" is set to http and is silently ignored
otherwise.
May be used in the following contexts: tcp, http
May be used in sections :
| defaults | frontend | listen | backend |
|---|---|---|---|
yes![]() | no![]() | yes![]() | yes![]() |
<keywords> is a space-delimited list of keywords or HTTP status codes, each
representing a type of failure event on which an attempt to
retry the request is desired. Please read the notes at the
bottom before changing this setting. The following keywords are
supported :
none never retry
conn-failure retry when the connection or the SSL handshake failed
and the request could not be sent. This is the default.
empty-response retry when the server connection was closed after part
of the request was sent, and nothing was received from
the server. This type of failure may be caused by the
request timeout on the server side, poor network
condition, or a server crash or restart while
processing the request.
junk-response retry when the server returned something not looking
like a complete HTTP response. This includes partial
responses headers as well as non-HTTP contents. It
usually is a bad idea to retry on such events, which
may be caused a configuration issue (wrong server port)
or by the request being harmful to the server (buffer
overflow attack for example).
response-timeout the server timeout stroke while waiting for the server
to respond to the request. This may be caused by poor
network condition, the reuse of an idle connection
which has expired on the path, or by the request being
extremely expensive to process. It generally is a bad
idea to retry on such events on servers dealing with
heavy database processing (full scans, etc) as it may
amplify denial of service attacks.
0rtt-rejected retry requests which were sent over early data and were
rejected by the server. These requests are generally
considered to be safe to retry.
<status> any HTTP status code among "401" (Unauthorized), "403"
(Forbidden), "404" (Not Found), "408" (Request Timeout),
"421" (Misdirected Request), "425" (Too Early),
"429" (Too Many Requests), "500" (Server Error),
"501" (Not Implemented), "502" (Bad Gateway),
"503" (Service Unavailable), "504" (Gateway Timeout).
all-retryable-errors
retry request for any error that are considered
retryable. This currently activates "conn-failure",
"empty-response", "junk-response", "response-timeout",
"0rtt-rejected", "500", "502", "503", and "504".
Using this directive replaces any previous settings with the new ones; it is not cumulative. Please note that using anything other than "none" and "conn-failure" requires to allocate a buffer and copy the whole request into it, so it has memory and performance impacts. Requests not fitting in a single buffer will never be retried (see the global tune.bufsize setting). You have to make sure the application has a replay protection mechanism built in such as a unique transaction IDs passed in requests, or that replaying the same request has no consequence, or it is very dangerous to use any retry-on value beside "conn-failure" and "none". Static file servers and caches are generally considered safe against any type of retry. Using a status code can be useful to quickly leave a server showing an abnormal behavior (out of memory, file system issues, etc), but in this case it may be a good idea to immediately redispatch the connection to another server (please see "option redispatch" for this). Last, it is important to understand that most causes of failures are the requests themselves and that retrying a request causing a server to misbehave will often make the situation even worse for this server, or for the whole service in case of redispatch. Unless you know exactly how the application deals with replayed requests, you should not use this directive. The default is "conn-failure".
retry-on 503 504
Declare a server in a backend May be used in the following contexts: tcp, http, log
May be used in sections :
| defaults | frontend | listen | backend |
|---|---|---|---|
no![]() | no![]() | yes![]() | yes![]() |
<name> is the internal name assigned to this server. This name will
appear in logs and alerts. If "http-send-name-header" is
set, it will be added to the request header sent to the server.
This name must be unique within the backend section.
<address> is the IPv4 or IPv6 address of the server. Alternatively, a
resolvable hostname is supported, but this name will be resolved
during start-up. Address "0.0.0.0" or "*" has a special meaning.
It indicates that the connection will be forwarded to the same IP
address as the one from the client connection. This is useful in
transparent proxy architectures where the client's connection is
intercepted and HAProxy must forward to the original destination
address. This is more or less what the "transparent" keyword does
except that with a server it's possible to limit concurrency and
to report statistics. Optionally, an address family prefix may be
used before the address to force the family regardless of the
address format, which can be useful to specify a path to a unix
socket with no slash ('/'). Currently supported prefixes are :
- 'ipv4@' -> address is always IPv4
- 'ipv6@' -> address is always IPv6
- 'unix@' -> address is a path to a local unix socket
- 'abns@' -> address is in abstract namespace (Linux only)
- 'abnsz@' -> address is in abstract namespace (Linux only)
but it is explicitly zero-terminated. This means no \0
padding is used to complete sun_path. It is useful to
interconnect with programs that don't implement the
default abns naming logic that haproxy uses.
- 'sockpair@' -> address is the FD of a connected unix
socket or of a socketpair. During a connection, the
backend creates a pair of connected sockets, and passes
one of them over the FD. The bind part will use the
received socket as the client FD. Should be used
carefully.
- 'quic4@' [ EXPERIMENTAL] -> address is resolved as IPv4
and protocol UDP is used. QUIC on the backend side is
considered experimental mainly because this prevents the
server removal at runtime. This requires the global
keyword "expose-experimental-directives" to use it.
- 'quic6@' [ EXPERIMENTAL] -> address is resolved as IPv6
and protocol UDP is used. It is considered similarly
flagged as experimental.
- 'rhttp@' [ EXPERIMENTAL ] -> custom address family for a
passive server in HTTP reverse context. This is an
experimental features which requires
"expose-experimental-directives" on a line before this
server.
You may want to reference some environment variables in the
address parameter, see section 2.3 about environment
variables. The "init-addr" setting can be used to modify the way
IP addresses should be resolved upon startup.
<port> is an optional port specification. If set, all connections will
be sent to this port. If unset, the same port the client
connected to will be used. The port may also be prefixed by a "+"
or a "-". In this case, the server's port will be determined by
adding this value to the client's port.
<param*> is a list of parameters for this server. The "server" keywords
accepts an important number of options and has a complete section
dedicated to it. Please refer to section 5 for more details.
server first 10.1.1.1:1080 cookie first check inter 1000
server second 10.1.1.2:1080 cookie second check inter 1000
server transp ipv4@
server backup "${SRV_BACKUP}:1080" backup
server www1_dc1 "${LAN_DC1}.101:80"
server www1_dc2 "${LAN_DC2}.101:80"
Note: regarding Linux's abstract namespace sockets, "abns" HAProxy sockets
uses the whole sun_path length is used for the address length. Some
other programs such as socat use the string length only by default.
Pass the option ",unix-tightsocklen=0" to any abstract socket
definition in socat to make it compatible with HAProxy's, or use the
"abnsz" HAProxy socket family instead.
Set the server state file to read, load and apply to servers available in this backend. May be used in the following contexts: tcp, http, log
May be used in sections :
| defaults | frontend | listen | backend |
|---|---|---|---|
no![]() | no![]() | yes![]() | yes![]() |
It only applies when the directive "load-server-state-from-file" is set to "local". When <file> is not provided, if "use-backend-name" is used or if this directive is not set, then backend name is used. If <file> starts with a slash '/', then it is considered as an absolute path. Otherwise, <file> is concatenated to the global directive "server-state-base".
The minimal configuration below would make HAProxy look for the state server file '/etc/haproxy/states/bk':global server-state-file-base /etc/haproxy/states backend bk load-server-state-from-file
Set a template to initialize servers with shared parameters. The names of these servers are built from <prefix> and <num | range> parameters. May be used in the following contexts: tcp, http, log
May be used in sections :
| defaults | frontend | listen | backend |
|---|---|---|---|
no![]() | no![]() | yes![]() | yes![]() |
<prefix> A prefix for the server names to be built.
<num | range>
If <num> is provided, this template initializes <num> servers
with 1 up to <num> as server name suffixes. A range of numbers
<num_low>-<num_high> may also be used to use <num_low> up to
<num_high> as server name suffixes.
<fqdn> A FQDN for all the servers this template initializes.
<port> Same meaning as "server" <port> argument (see "server" keyword).
<params*>
Remaining server parameters among all those supported by "server"
keyword.
# Initializes 3 servers with srv1, srv2 and srv3 as names,
# google.com as FQDN, and health-check enabled.
server-template srv 1-3 google.com:80 check
# or
server-template srv 3 google.com:80 check
# would be equivalent to:
server srv1 google.com:80 check
server srv2 google.com:80 check
server srv3 google.com:80 check
Set the source address for outgoing connections May be used in the following contexts: tcp, http
May be used in sections :
| defaults | frontend | listen | backend |
|---|---|---|---|
yes![]() | no![]() | yes![]() | yes![]() |
<addr> is the IPv4 address HAProxy will bind to before connecting to a
server. This address is also used as a source for health checks.
The default value of 0.0.0.0 means that the system will select
the most appropriate address to reach its destination. Optionally
an address family prefix may be used before the address to force
the family regardless of the address format, which can be useful
to specify a path to a unix socket with no slash ('/'). Currently
supported prefixes are :
- 'ipv4@' -> address is always IPv4
- 'ipv6@' -> address is always IPv6
- 'unix@' -> address is a path to a local unix socket
- 'abns@' -> address is in abstract namespace (Linux only)
- 'abnsz@' -> address is in zero-terminated abstract namespace
(Linux only)
You may want to reference some environment variables in the
address parameter, see section 2.3 about environment variables.
<port> is an optional port. It is normally not needed but may be useful
in some very specific contexts. The default value of zero means
the system will select a free port. Note that port ranges are not
supported in the backend. If you want to force port ranges, you
have to specify them on each "server" line.
<addr2> is the IP address to present to the server when connections are
forwarded in full transparent proxy mode. This is currently only
supported on some patched Linux kernels. When this address is
specified, clients connecting to the server will be presented
with this address, while health checks will still use the address
<addr>.
<port2> is the optional port to present to the server when connections
are forwarded in full transparent proxy mode (see <addr2> above).
The default value of zero means the system will select a free
port.
<hdr> is the name of a HTTP header in which to fetch the IP to bind to.
This is the name of a comma-separated header list which can
contain multiple IP addresses. By default, the last occurrence is
used. This is designed to work with the X-Forwarded-For header
and to automatically bind to the client's IP address as seen
by previous proxy, typically Stunnel. In order to use another
occurrence from the last one, please see the <occ> parameter
below. When the header (or occurrence) is not found, no binding
is performed so that the proxy's default IP address is used. Also
keep in mind that the header name is case insensitive, as for any
HTTP header.
<occ> is the occurrence number of a value to be used in a multi-value
header. This is to be used in conjunction with "hdr_ip(<hdr>)",
in order to specify which occurrence to use for the source IP
address. Positive values indicate a position from the first
occurrence, 1 being the first one. Negative values indicate
positions relative to the last one, -1 being the last one. This
is helpful for situations where an X-Forwarded-For header is set
at the entry point of an infrastructure and must be used several
proxy layers away. When this value is not specified, -1 is
assumed. Passing a zero here disables the feature.
<name> is an optional interface name to which to bind to for outgoing
traffic. On systems supporting this features (currently, only
Linux), this allows one to bind all traffic to the server to
this interface even if it is not the one the system would select
based on routing tables. This should be used with extreme care.
Note that using this option requires root privileges.
The "source" keyword is useful in complex environments where a specific address only is allowed to connect to the servers. It may be needed when a private address must be used through a public gateway for instance, and it is known that the system cannot determine the adequate source address by itself. An extension which is available on certain patched Linux kernels may be used through the "usesrc" optional keyword. It makes it possible to connect to the servers with an IP address which does not belong to the system itself. This is called "full transparent proxy mode". For this to work, the destination servers have to route their traffic back to this address through the machine running HAProxy, and IP forwarding must generally be enabled on this machine. In this "full transparent proxy" mode, it is possible to force a specific IP address to be presented to the servers. This is not much used in fact. A more common use is to tell HAProxy to present the client's IP address. For this, there are two methods : - present the client's IP and port addresses. This is the most transparent mode, but it can cause problems when IP connection tracking is enabled on the machine, because a same connection may be seen twice with different states. However, this solution presents the huge advantage of not limiting the system to the 64k outgoing address+port couples, because all of the client ranges may be used. - present only the client's IP address and select a spare port. This solution is still quite elegant but slightly less transparent (downstream firewalls logs will not match upstream's). It also presents the downside of limiting the number of concurrent connections to the usual 64k ports. However, since the upstream and downstream ports are different, local IP connection tracking on the machine will not be upset by the reuse of the same session. This option sets the default source for all servers in the backend. It may also be specified in a "defaults" section. Finer source address specification is possible at the server level using the "source" server option. Refer to section 5 for more information. In order to work, "usesrc" requires root privileges, or on supported systems, the "cap_net_raw" capability. See also the "setcap" global directive.
backend private
# Connect to the servers using our 192.168.1.200 source address
source 192.168.1.200
backend transparent_ssl1
# Connect to the SSL farm from the client's source address
source 192.168.1.200 usesrc clientip
backend transparent_ssl2
# Connect to the SSL farm from the client's source address and port
# not recommended if IP conntrack is present on the local machine.
source 192.168.1.200 usesrc client
backend transparent_ssl3
# Connect to the SSL farm from the client's source address. It
# is more conntrack-friendly.
source 192.168.1.200 usesrc clientip
backend transparent_smtp
# Connect to the SMTP farm from the client's source address/port
# with Tproxy version 4.
source 0.0.0.0 usesrc clientip
backend transparent_http
# Connect to the servers using the client's IP as seen by previous
# proxy.
source 0.0.0.0 usesrc hdr_ip(x-forwarded-for,-1)
Sets the maximum number of keepalive probes TCP should send before dropping the connection on the server side. May be used in the following contexts: tcp, http, log
May be used in sections :
| defaults | frontend | listen | backend |
|---|---|---|---|
yes![]() | no![]() | yes![]() | yes![]() |
<count> is the maximum number of keepalive probes.
This keyword corresponds to the socket option TCP_KEEPCNT. If this keyword is not specified, system-wide TCP parameter (tcp_keepalive_probes) is used. The availability of this setting depends on the operating system. It is known to work on Linux.
Sets the time the connection needs to remain idle before TCP starts sending keepalive probes, if enabled the sending of TCP keepalive packets on the server side. May be used in the following contexts: tcp, http, log
May be used in sections :
| defaults | frontend | listen | backend |
|---|---|---|---|
yes![]() | no![]() | yes![]() | yes![]() |
<timeout> is the time the connection needs to remain idle before TCP starts
sending keepalive probes. It is specified in seconds by default,
but can be in any other unit if the number is suffixed by the
unit, as explained at the top of this document.
This keyword corresponds to the socket option TCP_KEEPIDLE. If this keyword is not specified, system-wide TCP parameter (tcp_keepalive_time) is used. The availability of this setting depends on the operating system. It is known to work on Linux.
Sets the time between individual keepalive probes on the server side. May be used in the following contexts: tcp, http, log
May be used in sections :
| defaults | frontend | listen | backend |
|---|---|---|---|
yes![]() | no![]() | yes![]() | yes![]() |
<timeout> is the time between individual keepalive probes. It is specified
in seconds by default, but can be in any other unit if the number
is suffixed by the unit, as explained at the top of this
document.
This keyword corresponds to the socket option TCP_KEEPINTVL. If this keyword is not specified, system-wide TCP parameter (tcp_keepalive_intvl) is used. The availability of this setting depends on the operating system. It is known to work on Linux.
Enable statistics admin level if/unless a condition is matched May be used in the following contexts: http
May be used in sections :
| defaults | frontend | listen | backend |
|---|---|---|---|
no![]() | yes![]() | yes![]() | yes![]() |
This statement enables the statistics admin level if/unless a condition is matched. The admin level allows to enable/disable servers from the web interface. By default, statistics page is read-only for security reasons. If "stats scope" directives are set in the section, then only proxies designated by these directives will accept state changes; access to other ones will be denied. Currently, the POST request is limited to the buffer size minus the reserved buffer space, which means that if the list of servers is too long, the request won't be processed. It is recommended to alter few servers at a time. Those admin POST requests are prone to CSRF attacks. This is partially mitigated by checking that the Origin (or Referer if no Origin is present) matches the Host header, but this is not enough to totally prevent the attack. There is no way to be completely protected from those. It is recommended to avoid exposing it on a public interface, and to restrict who can access it.
# statistics admin level only for localhost
backend stats_localhost
stats enable
stats admin if LOCALHOST
# statistics admin level always enabled because of the authentication
backend stats_auth
stats enable
stats auth admin:AdMiN123
stats admin if TRUE
# statistics admin level depends on the authenticated user
userlist stats-auth
group admin users admin
user admin insecure-password 'AdMiN123'
group readonly users haproxy
user haproxy insecure-password 'haproxy'
backend stats_auth
stats enable
acl AUTH http_auth(stats-auth)
acl AUTH_ADMIN http_auth_group(stats-auth) admin
stats http-request auth unless AUTH
stats admin if AUTH_ADMIN
Assignate a certificate to the current frontend. May be used in the following contexts: tcp, http
May be used in sections :
| defaults | frontend | listen | backend |
|---|---|---|---|
no![]() | yes![]() | yes![]() | no![]() |
<sslbindconf> supports the following keywords from the bind line (see Section 5.1. Bind options): - allow-0rtt - alpn - ca-file - ca-verify-file - ciphers - ciphersuites - client-sigalgs - crl-file - curves - ecdhe - ktls - no-alpn - no-ca-names - npn - sigalgs - ssl-min-ver - ssl-max-ver - verify sslbindconf also supports the following keywords from the crt-store load keyword (see Section 12.7.1. Load options): - crt - key - ocsp - issuer - sctl - ocsp-update
Assignate a certificate <crtname> to a crt-list created automatically with the
frontend name and prefixed by @ (ex: '@frontend1').
This implicit crt-list will be assigned to every "ssl" bind lines in the
current frontend.
crt-list commands from the stats socket are effective with this crt-list, so
one could replace, remove or add certificates and SSL options to it.
frontend https
bind :443 ssl
bind quic4@:443 ssl
ssl-f-use crt foobar.pem.rsa sigalgs "RSA-PSS+SHA256"
ssl-f-use crt test.foobar.pem
ssl-f-use crt test2.foobar.crt key test2.foobar.key ocsp test2.foobar.ocsp ocsp-update on
Enable statistics with authentication and grant access to an account May be used in the following contexts: http
May be used in sections :
| defaults | frontend | listen | backend |
|---|---|---|---|
yes![]() | yes![]() | yes![]() | yes![]() |
<user> is a user name to grant access to <passwd> is the cleartext password associated to this user
This statement enables statistics with default settings, and restricts access to declared users only. It may be repeated as many times as necessary to allow as many users as desired. When a user tries to access the statistics without a valid account, a "401 Forbidden" response will be returned so that the browser asks the user to provide a valid user and password. The real which will be returned to the browser is configurable using "stats realm". Since the authentication method is HTTP Basic Authentication, the passwords circulate in cleartext on the network. Thus, it was decided that the configuration file would also use cleartext passwords to remind the users that those ones should not be sensitive and not shared with any other account. It is also possible to reduce the scope of the proxies which appear in the report using "stats scope". Though this statement alone is enough to enable statistics reporting, it is recommended to set all other settings in order to avoid relying on default unobvious parameters.
# public access (limited to this backend only)
backend public_www
server srv1 192.168.0.1:80
stats enable
stats hide-version
stats scope .
stats uri /admin?stats
stats realm HAProxy\ Statistics
stats auth admin1:AdMiN123
stats auth admin2:AdMiN321
# internal monitoring access (unlimited)
backend private_monitoring
stats enable
stats uri /admin?stats
stats refresh 5s
Enable statistics reporting with default settings May be used in the following contexts: http
May be used in sections :
| defaults | frontend | listen | backend |
|---|---|---|---|
yes![]() | yes![]() | yes![]() | yes![]() |
This statement enables statistics reporting with default settings defined at build time. Unless stated otherwise, these settings are used : - stats uri : /haproxy?stats - stats realm : "HAProxy Statistics" - stats auth : no authentication - stats scope : no restriction Though this statement alone is enough to enable statistics reporting, it is recommended to set all other settings in order to avoid relying on default unobvious parameters.
# public access (limited to this backend only)
backend public_www
server srv1 192.168.0.1:80
stats enable
stats hide-version
stats scope .
stats uri /admin?stats
stats realm HAProxy\ Statistics
stats auth admin1:AdMiN123
stats auth admin2:AdMiN321
# internal monitoring access (unlimited)
backend private_monitoring
stats enable
stats uri /admin?stats
stats refresh 5s
Enable statistics and hide HAProxy version reporting May be used in the following contexts: http
May be used in sections :
| defaults | frontend | listen | backend |
|---|---|---|---|
yes![]() | yes![]() | yes![]() | yes![]() |
The stats page can report some useful status information along with the statistics. Among them is HAProxy's version. However, it is generally considered dangerous to report precise version to anyone, as it can help them target known weaknesses with specific attacks. The "stats hide-version" statement removes the version from the statistics report. This is recommended for public sites or any site with a weak login/password, and is the default. Though this statement alone is enough to enable statistics reporting, it is recommended to set all other settings in order to avoid relying on default unobvious parameters.
# public access (limited to this backend only)
backend public_www
server srv1 192.168.0.1:80
stats enable
stats hide-version
stats scope .
stats uri /admin?stats
stats realm HAProxy\ Statistics
stats auth admin1:AdMiN123
stats auth admin2:AdMiN321
# internal monitoring access (unlimited)
backend private_monitoring
stats enable
stats uri /admin?stats
stats refresh 5s
Access control for statistics May be used in the following contexts: http
May be used in sections :
| defaults | frontend | listen | backend |
|---|---|---|---|
no![]() | no![]() | yes![]() | yes![]() |
As "http-request", these set of options allow to fine control access to statistics. Each option may be followed by if/unless and acl. First option with matched condition (or option without condition) is final. For "deny" a 403 error will be returned, for "allow" normal processing is performed, for "auth" a 401/407 error code is returned so the client should be asked to enter a username and password. There is no fixed limit to the number of http-request statements per instance.
Enable statistics and set authentication realm May be used in the following contexts: http
May be used in sections :
| defaults | frontend | listen | backend |
|---|---|---|---|
yes![]() | yes![]() | yes![]() | yes![]() |
<realm> is the name of the HTTP Basic Authentication realm reported to
the browser. The browser uses it to display it in the pop-up
inviting the user to enter a valid username and password.
The realm is read as a single word, so any spaces in it should be escaped
using a backslash ('\').
This statement is useful only in conjunction with "stats auth" since it is
only related to authentication.
Though this statement alone is enough to enable statistics reporting, it is
recommended to set all other settings in order to avoid relying on default
unobvious parameters.
# public access (limited to this backend only)
backend public_www
server srv1 192.168.0.1:80
stats enable
stats hide-version
stats scope .
stats uri /admin?stats
stats realm HAProxy\ Statistics
stats auth admin1:AdMiN123
stats auth admin2:AdMiN321
# internal monitoring access (unlimited)
backend private_monitoring
stats enable
stats uri /admin?stats
stats refresh 5s
Enable statistics with automatic refresh May be used in the following contexts: http
May be used in sections :
| defaults | frontend | listen | backend |
|---|---|---|---|
yes![]() | yes![]() | yes![]() | yes![]() |
<delay> is the suggested refresh delay, specified in seconds, which will
be returned to the browser consulting the report page. While the
browser is free to apply any delay, it will generally respect it
and refresh the page this every seconds. The refresh interval may
be specified in any other non-default time unit, by suffixing the
unit after the value, as explained at the top of this document.
This statement is useful on monitoring displays with a permanent page reporting the load balancer's activity. When set, the HTML report page will include a link "refresh"/"stop refresh" so that the user can select whether they want automatic refresh of the page or not. Though this statement alone is enough to enable statistics reporting, it is recommended to set all other settings in order to avoid relying on default unobvious parameters.
# public access (limited to this backend only)
backend public_www
server srv1 192.168.0.1:80
stats enable
stats hide-version
stats scope .
stats uri /admin?stats
stats realm HAProxy\ Statistics
stats auth admin1:AdMiN123
stats auth admin2:AdMiN321
# internal monitoring access (unlimited)
backend private_monitoring
stats enable
stats uri /admin?stats
stats refresh 5s
Enable statistics and limit access scope May be used in the following contexts: http
May be used in sections :
| defaults | frontend | listen | backend |
|---|---|---|---|
yes![]() | yes![]() | yes![]() | yes![]() |
<name> is the name of a listen, frontend or backend section to be
reported. The special name "." (a single dot) designates the
section in which the statement appears.
When this statement is specified, only the sections enumerated with this statement will appear in the report. All other ones will be hidden, and attempts to change their state in admin mode will be rejected. This statement may appear as many times as needed if multiple sections need to be reported. Please note that the name checking is performed as simple string comparisons, and that it is never checked that a give section name really exists. Though this statement alone is enough to enable statistics reporting, it is recommended to set all other settings in order to avoid relying on default unobvious parameters.
# public access (limited to this backend only)
backend public_www
server srv1 192.168.0.1:80
stats enable
stats hide-version
stats scope .
stats uri /admin?stats
stats realm HAProxy\ Statistics
stats auth admin1:AdMiN123
stats auth admin2:AdMiN321
# internal monitoring access (unlimited)
backend private_monitoring
stats enable
stats uri /admin?stats
stats refresh 5s
Enable reporting of a description on the statistics page. May be used in the following contexts: http
May be used in sections :
| defaults | frontend | listen | backend |
|---|---|---|---|
yes![]() | yes![]() | yes![]() | yes![]() |
<desc> is an optional description to be reported. If unspecified, the
description from global section is automatically used instead.
This statement is useful for users that offer shared services to their
customers, where node or description should be different for each customer.
Though this statement alone is enough to enable statistics reporting, it is
recommended to set all other settings in order to avoid relying on default
unobvious parameters. By default description is not shown.
# internal monitoring access (unlimited)
backend private_monitoring
stats enable
stats show-desc Master node for Europe, Asia, Africa
stats uri /admin?stats
stats refresh 5s
Enable reporting additional information on the statistics page May be used in the following contexts: http
May be used in sections :
| defaults | frontend | listen | backend |
|---|---|---|---|
yes![]() | yes![]() | yes![]() | yes![]() |
Enable reporting additional information on the statistics page : - cap: capabilities (proxy) - mode: one of tcp, http or health (proxy) - id: SNMP ID (proxy, socket, server) - IP (socket, server) - cookie (backend, server) Though this statement alone is enough to enable statistics reporting, it is recommended to set all other settings in order to avoid relying on default unobvious parameters. Default behavior is not to show this information.
Enable display of extra statistics module on the statistics page May be used in the following contexts: http
May be used in sections :
| defaults | frontend | listen | backend |
|---|---|---|---|
yes![]() | yes![]() | yes![]() | yes![]() |
New columns are added at the end of the line containing the extra statistics values as a tooltip. Though this statement alone is enough to enable statistics reporting, it is recommended to set all other settings in order to avoid relying on default unobvious parameters. Default behavior is not to show this information.
Enable reporting of a host name on the statistics page. May be used in the following contexts: http
May be used in sections :
| defaults | frontend | listen | backend |
|---|---|---|---|
yes![]() | yes![]() | yes![]() | yes![]() |
<name> is an optional name to be reported. If unspecified, the
node name from global section is automatically used instead.
This statement is useful for users that offer shared services to their customers, where node or description might be different on a stats page provided for each customer. Default behavior is not to show host name. Though this statement alone is enough to enable statistics reporting, it is recommended to set all other settings in order to avoid relying on default unobvious parameters.
# internal monitoring access (unlimited)
backend private_monitoring
stats enable
stats show-node Europe-1
stats uri /admin?stats
stats refresh 5s
Enable statistics and show HAProxy version reporting May be used in the following contexts: http
May be used in sections :
| defaults | frontend | listen | backend |
|---|---|---|---|
yes![]() | yes![]() | yes![]() | yes![]() |
The stats page can report some useful status information along with the statistics. Among them is HAProxy's version. However, it is generally considered dangerous to report precise version to anyone, as it can help them target known weaknesses with specific attacks, and so is disabled by default. The "stats show-version" enables displaying those informations. This is not recommanded for public sites or any site with a weak login/password.
Enable statistics and define the URI prefix to access them May be used in the following contexts: http
May be used in sections :
| defaults | frontend | listen | backend |
|---|---|---|---|
yes![]() | yes![]() | yes![]() | yes![]() |
<prefix> is the prefix of any URI which will be redirected to stats. This
prefix may contain a question mark ('?') to indicate part of a
query string.
The statistics URI is intercepted on the relayed traffic, so it appears as a page within the normal application. It is strongly advised to ensure that the selected URI will never appear in the application, otherwise it will never be possible to reach it in the application. The default URI compiled in HAProxy is "/haproxy?stats", but this may be changed at build time, so it's better to always explicitly specify it here. It is generally a good idea to include a question mark in the URI so that intermediate proxies refrain from caching the results. Also, since any string beginning with the prefix will be accepted as a stats request, the question mark helps ensuring that no valid URI will begin with the same words. It is sometimes very convenient to use "/" as the URI prefix, and put that statement in a "listen" instance of its own. That makes it easy to dedicate an address or a port to statistics only. Though this statement alone is enough to enable statistics reporting, it is recommended to set all other settings in order to avoid relying on default unobvious parameters.
# public access (limited to this backend only)
backend public_www
server srv1 192.168.0.1:80
stats enable
stats hide-version
stats scope .
stats uri /admin?stats
stats realm HAProxy\ Statistics
stats auth admin1:AdMiN123
stats auth admin2:AdMiN321
# internal monitoring access (unlimited)
backend private_monitoring
stats enable
stats uri /admin?stats
stats refresh 5s
Define a request pattern matching condition to stick a user to a server May be used in the following contexts: tcp, http
May be used in sections :
| defaults | frontend | listen | backend |
|---|---|---|---|
no![]() | no![]() | yes![]() | yes![]() |
<pattern> is a sample expression rule as described in section 7.3. It describes what elements of the incoming request or connection will be analyzed in the hope to find a matching entry in a stickiness table. This rule is mandatory. <table> is an optional stickiness table name. If unspecified, the same backend's table is used. A stickiness table is declared using the "stick-table" statement. <cond> is an optional matching condition. It makes it possible to match on a certain criterion only when other conditions are met (or not met). For instance, it could be used to match on a source IP address except when a request passes through a known proxy, in which case we'd match on a header containing that IP address.
Some protocols or applications require complex stickiness rules and cannot always simply rely on cookies nor hashing. The "stick match" statement describes a rule to extract the stickiness criterion from an incoming request or connection. See section 7 for a complete list of possible patterns and transformation rules. The table has to be declared using the "stick-table" statement. It must be of a type compatible with the pattern. By default it is the one which is present in the same backend. It is possible to share a table with other backends by referencing it using the "table" keyword. If another table is referenced, the server's ID inside the backends are used. By default, all server IDs start at 1 in each backend, so the server ordering is enough. But in case of doubt, it is highly recommended to force server IDs using their "id" setting. It is possible to restrict the conditions where a "stick match" statement will apply, using "if" or "unless" followed by a condition. See section 7 for ACL based conditions. There is no limit on the number of "stick match" statements. The first that applies and matches will cause the request to be directed to the same server as was used for the request which created the entry. That way, multiple matches can be used as fallbacks. The stick rules are checked after the persistence cookies, so they will not affect stickiness if a cookie has already been used to select a server. That way, it becomes very easy to insert cookies and match on IP addresses in order to maintain stickiness between HTTP and HTTPS.
# forward SMTP users to the same server they just used for POP in the
# last 30 minutes
backend pop
mode tcp
balance roundrobin
stick store-request src
stick-table type ip size 200k expire 30m
server s1 192.168.1.1:110
server s2 192.168.1.1:110
backend smtp
mode tcp
balance roundrobin
stick match src table pop
server s1 192.168.1.1:25
server s2 192.168.1.1:25
Define a request pattern to associate a user to a server May be used in the following contexts: tcp, http
May be used in sections :
| defaults | frontend | listen | backend |
|---|---|---|---|
no![]() | no![]() | yes![]() | yes![]() |
Note : This form is exactly equivalent to "stick match" followed by "stick store-request", all with the same arguments. Please refer to both keywords for details. It is only provided as a convenience for writing more maintainable configurations.
# The following form ...
stick on src table pop if !localhost
# ...is strictly equivalent to this one :
stick match src table pop if !localhost
stick store-request src table pop if !localhost
# Use cookie persistence for HTTP, and stick on source address for HTTPS as
# well as HTTP without cookie. Share the same table between both accesses.
backend http
mode http
balance roundrobin
stick on src table https
cookie SRV insert indirect nocache
server s1 192.168.1.1:80 cookie s1
server s2 192.168.1.1:80 cookie s2
backend https
mode tcp
balance roundrobin
stick-table type ip size 200k expire 30m
stick on src
server s1 192.168.1.1:443
server s2 192.168.1.1:443
Define a request pattern used to create an entry in a stickiness table May be used in the following contexts: tcp, http
May be used in sections :
| defaults | frontend | listen | backend |
|---|---|---|---|
no![]() | no![]() | yes![]() | yes![]() |
<pattern> is a sample expression rule as described in section 7.3. It describes what elements of the incoming request or connection will be analyzed, extracted and stored in the table once a server is selected. <table> is an optional stickiness table name. If unspecified, the same backend's table is used. A stickiness table is declared using the "stick-table" statement. <cond> is an optional storage condition. It makes it possible to store certain criteria only when some conditions are met (or not met). For instance, it could be used to store the source IP address except when the request passes through a known proxy, in which case we'd store a converted form of a header containing that IP address.
Some protocols or applications require complex stickiness rules and cannot always simply rely on cookies nor hashing. The "stick store-request" statement describes a rule to decide what to extract from the request and when to do it, in order to store it into a stickiness table for further requests to match it using the "stick match" statement. Obviously the extracted part must make sense and have a chance to be matched in a further request. Storing a client's IP address for instance often makes sense. Storing an ID found in a URL parameter also makes sense. Storing a source port will almost never make any sense because it will be randomly matched. See section 7 for a complete list of possible patterns and transformation rules. The table has to be declared using the "stick-table" statement. It must be of a type compatible with the pattern. By default it is the one which is present in the same backend. It is possible to share a table with other backends by referencing it using the "table" keyword. If another table is referenced, the server's ID inside the backends are used. By default, all server IDs start at 1 in each backend, so the server ordering is enough. But in case of doubt, it is highly recommended to force server IDs using their "id" setting. It is possible to restrict the conditions where a "stick store-request" statement will apply, using "if" or "unless" followed by a condition. This condition will be evaluated while parsing the request, so any criteria can be used. See section 7 for ACL based conditions. There is no limit on the number of "stick store-request" statements, but there is a limit of 8 simultaneous stores per request or response. This makes it possible to store up to 8 criteria, all extracted from either the request or the response, regardless of the number of rules. Only the 8 first ones which match will be kept. Using this, it is possible to feed multiple tables at once in the hope to increase the chance to recognize a user on another protocol or access method. Using multiple store-request rules with the same table is possible and may be used to find the best criterion to rely on, by arranging the rules by decreasing preference order. Only the first extracted criterion for a given table will be stored. All subsequent store- request rules referencing the same table will be skipped and their ACLs will not be evaluated. The "store-request" rules are evaluated once the server connection has been established, so that the table will contain the real server that processed the request.
# forward SMTP users to the same server they just used for POP in the
# last 30 minutes
backend pop
mode tcp
balance roundrobin
stick store-request src
stick-table type ip size 200k expire 30m
server s1 192.168.1.1:110
server s2 192.168.1.1:110
backend smtp
mode tcp
balance roundrobin
stick match src table pop
server s1 192.168.1.1:25
server s2 192.168.1.1:25
Define a response pattern used to create an entry in a stickiness table May be used in the following contexts: tcp, http
May be used in sections :
| defaults | frontend | listen | backend |
|---|---|---|---|
no![]() | no![]() | yes![]() | yes![]() |
<pattern> is a sample expression rule as described in section 7.3. It describes what elements of the response or connection will be analyzed, extracted and stored in the table once a server is selected. <table> is an optional stickiness table name. If unspecified, the same backend's table is used. A stickiness table is declared using the "stick-table" statement. <cond> is an optional storage condition. It makes it possible to store certain criteria only when some conditions are met (or not met). For instance, it could be used to store the SSL session ID only when the response is a SSL server hello.
Some protocols or applications require complex stickiness rules and cannot always simply rely on cookies nor hashing. The "stick store-response" statement describes a rule to decide what to extract from the response and when to do it, in order to store it into a stickiness table for further requests to match it using the "stick match" statement. Obviously the extracted part must make sense and have a chance to be matched in a further request. Storing an ID found in a header of a response makes sense. See section 7 for a complete list of possible patterns and transformation rules. The table has to be declared using the "stick-table" statement. It must be of a type compatible with the pattern. By default it is the one which is present in the same backend. It is possible to share a table with other backends by referencing it using the "table" keyword. If another table is referenced, the server's ID inside the backends are used. By default, all server IDs start at 1 in each backend, so the server ordering is enough. But in case of doubt, it is highly recommended to force server IDs using their "id" setting. It is possible to restrict the conditions where a "stick store-response" statement will apply, using "if" or "unless" followed by a condition. This condition will be evaluated while parsing the response, so any criteria can be used. See section 7 for ACL based conditions. There is no limit on the number of "stick store-response" statements, but there is a limit of 8 simultaneous stores per request or response. This makes it possible to store up to 8 criteria, all extracted from either the request or the response, regardless of the number of rules. Only the 8 first ones which match will be kept. Using this, it is possible to feed multiple tables at once in the hope to increase the chance to recognize a user on another protocol or access method. Using multiple store-response rules with the same table is possible and may be used to find the best criterion to rely on, by arranging the rules by decreasing preference order. Only the first extracted criterion for a given table will be stored. All subsequent store- response rules referencing the same table will be skipped and their ACLs will not be evaluated. However, even if a store-request rule references a table, a store-response rule may also use the same table. This means that each table may learn exactly one element from the request and one element from the response at once. The table will contain the real server that processed the request.
# Learn SSL session ID from both request and response and create affinity.
backend https
mode tcp
balance roundrobin
# maximum SSL session ID length is 32 bytes.
stick-table type binary len 32 size 30k expire 30m
acl clienthello req.ssl_hello_type 1
acl serverhello res.ssl_hello_type 2
# use tcp content accepts to detects ssl client and server hello.
tcp-request inspect-delay 5s
tcp-request content accept if clienthello
# no timeout on response inspect delay by default.
tcp-response content accept if serverhello
# SSL session ID (SSLID) may be present on a client or server hello.
# Its length is coded on 1 byte at offset 43 and its value starts
# at offset 44.
# Match and learn on request if client hello.
stick on req.payload_lv(43,1) if clienthello
# Learn on response if server hello.
stick store-response resp.payload_lv(43,1) if serverhello
server s1 192.168.1.1:443
server s2 192.168.1.1:443
Configure the stickiness table for the current section May be used in the following contexts: tcp, http
May be used in sections :
| defaults | frontend | listen | backend |
|---|---|---|---|
no![]() | yes![]() | yes![]() | yes![]() |
This is used to declare and configure a stick-table. Please refer to section 11.1 for the complete details and the list of supported arguments. Only the type and the size are mandatory.
Defines a comment for the following the tcp-check rule, reported in logs if it fails. May be used in the following contexts: tcp, http, log
May be used in sections :
| defaults | frontend | listen | backend |
|---|---|---|---|
yes![]() | no![]() | yes![]() | yes![]() |
<string> is the comment message to add in logs if the following tcp-check
rule fails.
It only works for connect, send and expect rules. It is useful to make user-friendly error reporting.
Opens a new connection May be used in the following contexts: tcp, http, log
May be used in sections :
| defaults | frontend | listen | backend |
|---|---|---|---|
yes![]() | no![]() | yes![]() | yes![]() |
comment <msg> defines a message to report if the rule evaluation fails.
default Use default options of the server line to do the health
checks. The server options are used only if not redefined.
port <expr> if not set, check port or server port is used.
It tells HAProxy where to open the connection to.
<port> must be a valid TCP port source integer, from 1 to
65535 or an sample-fetch expression.
addr <ip> defines the IP address to do the health check.
send-proxy send a PROXY protocol string
via-socks4 enables outgoing health checks using upstream socks4 proxy.
ssl opens a ciphered connection
sni <sni> specifies the SNI to use to do health checks over SSL.
alpn <alpn> defines which protocols to advertise with ALPN. The protocol
list consists in a comma-delimited list of protocol names,
for instance: "http/1.1,http/1.0" (without quotes).
If it is not set, the server ALPN is used.
proto <name> forces the multiplexer's protocol to use for this connection.
It must be a TCP mux protocol and it must be usable on the
backend side. The list of available protocols is reported in
haproxy -vv.
linger cleanly close the connection instead of using a single RST.
When an application lies on more than a single TCP port or when HAProxy load-balance many services in a single backend, it makes sense to probe all the services individually before considering a server as operational. When there are no TCP port configured on the server line neither server port directive, then the 'tcp-check connect port <port>' must be the first step of the sequence. In a tcp-check ruleset a 'connect' is required, it is also mandatory to start the ruleset with a 'connect' rule. Purpose is to ensure admin know what they do. When a connect must start the ruleset, if may still be preceded by set-var, unset-var or comment rules.
# check HTTP and HTTPs services on a server.
# first open port 80 thanks to server line port directive, then
# tcp-check opens port 443, ciphered and run a request on it:
option tcp-check
tcp-check connect
tcp-check send GET\ /\ HTTP/1.0\r\n
tcp-check send Host:\ haproxy.1wt.eu\r\n
tcp-check send \r\n
tcp-check expect rstring (2..|3..)
tcp-check connect port 443 ssl
tcp-check send GET\ /\ HTTP/1.0\r\n
tcp-check send Host:\ haproxy.1wt.eu\r\n
tcp-check send \r\n
tcp-check expect rstring (2..|3..)
server www 10.0.0.1 check port 80
# check both POP and IMAP from a single server:
option tcp-check
tcp-check connect port 110 linger
tcp-check expect string +OK\ POP3\ ready
tcp-check connect port 143
tcp-check expect string *\ OK\ IMAP4\ ready
server mail 10.0.0.1 check
Specify data to be collected and analyzed during a generic health check May be used in the following contexts: tcp, http, log
May be used in sections :
| defaults | frontend | listen | backend |
|---|---|---|---|
yes![]() | no![]() | yes![]() | yes![]() |
comment <msg> defines a message to report if the rule evaluation fails.
min-recv is optional and can define the minimum amount of data required to
evaluate the current expect rule. If the number of received bytes
is under this limit, the check will wait for more data. This
option can be used to resolve some ambiguous matching rules or to
avoid executing costly regex matches on content known to be still
incomplete. If an exact string (string or binary) is used, the
minimum between the string length and this parameter is used.
This parameter is ignored if it is set to -1. If the expect rule
does not match, the check will wait for more data. If set to 0,
the evaluation result is always conclusive.
ok-status <st> is optional and can be used to set the check status if
the expect rule is successfully evaluated and if it is
the last rule in the tcp-check ruleset. "L7OK", "L7OKC",
"L6OK" and "L4OK" are supported :
- L7OK : check passed on layer 7
- L7OKC : check conditionally passed on layer 7, set
server to NOLB state.
- L6OK : check passed on layer 6
- L4OK : check passed on layer 4
By default "L7OK" is used.
error-status <st> is optional and can be used to set the check status if
an error occurred during the expect rule evaluation.
"L7OKC", "L7RSP", "L7STS", "L6RSP" and "L4CON" are
supported :
- L7OKC : check conditionally passed on layer 7, set
server to NOLB state.
- L7RSP : layer 7 invalid response - protocol error
- L7STS : layer 7 response error, for example HTTP 5xx
- L6RSP : layer 6 invalid response - protocol error
- L4CON : layer 1-4 connection problem
By default "L7RSP" is used.
tout-status <st> is optional and can be used to set the check status if
a timeout occurred during the expect rule evaluation.
"L7TOUT", "L6TOUT", and "L4TOUT" are supported :
- L7TOUT : layer 7 (HTTP/SMTP) timeout
- L6TOUT : layer 6 (SSL) timeout
- L4TOUT : layer 1-4 timeout
By default "L7TOUT" is used.
on-success <fmt> is optional and can be used to customize the
informational message reported in logs if the expect
rule is successfully evaluated and if it is the last rule
in the tcp-check ruleset. <fmt> is a Custom log format
(see section 8.2.6).
on-error <fmt> is optional and can be used to customize the
informational message reported in logs if an error
occurred during the expect rule evaluation. <fmt> is a
Custom log format (see section 8.2.6).
status-code <expr> is optional and can be used to set the check status code
reported in logs, on success or on error. <expr> is a
standard HAProxy expression formed by a sample-fetch
followed by some converters.
<match> is a keyword indicating how to look for a specific pattern in the
response. The keyword may be one of "string", "rstring", "binary" or
"rbinary".
The keyword may be preceded by an exclamation mark ("!") to negate
the match. Spaces are allowed between the exclamation mark and the
keyword. See below for more details on the supported keywords.
<pattern> is the pattern to look for. It may be a string or a regular
expression. If the pattern contains spaces, they must be escaped
with the usual backslash ('\').
If the match is set to binary, then the pattern must be passed as
a series of hexadecimal digits in an even number. Each sequence of
two digits will represent a byte. The hexadecimal digits may be
used upper or lower case.
The available matches are intentionally similar to their http-check cousins :
string <string> : test the exact string matches in the response buffer.
A health check response will be considered valid if the
response's buffer contains this exact string. If the
"string" keyword is prefixed with "!", then the response
will be considered invalid if the body contains this
string. This can be used to look for a mandatory pattern
in a protocol response, or to detect a failure when a
specific error appears in a protocol banner.
rstring <regex> : test a regular expression on the response buffer.
A health check response will be considered valid if the
response's buffer matches this expression. If the
"rstring" keyword is prefixed with "!", then the response
will be considered invalid if the body matches the
expression.
string-lf <fmt> : test a Custom log format match in the response's buffer.
A health check response will be considered valid if the
response's buffer contains the string resulting of the
evaluation of <fmt>, which follows the Custom log format
rules described in section 8.2.6. If prefixed with "!",
then the response will be considered invalid if the
buffer contains the string.
binary <hexstring> : test the exact string in its hexadecimal form matches
in the response buffer. A health check response will
be considered valid if the response's buffer contains
this exact hexadecimal string.
Purpose is to match data on binary protocols.
rbinary <regex> : test a regular expression on the response buffer, like
"rstring". However, the response buffer is transformed
into its hexadecimal form, including NUL-bytes. This
allows using all regex engines to match any binary
content. The hexadecimal transformation takes twice the
size of the original response. As such, the expected
pattern should work on at-most half the response buffer
size.
binary-lf <hexfmt> : test a Custom log format in its hexadecimal form match
in the response's buffer. A health check response will
be considered valid if the response's buffer contains
the hexadecimal string resulting of the evaluation of
<fmt>, which follows the Custom log format rules (see
section 8.2.6). If prefixed with "!", then the
response will be considered invalid if the buffer
contains the hexadecimal string. The hexadecimal
string is converted in a binary string before matching
the response's buffer.
It is important to note that the responses will be limited to a certain size
defined by the global "tune.bufsize" option, which defaults to 16384 bytes.
Thus, too large responses may not contain the mandatory pattern when using
"string", "rstring" or binary. If a large response is absolutely required, it
is possible to change the default max size by setting the global variable.
However, it is worth keeping in mind that parsing very large responses can
waste some CPU cycles, especially when regular expressions are used, and that
it is always better to focus the checks on smaller resources. Also, in its
current state, the check will not find any string nor regex past a null
character in the response. Similarly it is not possible to request matching
the null character.
# perform a POP check
option tcp-check
tcp-check expect string +OK\ POP3\ ready
# perform an IMAP check
option tcp-check
tcp-check expect string *\ OK\ IMAP4\ ready
# look for the redis master server
option tcp-check
tcp-check send PING\r\n
tcp-check expect string +PONG
tcp-check send info\ replication\r\n
tcp-check expect string role:master
tcp-check send QUIT\r\n
tcp-check expect string +OK
Specify a string or a Custom log format to be sent as a question during a generic health check May be used in the following contexts: tcp, http, log
May be used in sections :
| defaults | frontend | listen | backend |
|---|---|---|---|
yes![]() | no![]() | yes![]() | yes![]() |
comment <msg> defines a message to report if the rule evaluation fails.
<data> is the string that will be sent during a generic health
check session.
<fmt> is the Custom log format that will be sent, once evaluated,
during a generic health check session (see section 8.2.6).
# look for the redis master server
option tcp-check
tcp-check send info\ replication\r\n
tcp-check expect string role:master
Specify an hex digits string or an hex digits Custom log format to be sent as a binary question during a raw tcp health check May be used in the following contexts: tcp, http, log
May be used in sections :
| defaults | frontend | listen | backend |
|---|---|---|---|
yes![]() | no![]() | yes![]() | yes![]() |
comment <msg> defines a message to report if the rule evaluation fails.
<hexstring> is the hexadecimal string that will be send, once converted
to binary, during a generic health check session.
<hexfmt> is the hexadecimal Custom log format that will be send, once
evaluated and converted to binary, during a generic health
check session (see section 8.2.6).
# redis check in binary
option tcp-check
tcp-check send-binary 50494e470d0a # PING\r\n
tcp-check expect binary 2b504F4e47 # +PONG
This operation sets the content of a variable. The variable is declared inline. May be used in the following contexts: tcp, http, log
May be used in sections :
| defaults | frontend | listen | backend |
|---|---|---|---|
yes![]() | no![]() | yes![]() | yes![]() |
<var-name> The name of the variable. Only "proc", "sess" and "check" scopes can be used. See section 2.8 about variables for details. <cond> A set of conditions that must all be true for the variable to actually be set (such as "ifnotempty", "ifgt" ...). See the set-var converter's description for a full list of possible conditions. <expr> Is a sample-fetch expression potentially followed by converters. <fmt> This is the value expressed using Custom log format rules (see Custom log format in section 8.2.6).
tcp-check set-var(check.port) int(1234)
tcp-check set-var-fmt(check.name) "%H"
Free a reference to a variable within its scope. May be used in the following contexts: tcp, http, log
May be used in sections :
| defaults | frontend | listen | backend |
|---|---|---|---|
yes![]() | no![]() | yes![]() | yes![]() |
<var-name> The name of the variable. Only "proc", "sess" and "check" scopes can be used. See section 2.8 about variables for details.
tcp-check unset-var(check.port)
Perform an action on an incoming connection depending on a layer 4 condition May be used in the following contexts: tcp, http
May be used in sections :
| defaults | frontend | listen | backend |
|---|---|---|---|
yes(!)![]() | yes![]() | yes![]() | no![]() |
<action> defines the action to perform if the condition applies. See
below.
<condition> is a standard layer4-only ACL-based condition (see section 7).
Immediately after acceptance of a new incoming connection, it is possible to evaluate some conditions to decide whether this connection must be accepted or dropped or have its counters tracked. Those conditions cannot make use of any data contents because the connection has not been read from yet, and the buffers are not yet allocated. This is used to selectively and very quickly accept or drop connections from various sources with a very low overhead. If some contents need to be inspected in order to take the decision, the "tcp-request content" statements must be used instead. The "tcp-request connection" rules are evaluated in their exact declaration order. If no rule matches or if there is no rule, the default action is to accept the incoming connection. There is no specific limit to the number of rules which may be inserted. Any rule may optionally be followed by an ACL-based condition, in which case it will only be evaluated if the condition evaluates to true. The condition is evaluated just before the action is executed, and the action is performed exactly once. As such, there is no problem if an action changes an element which is checked as part of the condition. This also means that multiple actions may rely on the same condition so that the first action that changes the condition's evaluation is sufficient to implicitly disable the remaining actions. This is used for example when trying to assign a value to a variable from various sources when it's empty. The first keyword after "tcp-request connection" in the syntax is the rule's action, optionally followed by a varying number of arguments for the action. The supported actions and their respective syntaxes are enumerated in section 4.3 "Actions" (look for actions which tick "TCP RqCon"). This directive is only available from named defaults sections, not anonymous ones. Rules defined in the defaults section are evaluated before ones in the associated proxy section. To avoid ambiguities, in this case the same defaults section cannot be used by proxies with the frontend capability and by proxies with the backend capability. It means a listen section cannot use a defaults section defining such rules. Note that the "if/unless" condition is optional. If no condition is set on the action, it is simply performed unconditionally. That can be useful for "track-sc*" actions as well as for changing the default action to a reject.
Accept all connections from white-listed hosts, reject too fast connection without counting them, and track accepted connections. This results in connection rate being capped from abusive sources.tcp-request connection accept if { src -f /etc/haproxy/whitelist.lst } tcp-request connection reject if { src_conn_rate gt 10 } tcp-request connection track-sc0 src
Accept all connections from white-listed hosts, count all other connections and reject too fast ones. This results in abusive ones being blocked as long as they don't slow down.tcp-request connection accept if { src -f /etc/haproxy/whitelist.lst } tcp-request connection track-sc0 src tcp-request connection reject if { sc0_conn_rate gt 10 }
Enable the PROXY protocol for traffic coming from all known proxies.tcp-request connection expect-proxy layer4 if { src -f proxies.lst }
See section 7 about ACL usage.
Perform an action on a new session depending on a layer 4-7 condition May be used in the following contexts: tcp, http
May be used in sections :
| defaults | frontend | listen | backend |
|---|---|---|---|
yes(!)![]() | yes![]() | yes![]() | yes![]() |
<action> defines the action to perform if the condition applies. See
below.
<condition> is a standard layer 4-7 ACL-based condition (see section 7).
A request's contents can be analyzed at an early stage of request processing called "TCP content inspection". During this stage, ACL-based rules are evaluated every time the request contents are updated, until either an "accept", a "reject" or a "switch-mode" rule matches, or the TCP request inspection delay expires with no matching rule. The first difference between these rules and "tcp-request connection" rules is that "tcp-request content" rules can make use of contents to take a decision. Most often, these decisions will consider a protocol recognition or validity. The second difference is that content-based rules can be used in both frontends and backends. In case of HTTP keep-alive with the client, all tcp-request content rules are evaluated again, so HAProxy keeps a record of what sticky counters were assigned by a "tcp-request connection" versus a "tcp-request content" rule, and flushes all the content-related ones after processing an HTTP request, so that they may be evaluated again by the rules being evaluated again for the next request. This is of particular importance when the rule tracks some L7 information or when it is conditioned by an L7-based ACL, since tracking may change between requests. Content-based rules are evaluated in their exact declaration order. If no rule matches or if there is no rule, the default action is to accept the contents. There is no specific limit to the number of rules which may be inserted. While there is nothing mandatory about it, it is recommended to use the track-sc0 in "tcp-request connection" rules, track-sc1 for "tcp-request content" rules in the frontend, and track-sc2 for "tcp-request content" rules in the backend, because that makes the configuration more readable and easier to troubleshoot, but this is just a guideline and all counters may be used everywhere. The first keyword after "tcp-request content" in the syntax is the rule's action, optionally followed by a varying number of arguments for the action. The supported actions and their respective syntaxes are enumerated in section 4.3 "Actions" (look for actions which tick "TCP RqCnt"). This directive is only available from named defaults sections, not anonymous ones. Rules defined in the defaults section are evaluated before ones in the associated proxy section. To avoid ambiguities, in this case the same defaults section cannot be used by proxies with the frontend capability and by proxies with the backend capability. It means a listen section cannot use a defaults section defining such rules. Note that the "if/unless" condition is optional. If no condition is set on the action, it is simply performed unconditionally. That can be useful for "track-sc*" actions as well as for changing the default action to a reject. Note also that it is recommended to use a "tcp-request session" rule to track information that does *not* depend on Layer 7 contents, especially for HTTP frontends. Some HTTP processing are performed at the session level and may lead to an early rejection of the requests. Thus, the tracking at the content level may be disturbed in such case. A warning is emitted during startup to prevent, as far as possible, such unreliable usage. It is perfectly possible to match layer 7 contents with "tcp-request content" rules from a TCP proxy, since HTTP-specific ACL matches are able to preliminarily parse the contents of a buffer before extracting the required data. If the buffered contents do not parse as a valid HTTP message, then the ACL does not match. The parser which is involved there is exactly the same as for all other HTTP processing, so there is no risk of parsing something differently. In an HTTP frontend or an HTTP backend, it is guaranteed that HTTP contents will always be immediately present when the rule is evaluated first because the HTTP parsing is performed in the early stages of the connection processing, at the session level. But for such proxies, using "http-request" rules is much more natural and recommended. Tracking layer7 information is also possible provided that the information are present when the rule is processed. The rule processing engine is able to wait until the inspect delay expires when the data to be tracked is not yet available.
tcp-request content use-service lua.deny if { src -f /etc/haproxy/blacklist.lst }
tcp-request content set-var(sess.my_var) src
tcp-request content set-var-fmt(sess.from) %[src]:%[src_port]
tcp-request content unset-var(sess.my_var2)
# Accept HTTP requests containing a Host header saying "example.com"
# and reject everything else. (Only works for HTTP/1 connections)
acl is_host_com hdr(Host) -i example.com
tcp-request inspect-delay 30s
tcp-request content accept if is_host_com
tcp-request content reject
# Accept HTTP requests containing a Host header saying "example.com"
# and reject everything else. (works for HTTP/1 and HTTP/2 connections)
acl is_host_com hdr(Host) -i example.com
tcp-request inspect-delay 5s
tcp-request content switch-mode http if HTTP
tcp-request content reject # non-HTTP traffic is implicit here
...
http-request reject unless is_host_com
# reject SMTP connection if client speaks first
tcp-request inspect-delay 30s
acl content_present req.len gt 0
tcp-request content reject if content_present
# Forward HTTPS connection only if client speaks
tcp-request inspect-delay 30s
acl content_present req.len gt 0
tcp-request content accept if content_present
tcp-request content reject
# Track the last IP(stick-table type string) from X-Forwarded-For
tcp-request inspect-delay 10s
tcp-request content track-sc0 hdr(x-forwarded-for,-1)
# Or track the last IP(stick-table type ip|ipv6) from X-Forwarded-For
tcp-request content track-sc0 req.hdr_ip(x-forwarded-for,-1)
# track request counts per "base" (concatenation of Host+URL)
tcp-request inspect-delay 10s
tcp-request content track-sc0 base table req-rate
Track per-frontend and per-backend counters, block abusers at the frontend when the backend detects abuse(and marks gpc0).frontend http # Use General Purpose Counter 0 in SC0 as a global abuse counter # protecting all our sites stick-table type ip size 1m expire 5m store gpc0 tcp-request connection track-sc0 src tcp-request connection reject if { sc0_get_gpc0 gt 0 } ... use_backend http_dynamic if { path_end .php } backend http_dynamic # if a source makes too fast requests to this dynamic site (tracked # by SC1), block it globally in the frontend. stick-table type ip size 1m expire 5m store http_req_rate(10s) acl click_too_fast sc1_http_req_rate gt 10 acl mark_as_abuser sc0_inc_gpc0(http) gt 0 tcp-request content track-sc1 src tcp-request content reject if click_too_fast mark_as_abuser
See section 7 about ACL usage.
Set the maximum allowed time to wait for data during content inspection May be used in the following contexts: tcp, http
May be used in sections :
| defaults | frontend | listen | backend |
|---|---|---|---|
yes(!)![]() | yes![]() | yes![]() | yes![]() |
<timeout> is the timeout value specified in milliseconds by default, but
can be in any other unit if the number is suffixed by the unit,
as explained at the top of this document.
People using HAProxy primarily as a TCP relay are often worried about the risk of passing any type of protocol to a server without any analysis. In order to be able to analyze the request contents, we must first withhold the data then analyze them. This statement simply enables withholding of data for at most the specified amount of time. TCP content inspection applies very early when a connection reaches a frontend, then very early when the connection is forwarded to a backend. This means that a connection may experience a first delay in the frontend and a second delay in the backend if both have tcp-request rules. Note that when performing content inspection, HAProxy will evaluate the whole rules for every new chunk which gets in, taking into account the fact that those data are partial. If no rule matches before the aforementioned delay, a last check is performed upon expiration, this time considering that the contents are definitive. If no delay is set, HAProxy will not wait at all and will immediately apply a verdict based on the available information. Obviously this is unlikely to be very useful and might even be racy, so such setups are not recommended. Note the inspection delay is shortened if an connection error or shutdown is experienced or if the request buffer appears as full. As soon as a rule matches, the request is released and continues as usual. If the timeout is reached and no rule matches, the default policy will be to let it pass through unaffected. For most protocols, it is enough to set it to a few seconds, as most clients send the full request immediately upon connection. Add 3 or more seconds to cover TCP retransmits but that's all. For some protocols, it may make sense to use large values, for instance to ensure that the client never talks before the server (e.g. SMTP), or to wait for a client to talk before passing data to the server (e.g. SSL). Note that the client timeout must cover at least the inspection delay, otherwise it will expire first. If the client closes the connection or if the buffer is full, the delay immediately expires since the contents will not be able to change anymore. This directive is only available from named defaults sections, not anonymous ones. Proxies inherit this value from their defaults section.
Perform an action on a validated session depending on a layer 5 condition May be used in the following contexts: tcp, http
May be used in sections :
| defaults | frontend | listen | backend |
|---|---|---|---|
yes(!)![]() | yes![]() | yes![]() | no![]() |
<action> defines the action to perform if the condition applies. See
below.
<condition> is a standard layer5-only ACL-based condition (see section 7).
Once a session is validated, (i.e. after all handshakes have been completed), it is possible to evaluate some conditions to decide whether this session must be accepted or dropped or have its counters tracked. Those conditions cannot make use of any data contents because no buffers are allocated yet and the processing cannot wait at this stage. The main use case is to copy some early information into variables (since variables are accessible in the session), or to keep track of some information collected after the handshake, such as SSL-level elements (SNI, ciphers, client cert's CN) or information from the PROXY protocol header (e.g. track a source forwarded this way). The extracted information can thus be copied to a variable or tracked using "track-sc" rules. Of course it is also possible to decide to accept/reject as with other rulesets. Most operations performed here could also be performed in "tcp-request content" rules, except that in HTTP these rules are evaluated for each new request, and that might not always be acceptable. For example a rule might increment a counter on each evaluation. It would also be possible that a country is resolved by geolocation from the source IP address, assigned to a session-wide variable, then the source address rewritten from an HTTP header for all requests. If some contents need to be inspected in order to take the decision, the "tcp-request content" statements must be used instead. The "tcp-request session" rules are evaluated in their exact declaration order. If no rule matches or if there is no rule, the default action is to accept the incoming session. There is no specific limit to the number of rules which may be inserted. The first keyword after "tcp-request session" in the syntax is the rule's action, optionally followed by a varying number of arguments for the action. The supported actions and their respective syntaxes are enumerated in section 4.3 "Actions" (look for actions which tick "TCP RqSes"). This directive is only available from named defaults sections, not anonymous ones. Rules defined in the defaults section are evaluated before ones in the associated proxy section. To avoid ambiguities, in this case the same defaults section cannot be used by proxies with the frontend capability and by proxies with the backend capability. It means a listen section cannot use a defaults section defining such rules. Note that the "if/unless" condition is optional. If no condition is set on the action, it is simply performed unconditionally. That can be useful for "track-sc*" actions as well as for changing the default action to a reject.
Track the original source address by default, or the one advertised in the PROXY protocol header for connection coming from the local proxies. The first connection-level rule enables receipt of the PROXY protocol for these ones, the second rule tracks whatever address we decide to keep after optional decoding.tcp-request connection expect-proxy layer4 if { src -f proxies.lst } tcp-request session track-sc0 src
Accept all sessions from white-listed hosts, reject too fast sessions without counting them, and track accepted sessions. This results in session rate being capped from abusive sources.tcp-request session accept if { src -f /etc/haproxy/whitelist.lst } tcp-request session reject if { src_sess_rate gt 10 } tcp-request session track-sc0 src
Accept all sessions from white-listed hosts, count all other sessions and reject too fast ones. This results in abusive ones being blocked as long as they don't slow down.tcp-request session accept if { src -f /etc/haproxy/whitelist.lst } tcp-request session track-sc0 src tcp-request session reject if { sc0_sess_rate gt 10 }
See section 7 about ACL usage.
Perform an action on a session response depending on a layer 4-7 condition May be used in the following contexts: tcp, http
May be used in sections :
| defaults | frontend | listen | backend |
|---|---|---|---|
yes(!)![]() | no![]() | yes![]() | yes![]() |
<action> defines the action to perform if the condition applies. See
below.
<condition> is a standard layer 4-7 ACL-based condition (see section 7).
Response contents can be analyzed at an early stage of response processing called "TCP content inspection". During this stage, ACL-based rules are evaluated every time the response contents are updated, until either a final rule matches, or a TCP response inspection delay is set and expires with no matching rule. Most often, these decisions will consider a protocol recognition or validity. Content-based rules are evaluated in their exact declaration order. If no rule matches or if there is no rule, the default action is to accept the contents. There is no specific limit to the number of rules which may be inserted. The first keyword after "tcp-response content" in the syntax is the rule's action, optionally followed by a varying number of arguments for the action. The supported actions and their respective syntaxes are enumerated in section 4.3 "Actions" (look for actions which tick "TCP RsCnt"). This directive is only available from named defaults sections, not anonymous ones. Rules defined in the defaults section are evaluated before ones in the associated proxy section. To avoid ambiguities, in this case the same defaults section cannot be used by proxies with the frontend capability and by proxies with the backend capability. It means a listen section cannot use a defaults section defining such rules. Note that the "if/unless" condition is optional. If no condition is set on the action, it is simply performed unconditionally. That can be useful for for changing the default action to a reject. Several types of actions are supported : It is perfectly possible to match layer 7 contents with "tcp-response content" rules, but then it is important to ensure that a full response has been buffered, otherwise no contents will match. In order to achieve this, the best solution involves detecting the HTTP protocol during the inspection period. See section 7 about ACL usage.
Set the maximum allowed time to wait for a response during content inspection May be used in the following contexts: tcp, http
May be used in sections :
| defaults | frontend | listen | backend |
|---|---|---|---|
yes(!)![]() | no![]() | yes![]() | yes![]() |
<timeout> is the timeout value specified in milliseconds by default, but
can be in any other unit if the number is suffixed by the unit,
as explained at the top of this document.
This directive is only available from named defaults sections, not anonymous ones. Proxies inherit this value from their defaults section.
Set additional check timeout, but only after a connection has been already established. May be used in the following contexts: tcp, http, log
May be used in sections :
| defaults | frontend | listen | backend |
|---|---|---|---|
yes![]() | no![]() | yes![]() | yes![]() |
<timeout> is the timeout value specified in milliseconds by default, but
can be in any other unit if the number is suffixed by the unit,
as explained at the top of this document.
If set, HAProxy uses min("timeout connect", "inter") as a connect timeout
for check and "timeout check" as an additional read timeout. The "min" is
used so that people running with *very* long "timeout connect" (e.g. those
who needed this due to the queue or tarpit) do not slow down their checks.
(Please also note that there is no valid reason to have such long connect
timeouts, because "timeout queue" and "timeout tarpit" can always be used to
avoid that).
If "timeout check" is not set HAProxy uses "inter" for complete check
timeout (connect + read) exactly like all <1.3.15 version.
In most cases check request is much simpler and faster to handle than normal
requests and people may want to kick out laggy servers so this timeout should
be smaller than "timeout server".
This parameter is specific to backends, but can be specified once for all in
"defaults" sections. This is in fact one of the easiest solutions not to
forget about it.
Set the maximum inactivity time on the client side. May be used in the following contexts: tcp, http
May be used in sections :
| defaults | frontend | listen | backend |
|---|---|---|---|
yes![]() | yes![]() | yes![]() | no![]() |
<timeout> is the timeout value specified in milliseconds by default, but
can be in any other unit if the number is suffixed by the unit,
as explained at the top of this document.
The inactivity timeout applies when the client is expected to acknowledge or send data. In HTTP mode, this timeout is particularly important to consider during the first phase, when the client sends the request, and during the response while it is reading data sent by the server. That said, for the first phase, it is preferable to set the "timeout http-request" to better protect HAProxy from Slowloris like attacks. The value is specified in milliseconds by default, but can be in any other unit if the number is suffixed by the unit, as specified at the top of this document. In TCP mode (and to a lesser extent, in HTTP mode), it is highly recommended that the client timeout remains equal to the server timeout in order to avoid complex situations to debug. It is a good practice to cover one or several TCP packet losses by specifying timeouts that are slightly above multiples of 3 seconds (e.g. 4 or 5 seconds). If some long-lived streams are mixed with short-lived streams (e.g. WebSocket and HTTP), it's worth considering "timeout tunnel", which overrides "timeout client" and "timeout server" for tunnels, as well as "timeout client-fin" for half-closed connections. This parameter is specific to frontends, but can be specified once for all in "defaults" sections. This is in fact one of the easiest solutions not to forget about it. An unspecified timeout results in an infinite timeout, which is not recommended. Such a usage is accepted and works but reports a warning during startup because it may result in accumulation of expired sessions in the system if the system's timeouts are not configured either.
Set the inactivity timeout on the client side for half-closed connections. May be used in the following contexts: tcp, http
May be used in sections :
| defaults | frontend | listen | backend |
|---|---|---|---|
yes![]() | yes![]() | yes![]() | no![]() |
<timeout> is the timeout value specified in milliseconds by default, but
can be in any other unit if the number is suffixed by the unit,
as explained at the top of this document.
The inactivity timeout applies when the client is expected to acknowledge or send data while one direction is already shut down. This timeout is different from "timeout client" in that it only applies to connections which are closed in one direction. This is particularly useful to avoid keeping connections in FIN_WAIT state for too long when clients do not disconnect cleanly. This problem is particularly common long connections such as RDP or WebSocket. Note that this timeout can override "timeout tunnel" when a connection shuts down in one direction. It is applied to idle HTTP/2 connections once a GOAWAY frame was sent, often indicating an expectation that the connection quickly ends. This parameter is specific to frontends, but can be specified once for all in "defaults" sections. By default it is not set, so half-closed connections will use the other timeouts (timeout.client or timeout.tunnel).
Set the maximum time to wait for a client TLS handshake to complete. This is usable both for TCP and QUIC connections. May be used in the following contexts: tcp, http
May be used in sections :
| defaults | frontend | listen | backend |
|---|---|---|---|
yes![]() | yes![]() | yes![]() | no![]() |
<timeout> is the timeout value specified in milliseconds by default, but
can be in any other unit if the number is suffixed by the unit,
as explained at the top of this document.
If this handshake timeout is not set, this is the client timeout which is used in place.
Set the maximum time to wait for a connection attempt to a server to succeed. May be used in the following contexts: tcp, http, log
May be used in sections :
| defaults | frontend | listen | backend |
|---|---|---|---|
yes![]() | no![]() | yes![]() | yes![]() |
<timeout> is the timeout value specified in milliseconds by default, but
can be in any other unit if the number is suffixed by the unit,
as explained at the top of this document.
If the server is located on the same LAN as HAProxy, the connection should be immediate (less than a few milliseconds). Anyway, it is a good practice to cover one or several TCP packet losses by specifying timeouts that are slightly above multiples of 3 seconds (e.g. 4 or 5 seconds). By default, the connect timeout also presets both queue and tarpit timeouts to the same value if these have not been specified. This parameter is specific to backends, but can be specified once for all in "defaults" sections. This is in fact one of the easiest solutions not to forget about it. An unspecified timeout results in an infinite timeout, which is not recommended. Such a usage is accepted and works but reports a warning during startup because it may result in accumulation of failed sessions in the system if the system's timeouts are not configured either.
Set the maximum allowed time to wait for a new HTTP request to appear May be used in the following contexts: http
May be used in sections :
| defaults | frontend | listen | backend |
|---|---|---|---|
yes![]() | yes![]() | yes![]() | yes![]() |
<timeout> is the timeout value specified in milliseconds by default, but
can be in any other unit if the number is suffixed by the unit,
as explained at the top of this document.
By default, the time to wait for a new request in case of keep-alive is set by "timeout http-request". However this is not always convenient because some people want very short keep-alive timeouts in order to release connections faster, and others prefer to have larger ones but still have short timeouts once the request has started to present itself. The "http-keep-alive" timeout covers these needs. It will define how long to wait for a new HTTP request to start coming after a response was sent. Once the first byte of request has been seen, the "http-request" timeout is used to wait for the complete request to come. Note that empty lines prior to a new request do not refresh the timeout and are not counted as a new request. There is also another difference between the two timeouts : when a connection expires during timeout http-keep-alive, no error is returned, the connection just closes. If the connection expires in "http-request" while waiting for a request to complete, an HTTP 408 error is returned to the client before closing the connection, unless "option http-ignore-probes" is set in the frontend. In general "timeout http-keep-alive" is best used to prevent clients from holding open an otherwise idle connection too long on sites seeing large amounts of short connections. This can be accomplished by setting the value to a few tens to hundreds of milliseconds in HTTP/1.1. This will close the connection after the client requests a page without having to hold that connection open to wait for more activity from the client. In that scenario, a new activity from the browser would result in a new handshake at the TCP and/or SSL layer. A common use case for this is HTTP sites serving only a redirect to the HTTPS page. Such connections are better not kept idle too long because they won't be reused, unless maybe to fetch a favicon. Another use case is the exact opposite: some sites want to permit clients to reuse idle connections for a long time (e.g. 30 seconds to one minute) but do not want to wait that long for the first request, in order to avoid a very inexpensive attack vector. In this case, the http-keep-alive timeout would be set to a large value, but http-request would remain low (a few seconds). When set to a very small value additional requests that are not pipelined are likely going to be handled over another connection unless the requests are truly pipelined, which is very rare with HTTP/1.1 (requests being sent back-to-back without waiting for a response). Most HTTP/1.1 implementations send a request, wait for a response and then send another request. A small value here for HTTP/1.1 may be advantageous to use less memory and sockets for sites with hundreds of thousands of clients, at the expense of an increase in handshake computation costs. Special care should be taken with small values when dealing with HTTP/2. The nature of HTTP/2 is to multiplex requests over a connection in order to save on the overhead of reconnecting the TCP and/or SSL layers. The protocol also uses control frames which cope poorly with early TCP connection closures, on very rare occasions this may result in truncated responses when data are destroyed in flight after leaving HAProxy (which then cannot even log an error). A suggested low starting value for HTTP/2 connections would be around 4 seconds. This would prevent most modern keep-alive implementations from needlessly holding open stale connections, and at the same time would allow subsequent requests to reuse the connection. However, this should be adjusted as needed and is simply a starting point. If this parameter is not set, the "http-request" timeout applies, and if both are not set, "timeout client" still applies at the lower level. It should be set in the frontend to take effect, unless the frontend is in TCP mode, in which case the HTTP backend's timeout will be used.
Set the maximum allowed time to wait for a complete HTTP request May be used in the following contexts: http
May be used in sections :
| defaults | frontend | listen | backend |
|---|---|---|---|
yes![]() | yes![]() | yes![]() | yes![]() |
<timeout> is the timeout value specified in milliseconds by default, but
can be in any other unit if the number is suffixed by the unit,
as explained at the top of this document.
In order to offer DoS protection, it may be required to lower the maximum accepted time to receive a complete HTTP request without affecting the client timeout. This helps protecting against established connections on which nothing is sent. The client timeout cannot offer a good protection against this abuse because it is an inactivity timeout, which means that if the attacker sends one character every now and then, the timeout will not trigger. With the HTTP request timeout, no matter what speed the client types, the request will be aborted if it does not complete in time. When the timeout expires, an HTTP 408 response is sent to the client to inform it about the problem, and the connection is closed. The logs will report termination codes "cR". Some recent browsers are having problems with this standard, well-documented behavior, so it might be needed to hide the 408 code using "option http-ignore-probes" or "errorfile 408 /dev/null". See more details in the explanations of the "cR" termination code in section 8.5. By default, this timeout only applies to the header part of the request, and not to any data. As soon as the empty line is received, this timeout is not used anymore. When combined with "option http-buffer-request", this timeout also applies to the body of the request.. It is used again on keep-alive connections to wait for a second request if "timeout http-keep-alive" is not set. Generally it is enough to set it to a few seconds, as most clients send the full request immediately upon connection. Add 3 or more seconds to cover TCP retransmits but that's all. Setting it to very low values (e.g. 50 ms) will generally work on local networks as long as there are no packet losses. This will prevent people from sending bare HTTP requests using telnet. If this parameter is not set, the client timeout still applies between each chunk of the incoming request. It should be set in the frontend to take effect, unless the frontend is in TCP mode, in which case the HTTP backend's timeout will be used.
Set the maximum time to wait in the queue for a connection slot to be free May be used in the following contexts: tcp, http
May be used in sections :
| defaults | frontend | listen | backend |
|---|---|---|---|
yes![]() | no![]() | yes![]() | yes![]() |
<timeout> is the timeout value specified in milliseconds by default, but
can be in any other unit if the number is suffixed by the unit,
as explained at the top of this document.
When a server's maxconn is reached, connections are left pending in a queue which may be server-specific or global to the backend. In order not to wait indefinitely, a timeout is applied to requests pending in the queue. If the timeout is reached, it is considered that the request will almost never be served, so it is dropped and a 503 error is returned to the client. The "timeout queue" statement allows to fix the maximum time for a request to be left pending in a queue. If unspecified, the same value as the backend's connection timeout ("timeout connect") is used, for backwards compatibility with older versions with no "timeout queue" parameter.
Set the maximum inactivity time on the server side. May be used in the following contexts: tcp, http, log
May be used in sections :
| defaults | frontend | listen | backend |
|---|---|---|---|
yes![]() | no![]() | yes![]() | yes![]() |
<timeout> is the timeout value specified in milliseconds by default, but
can be in any other unit if the number is suffixed by the unit,
as explained at the top of this document.
The inactivity timeout applies when the server is expected to acknowledge or send data. In HTTP mode, this timeout is particularly important to consider during the first phase of the server's response, when it has to send the headers, as it directly represents the server's processing time for the request. To find out what value to put there, it's often good to start with what would be considered as unacceptable response times, then check the logs to observe the response time distribution, and adjust the value accordingly. The value is specified in milliseconds by default, but can be in any other unit if the number is suffixed by the unit, as specified at the top of this document. In TCP mode (and to a lesser extent, in HTTP mode), it is highly recommended that the client timeout remains equal to the server timeout in order to avoid complex situations to debug. Whatever the expected server response times, it is a good practice to cover at least one or several TCP packet losses by specifying timeouts that are slightly above multiples of 3 seconds (e.g. 4 or 5 seconds minimum). If some long-lived streams are mixed with short-lived streams (e.g. WebSocket and HTTP), it's worth considering "timeout tunnel", which overrides "timeout client" and "timeout server" for tunnels. This parameter is specific to backends, but can be specified once for all in "defaults" sections. This is in fact one of the easiest solutions not to forget about it. An unspecified timeout results in an infinite timeout, which is not recommended. Such a usage is accepted and works but reports a warning during startup because it may result in accumulation of expired sessions in the system if the system's timeouts are not configured either.
Set the inactivity timeout on the server side for half-closed connections. May be used in the following contexts: tcp, http, log
May be used in sections :
| defaults | frontend | listen | backend |
|---|---|---|---|
yes![]() | no![]() | yes![]() | yes![]() |
<timeout> is the timeout value specified in milliseconds by default, but
can be in any other unit if the number is suffixed by the unit,
as explained at the top of this document.
The inactivity timeout applies when the server is expected to acknowledge or send data while one direction is already shut down. This timeout is different from "timeout server" in that it only applies to connections which are closed in one direction. This is particularly useful to avoid keeping connections in FIN_WAIT state for too long when a remote server does not disconnect cleanly. This problem is particularly common long connections such as RDP or WebSocket. Note that this timeout can override "timeout tunnel" when a connection shuts down in one direction. This setting was provided for completeness, but in most situations, it should not be needed. This parameter is specific to backends, but can be specified once for all in "defaults" sections. By default it is not set, so half-closed connections will use the other timeouts (timeout.server or timeout.tunnel).
Set the duration for which tarpitted connections will be maintained May be used in the following contexts: http
May be used in sections :
| defaults | frontend | listen | backend |
|---|---|---|---|
yes![]() | yes![]() | yes![]() | yes![]() |
<timeout> is the tarpit duration specified in milliseconds by default, but
can be in any other unit if the number is suffixed by the unit,
as explained at the top of this document.
When a connection is tarpitted using "http-request tarpit", it is maintained
open with no activity for a certain amount of time, then closed. "timeout
tarpit" defines how long it will be maintained open.
The value is specified in milliseconds by default, but can be in any other
unit if the number is suffixed by the unit, as specified at the top of this
document. If unspecified, the same value as the backend's connection timeout
("timeout connect") is used, for backwards compatibility with older versions
with no "timeout tarpit" parameter.
Set the maximum inactivity time on the client and server side for tunnels. May be used in the following contexts: tcp, http
May be used in sections :
| defaults | frontend | listen | backend |
|---|---|---|---|
yes![]() | no![]() | yes![]() | yes![]() |
<timeout> is the timeout value specified in milliseconds by default, but
can be in any other unit if the number is suffixed by the unit,
as explained at the top of this document.
The tunnel timeout applies when a bidirectional connection is established between a client and a server, and the connection remains inactive in both directions. This timeout supersedes both the client and server timeouts once the connection becomes a tunnel. In TCP, this timeout is used as soon as no analyzer remains attached to either connection (e.g. tcp content rules are accepted). In HTTP, this timeout is used when a connection is upgraded (e.g. when switching to the WebSocket protocol, or forwarding a CONNECT request to a proxy), or after the first response when no keepalive/close option is specified. Since this timeout is usually used in conjunction with long-lived connections, it usually is a good idea to also set "timeout client-fin" to handle the situation where a client suddenly disappears from the net and does not acknowledge a close, or sends a shutdown and does not acknowledge pending data anymore. This can happen in lossy networks where firewalls are present, and is detected by the presence of large amounts of sessions in a FIN_WAIT state. The value is specified in milliseconds by default, but can be in any other unit if the number is suffixed by the unit, as specified at the top of this document. Whatever the expected normal idle time, it is a good practice to cover at least one or several TCP packet losses by specifying timeouts that are slightly above multiples of 3 seconds (e.g. 4 or 5 seconds minimum). This parameter is specific to backends, but can be specified once for all in "defaults" sections. This is in fact one of the easiest solutions not to forget about it.
defaults http
option http-server-close
timeout connect 5s
timeout client 30s
timeout client-fin 30s
timeout server 30s
timeout tunnel 1h # timeout to use with WebSocket and CONNECT
Enable client-side transparent proxying May be used in the following contexts: tcp, http
May be used in sections :
| defaults | frontend | listen | backend |
|---|---|---|---|
yes![]() | no![]() | yes![]() | yes![]() |
This keyword was introduced in order to provide layer 7 persistence to layer 3 load balancers. The idea is to use the OS's ability to redirect an incoming connection for a remote address to a local process (here HAProxy), and let this process know what address was initially requested. When this option is used, sessions without cookies will be forwarded to the original destination IP address of the incoming request (which should match that of another equipment), while requests with cookies will still be forwarded to the appropriate server. The "transparent" keyword is deprecated, use "option transparent" instead. Note that contrary to a common belief, this option does NOT make HAProxy present the client's IP to the server when establishing the connection.
Generate a unique ID for each request. May be used in the following contexts: tcp, http
May be used in sections :
| defaults | frontend | listen | backend |
|---|---|---|---|
yes![]() | yes![]() | yes![]() | yes![]() |
<fmt> is a Custom log format string (see section 8.2.6).
This keyword creates a ID for each request using the custom log format. A unique ID is useful to trace a request passing through many components of a complex infrastructure. The newly created ID may also be logged using the %ID alias in the Custom log format string. The format should be composed from elements that are guaranteed to be unique when combined together. For instance, if multiple HAProxy instances are involved, it might be important to include the node name. It is often needed to log the incoming connection's source and destination addresses and ports. Note that since multiple requests may be performed over the same connection, including a request counter may help differentiate them. Similarly, a timestamp may protect against a rollover of the counter. Logging the process ID will avoid collisions after a service restart. It is recommended to use hexadecimal notation for many fields since it makes them more compact and saves space in logs. For regular connections the format configured in the frontend is used to generate the unique ID. For health checks the format of the backend is used when using the "unique-id" fetch within a tcp-check or an http-check ruleset.
unique-id-format %{+X}o\ %ci:%cp_%fi:%fp_%Ts_%rt:%pid
will generate:
7F000001:8296_7F00001E:1F90_4F7B0A69_0003:790A
Add a unique ID header in the HTTP request. May be used in the following contexts: http
May be used in sections :
| defaults | frontend | listen | backend |
|---|---|---|---|
yes![]() | yes![]() | yes![]() | no![]() |
<name> is the name of the header.
Add a unique-id header in the HTTP request sent to the server, using the unique-id-format. It can't work if the unique-id-format doesn't exist.
unique-id-format %{+X}o\ %ci:%cp_%fi:%fp_%Ts_%rt:%pid
unique-id-header X-Unique-ID
will generate:
X-Unique-ID: 7F000001:8296_7F00001E:1F90_4F7B0A69_0003:790A
See also: "unique-id-format"
Switch to a specific backend if/unless an ACL-based condition is matched. May be used in the following contexts: tcp, http
May be used in sections :
| defaults | frontend | listen | backend |
|---|---|---|---|
no![]() | yes![]() | yes![]() | no![]() |
<backend> is the name of a valid backend or "listen" section, or a
Custom log format resolving to a backend name (see Custom
Log Format in section 8.2.6).
<condition> is a condition composed of ACLs, as described in section 7. If
it is omitted, the rule is unconditionally applied.
When doing content-switching, connections arrive on a frontend and are then dispatched to various backends depending on a number of conditions. The relation between the conditions and the backends is described with the "use_backend" keyword. While it is normally used with HTTP processing, it can also be used in pure TCP, either without content using stateless ACLs (e.g. source address validation) or combined with a "tcp-request" rule to wait for some payload. There may be as many "use_backend" rules as desired. All of these rules are evaluated in their declaration order, and the first one which matches will assign the backend. This is even the case if the backend is considered as down. However, if a matching rule targets a disabled or unpublished backend, it is ignored instead and rules evaluation continue. In the first form, the backend will be used if the condition is met. In the second form, the backend will be used if the condition is not met. If no condition is valid, the backend defined with "default_backend" will be used unless it is disabled or unpublished. If no default backend is available, either the servers in the same section are used (in case of a "listen" section) or, in case of a frontend, no server is used and a 503 service unavailable response is returned. Note that it is possible to switch from a TCP frontend to an HTTP backend. In this case, either the frontend has already checked that the protocol is HTTP, and backend processing will immediately follow, or the backend will wait for a complete HTTP request to get in. This feature is useful when a frontend must decode several protocols on a unique port, one of them being HTTP. When <backend> is a simple name, it is resolved at configuration time, and an error is reported if the specified backend does not exist. If <backend> is a Custom log format instead, no check may be done at configuration time, so the backend name is resolved dynamically at run time. If the resulting backend name does not correspond to any valid backend, no other rule is evaluated, and the default_backend directive is applied instead. Note that when using dynamic backend names, it is highly recommended to use a prefix that no other backend uses in order to ensure that an unauthorized backend cannot be forced from the request. It is worth mentioning that "use_backend" rules with an explicit name are used to detect the association between frontends and backends to compute the backend's "fullconn" setting. This cannot be done for dynamic names.
Defines the FastCGI application to use for the backend. May be used in the following contexts: tcp, http
May be used in sections :
| defaults | frontend | listen | backend |
|---|---|---|---|
no![]() | no![]() | yes![]() | yes![]() |
<name> is the name of the FastCGI application to use.
See section 10.1 about FastCGI application setup for details.
Only use a specific server if/unless an ACL-based condition is matched. May be used in the following contexts: tcp, http
May be used in sections :
| defaults | frontend | listen | backend |
|---|---|---|---|
no![]() | no![]() | yes![]() | yes![]() |
<server> is the name of a valid server in the same backend section
or a Custom log format string resolving to a server name
(see section 8.2.6).
<condition> is a condition composed of ACLs, as described in section 7.
By default, connections which arrive to a backend are load-balanced across the available servers according to the configured algorithm, unless a persistence mechanism such as a cookie is used and found in the request. Sometimes it is desirable to forward a particular request to a specific server without having to declare a dedicated backend for this server. This can be achieved using the "use-server" rules. These rules are evaluated after the "redirect" rules and before evaluating cookies, and they have precedence on them. There may be as many "use-server" rules as desired. All of these rules are evaluated in their declaration order, and the first one which matches will assign the server. If a rule designates a server which is down, and "option persist" is not used and no force-persist rule was validated, it is ignored and evaluation goes on with the next rules until one matches. In the first form, the server will be used if the condition is met. In the second form, the server will be used if the condition is not met. If no condition is valid, the processing continues and the server will be assigned according to other persistence mechanisms. Note that even if a rule is matched, cookie processing is still performed but does not assign the server. This allows prefixed cookies to have their prefix stripped. The "use-server" statement works both in HTTP and TCP mode. This makes it suitable for use with content-based inspection. For instance, a server could be selected in a farm according to the TLS SNI field when using protocols with implicit TLS (also see "req.ssl_sni"). And if these servers have their weight set to zero, they will not be used for other traffic.
# intercept incoming TLS requests based on the SNI field
use-server www if { req.ssl_sni -i www.example.com }
server www 192.168.0.1:443 weight 0
use-server mail if { req.ssl_sni -i mail.example.com }
server mail 192.168.0.1:465 weight 0
use-server imap if { req.ssl_sni -i imap.example.com }
server imap 192.168.0.1:993 weight 0
# all the rest is forwarded to this server
server default 192.168.0.2:443 check
When <server> is a simple name, it is checked against existing servers in the configuration and an error is reported if the specified server does not exist. If it is a Custom log format, no check is performed when parsing the configuration, and if we can't resolve a valid server name at runtime but the use-server rule was conditioned by an ACL returning true, no other use-server rule is applied and we fall back to load balancing.
Several rule sets are evaluated at various stages of the request or response processing, and for each rule found in these rule sets, an action may be executed if the optional condition is met. A large number of actions are provided by default, they can modify contents, accept/block processing, change internal states etc. And it is possible to define new actions in Lua (in which case their names will always be prefixed with "lua."). While historically some actions did only exist in specific rule sets, nowadays many actions are usable with many rule sets. The listing in this section will indicate for which supported action where it may be used, by ticking the corresponding abbreviated entry names among the following rule sets: - QUIC Ini: the action is valid for "quic-initial" rules - TCP RqCon: the action is valid for "tcp-request connection" rules - TCP RqSes: the action is valid for "tcp-request session" rules - TCP RqCnt: the action is valid for "tcp-request content" rules - TCP RsCnt: the action is valid for "tcp-response content" rules - HTTP Req: the action is valid for "http-request" rules - HTTP Res: the action is valid for "http-response" rules - HTTP Aft: the action is valid for "http-after-response" rules The same abbreviations are used in the reference section 4.4 below.
This section provides a detailed description of each action and its usage, using the same ruleset terminology marking as described in section 4.3 above.
Usable in :
| QUIC Ini | TCP RqCon | RqSes | RqCnt | RsCnt | HTTP Req | Res | Aft |
|---|---|---|---|---|---|---|---|
![]() | ![]() | ![]() | ![]() | ![]() |
This stops the evaluation of the rules and lets the request or response pass the check. This action is final, i.e. no further rules from the same rule set are evaluated for the current section. There is no difference between this and the "allow" action except that for historical compatibility, "accept" is used for TCP and QUIC rules and "allow" for HTTP rules. See also the "allow" action below.
Usable in :
| QUIC Ini | TCP RqCon | RqSes | RqCnt | RsCnt | HTTP Req | Res | Aft |
|---|---|---|---|---|---|---|---|
![]() | ![]() |
This is used to add a new entry into an ACL. The ACL must be loaded from a file (even a dummy empty file). The file name of the ACL to be updated is passed between parentheses. It takes one argument: <key fmt>, which follows Custom log format rules described in section 8.2.6, to collect content of the new entry. It performs a lookup in the ACL before insertion, to avoid duplicated (or more) values. It is the equivalent of the "add acl" command from the stats socket, but can be triggered by an HTTP request.
Usable in :
| QUIC Ini | TCP RqCon | RqSes | RqCnt | RsCnt | HTTP Req | Res | Aft |
|---|---|---|---|---|---|---|---|
![]() | ![]() | ![]() |
This appends an HTTP header field whose name is specified in <name> and whose value is defined by <fmt> which follows the Custom log format rules (see Custom log format in section 8.2.6). This is particularly useful to pass connection-specific information to the server (e.g. the client's SSL certificate), or to combine several headers into one. This rule is not final, so it is possible to add other similar rules. Note that header addition is performed immediately, so one rule might reuse the resulting header from a previous rule.
Usable in :
| QUIC Ini | TCP RqCon | RqSes | RqCnt | RsCnt | HTTP Req | Res | Aft |
|---|---|---|---|---|---|---|---|
![]() | ![]() | ![]() |
This is a variant of the "add-header" action where the header names and values are passed as a varint encoded binary string. See the "req.hdrs_bin" sample fetch about the varint format. This is useful when you want to set multiple headers at once, without having to know the header names in advance. Note that these headers have not been validated by the HTTP parser and could lead to emitting invalid messages and in worst cases lead to request smuggling attacks. The number of headers inserted are also of importance, as that is limited by tune.http.maxhdr. Optional prefix will only set the headers from the encoded string that start with <str>.
# This would reset the Accept/UA/Host headers to their initial values
http-request set-var(txn.oldheaders) req.hdrs_bin
http-request del-header Accept
http-request del-header User-Agent
http-request del-header Host
http-request add-headers-bin var(txn.oldheaders)
Usable in :
| QUIC Ini | TCP RqCon | RqSes | RqCnt | RsCnt | HTTP Req | Res | Aft |
|---|---|---|---|---|---|---|---|
![]() | ![]() | ![]() |
This stops the evaluation of the rules and lets the request pass the check. This action is final, i.e. no further rules from the same rule set are evaluated for the current section. There is no difference between this and the "accept" action except that for historical compatibility, "accept" is used for TCP rules and "allow" for HTTP rules. See also the "accept" action above.
Usable in :
| QUIC Ini | TCP RqCon | RqSes | RqCnt | RsCnt | HTTP Req | Res | Aft |
|---|---|---|---|---|---|---|---|
![]() |
This is used to intercept the connection after proper HTTP/2 establishment. The connection is reversed to the backend side and inserted into the idle pool of server <srv>. This may only be used with servers having an 'rhttp@' address. The connection is inserted into the server idle pool with a name defined by the result of the <expr> evaluation. This is the name that will be matched against by requests subject to "pool-conn-name" or "sni" parameter. See "http-reuse" for more details. Reverse HTTP is currently still in active development. Configuration mechanism may change in the future. For this reason it is internally marked as experimental, meaning that "expose-experimental-directives" must appear on a line before this directive. Note that a very similar but independent protocol is under development. See https://www.ietf.org/archive/id/draft-bt-httpbis-reverse-http-00.html.
Usable in :
| QUIC Ini | TCP RqCon | RqSes | RqCnt | RsCnt | HTTP Req | Res | Aft |
|---|---|---|---|---|---|---|---|
![]() |
This stops the evaluation of the rules and immediately responds with an HTTP 401 or 407 error code to invite the user to present a valid user name and password. No further "http-request" rules are evaluated. An optional "realm" parameter is supported, it sets the authentication realm that is returned with the response (typically the application's name). The corresponding proxy's error message is used. It may be customized using an "errorfile" or an "http-error" directive. For 401 responses, all occurrences of the WWW-Authenticate header are removed and replaced by a new one with a basic authentication challenge for realm "<realm>". For 407 responses, the same is done on the Proxy-Authenticate header. If the error message must not be altered, consider to use "http-request return" rule instead.
acl auth_ok http_auth_group(L1) G1
http-request auth unless auth_ok
Usable in :
| QUIC Ini | TCP RqCon | RqSes | RqCnt | RsCnt | HTTP Req | Res | Aft |
|---|---|---|---|---|---|---|---|
![]() |
Store an http-response within the cache. The storage of the response headers is done at this step, which means you can use others http-response actions to modify headers before or after the storage of the response. This action is responsible for the setup of the cache storage filter. See section 6.2 about cache setup.
Usable in :
| QUIC Ini | TCP RqCon | RqSes | RqCnt | RsCnt | HTTP Req | Res | Aft |
|---|---|---|---|---|---|---|---|
![]() |
Try to deliver a cached object from the cache <name>. This directive is also mandatory to store the cache as it calculates the cache hash. If you want to use a condition for both storage and delivering that's a good idea to put it after this one. See section 6.2 about cache setup.
Usable in :
| QUIC Ini | TCP RqCon | RqSes | RqCnt | RsCnt | HTTP Req | Res | Aft |
|---|---|---|---|---|---|---|---|
![]() | ![]() | ![]() | ![]() |
This captures sample expression <sample> from the request or response buffer, and converts it to a string of at most <len> characters. The resulting string is stored into the next "capture" slot (either request or response), so it will possibly appear next to some captured HTTP headers. It will then automatically appear in the logs, and it will be possible to extract it using sample fetch methods to feed it into headers or anything. The length should be limited given that this size will be allocated for each capture during the whole stream life. Note that the length is only usable with "http-request" rules. Please check section 7.3 (Fetching samples), "capture request header" and "capture response header" for more information. If the keyword "id" is used instead of "len", the action tries to store the captured string in a previously declared capture slot. This is useful to run captures in backends. The slot id can be declared by a previous directive "http-request capture" or with the "declare capture" keyword. When using this action in a backend, please double check that the relevant frontend(s) have the required capture slots otherwise, this rule will be ignored at run time. This can't be detected at configuration parsing time due to HAProxy's ability to dynamically resolve backend name at runtime.
Usable in :
| QUIC Ini | TCP RqCon | RqSes | RqCnt | RsCnt | HTTP Req | Res | Aft |
|---|---|---|---|---|---|---|---|
![]() |
This is used to immediately close the connection with the server. No further "tcp-response content" rules are evaluated. The main purpose of this action is to force a connection to be finished between a client and a server after an exchange when the application protocol expects some long time outs to elapse first. The goal is to eliminate idle connections which take significant resources on servers with certain protocols.
Usable in :
| QUIC Ini | TCP RqCon | RqSes | RqCnt | RsCnt | HTTP Req | Res | Aft |
|---|---|---|---|---|---|---|---|
![]() | ![]() |
This is used to delete an entry from an ACL. The ACL must be loaded from a file (even a dummy empty file). The file name of the ACL to be updated is passed between parentheses. It takes one argument: <key fmt>, which follows Custom log format rules of section 8.2.6, to collect content of the entry to delete. It is the equivalent of the "del acl" command from the stats socket, but can be triggered by an HTTP request or response.
Usable in :
| QUIC Ini | TCP RqCon | RqSes | RqCnt | RsCnt | HTTP Req | Res | Aft |
|---|---|---|---|---|---|---|---|
![]() | ![]() | ![]() |
This removes all HTTP header fields whose name is specified in <name>. <meth> is the matching method, applied on the header name. Supported matching methods are "str" (exact match), "beg" (prefix match), "end" (suffix match), "sub" (substring match) and "reg" (regex match). If not specified, exact matching method is used.
Usable in :
| QUIC Ini | TCP RqCon | RqSes | RqCnt | RsCnt | HTTP Req | Res | Aft |
|---|---|---|---|---|---|---|---|
![]() | ![]() | ![]() |
This removes all HTTP header fields whose names are specified in <expr>. <expr> must return a varint encoded binary string of all header names that should be deleted. See "add-headers-bin" and "set-headers-bin" for the description of encoding and examples. <meth> is the matching method, applied on all the header names. Supported matching methods are "str" (exact match), "beg" (prefix match), "end" (suffix match) and "sub" (substring match). The "reg" (regex match) is not supported due to unpredictable performance during runtime. If not specified, exact matching method is used.
Usable in :
| QUIC Ini | TCP RqCon | RqSes | RqCnt | RsCnt | HTTP Req | Res | Aft |
|---|---|---|---|---|---|---|---|
![]() | ![]() | ![]() |
This is used to delete an entry from a MAP. <map-name> must follow the format described in 2.7. about name format for maps and ACLs. The name of the MAP to be updated is passed between parentheses. It takes one argument: <key fmt>, which follows Custom log format rules of section 8.2.6, to collect content of the entry to delete. It takes one argument: "file name" It is the equivalent of the "del map" command from the stats socket, but can be triggered by an HTTP request or response.
Usable in :
| QUIC Ini | TCP RqCon | RqSes | RqCnt | RsCnt | HTTP Req | Res | Aft |
|---|---|---|---|---|---|---|---|
![]() | ![]() |
This stops the evaluation of the rules and immediately rejects the request or response. By default an HTTP 403 error is returned for requests, and 502 for responses, but the returned response may be customized using same syntax as for the "return" action. Thus, see "return" below for details. For compatibility purposes, when no argument is defined, or only "deny_status", the argument "default-errorfiles" is implied. It means "deny [deny_status <status>]" is an alias of "deny [status <status>] default-errorfiles". This action is final, i.e. no further rules from the same rule set are evaluated for the current section. See also the "return" action for the advanced syntax.
Usable in :
| QUIC Ini | TCP RqCon | RqSes | RqCnt | RsCnt | HTTP Req | Res | Aft |
|---|---|---|---|---|---|---|---|
![]() |
This silently ignores the reception of a QUIC initial packet which otherwise would have resulted in a new QUIC connection instantiation and its SSL handshake execution.
Usable in :
| QUIC Ini | TCP RqCon | RqSes | RqCnt | RsCnt | HTTP Req | Res | Aft |
|---|---|---|---|---|---|---|---|
![]() |
This disables any attempt to retry the request if it fails for any other reason than a connection failure. This can be useful for example to make sure POST requests aren't retried on failure.
Usable in :
| QUIC Ini | TCP RqCon | RqSes | RqCnt | RsCnt | HTTP Req | Res | Aft |
|---|---|---|---|---|---|---|---|
![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() |
This action manually triggers a log emission on the proxy. This means log options on the proxy will be considered (including formatting options such as "log-format"), but it will not interfere with the logs automatically generated by the proxy during transaction handling. Using "log-profile", it is possible to precisely describe how the log should be emitted for each of the available contexts where the action may be used. That is, 'on' keyword followed by of the following values: 'quic-init', 'tcp-req-conn', 'tcp-req-sess', 'tcp-req-cont', 'tcp-res-cont', 'http-req', 'http-res', 'http-after-res'. Also, they will be properly reported when using "%OG" logformat alias. Optional "profile" argument may be used to specify the name of a log-profile section that should be used for this do-log action specifically instead of the one associated to the current logger that applies by default.
log-profile my-dft-prof
on tcp-req-conn format "Connect: %ci"
log-profile my-local-prof
on tcp-req-conn format "Local Connect: %ci"
frontend myfront
log stdout format rfc5424 profile my-dft-prof local0
log-format "log generated using proxy logformat, from '%OG'"
acl local src 127.0.0.1
# on connection use either log-profile from the logger (my-dft-prof) or
# explicit my-local-prof if source ip is localhost
tcp-request connection do-log if !local
tcp-request connection do-log profile my-local-prof if local
# on content use proxy logformat, since no override was specified
# in my-dft-prof
tcp-request content do-log
Usable in :
| QUIC Ini | TCP RqCon | RqSes | RqCnt | RsCnt | HTTP Req | Res | Aft |
|---|---|---|---|---|---|---|---|
![]() | ![]() |
This action performs a DNS resolution of the output of <expr> and stores the result in the variable <var>. It uses the DNS resolvers section pointed by <resolvers>. It is possible to choose a resolution preference using the optional arguments 'ipv4' or 'ipv6'. See also the global "dns-accept-family" keyword to enforce strict usage of a specific family. When performing the DNS resolution, the client side connection is on pause waiting till the end of the resolution. If an IP address can be found, it is stored into <var>. If any kind of error occurs, then <var> is not set. One can use this action to discover a server IP address at run time and based on information found in the request (IE a Host header). If this action is used to find the server's IP address (using the "set-dst" action), then the server IP address in the backend must be set to 0.0.0.0. The do-resolve action takes an host-only parameter, any port must be removed from the string.
resolvers mydns
nameserver local 127.0.0.53:53
nameserver google 8.8.8.8:53
timeout retry 1s
hold valid 10s
hold nx 3s
hold other 3s
hold obsolete 0s
accepted_payload_size 8192
frontend fe
bind 10.42.0.1:80
http-request do-resolve(txn.myip,mydns,ipv4) hdr(Host),host_only
http-request capture var(txn.myip) len 40
# return 503 when the variable is not set,
# which mean DNS resolution error
use_backend b_503 unless { var(txn.myip) -m found }
default_backend be
backend b_503
# dummy backend used to return 503.
# one can use the errorfile directive to send a nice
# 503 error page to end users
backend be
# rule to prevent HAProxy from reconnecting to services
# on the local network (forged DNS name used to scan the network)
http-request deny if { var(txn.myip) -m ip 127.0.0.0/8 10.0.0.0/8 }
http-request set-dst var(txn.myip)
server clear 0.0.0.0:0
NOTE: Don't forget to set the "protection" rules to ensure HAProxy won't
be used to scan the network or worst won't loop over itself...
Usable in :
| QUIC Ini | TCP RqCon | RqSes | RqCnt | RsCnt | HTTP Req | Res | Aft |
|---|---|---|---|---|---|---|---|
![]() |
This is used to build an HTTP 103 Early Hints response prior to any other one. This appends an HTTP header field to this response whose name is specified in <name> and whose value is defined by <fmt> which follows the Custom Log Format rules (see Custom log format in section 8.2.6). This is particularly useful to pass to the client some Link headers to preload resources required to render the HTML documents. See RFC 8297 for more information.
Usable in :
| QUIC Ini | TCP RqCon | RqSes | RqCnt | RsCnt | HTTP Req | Res | Aft |
|---|---|---|---|---|---|---|---|
![]() |
This configures the client-facing connection to receive a NetScaler Client IP insertion protocol header before any byte is read from the socket. This is equivalent to having the "accept-netscaler-cip" keyword on the "bind" line, except that using the TCP rule allows the PROXY protocol to be accepted only for certain IP address ranges using an ACL. This is convenient when multiple layers of load balancers are passed through by traffic coming from public hosts.
Usable in :
| QUIC Ini | TCP RqCon | RqSes | RqCnt | RsCnt | HTTP Req | Res | Aft |
|---|---|---|---|---|---|---|---|
![]() |
This configures the client-facing connection to receive a PROXY protocol header before any byte is read from the socket. This is equivalent to having the "accept-proxy" keyword on the "bind" line, except that using the TCP rule allows the PROXY protocol to be accepted only for certain IP address ranges using an ACL. This is convenient when multiple layers of load balancers are passed through by traffic coming from public hosts.
Usable in :
| QUIC Ini | TCP RqCon | RqSes | RqCnt | RsCnt | HTTP Req | Res | Aft |
|---|---|---|---|---|---|---|---|
![]() |
Performs normalization of the request's URI.
URI normalization in HAProxy 2.4 is currently available as an experimental
technical preview. As such, it requires the global directive
'expose-experimental-directives' first to be able to invoke it. You should be
prepared that the behavior of normalizers might change to fix possible
issues, possibly breaking proper request processing in your infrastructure.
Each normalizer handles a single type of normalization to allow for a
fine-grained selection of the level of normalization that is appropriate for
the supported backend.
As an example the "path-strip-dotdot" normalizer might be useful for a static
fileserver that directly maps the requested URI to the path within the local
filesystem. However it might break routing of an API that expects a specific
number of segments in the path.
It is important to note that some normalizers might result in unsafe
transformations for broken URIs. It might also be possible that a combination
of normalizers that are safe by themselves results in unsafe transformations
when improperly combined.
As an example the "percent-decode-unreserved" normalizer might result in
unexpected results when a broken URI includes bare percent characters. One
such a broken URI is "/%%36%36" which would be decoded to "/%66" which in
turn is equivalent to "/f". By specifying the "strict" option requests to
such a broken URI would safely be rejected.
The following normalizers are available:
- fragment-encode: Encodes "#" as "%23".
The "fragment-strip" normalizer should be preferred, unless it is known
that broken clients do not correctly encode '#' within the path component.
- /#foo -> /%23foo
- fragment-strip: Removes the URI's "fragment" component.
According to RFC 3986#3.5 the "fragment" component of an URI should not
be sent, but handled by the User Agent after retrieving a resource.
This normalizer should be applied first to ensure that the fragment is
not interpreted as part of the request's path component.
- /#foo -> /
- path-strip-dot: Removes "/./" segments within the "path" component (RFC 3986#6.2.2.3). Segments including percent encoded dots ("%2E") will not be detected. Use the "percent-decode-unreserved" normalizer first if this is undesired.
- /. -> /
- /./bar/ -> /bar/
- /a/./a -> /a/a
- /.well-known/ -> /.well-known/ (no change)
- path-strip-dotdot: Normalizes "/../" segments within the "path" component (RFC 3986#6.2.2.3). This merges segments that attempt to access the parent directory with their preceding segment. Empty segments do not receive special treatment. Use the "merge-slashes" normalizer first if this is undesired. Segments including percent encoded dots ("%2E") will not be detected. Use the "percent-decode-unreserved" normalizer first if this is undesired.
- /foo/../ -> /
- /foo/../bar/ -> /bar/
- /foo/bar/../ -> /foo/
- /../bar/ -> /../bar/
- /bar/../../ -> /../
- /foo//../ -> /foo/
- /foo/%2E%2E/ -> /foo/%2E%2E/
If the "full" option is specified then "../" at the beginning will be removed as well:
- /../bar/ -> /bar/
- /bar/../../ -> /
- path-merge-slashes: Merges adjacent slashes within the "path" component into a single slash.
- // -> /
- /foo//bar -> /foo/bar
- percent-decode-unreserved: Decodes unreserved percent encoded characters to
their representation as a regular character (RFC 3986#6.2.2.2).
The set of unreserved characters includes all letters, all digits, "-",
".", "_", and "~".
- /%61dmin -> /admin
- /foo%3Fbar=baz -> /foo%3Fbar=baz (no change)
- /%%36%36 -> /%66 (unsafe)
- /%ZZ -> /%ZZ
If the "strict" option is specified then invalid sequences will result in a HTTP 400 Bad Request being returned.
- /%%36%36 -> HTTP 400
- /%ZZ -> HTTP 400
- percent-to-uppercase: Uppercases letters within percent-encoded sequences
(RFC 3986#6.2.2.1).
- /%6f -> /%6F
- /%zz -> /%zz
If the "strict" option is specified then invalid sequences will result in a HTTP 400 Bad Request being returned.
- /%zz -> HTTP 400
- query-sort-by-name: Sorts the query string parameters by parameter name.
Parameters are assumed to be delimited by '&'. Shorter names sort before
longer names and identical parameter names maintain their relative order.
- /?c=3&a=1&b=2 -> /?a=1&b=2&c=3
- /?aaa=3&a=1&aa=2 -> /?a=1&aa=2&aaa=3
- /?a=3&b=4&a=1&b=5&a=2 -> /?a=3&a=1&a=2&b=4&b=5
Usable in :
| QUIC Ini | TCP RqCon | RqSes | RqCnt | RsCnt | HTTP Req | Res | Aft |
|---|---|---|---|---|---|---|---|
![]() | ![]() |
This suspends the message analysis for the specified number of milliseconds. The timeout can be specified in milliseconds or with any other unit if the number is suffixed by the unit as explained at the top of this document. It is also possible to write an expression which must return a number interpreted as a timeout in milliseconds. If the expression evaluation fails or if it returns an invalid value, the action is ignored and the evaluation continues. This action may be used for debugging purpose. But it could also be used to slow down some clients based on specific criteria. For instance, it is possible to slow down clients if their requests rate is too high, by tracking them via a "track-sc" rule.
Usable in :
| QUIC Ini | TCP RqCon | RqSes | RqCnt | RsCnt | HTTP Req | Res | Aft |
|---|---|---|---|---|---|---|---|
![]() | ![]() |
This performs an HTTP redirection based on a redirect rule. This is exactly the same as the "redirect" statement except that it inserts a redirect rule which is processed in the middle of other "http-request" or "http-response" rules and that these rules use the Custom log format. For responses, only the "location" type of redirect is permitted. In addition, when a redirect is performed during a response, the transfer from the server to HAProxy is interrupted so that no payload can be forwarded to the client. This may cause some connections to be closed on HTTP/1. This action is final, i.e. no further rules from the same rule set are evaluated for the current section. See the "redirect" keyword for the rule's syntax.
Usable in :
| QUIC Ini | TCP RqCon | RqSes | RqCnt | RsCnt | HTTP Req | Res | Aft |
|---|---|---|---|---|---|---|---|
![]() | ![]() | ![]() | ![]() | ![]() | ![]() |
This stops the evaluation of the rules and immediately closes the connection without sending any response. For HTTP rules, it acts similarly to the "tcp-request content reject" rules. It can be useful to force an immediate connection closure on HTTP/2 connections. In "tcp-request connection" rules, rejected connections do not even become a session, which is why they are accounted separately for in the stats, as "denied connections". They are not considered for the session rate-limit and are not logged either. The reason is that these rules should only be used to filter extremely high connection rates such as the ones encountered during a massive DDoS attack. Under these extreme conditions, the simple action of logging each event would make the system collapse and would considerably lower the filtering capacity. If logging is absolutely desired, then "tcp-request content" rules should be used instead, as "tcp-request session" rules will not log either. When used in "tcp-response content" rules, the server connection will be closed and the response aborted. This is generally used to prevent sensitive information from leaking, typically after inspecting contents in conjunction with the "wait-for-body" action. This action can also be used in "quic-initial" rules. The newly opened QUIC connection is immediately closed without any SSL handshake processing and the client is notified via a CONNECTION_REFUSED error code.
Usable in :
| QUIC Ini | TCP RqCon | RqSes | RqCnt | RsCnt | HTTP Req | Res | Aft |
|---|---|---|---|---|---|---|---|
![]() | ![]() | ![]() |
This matches the value of all occurrences of header field <name> against
<match-regex>. Matching is performed case-sensitively. Matching values are
completely replaced by <replace-fmt>. Format characters are allowed in
<replace-fmt> and work like <fmt> arguments in "http-request add-header".
Standard back-references using the backslash ('\') followed by a number are
supported.
This action acts on whole header lines, regardless of the number of values
they may contain. Thus it is well-suited to process headers naturally
containing commas in their value, such as If-Modified-Since or Set-Cookie.
Headers that contain a comma-separated list of values, such as Accept, or
Cache-Control should be processed using the "replace-value" action instead.
See also the "replace-value" action.
http-request replace-header Cookie foo=([^;]*);(.*) foo=\1;ip=%bi;\2
# applied to:
Cookie: foo=foobar; expires=Tue, 14-Jun-2016 01:40:45 GMT;
# outputs:
Cookie: foo=foobar;ip=192.168.1.20; expires=Tue, 14-Jun-2016 01:40:45 GMT;
# assuming the backend IP is 192.168.1.20
http-request replace-header User-Agent curl foo
# applied to:
User-Agent: curl/7.47.0
# outputs:
User-Agent: foo
http-response replace-header Set-Cookie (C=[^;]*);(.*) \1;ip=%bi;\2
# applied to:
Set-Cookie: C=1; expires=Tue, 14-Jun-2016 01:40:45 GMT
# outputs:
Set-Cookie: C=1;ip=192.168.1.20; expires=Tue, 14-Jun-2016 01:40:45 GMT
# assuming the backend IP is 192.168.1.20.
Usable in :
| QUIC Ini | TCP RqCon | RqSes | RqCnt | RsCnt | HTTP Req | Res | Aft |
|---|---|---|---|---|---|---|---|
![]() |
This works like "replace-header" except that it works on the request's path component instead of a header. The path component starts at the first '/' after an optional scheme+authority and ends before the question mark. Thus, the replacement does not modify the scheme, the authority and the query-string. It is worth noting that regular expressions may be more expensive to evaluate than certain ACLs, so rare replacements may benefit from a condition to avoid performing the evaluation at all if it does not match.
# prefix /foo : turn /bar?q=1 into /foo/bar?q=1 :
http-request replace-path (.*) /foo\1
# strip /foo : turn /foo/bar?q=1 into /bar?q=1
http-request replace-path /foo/(.*) /\1
# or more efficient if only some requests match :
http-request replace-path /foo/(.*) /\1 if { url_beg /foo/ }
Usable in :
| QUIC Ini | TCP RqCon | RqSes | RqCnt | RsCnt | HTTP Req | Res | Aft |
|---|---|---|---|---|---|---|---|
![]() |
This does the same as "http-request replace-path" except that the path contains the query-string if any is present. Thus, the path and the query-string are replaced.
# suffix /foo : turn /bar?q=1 into /bar/foo?q=1 :
http-request replace-pathq ([^?]*)(\?(.*))? \1/foo\2
Usable in :
| QUIC Ini | TCP RqCon | RqSes | RqCnt | RsCnt | HTTP Req | Res | Aft |
|---|---|---|---|---|---|---|---|
![]() |
This works like "replace-header" except that it works on the request's URI part instead of a header. The URI part may contain an optional scheme, authority or query string. These are considered to be part of the value that is matched against. It is worth noting that regular expressions may be more expensive to evaluate than certain ACLs, so rare replacements may benefit from a condition to avoid performing the evaluation at all if it does not match. IMPORTANT NOTE: historically in HTTP/1.x, the vast majority of requests sent by browsers use the "origin form", which differs from the "absolute form" in that they do not contain a scheme nor authority in the URI portion. Mostly only requests sent to proxies, those forged by hand and some emitted by certain applications use the absolute form. As such, "replace-uri" usually works fine most of the time in HTTP/1.x with rules starting with a "/". But with HTTP/2, clients are encouraged to send absolute URIs only, which look like the ones HTTP/1 clients use to talk to proxies. Such partial replace-uri rules may then fail in HTTP/2 when they work in HTTP/1. Either the rules need to be adapted to optionally match a scheme and authority, or replace-path should be used.
# rewrite all "http" absolute requests to "https":
http-request replace-uri ^http://(.*) https://\1
# prefix /foo : turn /bar?q=1 into /foo/bar?q=1 :
http-request replace-uri ([^/:]*://[^/]*)?(.*) \1/foo\2
Usable in :
| QUIC Ini | TCP RqCon | RqSes | RqCnt | RsCnt | HTTP Req | Res | Aft |
|---|---|---|---|---|---|---|---|
![]() | ![]() | ![]() |
This works like "replace-header" except that it matches the regex against every comma-delimited value of the header field <name> instead of the entire header. This is suited for all headers which are allowed to carry more than one value. An example could be the Accept request header, or Cache-Control for requests or responses.
http-request replace-value X-Forwarded-For ^192\.168\.(.*)$ 172.16.\1
# applied to:
X-Forwarded-For: 192.168.10.1, 192.168.13.24, 10.0.0.37
# outputs:
X-Forwarded-For: 172.16.10.1, 172.16.13.24, 10.0.0.37
http-after-response replace-value Cache-control ^public$ private
# applied to:
Cache-Control: max-age=3600, public
# outputs:
Cache-Control: max-age=3600, private
Usable in :
| QUIC Ini | TCP RqCon | RqSes | RqCnt | RsCnt | HTTP Req | Res | Aft |
|---|---|---|---|---|---|---|---|
![]() | ![]() |
This stops the evaluation of the rules and immediately returns a response. The default status code used for the response is 200. It can be optionally specified as an arguments to "status". The response content-type may also be specified as an argument to "content-type". Finally the response itself may be defined. It can be a full HTTP response specifying the errorfile to use, or the response payload specifying the file or the string to use. These rules are followed to create the response : * If neither the errorfile nor the payload to use is defined, a dummy response is returned. Only the "status" argument is considered. It can be any code in the range [200, 599]. The "content-type" argument, if any, is ignored. * If "default-errorfiles" argument is set, the proxy's errorfiles are considered. If the "status" argument is defined, it must be one of the status code handled by HAProxy (200, 400, 403, 404, 405, 408, 410, 413, 414, 425, 429, 431, 500, 501, 502, 503, and 504). The "content-type" argument, if any, is ignored. * If a specific errorfile is defined, with an "errorfile" argument, the corresponding file, containing a full HTTP response, is returned. Only the "status" argument is considered. It must be one of the status code handled by HAProxy (200, 400, 403, 404, 405, 408, 410, 413, 414, 425, 429, 431, 500, 501, 502, 503, and 504). The "content-type" argument, if any, is ignored. * If an http-errors section is defined, with an "errorfiles" argument, the corresponding file in the specified http-errors section, containing a full HTTP response, is returned. Only the "status" argument is considered. It must be one of the status code handled by HAProxy (200, 400, 403, 404, 405, 408, 410, 413, 414, 425, 429, 431, 500, 501, 502, 503, and 504). The "content-type" argument, if any, is ignored. * If a "file" or a "lf-file" argument is specified, the file's content is used as the response payload. If the file is not empty, its content-type must be set as argument to "content-type". Otherwise, any "content-type" argument is ignored. With a "lf-file" argument, the file's content is evaluated as a Custom log format (see section 8.2.6). With a "file" argument, it is considered as a raw content. * If a "string" or "lf-string" argument is specified, the defined string is used as the response payload. The content-type must always be set as argument to "content-type". With a "lf-string" argument, the string is evaluated as a Custom log format (see section 8.2.6). With a "string" argument, it is considered as a raw string. When the response is not based on an errorfile, it is possible to append HTTP header fields to the response using "hdr" arguments. Otherwise, all "hdr" arguments are ignored. For each one, the header name is specified in <name> and its value is defined by <fmt> which follows the Custom log format rules described in section 8.2.6. Note that the generated response must be smaller than a buffer. And to avoid any warning, when an errorfile or a raw file is loaded, the buffer space reserved for the headers rewriting should also be free. This action is final, i.e. no further rules from the same rule set are evaluated for the current section.
http-request return errorfile /etc/haproxy/errorfiles/200.http \
if { path /ping }
http-request return content-type image/x-icon file /var/www/favicon.ico \
if { path /favicon.ico }
http-request return status 403 content-type text/plain \
lf-string "Access denied. IP %[src] is blacklisted." \
if { src -f /etc/haproxy/blacklist.lst }
Usable in :
| QUIC Ini | TCP RqCon | RqSes | RqCnt | RsCnt | HTTP Req | Res | Aft |
|---|---|---|---|---|---|---|---|
![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() |
This action increments the General Purpose Counter at the index <idx> of the array associated to the sticky counter designated by <sc-id> by the value of either integer <int> or the integer evaluation of expression <expr>. Integers and expressions are limited to unsigned 32-bit values. If an error occurs, this action silently fails and the actions evaluation continues. <idx> is an integer between 0 and 99 and <sc-id> is an integer between 0 and 2. It also silently fails if the there is no GPC stored at this index. The entry in the table is refreshed even if the value is zero. The 'gpc_rate' is automatically adjusted to reflect the average growth rate of the gpc value. This action applies only to the 'gpc' and 'gpc_rate' array data_types (and not to the legacy 'gpc0', 'gpc1', 'gpc0_rate' nor 'gpc1_rate' data_types). There is no equivalent function for legacy data types, but if the value is always 1, please see 'sc-inc-gpc()', 'sc-inc-gpc0()' and 'sc-inc-gpc1()'. There is no way to decrement the value either, but it is possible to store exact values in a General Purpose Tag using 'sc-set-gpt()' instead. The main use of this action is to count scores or total volumes (e.g. estimated danger per source IP reported by the server or a WAF, total uploaded bytes, etc).
Usable in :
| QUIC Ini | TCP RqCon | RqSes | RqCnt | RsCnt | HTTP Req | Res | Aft |
|---|---|---|---|---|---|---|---|
![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() |
This actions increments the General Purpose Counter at the index <idx> of the array associated to the sticky counter designated by <sc-id>. If an error occurs, this action silently fails and the actions evaluation continues. <idx> is an integer between 0 and 99 and <sc-id> is an integer between 0 and 2. It also silently fails if the there is no GPC stored at this index. This action applies only to the 'gpc' and 'gpc_rate' array data_types (and not to the legacy 'gpc0', 'gpc1', 'gpc0_rate' nor 'gpc1_rate' data_types).
Usable in :
| QUIC Ini | TCP RqCon | RqSes | RqCnt | RsCnt | HTTP Req | Res | Aft |
|---|---|---|---|---|---|---|---|
![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() |
This actions increments the GPC0 or GPC1 counter according with the sticky counter designated by <sc-id>. If an error occurs, this action silently fails and the actions evaluation continues.
Usable in :
| QUIC Ini | TCP RqCon | RqSes | RqCnt | RsCnt | HTTP Req | Res | Aft |
|---|---|---|---|---|---|---|---|
![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() |
This action sets the 32-bit unsigned GPT at the index <idx> of the array associated to the sticky counter designated by <sc-id> at the value of <int>/<expr>. The expected result is a boolean. If an error occurs, this action silently fails and the actions evaluation continues. <idx> is an integer between 0 and 99 and <sc-id> is an integer between 0 and 2. It also silently fails if the there is no GPT stored at this index. This action applies only to the 'gpt' array data_type (and not to the legacy 'gpt0' data-type).
Usable in :
| QUIC Ini | TCP RqCon | RqSes | RqCnt | RsCnt | HTTP Req | Res | Aft |
|---|---|---|---|---|---|---|---|
![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() |
This action sets the 32-bit unsigned GPT0 tag according to the sticky counter designated by <sc-id> and the value of <int>/<expr>. The expected result is a boolean. If an error occurs, this action silently fails and the actions evaluation continues. This action is an alias for "sc-set-gpt(0,<sc-id>)". See also the "sc-set-gpt" action.
Usable in :
| QUIC Ini | TCP RqCon | RqSes | RqCnt | RsCnt | HTTP Req | Res | Aft |
|---|---|---|---|---|---|---|---|
![]() |
This action forces the emission of a Retry packet in response to a client Initial packet without token. This is useful to ensure client address is validated prior to instantiating any connection elements and starting the handshake.
Usable in :
| QUIC Ini | TCP RqCon | RqSes | RqCnt | RsCnt | HTTP Req | Res | Aft |
|---|---|---|---|---|---|---|---|
![]() | ![]() | ![]() | ![]() |
This action is used to trigger sending of a group of SPOE messages. To do so, the SPOE engine used to send messages must be defined, as well as the SPOE group to send. Of course, the SPOE engine must refer to an existing SPOE filter. If not engine name is provided on the SPOE filter line, the SPOE agent name must be used.
<engine-name> The SPOE engine name.
<group-name> The SPOE group name as specified in the engine
configuration.
Usable in :
| QUIC Ini | TCP RqCon | RqSes | RqCnt | RsCnt | HTTP Req | Res | Aft |
|---|---|---|---|---|---|---|---|
![]() | ![]() | ![]() | ![]() |
This action is used to enable the bandwidth limitation filter <name>, either on the upload or download direction depending on the filter type. Custom limit and period may be defined, if and only if <name> references a per-stream bandwidth limitation filter. When a set-bandwidth-limit rule is executed, it first resets all settings of the filter to their defaults prior to enabling it. As a consequence, if several "set-bandwidth-limit" actions are executed for the same filter, only the last one is considered. Several bandwidth limitation filters can be enabled on the same stream. Note that this action cannot be used in a defaults section because bandwidth limitation filters cannot be defined in defaults sections. In addition, only the HTTP payload transfer is limited. The HTTP headers are not considered.
<expr> Is a standard HAProxy expression formed by a sample-fetch followed
by some converters. The result is converted to an integer. It is
interpreted as a size in bytes for the "limit" parameter and as a
duration in milliseconds for the "period" parameter.
<size> Is a number. It follows the HAProxy size format and is expressed in
bytes.
<time> Is a number. It follows the HAProxy time format and is expressed in
milliseconds.
http-request set-bandwidth-limit global-limit
http-request set-bandwidth-limit my-limit limit 1m period 10s
See section 9.7 about bandwidth limitation filter setup.
Usable in :
| QUIC Ini | TCP RqCon | RqSes | RqCnt | RsCnt | HTTP Req | Res | Aft |
|---|---|---|---|---|---|---|---|
![]() | ![]() |
This is used to set the Netfilter/IPFW MARK on the backend connection (all packets sent to the server) to the value passed in <mark> or <expr> on platforms which support it. This value is an unsigned 32 bit value which can be matched by netfilter/ipfw and by the routing table or monitoring the packets through DTrace. <mark> can be expressed both in decimal or hexadecimal format (prefixed by "0x"). Alternatively, <expr> can be used: it is a standard HAProxy expression formed by a sample-fetch followed by some converters which must resolve to integer type. This action can be useful to force certain packets to take a different route (for example a cheaper network path for bulk downloads). This works on Linux kernels 2.6.32 and above and requires admin privileges, as well on FreeBSD and OpenBSD. The mark will be set for the whole duration of the backend/server connection (from connect to close).
Usable in :
| QUIC Ini | TCP RqCon | RqSes | RqCnt | RsCnt | HTTP Req | Res | Aft |
|---|---|---|---|---|---|---|---|
![]() | ![]() |
This is used to set the TOS or DSCP field value on the backend connection (all packets sent to the server) to the value passed in <tos> or <expr> on platforms which support this. This value represents the whole 8 bits of the IP TOS field. Note that only the 6 higher bits are used in DSCP or TOS, and the two lower bits are always 0. Alternatively, <expr> can be used: it is a standard HAProxy expression formed by a sample-fetch followed by some converters which must resolve to integer type. This action can be used to adjust some routing behavior on inner routers based on some information from the request. The tos will be set for the whole duration of the backend/server connection (from connect to close). See RFC 2474, 2597, 3260 and 4594 for more information.
Usable in :
| QUIC Ini | TCP RqCon | RqSes | RqCnt | RsCnt | HTTP Req | Res | Aft |
|---|---|---|---|---|---|---|---|
![]() | ![]() | ![]() | ![]() |
This is used to set the destination IP address to the value of specified expression. Useful when a proxy in front of HAProxy rewrites destination IP, but provides the correct IP in a HTTP header; or you want to mask the IP for privacy. If you want to connect to the new address/port, use '0.0.0.0:0' as a server address in the backend.
<expr> Is a standard HAProxy expression formed by a sample-fetch followed
by some converters.
http-request set-dst hdr(x-dst)
http-request set-dst dst,ipmask(24)
When possible, set-dst preserves the original destination port as long as the address family allows it, otherwise the destination port is set to 0.
Usable in :
| QUIC Ini | TCP RqCon | RqSes | RqCnt | RsCnt | HTTP Req | Res | Aft |
|---|---|---|---|---|---|---|---|
![]() | ![]() | ![]() | ![]() |
This is used to set the destination port address to the value of specified expression. If you want to connect to the new address/port, use '0.0.0.0:0' as a server address in the backend.
<expr> Is a standard HAProxy expression formed by a sample-fetch
followed by some converters.
http-request set-dst-port hdr(x-port)
http-request set-dst-port int(4000)
When possible, set-dst-port preserves the original destination address as long as the address family supports a port, otherwise it forces the destination address to IPv4 "0.0.0.0" before rewriting the port.
Usable in :
| QUIC Ini | TCP RqCon | RqSes | RqCnt | RsCnt | HTTP Req | Res | Aft |
|---|---|---|---|---|---|---|---|
![]() | ![]() | ![]() | ![]() | ![]() | ![]() |
This is used to set the Netfilter/IPFW MARK on all packets sent to the client to the value passed in <mark> or <expr> on platforms which support it. This value is an unsigned 32 bit value which can be matched by netfilter/ipfw and by the routing table or monitoring the packets through DTrace. <mark> can be expressed both in decimal or hexadecimal format (prefixed by "0x"). Alternatively, <expr> can be used: it is a standard HAProxy expression formed by a sample-fetch followed by some converters which must resolve to integer type. This action can be useful to force certain packets to take a different route (for example a cheaper network path for bulk downloads). This works on Linux kernels 2.6.32 and above and requires admin privileges, as well on FreeBSD and OpenBSD.
Usable in :
| QUIC Ini | TCP RqCon | RqSes | RqCnt | RsCnt | HTTP Req | Res | Aft |
|---|---|---|---|---|---|---|---|
![]() | ![]() | ![]() | ![]() | ![]() | ![]() |
This is used to set the TOS or DSCP field value of packets sent to the client to the value passed in <tos> or <expr> on platforms which support this. This value represents the whole 8 bits of the IP TOS field. Note that only the 6 higher bits are used in DSCP or TOS, and the two lower bits are always 0. Alternatively, <expr> can be used: it is a standard HAProxy expression formed by a sample-fetch followed by some converters which must resolve to integer type. This action can be used to adjust some routing behavior on border routers based on some information from the request. See RFC 2474, 2597, 3260 and 4594 for more information.
Usable in :
| QUIC Ini | TCP RqCon | RqSes | RqCnt | RsCnt | HTTP Req | Res | Aft |
|---|---|---|---|---|---|---|---|
![]() | ![]() | ![]() |
This does the same as the "add-header" action except that the header is first removed if it existed. This is useful when passing security information to the server, where the header must not be manipulated by external users, or to force certain response headers such as "Server" to hide external information. Note that the new value is computed before the removal so it is possible to concatenate a value to an existing header.
http-request set-header X-Haproxy-Current-Date %T
http-request set-header X-SSL %[ssl_fc]
http-request set-header X-SSL-Session_ID %[ssl_fc_session_id,hex]
http-request set-header X-SSL-Client-Verify %[ssl_c_verify]
http-request set-header X-SSL-Client-DN %{+Q}[ssl_c_s_dn]
http-request set-header X-SSL-Client-CN %{+Q}[ssl_c_s_dn(cn)]
http-request set-header X-SSL-Issuer %{+Q}[ssl_c_i_dn]
http-request set-header X-SSL-Client-NotBefore %{+Q}[ssl_c_notbefore]
http-request set-header X-SSL-Client-NotAfter %{+Q}[ssl_c_notafter]
Usable in :
| QUIC Ini | TCP RqCon | RqSes | RqCnt | RsCnt | HTTP Req | Res | Aft |
|---|---|---|---|---|---|---|---|
![]() | ![]() | ![]() |
This is a variant of the "set-header" action where the header names and values are passed as a varint encoded binary string. See the "req.hdrs_bin" sample fetch about the varint format. This is useful when you want to set multiple headers at once, without having to know the header names in advance. Note that these headers have not been validated by the HTTP parser and could lead to emitting invalid messages and in worst cases lead to request smuggling attacks. The number of headers inserted are also of importance, as that is limited by tune.http.maxhdr. Optional prefix will only set the headers from the encoded string that start with <str>.
# This would reset the Accept/UA/Host headers to their initial values
http-request set-var(txn.oldheaders) req.hdrs_bin
http-request del-header Accept
http-request del-header User-Agent
http-request del-header Host
http-request set-headers-bin var(txn.oldheaders)
Usable in :
| QUIC Ini | TCP RqCon | RqSes | RqCnt | RsCnt | HTTP Req | Res | Aft |
|---|---|---|---|---|---|---|---|
![]() | ![]() | ![]() | ![]() | ![]() |
This is used to change the log level of the current request when a certain
condition is met. Valid levels are the 8 syslog levels (see the "log"
keyword) plus the special level "silent" which disables logging for this
request. This rule is not final so the last matching rule wins. This rule
can be useful to disable health checks coming from another equipment.
Usable in :
| QUIC Ini | TCP RqCon | RqSes | RqCnt | RsCnt | HTTP Req | Res | Aft |
|---|---|---|---|---|---|---|---|
![]() | ![]() | ![]() |
This is used to add a new entry into a map. <map-name> must follow the format described in 2.7. about name format for maps and ACLs. The name of the MAP to be updated is passed between parentheses. It takes 2 arguments: <key fmt>, which follows Custom log format rules described in section 8.2.6, used to collect map key, and <value fmt>, which follows Custom log format rules, used to collect content for the new entry. It performs a lookup in the map before insertion, to avoid duplicated (or more) values. It is the equivalent of the "set map" command from the stats socket, but can be triggered by an HTTP request.
This is an alias for "set-fc-mark" (which should be used instead).
Usable in :
| QUIC Ini | TCP RqCon | RqSes | RqCnt | RsCnt | HTTP Req | Res | Aft |
|---|---|---|---|---|---|---|---|
![]() |
This rewrites the request method with the result of the evaluation of format string <fmt>. There should be very few valid reasons for having to do so as this is more likely to break something than to fix it.
Usable in :
| QUIC Ini | TCP RqCon | RqSes | RqCnt | RsCnt | HTTP Req | Res | Aft |
|---|---|---|---|---|---|---|---|
![]() | ![]() | ![]() | ![]() |
This sets the "nice" factor of the current request/response being processed. It only has effect against the other requests being processed at the same time. The default value is 0, unless altered by the "nice" setting on the "bind" line. The accepted range is -1024..1024. The higher the value, the nicest the request will be. Lower values will make the request more important than other ones. This can be useful to improve the speed of some requests, or lower the priority of non-important requests. Using this setting without prior experimentation can cause some major slowdown.
Usable in :
| QUIC Ini | TCP RqCon | RqSes | RqCnt | RsCnt | HTTP Req | Res | Aft |
|---|---|---|---|---|---|---|---|
![]() |
This rewrites the request path with the result of the evaluation of format
string <fmt>. The query string, if any, is left intact. If a scheme and
authority is found before the path, they are left intact as well. If the
request doesn't have a path ("*"), this one is replaced with the format.
This can be used to prepend a directory component in front of a path for
example. See also "http-request set-query" and "http-request set-uri".
# prepend the host name before the path
http-request set-path /%[hdr(host)]%[path]
Usable in :
| QUIC Ini | TCP RqCon | RqSes | RqCnt | RsCnt | HTTP Req | Res | Aft |
|---|---|---|---|---|---|---|---|
![]() |
This does the same as "http-request set-path" except that the query-string is also rewritten. It may be used to remove the query-string, including the question mark (it is not possible using "http-request set-query").
Usable in :
| QUIC Ini | TCP RqCon | RqSes | RqCnt | RsCnt | HTTP Req | Res | Aft |
|---|---|---|---|---|---|---|---|
![]() | ![]() |
This is used to set the queue priority class of the current request. The value must be a sample expression which converts to an integer in the range -2047..2047. Results outside this range will be truncated. The priority class determines the order in which queued requests are processed. Lower values have higher priority.
Usable in :
| QUIC Ini | TCP RqCon | RqSes | RqCnt | RsCnt | HTTP Req | Res | Aft |
|---|---|---|---|---|---|---|---|
![]() | ![]() |
This is used to set the queue priority timestamp offset of the current request. The value must be a sample expression which converts to an integer in the range -524287..524287. Results outside this range will be truncated. When a request is queued, it is ordered first by the priority class, then by the current timestamp adjusted by the given offset in milliseconds. Lower values have higher priority. Note that the resulting timestamp is is only tracked with enough precision for 524,287ms (8m44s287ms). If the request is queued long enough to where the adjusted timestamp exceeds this value, it will be misidentified as highest priority. Thus it is important to set "timeout queue" to a value, where when combined with the offset, does not exceed this limit.
Usable in :
| QUIC Ini | TCP RqCon | RqSes | RqCnt | RsCnt | HTTP Req | Res | Aft |
|---|---|---|---|---|---|---|---|
![]() |
This rewrites the request's query string which appears after the first
question mark ("?") with the result of the evaluation of format string <fmt>.
The part prior to the question mark is left intact. If the request doesn't
contain a question mark and the new value is not empty, then one is added at
the end of the URI, followed by the new value. If a question mark was
present, it will never be removed even if the value is empty. This can be
used to add or remove parameters from the query string.
See also "http-request set-query" and "http-request set-uri".
# replace "%3D" with "=" in the query string
http-request set-query %[query,regsub(%3D,=,g)]
Usable in :
| QUIC Ini | TCP RqCon | RqSes | RqCnt | RsCnt | HTTP Req | Res | Aft |
|---|---|---|---|---|---|---|---|
![]() | ![]() |
This action overrides the specified "retries" value for the current stream only. It can be an integer value, in the range [0, 100], or an expression which must return a integer in the range [0, 100]. Note that this action is only relevant on the backend side and thus this rule is only available for the proxies with backend capability. It is also not allowed in "defaults" sections. When the action is used for a listener, it is evaluated in the frontend context. So retries value is conserved only if stream is not routed to a different backend, via a use-backend rule for instance. Otherwise the default retries value of the selected backend will be preset.
tcp-request content set-retries 3
http-request set-retries var(txn.retries)
Usable in :
| QUIC Ini | TCP RqCon | RqSes | RqCnt | RsCnt | HTTP Req | Res | Aft |
|---|---|---|---|---|---|---|---|
![]() | ![]() | ![]() | ![]() |
This is used to set the source IP address to the value of specified expression. Useful when a proxy in front of HAProxy rewrites source IP, but provides the correct IP in a HTTP header; or you want to mask source IP for privacy. All subsequent calls to "src" fetch will return this value (see example).
<expr> Is a standard HAProxy expression formed by a sample-fetch followed
by some converters.
See also "option forwardfor".
http-request set-src hdr(x-forwarded-for)
http-request set-src src,ipmask(24)
# After the masking this will track connections
# based on the IP address with the last byte zeroed out.
http-request track-sc0 src
When possible, set-src preserves the original source port as long as the address family allows it, otherwise the source port is set to 0.
Usable in :
| QUIC Ini | TCP RqCon | RqSes | RqCnt | RsCnt | HTTP Req | Res | Aft |
|---|---|---|---|---|---|---|---|
![]() | ![]() | ![]() | ![]() |
This is used to set the source port address to the value of specified expression.
<expr> Is a standard HAProxy expression formed by a sample-fetch followed
by some converters.
http-request set-src-port hdr(x-port)
http-request set-src-port int(4000)
When possible, set-src-port preserves the original source address as long as the address family supports a port, otherwise it forces the source address to IPv4 "0.0.0.0" before rewriting the port.
Usable in :
| QUIC Ini | TCP RqCon | RqSes | RqCnt | RsCnt | HTTP Req | Res | Aft |
|---|---|---|---|---|---|---|---|
![]() | ![]() |
This replaces the response status code with <status> which must be an integer between 100 and 999. Optionally, a custom reason text can be provided defined by <str>, or the default reason for the specified code will be used as a fallback. Note that the reason string only exists in HTTP/1.x and is ignored by other versions of the protocol.
# return "431 Request Header Fields Too Large"
http-response set-status 431
# return "503 Slow Down", custom reason
http-response set-status 503 reason "Slow Down".
Usable in :
| QUIC Ini | TCP RqCon | RqSes | RqCnt | RsCnt | HTTP Req | Res | Aft |
|---|---|---|---|---|---|---|---|
![]() | ![]() |
This action overrides the specified "client", "connect", "queue", "server", "tarpit" or "tunnel" timeout for the current stream only. Changing one timeout does not influence any other timeouts, even if they are inherited from each other during configuration parsing (see last example). The timeout can be specified in milliseconds or with any other unit if the number is suffixed by the unit as explained at the top of this document. It is also possible to write an expression which must return a number interpreted as a timeout in milliseconds. Note that the connect, queue, server and tunnel timeouts are only relevant on the backend side and thus this rule is only available for the proxies with backend capabilities. Likewise, client timeout is only relevant for frontend side. Tarpit timeout is available to both sides. The timeout value must be non-null to obtain the expected results. When the action is used for a listener, it is evaluated in the frontend context. So custom values for backend-side timeouts are conserved only if stream is not routed to a different backend, via a use-backend rule for instance. Otherwise the default values of the selected backend will be preset.
http-request set-timeout tunnel 5s
http-request set-timeout server req.hdr(host),map_int(host.lst)
http-response set-timeout tunnel 5s
http-response set-timeout server res.hdr(X-Refresh-Seconds),mul(1000)
defaults
# This will set both tarpit and queue timeout to 5s as they are not
# defined
timeout connect 5s
timeout client 30s
timeout server 30s
listen foo
# This will only change the connect timeout to 10s without affecting
# queue or tarpit timeouts
http-request set-timeout connect 10s
This is an alias for "set-fc-tos" (which should be used instead).
Usable in :
| QUIC Ini | TCP RqCon | RqSes | RqCnt | RsCnt | HTTP Req | Res | Aft |
|---|---|---|---|---|---|---|---|
![]() |
This rewrites the request URI with the result of the evaluation of format string <fmt>. The scheme, authority, path and query string are all replaced at once. This can be used to rewrite hosts in front of proxies, or to perform complex modifications to the URI such as moving parts between the path and the query string. If an absolute URI is set, it will be sent as is to HTTP/1.1 servers. If it is not the desired behavior, the host, the path and/or the query string should be set separately. See also "http-request set-path" and "http-request set-query".
Usable in :
| QUIC Ini | TCP RqCon | RqSes | RqCnt | RsCnt | HTTP Req | Res | Aft |
|---|---|---|---|---|---|---|---|
![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() |
This is used to set the contents of a variable. The variable is declared inline.
<var-name> The name of the variable. Variable of the parent stream cannot
be set. See section 2.8 about variables for details.
<cond> A set of conditions that must all be true for the variable to
actually be set (such as "ifnotempty", "ifgt" ...). See the
set-var converter's description for a full list of possible
conditions.
<expr> Is a standard HAProxy expression formed by a sample-fetch
followed by some converters.
<fmt> This is the value expressed using Custom log format rules (see
Custom log format in section 8.2.6).
All scopes are usable for HTTP rules, but scopes "proc" and "sess" are the only usable ones in rule sets which do not have access to contents such as "tcp-request connection" and "tcp-request session".
http-request set-var(req.my_var) req.fhdr(user-agent),lower
http-request set-var-fmt(txn.from) %[src]:%[src_port]
Usable in :
| QUIC Ini | TCP RqCon | RqSes | RqCnt | RsCnt | HTTP Req | Res | Aft |
|---|---|---|---|---|---|---|---|
![]() | ![]() | ![]() | ![]() | ![]() | ![]() |
This stops the evaluation of the rules and makes the client-facing connection suddenly disappear using a system-dependent way that tries to prevent the client from being notified. When called without the rst-ttl argument, we try to prevent sending any FIN or RST packet back to the client by using TCP_REPAIR. If this fails (mainly because of missing privileges), we fall back to sending a RST packet with a TTL of 1. The effect is that the client still sees an established connection while there is none on HAProxy, saving resources. However, stateful equipment placed between the HAProxy and the client (firewalls, proxies, load balancers) will also keep the established connection in their session tables. The optional rst-ttl changes this behaviour: TCP_REPAIR is not used, and an RST packet with a configurable TTL is sent. When set to a reasonable value, the RST packet travels through the local infrastructure, deleting the connection in firewalls and other systems, but disappears before reaching the client. Future packets from the client will then be dropped already by front equipment. These local RSTs protect local resources, but not the client's. This must not be used unless the consequences of doing this are fully understood.
Usable in :
| QUIC Ini | TCP RqCon | RqSes | RqCnt | RsCnt | HTTP Req | Res | Aft |
|---|---|---|---|---|---|---|---|
![]() | ![]() | ![]() |
This enables or disables the strict rewriting mode for following rules. It does not affect rules declared before it and it is only applicable on rules performing a rewrite on the requests. When the strict mode is enabled, any rewrite failure triggers an internal error. Otherwise, such errors are silently ignored. The purpose of the strict rewriting mode is to make some rewrites optional while others must be performed to continue the request processing. By default, the strict rewriting mode is enabled. Its value is also reset when a ruleset evaluation ends. So, for instance, if you change the mode on the frontend, the default mode is restored when HAProxy starts the backend rules evaluation.
Usable in :
| QUIC Ini | TCP RqCon | RqSes | RqCnt | RsCnt | HTTP Req | Res | Aft |
|---|---|---|---|---|---|---|---|
![]() |
This action is used to perform a connection upgrade. Only HTTP upgrades are supported for now. The protocol may optionally be specified. This action is only available for a proxy with the frontend capability. The connection upgrade is immediately performed, following "tcp-request content" rules are not evaluated. This upgrade method should be preferred to the implicit one consisting to rely on the backend mode. When used, it is possible to set HTTP directives in a frontend without any warning. These directives will be conditionally evaluated if the HTTP upgrade is performed. However, an HTTP backend must still be selected. It remains unsupported to route an HTTP connection (upgraded or not) to a TCP server. See section 4 about Proxies for more details on HTTP upgrades.
Usable in :
| QUIC Ini | TCP RqCon | RqSes | RqCnt | RsCnt | HTTP Req | Res | Aft |
|---|---|---|---|---|---|---|---|
![]() |
This stops the evaluation of the rules and immediately blocks the request without responding for a delay specified by "timeout tarpit" or "timeout connect" if the former is not set. After that delay, if the client is still connected, a response is returned so that the client does not suspect it has been tarpitted. Logs will report the flags "PT". The goal of the tarpit rule is to slow down robots during an attack when they're limited on the number of concurrent requests. It can be very efficient against very dumb robots, and will significantly reduce the load on firewalls compared to a "deny" rule. But when facing "correctly" developed robots, it can make things worse by forcing HAProxy and the front firewall to support insane number of concurrent connections. By default an HTTP error 500 is returned. But the response may be customized using same syntax than "http-request return" rules. Thus, see "http-request return" for details. For compatibility purpose, when no argument is defined, or only "deny_status", the argument "default-errorfiles" is implied. It means "http-request tarpit [deny_status <status>]" is an alias of "http-request tarpit [status <status>] default-errorfiles". No further "http-request" rules are evaluated. See also "http-request return" and "http-request silent-drop".
Usable in :
| QUIC Ini | TCP RqCon | RqSes | RqCnt | RsCnt | HTTP Req | Res | Aft |
|---|---|---|---|---|---|---|---|
![]() | ![]() | ![]() | ![]() | ![]() |
This enables tracking of sticky counters from current request. These rules do not stop evaluation and do not change default action. The number of counters that may be simultaneously tracked by the same connection is set by the global "tune.stick-counters" setting, which defaults to MAX_SESS_STKCTR if set at build time (it is reported in haproxy -vv) and which defaults to 3, so the track-sc number is between 0 and (tune.stick-counters-1). The first "track-sc0" rule executed enables tracking of the counters of the specified table as the first set. The first "track-sc1" rule executed enables tracking of the counters of the specified table as the second set. The first "track-sc2" rule executed enables tracking of the counters of the specified table as the third set. It is a recommended practice to use the first set of counters for the per-frontend counters and the second set for the per-backend ones. But this is just a guideline, all may be used everywhere.
<key> is mandatory, and is a sample expression rule as described in
section 7.3. It describes what elements of the incoming connection,
request or response will be analyzed, extracted, combined, and used
to select which table entry to update the counters.
<table> is an optional table to be used instead of the default one, which
is the stick-table declared in the current proxy. All the counters
for the matches and updates for the key will then be performed in
that table until the session ends.
Once a "track-sc*" rule is executed, the key is looked up in the table and if it is not found, an entry is allocated for it. Then a pointer to that entry is kept during all the session's life, and this entry's counters are updated as often as possible, every time the session's counters are updated, and also systematically when the session ends. Counters are only updated for events that happen after the tracking has been started. As an exception, connection counters and request counters are systematically updated so that they reflect useful information. If the entry tracks concurrent connection counters, one connection is counted for as long as the entry is tracked, and the entry will not expire during that time. Tracking counters also provides a performance advantage over just checking the keys, because only one table lookup is performed for all ACL checks that make use of it.
Usable in :
| QUIC Ini | TCP RqCon | RqSes | RqCnt | RsCnt | HTTP Req | Res | Aft |
|---|---|---|---|---|---|---|---|
![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() |
This is used to unset a variable. See the "set-var" action for details about
<var-name>.
http-request unset-var(req.my_var)
Usable in :
| QUIC Ini | TCP RqCon | RqSes | RqCnt | RsCnt | HTTP Req | Res | Aft |
|---|---|---|---|---|---|---|---|
![]() | ![]() |
This action executes the configured TCP or HTTP service to reply to the request, depending on the rule set it's used in. The rule is final, i.e. no further rules are evaluated in the same rule set. A service may choose to reply by sending any valid response or it may immediately close the connection without sending any response. For HTTP services, a valid response requires a valid HTTP response. Outside natives services, for instance the Prometheus exporter for HTTP services, it is possible to write custom TCP and HTTP services in Lua.
<service-name> is mandatory. It is the service to call
http-request use-service prometheus-exporter if { path /metrics }
Usable in :
| QUIC Ini | TCP RqCon | RqSes | RqCnt | RsCnt | HTTP Req | Res | Aft |
|---|---|---|---|---|---|---|---|
![]() | ![]() |
This will delay the processing of the request or response until one of the following conditions occurs: - The full request body is received, in which case processing proceeds normally. - <bytes> bytes have been received, when the "at-least" argument is given and <bytes> is non-zero, in which case processing proceeds normally. - The request buffer is full, in which case processing proceeds normally. The size of this buffer is determined by the "tune.bufsize" option. - The request has been waiting for more than <time> milliseconds. In this case HAProxy will respond with a 408 "Request Timeout" error to the client and stop processing the request. Note that if any of the other conditions happens first, this timeout will not occur even if the full body has not yet been received. "use-large-buffer" option may be set to allocate a large buffer if regular one is to small to store the message body. To be used, "tune.bufsize.large" global option must be defined. This action may be used as a replacement for "option http-buffer-request".
<time> is mandatory. It is the maximum time to wait for the body. It
follows the HAProxy time format and is expressed in milliseconds.
<bytes> is optional. It is the minimum payload size to receive to stop to
wait. It follows the HAProxy size format and is expressed in
bytes. A value of 0 (the default) means no limit.
http-request wait-for-body time 1s at-least 1k if METH_POST
Usable in :
| QUIC Ini | TCP RqCon | RqSes | RqCnt | RsCnt | HTTP Req | Res | Aft |
|---|---|---|---|---|---|---|---|
![]() |
This will delay the processing of the request until the SSL handshake happened. This is mostly useful to delay processing early data until we're sure they are valid.
The "bind", "server" and "default-server" keywords support a number of settings depending on some build options and on the system HAProxy was built on. These settings generally each consist in one word sometimes followed by a value, written on the same line as the "bind" or "server" line. All these options are described in this section.
The "bind" keyword supports a certain number of settings which are all passed
as arguments on the same line. The order in which those arguments appear makes
no importance, provided that they appear after the bind address. All of these
parameters are optional. Some of them consist in a single words (booleans),
while other ones expect a value after them. In this case, the value must be
provided immediately after the setting name.
The currently supported settings are the following ones.
Enforces the use of the NetScaler Client IP insertion protocol over any connection accepted by any of the TCP sockets declared on the same line. The NetScaler Client IP insertion protocol dictates the layer 3/4 addresses of the incoming connection to be used everywhere an address is used, with the only exception of "tcp-request connection" rules which will only see the real connection address. Logs will reflect the addresses indicated in the protocol, unless it is violated, in which case the real address will still be used. This keyword combined with support from external components can be used as an efficient and reliable alternative to the X-Forwarded-For mechanism which is not always reliable and not even always usable. See also "tcp-request connection expect-netscaler-cip" for a finer-grained setting of which client is allowed to use the protocol.
Enforces the use of the PROXY protocol over any connection accepted by any of the sockets declared on the same line. Versions 1 and 2 of the PROXY protocol are supported and correctly detected. The PROXY protocol dictates the layer 3/4 addresses of the incoming connection to be used everywhere an address is used, with the only exception of "tcp-request connection" rules which will only see the real connection address. Logs will reflect the addresses indicated in the protocol, unless it is violated, in which case the real address will still be used. This keyword combined with support from external components can be used as an efficient and reliable alternative to the X-Forwarded-For mechanism which is not always reliable and not even always usable. See also "tcp-request connection expect-proxy" for a finer-grained setting of which client is allowed to use the protocol.
Allow receiving early data when using TLSv1.3. This is disabled by default, due to security considerations. Because it is vulnerable to replay attacks, you should only allow if for requests that are safe to replay, i.e. requests that are idempotent. You can use the "wait-for-handshake" action for any request that wouldn't be safe with early data. With QUIC, 0rtt is supported with QuicTLS, OpenSSL >= 3.5.2 and AWS-LC. With TCP/TLS, 0rtt is only supported with OpenSSL, and requires that the client sends an ALPN, otherwise the early data won't be considered before the handshake happens.
This enables the TLS ALPN extension and advertises the specified protocol list as supported on top of ALPN. The protocol list consists in a comma- delimited list of protocol names, for instance: "http/1.1,http/1.0" (without quotes). This requires that the SSL library is built with support for TLS extensions enabled (check with haproxy -vv). The ALPN extension replaces the initial NPN extension. At the protocol layer, ALPN is required to enable HTTP/2 on an HTTPS frontend and HTTP/3 on a QUIC frontend. However, when such frontends have none of "npn", "alpn" and "no-alpn" set, a default value of "h2,http/1.1" will be used for a regular HTTPS frontend, and "h3" for a QUIC frontend. Versions of OpenSSL prior to 1.0.2 didn't support ALPN and only supposed the now obsolete NPN extension. At the time of writing this, most browsers still support both ALPN and NPN for HTTP/2 so a fallback to NPN may still work for a while. But ALPN must be used whenever possible. Protocols not advertised are not negotiated. For example it is possible to only accept HTTP/2 connections with this: bind :443 ssl crt pub.pem alpn h2 # explicitly disable HTTP/1.1 QUIC supports only h3 and hq-interop as ALPN. h3 is for HTTP/3 and hq-interop is used for http/0.9 and QUIC interop runner (see https://interop.seemann.io). Each "alpn" statement will replace a previous one. In order to remove them, use "no-alpn". Note that some old browsers such as Firefox 88 used to experience issues with WebSocket over H2, and in case such a setup is encountered, it may be needed to either explicitly disable HTTP/2 in the "alpn" string by forcing it to "http/1.1" or "no-alpn", or to enable "h2-workaround-bogus-websocket-clients" globally.
Sets the socket's backlog to this value. If unspecified or 0, the frontend's backlog is used instead, which generally defaults to the maxconn value.
This setting is only available when support for OpenSSL was built in. It designates a PEM file from which to load CA certificates used to verify client's certificate. It is possible to load a directory containing multiple CAs, in this case HAProxy will try to load every ".pem", ".crt", ".cer", and .crl" available in the directory, files starting with a dot are ignored. Warning: The "@system-ca" parameter could be used in place of the cafile in order to use the trusted CAs of your system, like its done with the server directive. But you mustn't use it unless you know what you are doing. Configuring it this way basically mean that the bind will accept any client certificate generated from one of the CA present on your system, which is extremely insecure.
This setting is only available when support for OpenSSL was built in. Sets a comma separated list of errorIDs to ignore during verify at depth > 0. It could be a numerical ID, or the constant name (X509_V_ERR) which is available in the OpenSSL documentation: https://www.openssl.org/docs/manmaster/man3/X509_STORE_CTX_get_error.html#ERROR-CODES It is recommended to use the constant name as the numerical value can change in new version of OpenSSL. If set to 'all', all errors are ignored. SSL handshake is not aborted if an error is ignored.
This setting is only available when support for OpenSSL was built in. It designates a PEM file containing both the CA certificate and the CA private key used to create and sign server's certificates. This is a mandatory setting when the dynamic generation of certificates is enabled. See 'generate-certificates' for details.
This setting is only available when support for OpenSSL was built in. It is the CA private key passphrase. This setting is optional and used only when the dynamic generation of certificates is enabled. See 'generate-certificates' for details.
This setting designates a PEM file from which to load CA certificates used to verify client's certificate. It designates CA certificates which must not be included in CA names sent in server hello message. Typically, "ca-file" must be defined with intermediate certificates, and "ca-verify-file" with certificates to ending the chain, like root CA.
This setting is only available on systems which define TCP_CONGESTION, and was validated on Linux and FreeBSD. It takes the name of a TCP congestion control algorithm and configures the listener to use this algorithm on all connections that are accepted from this listener. Typical names include "reno", "cubic" and will depend on the operating system. On some systems, special permissions may be required to configure certain algorithms. On Linux, the list of available algorithms may be found in the sysctl "net.ipv4.tcp_available_congestion_control", and the list of those permitted without privileges is in "net.ipv4.tcp_allowed_congestion_control". In order to access algorithms requiring extra permissions, the "cap_net_admin" capability might be required (see "setcap" in the global section). In case of failure to configure a specific congestion control algorithm, the default one will remain unchanged and a warning will be emitted to report the problem.
frontend public
bind :443 cc bbr # use the BBR algorithm for high bandwidths
This setting is only available when support for OpenSSL was built in. It sets
the string describing the list of cipher algorithms ("cipher suite") that are
negotiated during the SSL/TLS handshake up to TLSv1.2. The format of the
string is defined in "man 1 ciphers" from OpenSSL man pages. For background
information and recommendations see e.g.
(https://wiki.mozilla.org/Security/Server_Side_TLS) and
(https://mozilla.github.io/server-side-tls/ssl-config-generator/). For TLSv1.3
cipher configuration, please check the "ciphersuites" keyword.
This setting is only available when support for OpenSSL was built in and
OpenSSL 1.1.1 or later was used to build HAProxy. It sets the string describing
the list of cipher algorithms ("cipher suite") that are negotiated during the
TLSv1.3 handshake. The format of the string is defined in "man 1 ciphers" from
OpenSSL man pages under the "ciphersuites" section. For cipher configuration
for TLSv1.2 and earlier, please check the "ciphers" keyword.
This setting might accept TLSv1.2 ciphersuites however this is an
undocumented behavior and not recommended as it could be inconsistent or buggy.
The default TLSv1.3 ciphersuites of OpenSSL are:
"TLS_AES_256_GCM_SHA384:TLS_CHACHA20_POLY1305_SHA256:TLS_AES_128_GCM_SHA256"
TLSv1.3 only supports 5 ciphersuites:
- TLS_AES_128_GCM_SHA256
- TLS_AES_256_GCM_SHA384
- TLS_CHACHA20_POLY1305_SHA256
- TLS_AES_128_CCM_SHA256
- TLS_AES_128_CCM_8_SHA256
ciphers ECDHE-RSA-AES256-GCM-SHA384:ECDHE-RSA-CHACHA20-POLY1305:ECDHE-RSA-AES128-GCM-SHA256
ciphersuites TLS_AES_256_GCM_SHA384:TLS_CHACHA20_POLY1305_SHA256:TLS_AES_128_GCM_SHA256
This setting is only available when support for OpenSSL was built in. It sets the string describing the list of signature algorithms related to client authentication that are negotiated . The format of the string is defined in "man 3 SSL_CTX_set1_client_sigalgs" from the OpenSSL man pages. It is not recommended to use this setting if no specific usecase was identified.
This setting is only available when support for OpenSSL was built in. It designates a PEM file from which to load certificate revocation list used to verify client's certificate. You need to provide a certificate revocation list for every certificate of your certificate authority chain.
This setting is only available when support for OpenSSL was built in. HAProxy uses a cache system, the files are loaded only once in the certificate storage, and each next "crt" keyword will use this cached version. When the certificate was declared in a "crt-store", the certificate storage is populated from there and don't try to load additional files by detecting file extensions. It designates a PEM file containing both the required certificates and any associated private keys. This file can be built by concatenating multiple PEM files into one (e.g. cat cert.pem key.pem > combined.pem). If your CA requires an intermediate certificate, this can also be concatenated into this file. Intermediate certificate can also be shared in a directory via "issuers-chain-path" directive. If the file does not contain a private key, HAProxy will try to load the key at the same path suffixed by a ".key". If the OpenSSL used supports Diffie-Hellman, parameters present in this file are loaded. If a directory name is used instead of a PEM file, then all files found in that directory will be loaded in alphabetic order unless their name ends with '.key', '.issuer', '.ocsp' or '.sctl' (reserved extensions). Files starting with a dot are also ignored. This directive may be specified multiple times in order to load certificates from multiple files or directories. The certificates will be presented to clients who provide a valid TLS Server Name Indication field matching one of their CN or alt subjects. Wildcards are supported, where a wildcard character '*' is used instead of the first hostname component (e.g. *.example.org matches www.example.org but not www.sub.example.org). If an empty directory is used, HAProxy will not start unless the "strict-sni" keyword is used. If no SNI is provided by the client or if the SSL library does not support TLS extensions, or if the client provides an SNI hostname which does not match any certificate, then the first loaded certificate will be presented. This means that when loading certificates from a directory, it is highly recommended to load the default one first as a file or to ensure that it will always be the first one in the directory. In order to chose multiple default certificates (1 rsa and 1 ecdsa), there are 3 options: - A multi-cert bundle can be configured as the first certificate (`crt foobar.pem` in the configuration where the existing files are `foobar.pem.ecdsa` and `foobar.pem.rsa`. - Or a '*' filter for each certificate in a crt-list line. - The 'default-crt' keyword can be used. Note that the same cert may be loaded multiple times without side effects. Some CAs (such as GoDaddy) offer a drop down list of server types that do not include HAProxy when obtaining a certificate. If this happens be sure to choose a web server that the CA believes requires an intermediate CA (for GoDaddy, selection Apache Tomcat will get the correct bundle, but many others, e.g. nginx, result in a wrong bundle that will not work for some clients). For each PEM file, HAProxy checks for the presence of file at the same path suffixed by ".ocsp". If such file is found, support for the TLS Certificate Status Request extension (also known as "OCSP stapling") is automatically enabled. The content of this file is optional. If not empty, it must contain a valid OCSP Response in DER format. In order to be valid an OCSP Response must comply with the following rules: it has to indicate a good status, it has to be a single response for the certificate of the PEM file, and it has to be valid at the moment of addition. If these rules are not respected the OCSP Response is ignored and a warning is emitted. In order to identify which certificate an OCSP Response applies to, the issuer's certificate is necessary. If the issuer's certificate is not found in the PEM file, it will be loaded from a file at the same path as the PEM file suffixed by ".issuer" if it exists otherwise it will fail with an error. For each PEM file, HAProxy also checks for the presence of file at the same path suffixed by ".sctl". If such file is found, support for Certificate Transparency (RFC6962) TLS extension is enabled. The file must contain a valid Signed Certificate Timestamp List, as described in RFC. File is parsed to check basic syntax, but no signatures are verified. There are cases where it is desirable to support multiple key types, e.g. RSA and ECDSA in the cipher suites offered to the clients. This allows clients that support EC certificates to be able to use EC ciphers, while simultaneously supporting older, RSA only clients. To achieve this, OpenSSL 1.1.1 is required, you can configure this behavior by providing one crt entry per certificate type, or by configuring a "cert bundle" like it was required before HAProxy 1.8. See "ssl-load-extra-files".
This setting is only available when support for OpenSSL was built in. Sets a comma separated list of errorIDs to ignore during verify at depth == 0. It could be a numerical ID, or the constant name (X509_V_ERR) which is available in the OpenSSL documentation: https://www.openssl.org/docs/manmaster/man3/X509_STORE_CTX_get_error.html#ERROR-CODES It is recommended to use the constant name as the numerical value can change in new version of OpenSSL. If set to 'all', all errors are ignored. SSL handshake is not aborted if an error is ignored.
This setting is only available when support for OpenSSL was built in. It
designates a list of PEM file with an optional ssl configuration and a SNI
filter per certificate, with the following format for each line :
<crtfile> [\[<sslbindconf> ...\]] [[!]<snifilter> ...]
Empty lines as well as lines beginning with a hash ('#') will be ignored.
The crt-list can be manipulated dynamically over the stats socket. (See "add
ssl crt-list", "del ssl crt-list", "show ssl crt-list" in the management
guide).
crt-list are usually dedicated files, however a directory loaded with the "crt"
directive is represented internally as a crt-list. The "ssl-f-use" directive
in a frontend also declares a crt-list linked to this frontend.
crtfile:
This is the filename of the certificate, or an identifier if it was declared
elsewhere (over the CLI or in a crt-store with an alias for example).
It is possible to use the same <crtfile> on multiple lines with different
options and filters.
Multi-cert bundling (see "ssl-load-extra-files") is supported in a
crt-list, as long as only the base name is given in <crtfile>. HAProxy
will duplicate the crt-list line internally, adding an algorithm extension
(.rsa, .ecdsa, .dsa) when loading the file.
sslbindconf:
<sslbindconf> supports the following keywords from the bind line (see
Section 5.1. Bind options):
- allow-0rtt
- alpn
- ca-file
- ca-verify-file
- ciphers
- ciphersuites
- client-sigalgs
- crl-file
- curves
- ecdhe
- no-alpn
- no-ca-names
- npn
- sigalgs
- ssl-min-ver
- ssl-max-ver
- verify
<sslbindconf> also supports the following keywords from the crt-store load
keyword (see Section 12.7.1. Load options):
- crt
- key
- ocsp
- issuer
- sctl
- ocsp-update
Parameters from the bind line are inherited in <sslbindconf>, if none were
specified, the default options are inherited, the parameters specified in
<sslbindconf> overwrite those inherited settings.
snifilter:
When the <snifilter> parameter is used on a crt-list line, the CN and SAN
are not used anymore to select the certificate on this line during the
handshake but the <snifilter> is used instead.
<snifilter> is a list of entries separated by spaces. This list can contain
domains, or wildcards. The wildcards are in wildcard DNS format, using a
single asterisk as the first character of the entry. It is possible to
exclude a domain from a wildcard with a negative filter by specifying a '!'
in front of a single domain. Having a ! in front of a * is ignored. Having
negative filters without a wildcard on the same line is not supported as
well. The special entry '*' is used to specify default certificates, which
are used as fallback when no domain matched.
The certificates will be presented to clients who provide a valid TLS
Server Name Indication field matching one of the SNI filters, or the CN and
SAN of a <crtfile>. The matching algorithm first looks for a positive domain
entry in the list, if not found it will try to look for a wildcard in the
list. If a wildcard match, haproxy checks for a negative filter from the
same line and unmatch if necessary. In case of multiple key algorithms
(RSA,ECDSA,DSA), HAProxy will try to match one certificate per type and
chose the right one depending on what is supported by the client.
If no SNI is presented by the client or if no certificate matched, this
will fallback to one of the default certificate. To disable the default
certificate fallback, the 'strict-sni' option may be used.
When multiple default certificates are defined, HAProxy is able to chose
the right ECDSA or RSA one depending on what the client supports.
The first declared certificate of a bind line is used as a default
certificate, either from crt or crt-list option.
It is also possible to declare a '*' filter, which will add this
certificate to the list of default certificates. To clarify the
configuration, the default certificates could be explicit (with a '*'
filter) at the beginning of the list, so an implicit default is not added
before.
Due to multi-cert bundles being duplicated for each algorithm in the
crt-list, only one algorithm will occupy the first line in the crt-list and
be considered as default. Either specify the entire bundle as default by
declaring '*' as the filter or setting it on the bind line.
The "show ssl sni" command on the stats socket could be used to debug your
configuration. (See "show ssl sni" in the management guide)
# comment
default.pem.rsa *
default.pem.ecdsa *
cert2.pem [alpn h2,http/1.1]
certW.pem *.domain.tld !secure.domain.tld
certS.pem [curves X25519:P-256 ciphers ECDHE-ECDSA-AES256-GCM-SHA384] secure.domain.tld
foo.crt [key bar.pem ocsp foo.ocsp ocsp-update on] foo.bar.com
This option does the same as the "crt" option, with the difference that this certificate will be used as a default one as well. It is possible to add multiple default certificates to have an ECDSA and an RSA one, having more is not really useful. This option does not disable implicit default certificates, if a 'crt' certificate is declared first before any 'default-crt' or other 'crt' it will still be used as a default certificate. A default certificate is used when no "strict-sni" option is used on the bind line. A default certificate is provided when the servername extension was not used by the client, or when the servername does not match any configured certificate.
# this bind line has 2 default certificates
bind *:443 default-crt foobar.pem.rsa default-crt foobar.pem.ecdsa crt website.pem.rsa
# this bind line has 3 default certificates
bind *:443 crt website.pem.rsa default-crt foobar.pem.rsa default-crt foobar.pem.ecdsa
See also the "crt" keyword.
This setting is only available when support for OpenSSL was built in. It sets
the string describing the list of elliptic curves algorithms ("curve suite")
that are negotiated during the SSL/TLS handshake with ECDHE. The format of the
string is a colon-delimited list of curve name.
Is an optional keyword which is supported only on certain Linux kernels. It states that a connection will only be accepted once some data arrive on it, or at worst after the first retransmit. This should be used only on protocols for which the client talks first (e.g. HTTP). It can slightly improve performance by ensuring that most of the request is already available when the connection is accepted. On the other hand, it will not be able to detect connections which don't talk. It is important to note that this option is broken in all kernels up to 2.6.31, as the connection is never accepted until the client talks. This can cause issues with front firewalls which would see an established connection while the proxy will only see it in SYN_RECV. This option is only supported on TCPv4/TCPv6 sockets and ignored by other ones.
This setting is only available when support for OpenSSL was built in. It sets the named curve (RFC 4492) used to generate ECDH ephemeral keys. By default, used named curve is prime256v1.
Apply all ECH keys from <dir> to the bind line. The files must have the .ech extension and must use the PEM file format for ECH. ( https://datatracker.ietf.org/doc/draft-farrell-tls-pemesni/ ) This keyword enables ECH in shared-mode. with HAProxy acting as both the TLS endpoint and the ECH endpoint. See https://datatracker.ietf.org/doc/draft-ietf-tls-esni/ This is an experimental feature, which requires the "expose-experimental-directives" option in the global section. It also necessitates an OpenSSL version that supports ECH ( https://github.com/openssl/openssl/tree/feature/ech), and HAProxy must be compiled with USE_ECH=1. The ECH API of AWS-LC is not supported.
$ openssl ech -public_name foobar.com -out /etc/haproxy/echkeydir/foobar.com.ech
$ cat haproxy.cfg
[...]
bind :443 ech /etc/haproxy/echkeydir/ ssl crt example.com.pem
// Use the ECHCONFIG section of your .ech file
$ openssl s_client -tls1_3 -connect example.com:443 -servername example.com \
-ech_config_list AD3+DQA5cwAgACB6ybtgtFYoM5r8nJSotus4c7K0EG..9vYmFyLmNvbQAA
This option is only usable with the stats socket. It gives your stats socket the capability to pass listeners FD to another HAProxy process. In master-worker mode, this is not required anymore, the listeners will be passed using the internal socketpairs between the master and the workers. See also "-x" in the management guide.
This option enforces use of SSLv3 only on SSL connections instantiated from this listener. SSLv3 is generally less expensive than the TLS counterparts for high connection rates. This option is also available on global statement "ssl-default-bind-options". See also "ssl-min-ver" and "ssl-max-ver".
This option enforces use of TLSv1.0 only on SSL connections instantiated from this listener. This option is also available on global statement "ssl-default-bind-options". See also "ssl-min-ver" and "ssl-max-ver".
This option enforces use of TLSv1.1 only on SSL connections instantiated from this listener. This option is also available on global statement "ssl-default-bind-options". See also "ssl-min-ver" and "ssl-max-ver".
This option enforces use of TLSv1.2 only on SSL connections instantiated from this listener. This option is also available on global statement "ssl-default-bind-options". See also "ssl-min-ver" and "ssl-max-ver".
This option enforces use of TLSv1.3 only on SSL connections instantiated from this listener. This option is also available on global statement "ssl-default-bind-options". See also "ssl-min-ver" and "ssl-max-ver".
This setting is only available when support for OpenSSL was built in. It enables the dynamic SSL certificates generation. A CA certificate and its private key are necessary (see 'ca-sign-file'). When HAProxy is configured as a transparent forward proxy, SSL requests generate errors because of a common name mismatch on the certificate presented to the client. With this option enabled, HAProxy will try to forge a certificate using the SNI hostname indicated by the client. This is done only if no certificate matches the SNI hostname (see 'crt-list'). In the event of a certificate generation error, the connection will fall back on the default certificate. When using 'strict-sni', the default certificate will not be used and the connection will result in a handshake failure. It can also be used when HAProxy is configured as a reverse proxy to ease the deployment of an architecture with many backends. Creating a SSL certificate is an expensive operation, so a LRU cache is used to store forged certificates (see 'tune.ssl.ssl-ctx-cache-size'). It increases the HAProxy's memory footprint to reduce latency when the same certificate is used many times.
Sets the group of the UNIX sockets to the designated system gid. It can also be set by default in the global section's "unix-bind" statement. Note that some platforms simply ignore this. This setting is equivalent to the "group" setting except that the group ID is used instead of its name. This setting is ignored by non UNIX sockets.
Sets the group of the UNIX sockets to the designated system group. It can also be set by default in the global section's "unix-bind" statement. Note that some platforms simply ignore this. This setting is equivalent to the "gid" setting except that the group name is used instead of its gid. This setting is ignored by non UNIX sockets.
Generate case-sensitive global unique IDs for each listening sockets allocated on this bind line. Prefix will be concatenated to listeners position index on the current bind line, with character '-' as separator. See "guid" proxy keyword description for more information on its format. See also "shm-stats-file".
Fixes the socket ID. By default, socket IDs are automatically assigned, but sometimes it is more convenient to fix them to ease monitoring. This value must be strictly positive and unique within the listener/frontend. This option can only be used when defining only a single socket.
May be used in the following contexts: tcp, http, log Define an interval for periodic liveliness on idle frontend connections. If the peer is unable to respond before the next scheduled test, the connection is closed. Else, the client timeout is refreshed and the connection is kept. Note that http-request/http-keep-alive timers run in parallel and are not refreshed by idle-ping. This feature relies on specific underlying protocol support. For now, only H2 mux implements it. Idle-ping is simply ignored by other protocols. This option is particularly useful when using reverse HTTP. Setting it on the bind line is useful for the peer which is responsible to actively initiate connections and will then receive incoming traffic through them.
Restricts the socket to a specific interface. When specified, only packets received from that particular interface are processed by the socket. This is currently only supported on Linux. The interface must be a primary system interface, not an aliased interface. It is also possible to bind multiple frontends to the same address if they are bound to different interfaces. Note that binding to a network interface requires root privileges. This parameter is only compatible with TCPv4/TCPv6 sockets. When specified, return traffic uses the same interface as inbound traffic, and its associated routing table, even if there are explicit routes through different interfaces configured. This can prove useful to address asymmetric routing issues when the same client IP addresses need to be able to reach frontends hosted on different interfaces.
Enables or disables ktls for those sockets. If enabled, kTLS will be used
if the kernel supports it and the cipher is compatible. This is only
available on Linux kernel 4.17 and above. Please note that some network
drivers and/or TLS stacks might restrict kTLS usage to TLS v1.2 only. See
also "force-tlsv12".
Sets an optional label for these sockets. It could be used group sockets by label, independently of where the bind lines were declared.
This setting is used with the stats sockets only to restrict the nature of
the commands that can be issued on the socket. It is ignored by other
sockets. <level> can be one of :
- "user" is the least privileged level; only non-sensitive stats can be
read, and no change is allowed. It would make sense on systems where it
is not easy to restrict access to the socket.
- "operator" is the default level and fits most common uses. All data can
be read, and only non-sensitive changes are permitted (e.g. clear max
counters).
- "admin" should be used with care, as everything is permitted (e.g. clear
all counters).
Limits the sockets to this number of concurrent connections. Extraneous connections will remain in the system's backlog until a connection is released. If unspecified, the limit will be the same as the frontend's maxconn. Note that in case of port ranges or multiple addresses, the same value will be applied to each socket. This setting enables different limitations on expensive sockets, for instance SSL entries which may easily eat all memory.
Sets the octal mode used to define access permissions on the UNIX socket. It can also be set by default in the global section's "unix-bind" statement. Note that some platforms simply ignore this. This setting is ignored by non UNIX sockets.
Sets the TCP Maximum Segment Size (MSS) value to be advertised on incoming connections. This can be used to force a lower MSS for certain specific ports, for instance for connections passing through a VPN. Note that this relies on a kernel feature which is theoretically supported under Linux but was buggy in all versions prior to 2.6.28. It may or may not work on other operating systems. It may also not change the advertised value but change the effective size of outgoing segments. The commonly advertised value for TCPv4 over Ethernet networks is 1460 = 1500(MTU) - 40(IP+TCP). If this value is positive, it will be used as the advertised MSS. If it is negative, it will indicate by how much to reduce the incoming connection's advertised MSS for outgoing segments. This parameter is only compatible with TCP v4/v6 sockets.
Sets an optional name for these sockets, which will be reported on the stats page.
On Linux, it is possible to specify which network namespace a socket will belong to. This directive makes it possible to explicitly bind a listener to a namespace different from the default one. Please refer to your operating system's documentation to find more details about network namespaces.
This setting is only valid for listener instances which uses reverse HTTP. This will define the count of connections which will be mounted in parallel. If not specified, a default value of 1 is used. Reverse HTTP is currently still in active development. Configuration mechanism may change in the future. For this reason it is internally marked as expirmental, meaning that "expose-experimental-directives" must appear on a line before this directive.
Sets the 'niceness' of connections initiated from the socket. Value must be in the range -1024..1024 inclusive, and defaults to zero. Positive values means that such connections are more friendly to others and easily offer their place in the scheduler. On the opposite, negative values mean that connections want to run with a higher priority than others. The difference only happens under high loads when the system is close to saturation. Negative values are appropriate for low-latency or administration services, and high values are generally recommended for CPU intensive tasks such as SSL processing or bulk transfers which are less sensible to latency. For example, it may make sense to use a positive value for an SMTP socket and a negative one for an RDP socket.
Disables ALPN processing (technically speaking this sets the ALPN string to an empty string that will not be advertised). It permits to cancel a previous occurrence of an "alpn" setting and to disable application protocol negotiation. It may also be used to prevent a listener from negotiating ALPN with a client on an HTTPS or QUIC listener; by default, HTTPS listeners will advertise "h2,http/1.1" and QUIC listeners will advertise "h3". See also "alpn" bove. Note that when using "crt-list", a certificate may override the "alpn" setting and re-enable its processing.
This setting is only available when support for OpenSSL was built in. It prevents from send CA names in server hello message when ca-file is used. Use "ca-verify-file" instead of "ca-file" with "no-ca-names".
This setting is only available when support for OpenSSL was built in. It disables support for SSLv3 on any sockets instantiated from the listener when SSL is supported. Note that SSLv2 is forced disabled in the code and cannot be enabled using any configuration option. This option is also available on global statement "ssl-default-bind-options". Use "ssl-min-ver" and "ssl-max-ver" instead.
This setting is only available when support for OpenSSL was built in. It disables strict-sni enforcement from a previous "strict-sni" directive. It may be needed in order to selectively disable strict-sni usage on a "bind" line when it was already globally enforced via "ssl-default-bind-options". See also the "strict-sni" bind option.
This setting is only available when support for OpenSSL was built in. It disables the stateless session resumption (RFC 5077 TLS Ticket extension) and force to use stateful session resumption. Stateless session resumption is more expensive in CPU usage. This option is also available on global statement "ssl-default-bind-options". The TLS ticket mechanism is only used up to TLS 1.2. Forward Secrecy is compromised with TLS tickets, unless ticket keys are periodically rotated (via reload or by using "tls-ticket-keys").
This setting is only available when support for OpenSSL was built in. It disables support for TLSv1.0 on any sockets instantiated from the listener when SSL is supported. Note that SSLv2 is forced disabled in the code and cannot be enabled using any configuration option. This option is also available on global statement "ssl-default-bind-options". Use "ssl-min-ver" and "ssl-max-ver" instead.
This setting is only available when support for OpenSSL was built in. It disables support for TLSv1.1 on any sockets instantiated from the listener when SSL is supported. Note that SSLv2 is forced disabled in the code and cannot be enabled using any configuration option. This option is also available on global statement "ssl-default-bind-options". Use "ssl-min-ver" and "ssl-max-ver" instead.
This setting is only available when support for OpenSSL was built in. It disables support for TLSv1.2 on any sockets instantiated from the listener when SSL is supported. Note that SSLv2 is forced disabled in the code and cannot be enabled using any configuration option. This option is also available on global statement "ssl-default-bind-options". Use "ssl-min-ver" and "ssl-max-ver" instead.
This setting is only available when support for OpenSSL was built in. It disables support for TLSv1.3 on any sockets instantiated from the listener when SSL is supported. Note that SSLv2 is forced disabled in the code and cannot be enabled using any configuration option. This option is also available on global statement "ssl-default-bind-options". Use "ssl-min-ver" and "ssl-max-ver" instead.
This enables the NPN TLS extension and advertises the specified protocol list
as supported on top of NPN. The protocol list consists in a comma-delimited
list of protocol names, for instance: "http/1.1,http/1.0" (without quotes).
This requires that the SSL library is built with support for TLS extensions
enabled (check with haproxy -vv). Note that the NPN extension has been
replaced with the ALPN extension (see the "alpn" keyword), though this one is
only available starting with OpenSSL 1.0.2. If HTTP/2 is desired on an older
version of OpenSSL, NPN might still be used as most clients still support it
at the time of writing this. It is possible to enable both NPN and ALPN
though it probably doesn't make any sense out of testing.
Use the client's preference when selecting the cipher suite, by default the server's preference is enforced. This option is also available on global statement "ssl-default-bind-options". Note that with OpenSSL >= 1.1.1 ChaCha20-Poly1305 is reprioritized anyway (without setting this option), if a ChaCha20-Poly1305 cipher is at the top of the client cipher list. When using a dual algorithms setup (RSA + ECDSA), the selection algorithm will chose between RSA and ECDSA and will always prioritize ECDSA. Once the right certificate is chosen, it will let the SSL library prioritize ciphers, curves etc. Meaning this option can't be used to prioritize an RSA certificate over an ECDSA one.
Forces the multiplexer's protocol to use for the incoming connections. It
must be compatible with the mode of the frontend (TCP or HTTP). It must also
be usable on the frontend side. The list of available protocols is reported
in haproxy -vv. The protocols properties are reported : the mode (TCP/HTTP),
the side (FE/BE), the mux name and its flags.
Some protocols are subject to the head-of-line blocking on server side
(flag=HOL_RISK). Finally some protocols don't support upgrades (flag=NO_UPG).
The HTX compatibility is also reported (flag=HTX).
Here are the protocols that may be used as argument to a "proto" directive on
a bind line :
quic : mode=HTTP side=FE|BE mux=QUIC flags=HTX|NO_UPG|FRAMED
qmux : mode=HTTP side=FE|BE mux=QMUX flags=HTX|NO_UPG
h2 : mode=HTTP side=FE|BE mux=H2 flags=HTX|HOL_RISK|NO_UPG
h1 : mode=HTTP side=FE|BE mux=H1 flags=HTX|NO_UPG
none : mode=TCP side=FE|BE mux=PASS flags=NO_UPG
Idea behind this option is to bypass the selection of the best multiplexer's
protocol for all connections instantiated from this listening socket. For
instance, it is possible to force the http/2 on clear TCP by specifying
"proto h2" on the bind line.
If the ALPN or the NPN settings are configured, the specified protocols
should be compatible with the multiplexer's protocol to avoid any issue. For
instance, if "proto h1" is set, the ALPN should not be set to "h2".
QMux is a subset of QUIC which runs over TCP. It corresponds to the following
draft protocol https://www.ietf.org/archive/id/draft-ietf-quic-qmux-01.html.
It is considered experimental in haproxy for now.
This is a QUIC specific setting to select the congestion control algorithm for any connection attempts to the configured QUIC listeners. They are similar to those used by TCP. Pacing is activated on top of the congestion algorithm to reduce loss and improve throughput. It can be turned off via "tune.quic.fe.tx.pacing" global keyword. In most cases, pacing should remain activated, especially when using BBR as it relies on it to work as expected. Using BBR without pacing may cause slowdowns or high loss rates during transfers. Default value: cubic For further customization, a list of parameters can be specified after the algorithm token. It must be written between parenthesis, separated by a comma. Each argument is optional and can be empty if needed. Here is the mandatory order of each parameters : - maximum window size in bytes. It must be greater than 10k and smaller than 4g. By default "tune.quic.fe.cc.max-win-size" value is used.
# newreno congestion control algorithm
quic-cc-algo newreno
# cubic congestion control algorithm with one megabytes as window
quic-cc-algo cubic(1m)
A special value "nocc" may be used to force a fixed congestion window always set at the maximum size. It is reserved for debugging scenarios to remove any side effects caused by the congestion controller. It must not be used in production as it can quickly lead to network issues such as a high loss rate.
This is a QUIC specific setting which forces the use of the QUIC Retry feature for all the connection attempts to the configured QUIC listeners. It consists in verifying the peers are able to receive packets at the transport address they used to initiate a new connection, sending them a Retry packet which contains a token. This token must be sent back to the Retry packet sender, this latter being the only one to be able to validate the token. Note that QUIC Retry will always be used even if a Retry threshold was set (see "tune.quic.fe.sec.retry-threshold" setting). This setting requires the cluster secret to be set or else an error will be reported on startup (see "cluster-secret"). See https://www.rfc-editor.org/rfc/rfc9000.html#section-8.1.2 for more information about QUIC retry.
This QUIC specific setting allows to define the socket allocation mode for the specific listeners. See "tune.quic.fe.sock-per-conn" for a full description of the pros and cons of each mode. This setting is applied in conjunction with the global "tune.quic.fe.sock-per-conn" option. If "default-on" mode is active on the global tuning (this is the default value), each QUIC connection will use its owned socket, except for listeners with "quic-socket listener". However, if the global mode is set to "force-off", individual listener configuration will be ignored.
This setting is used with the stats sockets only to configure severity level output prepended to informational feedback messages. Severity level of messages can range between 0 and 7, conforming to syslog rfc5424. Valid and successful socket commands requesting data (i.e. "show map", "get acl foo" etc.) will never have a severity level prepended. It is ignored by other sockets. <format> can be one of : - "none" (default) no severity level is prepended to feedback messages. - "number" severity level is prepended as a number. - "string" severity level is prepended as a string following the rfc5424 convention.
In multi-threaded mode, on operating systems supporting multiple listeners on
the same IP:port, this will automatically create this number of multiple
identical listeners for the same line, all bound to a fair share of the number
of the threads attached to this listener. This can sometimes be useful when
using very large thread counts where the in-kernel locking on a single socket
starts to cause a significant overhead. In this case the incoming traffic is
distributed over multiple sockets and the contention is reduced. Note that
doing this can easily increase the CPU usage by making more threads work a
little bit.
If the number of shards is higher than the number of available threads, it
will automatically be trimmed to the number of threads (i.e. one shard per
thread). The special "by-thread" value also creates as many shards as there
are threads on the "bind" line. Since the system will evenly distribute the
incoming traffic between all these shards, it is important that this number
is an integral divisor of the number of threads. Alternately, the other
special value "by-group" will create one shard per thread group. This can
be useful when dealing with many threads and not wanting to create too many
sockets. The load distribution will be a bit less optimal but the contention
(especially in the system) will still be lower than with a single socket.
On operating systems that do not support multiple sockets bound to the same
address, "by-thread" and "by-group" will automatically fall back to a single
shard. For "by-group" this is done without any warning since it doesn't
change anything for a single group, and will result in sockets being
duplicated for each group anyway. However, for "by-thread", a diagnostic
warning will be emitted if this happens since the resulting number of
listeners will not be the expected one.
This setting is only available when support for OpenSSL was built in. It sets the string describing the list of signature algorithms that are negotiated during the TLSv1.2 and TLSv1.3 handshake. The format of the string is defined in "man 3 SSL_CTX_set1_sigalgs" from the OpenSSL man pages. It is not recommended to use this setting unless compatibility with a middlebox is required.
This setting is only available when support for OpenSSL was built in. It
enables SSL deciphering on connections instantiated from this listener. A
certificate is necessary (see "crt" above). All contents in the buffers will
appear in clear text, so that ACLs and HTTP processing will only have access
to deciphered contents. SSLv3 is disabled per default, use "ssl-min-ver SSLv3"
to enable it.
This option enforces use of <version> or lower on SSL connections instantiated from this listener. Using this setting without "ssl-min-ver" can be ambiguous because the default ssl-min-ver value could change in future HAProxy versions. This option is also available on global statement "ssl-default-bind-options". See also "ssl-min-ver".
This option enforces use of <version> or upper on SSL connections instantiated from this listener. The default value is "TLSv1.2". This option is also available on global statement "ssl-default-bind-options". See also "ssl-max-ver".
This setting is only available when support for OpenSSL was built in. The SSL/TLS negotiation is allowed only if the client provided an SNI that matches a certificate. The default certificate is not used. This option also allows starting without any certificate on a bind line, so an empty directory could be used and filled later from the stats socket. This option is also available on global statement "ssl-default-bind-options", and may be selectively disabled on a "bind" line using "no-strict-sni". See the "crt" option for more information. See "add ssl crt-list" command in the management guide.
Enables the TCP MD5 signature (RFC 2385 Protection of BGP Sessions via the TCP MD5 Signature Option) for all incoming connections instantiated from this listening socket. This option is only available on Linux. When enabled, <password> string is used to sign every TCP segments with a 16-byte MD5 digest. This will protect the TCP connection against spoofing. The primary use case for this option is to allow BGP to protect itself against the introduction of spoofed TCP segments into the connection stream. But it can be useful for any very long-lived TCP connections.
Sets the TCP Save SYN option for all incoming connections instantiated from this listening socket. This option is available on Linux since version 4.3. It instructs the kernel to try to keep a copy of the incoming IP packet containing the TCP SYN flag, for later inspection via the "fc_saved_syn" sample fetch function. The option knows 3 modes: - 0 SYN packet saving is disabled, this is the default - 1 SYN packet saving is enabled, and contains IP and TCP headers - 2 SYN packet saving is enabled, and contains ETH, IP and TCP headers This only works for regular TCP connections, and is ignored for other protocols (e.g. UNIX sockets). See also "fc_saved_syn".
Sets the TCP User Timeout for all incoming connections instantiated from this listening socket. This option is available on Linux since version 2.6.37. It allows HAProxy to configure a timeout for sockets which contain data not receiving an acknowledgment for the configured delay. This is especially useful on long-lived connections experiencing long idle periods such as remote terminals or database connection pools, where the client and server timeouts must remain high to allow a long period of idle, but where it is important to detect that the client has disappeared in order to release all resources associated with its connection (and the server's session). The argument is a delay expressed in milliseconds by default. This only works for regular TCP connections, and is ignored for other protocols.
Is an optional keyword which is supported only on Linux kernels >= 3.7. It enables TCP Fast Open on the listening socket, which means that clients which support this feature will be able to send a request and receive a response during the 3-way handshake starting from second connection, thus saving one round-trip after the first connection. This only makes sense with protocols that use high connection rates and where each round trip matters. This can possibly cause issues with many firewalls which do not accept data on SYN packets, so this option should only be enabled once well tested. This option is only supported on TCPv4/TCPv6 sockets and ignored by other ones. You may need to build HAProxy with USE_TFO=1 if your libc doesn't define TCP_FASTOPEN.
This restricts the list of threads on which this listener is allowed to run.
It does not enforce any of them but eliminates those which do not match. It
limits the threads allowed to process incoming connections for this listener.
There are two numbering schemes. By default, thread numbers are absolute in
the process, comprised between 1 and the value specified in global.nbthread.
It is also possible to designate a thread number using its relative number
inside its thread group, by specifying the thread group number first, then a
slash ('/') and the relative thread number(s). In this case thread numbers
also start at 1 and end at 32 or 64 depending on the platform. When absolute
thread numbers are specified, they will be automatically translated to
relative numbers once thread groups are known. Usually, absolute numbers are
preferred for simple configurations, and relative ones are preferred for
complex configurations where CPU arrangement matters for performance.
After the optional thread group number, the "thread-set" specification must
use the following format:
"all" | "odd" | "even" | [number][-[number]]
As their names imply, "all" validates all threads within the set (either all
of the group's when a group is specified, or all of the process' threads),
"odd" validates all odd-numberred threads (every other thread starting at 1)
either for the process or the group, and "even" validates all even-numberred
threads (every other thread starting at 2). If instead thread number ranges
are used, then all threads included in the range from the first to the last
thread number are validated. The numbers are either relative to the group
or absolute depending on the presence of a thread group number. If the first
thread number is omitted, "1" is used, representing either the first thread
of the group or the first thread of the process. If the last thread number is
omitted, either the last thread number of the group (32 or 64) is used, or
the last thread number of the process (global.nbthread).
These ranges may be repeated and delimited by a comma, so that non-contiguous
thread sets can be specified, and the group, if present, must be specified
again for each new range. Note that it is not permitted to mix group-relative
and absolute specifications because the whole "bind" line must use either
an absolute notation or a relative one, as those not set will be resolved at
the end of the parsing.
It is important to know that each listener described by a "bind" line creates
at least one socket represented by at least one file descriptor. Since file
descriptors cannot span multiple thread groups, if a "bind" line specifies a
thread range that covers more than one group, several file descriptors will
automatically be created so that there is at least one per group. Technically
speaking they all refer to the same socket in the kernel, but they will get a
distinct identifier in haproxy and will even have a dedicated stats entry if
"option socket-stats" is used.
The main purpose is to have multiple bind lines sharing the same IP:port but
not the same thread in a listener, so that the system can distribute the
incoming connections into multiple queues, bypassing haproxy's internal queue
load balancing. Currently Linux 3.9 and above is known for supporting this.
See also the "shards" keyword above that automates duplication of "bind"
lines and their assignment to multiple groups of threads.
This keyword is compatible with reverse HTTP binds. However, it is forbidden
to specify a thread set which spans across several thread groups for such a
listener as this may caused "nbconn" to not work as intended.
This setting is only available when support for OpenSSL was built in. It enables the stateless session resumption (RFC 5077 TLS Ticket extension). It is the default, but it may be needed to selectively re-enable the feature on a "bind" line if it had been globally disabled via "no-tls-tickets" mentioned in "ssl-default-bind-options". See also the "no-tls-tickets" bind keyword.
Sets the TLS ticket keys file to load the keys from. The keys need to be 48 or 80 bytes long, depending if aes128 or aes256 is used, encoded with base64 with one line per key (ex. openssl rand 80 | openssl base64 -A | xargs echo). The first key determines the key length used for next keys: you can't mix aes128 and aes256 keys. Number of keys is specified by the TLS_TICKETS_NO build option (default 3) and at least as many keys need to be present in the file. Last TLS_TICKETS_NO keys will be used for decryption and the penultimate one for encryption. This enables easy key rotation by just appending new key to the file and reloading the process. Keys must be periodically rotated (ex. every 12h) or Perfect Forward Secrecy is compromised. It is also a good idea to keep the keys off any permanent storage such as hard drives (hint: use tmpfs and don't swap those files). Lifetime hint can be changed using tune.ssl.timeout.
Is an optional keyword which is supported only on certain Linux kernels. It indicates that the addresses will be bound even if they do not belong to the local machine, and that packets targeting any of these addresses will be intercepted just as if the addresses were locally configured. This normally requires that IP forwarding is enabled. Caution! do not use this with the default address '*', as it would redirect any traffic for the specified port. This keyword is available only when HAProxy is built with USE_LINUX_TPROXY=1. This parameter is only compatible with TCPv4 and TCPv6 sockets, depending on kernel version. Some distribution kernels include backports of the feature, so check for support with your vendor.
Sets the owner of the UNIX sockets to the designated system uid. It can also be set by default in the global section's "unix-bind" statement. Note that some platforms simply ignore this. This setting is equivalent to the "user" setting except that the user numeric ID is used instead of its name. This setting is ignored by non UNIX sockets.
Sets the owner of the UNIX sockets to the designated system user. It can also be set by default in the global section's "unix-bind" statement. Note that some platforms simply ignore this. This setting is equivalent to the "uid" setting except that the user name is used instead of its uid. This setting is ignored by non UNIX sockets.
Is an optional keyword which is supported only on most recent systems including Linux kernels >= 2.4.21. It is used to bind a socket to both IPv4 and IPv6 when it uses the default address. Doing so is sometimes necessary on systems which bind to IPv6 only by default. It has no effect on non-IPv6 sockets, and is overridden by the "v6only" option.
Is an optional keyword which is supported only on most recent systems including Linux kernels >= 2.4.21. It is used to bind a socket to IPv6 only when it uses the default address. Doing so is sometimes preferred to doing it system-wide as it is per-listener. It has no effect on non-IPv6 sockets and has precedence over the "v4v6" option.
This setting is only available when support for OpenSSL was built in. If set to 'none', client certificate is not requested. This is the default. In other cases, a client certificate is requested. If the client does not provide a certificate after the request and if 'verify' is set to 'required', then the handshake is aborted, while it would have succeeded if set to 'optional'. The certificate provided by the client is always verified using CAs from 'ca-file' and optional CRLs from 'crl-file'. On verify failure the handshake is aborted, regardless of the 'verify' option, unless the error code exactly matches one of those listed with 'ca-ignore-err' or 'crt-ignore-err'.
The "server" and "default-server" keywords support a certain number of settings which are all passed as arguments on the server line. The order in which those arguments appear does not count, and they are all optional. Some of those settings are single words (booleans) while others expect one or several values after them. In this case, the values must immediately follow the setting name. Except default-server, all those settings must be specified after the server's address if they are used: server <name> <address>[:port] [settings ...] default-server [settings ...] Note that all these settings are supported both by "server" and "default-server" keywords, except "id" which is only supported by "server". The currently supported settings are the following ones.
May be used in the following contexts: tcp, http, log Using the "addr" parameter, it becomes possible to use a different IP address to send health-checks or to probe the agent-check. On some servers, it may be desirable to dedicate an IP address to specific component able to perform complex tests which are more suitable to health-checks than the application. This parameter is ignored if the "check" parameter is not set. See also the "port" parameter.
May be used in the following contexts: tcp, http, log Enable an auxiliary agent check which is run independently of a regular health check. An agent health check is performed by making a TCP connection to the port set by the "agent-port" parameter and reading an ASCII string terminated by the first '\r' or '\n' met. The string is made of a series of words delimited by spaces, tabs or commas in any order, each consisting of : - An ASCII representation of a positive integer percentage, e.g. "75%". Values in this format will set the weight proportional to the initial weight of a server as configured when HAProxy starts. Note that a zero weight is reported on the stats page as "DRAIN" since it has the same effect on the server (it's removed from the LB farm). It is the legacy way to set the weight of a server. Setting it with the "weight:" prefix is preferred. - The string "weight:" following by an positive integer or a positive integer percentage, with no space. If the value ends with the '%' sign, then the new weight will be proportional to the initially weight of the server. Otherwise, the value is considered as an absolute weight and must be between 0 and 256. Servers which are part of a farm running a static load-balancing algorithm have stricter limitations because the weight cannot change once set. Thus for these servers, the only accepted values are 0 and 100% (or 0 and the initial weight). Changes take effect immediately, though certain LB algorithms require a certain amount of requests to consider changes. Note that a zero weight is reported on the stats page as "DRAIN" since it has the same effect on the server (it's removed from the LB farm). - The string "maxconn:" followed by an integer (no space between). Values in this format will set the maxconn of a server. The maximum number of connections advertised needs to be multiplied by the number of load balancers and different backends that use this health check to get the total number of connections the server might receive. Example: maxconn:30 - The word "ready". This will turn the server's administrative state to the READY mode, thus canceling any DRAIN or MAINT state - The word "drain". This will turn the server's administrative state to the DRAIN mode, thus it will not accept any new connections other than those that are accepted via persistence. - The word "maint". This will turn the server's administrative state to the MAINT mode, thus it will not accept any new connections at all, and health checks will be stopped. - The words "down", "fail", or "stopped", optionally followed by a description string after a sharp ('#'). All of these mark the server's operating state as DOWN, but since the word itself is reported on the stats page, the difference allows an administrator to know if the situation was expected or not : the service may intentionally be stopped, may appear up but fail some validity tests, or may be seen as down (e.g. missing process, or port not responding). - The word "up" sets back the server's operating state as UP if health checks also report that the service is accessible. Parameters which are not advertised by the agent are not changed. For example, an agent might be designed to monitor CPU usage and only report a relative weight and never interact with the operating status. Similarly, an agent could be designed as an end-user interface with 3 radio buttons allowing an administrator to change only the administrative state. However, it is important to consider that only the agent may revert its own actions, so if a server is set to DRAIN mode or to DOWN state using the agent, the agent must implement the other equivalent actions to bring the service into operations again. Failure to connect to the agent is not considered an error as connectivity is tested by the regular health check which is enabled by the "check" parameter. Warning though, it is not a good idea to stop an agent after it reports "down", since only an agent reporting "up" will be able to turn the server up again. Note that the CLI on the Unix stats socket is also able to force an agent's result in order to work around a bogus agent if needed. Requires the "agent-port" parameter to be set. See also the "agent-inter" and "no-agent-check" parameters.
May be used in the following contexts: tcp, http, log If this option is specified, HAProxy will send the given string (verbatim) to the agent server upon connection. You could, for example, encode the backend name into this string, which would enable your agent to send different responses based on the backend. Make sure to include a '\n' if you want to terminate your request with a newline.
May be used in the following contexts: tcp, http, log The "agent-inter" parameter sets the interval between two agent checks to <delay> milliseconds. If left unspecified, the delay defaults to 2000 ms. Just as with every other time-based parameter, it may be entered in any other explicit unit among { us, ms, s, m, h, d }. The "agent-inter" parameter also serves as a timeout for agent checks "timeout check" is not set. In order to reduce "resonance" effects when multiple servers are hosted on the same hardware, the agent and health checks of all servers are started with a small time offset between them. It is also possible to add some random noise in the agent and health checks interval using the global "spread-checks" keyword. This makes sense for instance when a lot of backends use the same servers. See also the "agent-check" and "agent-port" parameters.
May be used in the following contexts: tcp, http, log The "agent-addr" parameter sets address for agent check. You can offload agent-check to another target, so you can make single place managing status and weights of servers defined in HAProxy in case you can't make self-aware and self-managing services. You can specify both IP or hostname, it will be resolved.
May be used in the following contexts: tcp, http, log The "agent-port" parameter sets the TCP port used for agent checks. See also the "agent-check" and "agent-inter" parameters.
May be used in the following contexts: tcp, http, log, peers, ring Allow sending early data to the server when using TLS 1.3. Note that early data will be sent only if the client used early data, or if the backend uses "retry-on" with the "0rtt-rejected" keyword. With QUIC, 0rtt is supported with QuicTLS, OpenSSL >= 3.5.2 and AWS-LC. With TCP/TLS, 0rtt is only supported with OpenSSL.
May be used in the following contexts: tcp, http This enables the TLS ALPN extension and advertises the specified protocol list as supported on top of ALPN. The protocol list consists in a comma- delimited list of protocol names, for instance: "http/1.1,http/1.0" (without quotes). This requires that the SSL library is built with support for TLS extensions enabled (check with haproxy -vv). The ALPN extension replaces the initial NPN extension. ALPN is required to connect to HTTP/2 servers. It is also required to be able to use HTTP/3 via a QUIC server, "h3" serves as a default value for QUIC servers without "alpn" setting. Versions of OpenSSL prior to 1.0.2 didn't support ALPN and only supposed the now obsolete NPN extension. If both HTTP/2 and HTTP/1.1 are expected to be supported, both versions can be advertised, in order of preference, like below : server 127.0.0.1:443 ssl crt pub.pem alpn h2,http/1.1 See also "ws" to use an alternative ALPN for websocket streams.
May be used in the following contexts: tcp, http, log When "backup" is present on a server line, the server is only used in load balancing when all other non-backup servers are unavailable. Requests coming with a persistence cookie referencing the server will always be served though. By default, only the first operational backup server is used, unless the "allbackups" option is set in the backend. See also the "no-backup" and "allbackups" options.
May be used in the following contexts: tcp, http, log, peers, ring This setting is only available when support for OpenSSL was built in. It designates a PEM file from which to load CA certificates used to verify server's certificate. It is possible to load a directory containing multiple CAs, in this case HAProxy will try to load every ".pem", ".crt", ".cer", and .crl" available in the directory, files starting with a dot are ignored. In order to use the trusted CAs of your system, the "@system-ca" parameter could be used in place of the cafile. The location of this directory could be overwritten by setting the SSL_CERT_DIR environment variable.
May be used in the following contexts: tcp, http, log, peers, ring This setting is only available on systems which define TCP_CONGESTION, and was validated on Linux and FreeBSD. It takes the name of a TCP congestion control algorithm and configures outgoing connections to use this algorithm. Typical names include "reno" or "cubic" and will depend on the operating system. On some systems, special permissions may be required to configure certain algorithms. On Linux, available algorithms are listed in sysctl "net.ipv4.tcp_available_congestion_control", and those permitted without privileges are in "net.ipv4.tcp_allowed_congestion_control". In order to access algorithms requiring extra permissions, the "cap_net_admin" capability might be required (see "setcap" in the global section). In case of failure to configure a specific congestion control algorithm, the default one remains
May be used in the following contexts: tcp, http, log
This option enables health checks on a server:
- when not set, no health checking is performed, and the server is always
considered available.
- when set and no other check method is configured, the server is considered
available when a connection can be established at the highest configured
transport layer. This means TCP by default, or SSL/TLS when "ssl" or
"check-ssl" are set, both possibly combined with connection prefixes such
as a PROXY protocol header when "send-proxy" or "check-send-proxy" are
set. This behavior is slightly different for dynamic servers, read the
following paragraphs for more details.
- when set and an application-level health check is defined, the
application-level exchanges are performed on top of the configured
transport layer and the server is considered available if all of the
exchanges succeed.
By default, health checks are performed on the same address and port as
configured on the server, using the same encapsulation parameters (SSL/TLS,
proxy-protocol header, etc... ). It is possible to change the destination
address using "addr" and the port using "port". When done, it is assumed the
server isn't checked on the service port, and configured encapsulation
parameters are not reused. One must explicitly set "check-send-proxy" to send
connection headers, "check-ssl" to use SSL/TLS.
Note that the implicit configuration of ssl and PROXY protocol is not
performed for dynamic servers. In this case, it is required to explicitly
use "check-ssl" and "check-send-proxy" when wanted, even if the check port is
not overridden.
When "sni" or "alpn" are set on the server line, their value is not used for
health checks and one must use "check-sni" or "check-alpn".
The default source address for health check traffic is the same as the one
defined in the backend. It can be changed with the "source" keyword.
The interval between checks can be set using the "inter" keyword, and the
"rise" and "fall" keywords can be used to define how many successful or
failed health checks are required to flag a server available or not
available.
Optional application-level health checks can be configured with "option
httpchk", "option mysql-check" "option smtpchk", "option pgsql-check",
"option ldap-check", or "option redis-check".
# simple tcp check
backend foo
server s1 192.168.0.1:80 check
# this does a tcp connect + tls handshake
backend foo
server s1 192.168.0.1:443 ssl check
# simple tcp check is enough for check success
backend foo
option tcp-check
tcp-check connect
server s1 192.168.0.1:443 ssl check
May be used in the following contexts: tcp, http This option permits checks to reuse idle connections if available instead of opening a dedicated one. The connection is reinserted in the pool on check completion. The main objective is to limit the number of connections opening and closure on a specific server. This feature is compatible only with http-check rulesets. It is silently ignored for other check types. Furthermore, reuse policy should be set to aggressive on the backend as each check attempt is performed over a dedicated session. For configuration simplicity, this option is silently ignored if any specific check connect option is defined, either on the server line or via a custom tcp-check connect rule. This option is automatically enabled for servers acting as passive reverse HTTP gateway, as for those servers connect is only supported through reuse.
May be used in the following contexts: tcp, http This option forces emission of a PROXY protocol line with outgoing health checks, regardless of whether the server uses send-proxy or not for the normal traffic. By default, the PROXY protocol is enabled for health checks if it is already enabled for normal traffic and if no "port" nor "addr" directive is present. However, if such a directive is present, the "check-send-proxy" option needs to be used to force the use of the protocol. See also the "send-proxy" option for more information.
May be used in the following contexts: tcp, http Defines which protocols to advertise with ALPN. The protocol list consists in a comma-delimited list of protocol names, for instance: "http/1.1,http/1.0" (without quotes). If it is not set, the server ALPN is used.
May be used in the following contexts: tcp, http When connection reuse is performed for checks, uses <name> if set as a connection identifier to match a corresponding connection in the pool. This serves as the equivalent to the "pool-conn-name" server keyword. "check-sni" will also be used as a fallback if the current option is not used.
May be used in the following contexts: tcp, http Forces the multiplexer's protocol to use for the server's health-check connections. It must be compatible with the health-check type (TCP or HTTP). It must also be usable on the backend side. The list of available protocols is reported in haproxy -vv