Haproxy Configuration
haproxy
configuration manual
----------------------
version 1.6
willy tarreau
2015/07/22
this document covers the configuration language as implemented in the version
specified above. it does not provide any hint, example or advice. for such
documentation, please refer to the reference manual or the architecture manual.
the summary below is meant to help you search 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 outs) with 3
closing angle brackets (‘>>>’) in order to help get the difference between
inputs and outputs when it can become ambiguous. if you add sections,
please update the summary below for easier searching.
summary
1. quick reminder about http
1.1. the http transaction model
1.2. http request
1.2.1. the request line
1.2.2. the request headers
1.3. http response
1.3.1. the response line
1.3.2. the response headers
2. configuring haproxy
2.1. configuration file format
2.2. quoting and escaping
2.3. environment variables
2.4. time format
2.5. examples
3. global parameters
3.1. process management and security
3.2. performance tuning
3.3. debugging
3.4. userlists
3.5. peers
4. proxies
4.1. proxy keywords matrix
4.2. alphabetically sorted keywords reference
5. bind and server options
5.1. bind options
5.2. server and default-server options
5.3. server dns resolution
5.3.1. global overview
5.3.2. the resolvers section
6. http header manipulation
7. using acls and fetching samples
7.1. acl basics
7.1.1. matching booleans
7.1.2. matching integers
7.1.3. matching strings
7.1.4. matching regular expressions (regexes)
7.1.5. matching arbitrary data blocks
7.1.6. matching ipv4 and ipv6 addresses
7.2. using acls to form conditions
7.3. fetching samples
7.3.1. converters
7.3.2. fetching samples from internal states
7.3.3. fetching samples at layer 4
7.3.4. fetching samples at layer 5
7.3.5. fetching samples from buffer contents (layer 6)
7.3.6. fetching http samples (layer 7)
7.4. pre-defined acls
8. logging
8.1. log levels
8.2. log formats
8.2.1. default log format
8.2.2. tcp log format
8.2.3. http log format
8.2.4. custom log format
8.2.5. error log format
8.3. advanced logging options
8.3.1. disabling logging of external tests
8.3.2. logging before waiting for the session to terminate
8.3.3. raising log level upon errors
8.3.4. disabling logging of successful connections
8.4. timing events
8.5. session state at disconnection
8.6. non-printable characters
8.7. capturing http cookies
8.8. capturing http headers
8.9. examples of logs
9. statistics and monitoring
9.1. csv format
9.2. unix socket commands
1. quick reminder about http
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.
1.1. the http transaction model
the http protocol is transaction-driven. this means that each request will lead
to one and only one response. traditionally, a tcp connection is established
from the client to the server, a request is sent by the client on the
connection, the server responds and the connection is closed. a new request
will involve a new connection :
[con1] [req1] … [resp1] [clo1] [con2] [req2] … [resp2] [clo2] …
in this mode, 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.
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 :
[con] [req1] … [resp1] [req2] … [resp2] [clo] …
its advantages are a reduced latency between transactions, and less processing
power required on the server side. it is generally better than the close mode,
but not always because the clients often limit their concurrent connections to
a smaller value.
a last 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.
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.
haproxy supports 5 connection modes :
- keep alive : all requests and responses are processed (default)
- tunnel : only the first request and response are processed,
everything else is forwarded with no analysis.
- passive close : tunnel with “connection: close” added in both directions.
- server close : the server-facing connection is closed after the response.
- forced close : the connection is actively closed after end of response.
1.2. http request
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
1.2.1. the request line
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.
1.2.2. the request headers
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.2, lines 4 and 5
define a total of 3 values for the “accept:” header.
contrary to a common mis-conception, header names are not case-sensitive, and
their values are not either if they refer to other header names (such as the
“connection:” header).
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 rfc2616, 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.
1.3. http response
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 are http/1.1 only). 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.
1.3.1. the response line
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 (eg: 100, 101)
- 2xx = ok, content is following (eg: 200, 206)
- 3xx = ok, no content following (eg: 302, 304)
- 4xx = error caused by the client (eg: 401, 403, 404)
- 5xx = error caused by the server (eg: 500, 502, 503)
please refer to rfc2616 for the detailed meaning of all such codes. 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”.
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 “block” acl or “reqdeny” filter
408 when the request timeout strikes before the request is complete
500 when haproxy encounters an unrecoverable internal error, such as a
memory allocation failure, which should never happen
502 when the server returns an empty, invalid or incomplete response, or
when an “rspdeny” filter 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).
1.3.2. the response headers
response headers work exactly like request headers, and as such, haproxy uses
the same parsing function for both. please refer to paragraph 1.2.2 for more
details.
2. configuring haproxy
2.1. configuration file format
haproxy’s configuration process involves 3 major sources of parameters :
- the arguments from the command-line, which always take precedence
- the “global” section, which sets process-wide parameters
- the proxies sections which can take form of “defaults”, “listen”,
“frontend” and “backend”.
the configuration file syntax consists in lines beginning with a keyword
referenced in this manual, optionally followed by one or several parameters
delimited by spaces.
2.2. quoting and escaping
haproxy’s configuration introduces a quoting and escaping system similar to
many programming languages. the configuration file supports 3 types: escaping
with a backslash, weak quoting with double quotes, and strong quoting with
single quotes.
if spaces have to be entered in strings, then they must be escaped by preceding
them by a backslash (‘') or by quoting them. backslashes also have to be
escaped by doubling or strong quoting them.
escaping 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
weak quoting is achieved by using double quotes (“”). weak quoting prevents
the interpretation of:
space as a parameter separator
‘ single quote as a strong quoting delimiter
hash as a comment start
weak quoting permits the interpretation of variables, if you want to use a non
-interpreted dollar within a double quoted string, you should escape it with a
backslash (“$“), it does not work outside weak quoting.
interpretation of escaping and special characters are not prevented by weak
quoting.
strong quoting is achieved by using single quotes (‘’). inside single quotes,
nothing is interpreted, it’s the efficient way to quote regexes.
quoted and escaped strings are replaced in memory by their interpreted
equivalent, it allows you to perform concatenation.
example:
# those are equivalents:
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
# those are equivalents:
reqrep "^([^\ :]*)\ /static/(.*)" \1\ /\2
reqrep "^([^ :]*)\ /static/(.*)" '\1 /\2'
reqrep "^([^ :]*)\ /static/(.*)" "\1 /\2"
reqrep "^([^ :]*)\ /static/(.*)" "\1\ /\2"
2.3. environment variables
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.
example:
bind "fd@${fd_app1}"
log "${local_syslog}:514" local0 notice # send to local server
user "$haproxy_user"
2.4. time format
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
2.4. examples
# 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
3. global parameters
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
- ca-base
- chroot
- crt-base
- daemon
- external-check
- gid
- group
- log
- log-send-hostname
- nbproc
- pidfile
- uid
- ulimit-n
- user
- stats
- ssl-server-verify
- node
- description
- unix-bind
- 51degrees-data-file
- 51degrees-property-name-list
- 51degrees-property-separator
- 51degrees-cache-size
performance tuning
- max-spread-checks
- maxconn
- maxconnrate
- maxcomprate
- maxcompcpuusage
- maxpipes
- maxsessrate
- maxsslconn
- maxsslrate
- noepoll
- nokqueue
- nopoll
- nosplice
- nogetaddrinfo
- spread-checks
- tune.bufsize
- tune.chksize
- tune.comp.maxlevel
- tune.http.cookielen
- tune.http.maxhdr
- tune.idletimer
- tune.lua.forced-yield
- tune.lua.maxmem
- tune.lua.session-timeout
- tune.lua.task-timeout
- tune.maxaccept
- tune.maxpollevents
- tune.maxrewrite
- tune.pattern.cache-size
- tune.pipesize
- tune.rcvbuf.client
- tune.rcvbuf.server
- tune.sndbuf.client
- tune.sndbuf.server
- tune.ssl.cachesize
- tune.ssl.lifetime
- tune.ssl.force-private-cache
- tune.ssl.maxrecord
- tune.ssl.default-dh-param
- tune.ssl.ssl-ctx-cache-size
- tune.vars.global-max-size
- tune.vars.reqres-max-size
- tune.vars.sess-max-size
- tune.vars.txn-max-size
- tune.zlib.memlevel
- tune.zlib.windowsize
debugging
- debug
- quiet
3.1. process management and security
ca-base
assigns a default directory to fetch ssl ca certificates and crls from when a
relative path is used with “ca-file” or “crl-file” directives. absolute
locations specified in “ca-file” and “crl-file” prevail and ignore “ca-base”.
chroot
changes current directory to
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. this only works when the process is started
with superuser privileges. it is important to ensure that
empty and unwritable to anyone.
cpu-map <”all”|”odd”|”even”|process_num>
on linux 2.6 and above, it is possible to bind a process to a specific cpu
set. this means that the process will never run on other cpus. the “cpu-map”
directive specifies cpu sets for process sets. the first argument is the
process number to bind. this process must have a number between 1 and 32 or
64, depending on the machine’s word size, and any process ids above nbproc
are ignored. it is possible to specify all processes at once using “all”,
only odd numbers using “odd” or even numbers using “even”, just like with the
“bind-process” directive. the second and forthcoming arguments are cpu sets.
each cpu set is either a unique number between 0 and 31 or 63 or a range with
two such numbers delimited by a dash (‘-‘). multiple cpu numbers or ranges
may be specified, and the processes will be allowed to bind to all of them.
obviously, multiple “cpu-map” directives may be specified. each “cpu-map”
directive will replace the previous ones when they overlap.
crt-base
assigns a default directory to fetch ssl certificates from when a relative
path is used with “crtfile” directives. absolute locations specified after
“crtfile” prevail and ignore “crt-base”.
daemon
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.
deviceatlas-json-file
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.
deviceatlas-log-level
sets the level of informations returned by the api. this directive is
optional and set to 0 by default if not set.
deviceatlas-separator
sets the character separator for the api properties results. this directive
is optional and set to | by default if not set.
external-check
allows the use of an external agent to perform health checks.
this is disabled by default as a security precaution.
see “option external-check”.
gid
changes the process’ group id to
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”.
group
similar to “gid” but uses the gid of group name
see also “gid” and “user”.
log
[lenadds a global syslog server. up to two global servers can be defined. they
will receive logs for startups and exits, as well as all logs from proxies
configured with “log global”. 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
writeable).
you may want to reference some environment variables in the address
parameter, see section 2.3 about environment variables.
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-formated logs may require larger values.
kern user mail daemon auth syslog lpr news
uucp cron auth2 ftp ntp audit alert cron2
local0 local1 local2 local3 local4 local5 local6 local7
an optional level can be specified to filter outgoing messages. by default,
all messages are sent. if a maximum 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
log-send-hostname [
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.
log-tag
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.
lua-load
this global directive loads and executes a lua file. this directive can be
used multiple times.
nbproc
creates
mode. by default, only one process is created, which is the recommended mode
of operation. for systems limited to small sets of file descriptors per
process, it may be needed to fork multiple daemons. using multiple processes
is harder to debug and is really discouraged. see also “daemon”.
pidfile
writes pids of all daemons into file
the “-p” command line argument. the file must be accessible to the user
starting the process. see also “daemon”.
stats bind-process [ all | odd | even | <number 1-64>[-<number 1-64>] ] …
limits the stats socket to a certain set of processes numbers. by default the
stats socket is bound to all processes, causing a warning to be emitted when
nbproc is greater than 1 because there is no way to select the target process
when connecting. however, by using this setting, it becomes possible to pin
the stats socket to a specific set of processes, typically the first one. the
warning will automatically be disabled when this setting is used, whatever
the number of processes used. the maximum process id depends on the machine’s
word size (32 or 64). a better option consists in using the “process” setting
of the “stats socket” line to force the process on each line.
ssl-default-bind-ciphers
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 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, and can be for instance a string such
as “aes:all:!anull:!enull:+rc4:@strength” (without quotes). please check the
“bind” keyword for more information.
ssl-default-bind-options [
example:
global
ssl-default-bind-options no-sslv3 no-tls-tickets
ssl-default-server-ciphers
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 with the server, for all “server”
lines which do not explicitly define theirs. the format of the string is
defined in “man 1 ciphers”. please check the “server” keyword for more
information.
ssl-default-server-options [
ssl-dh-param-file
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 explicitely 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, pre-generated dh parameters of the size specified
by tune.ssl.default-dh-param 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
parameters should not be considered secure anymore.
ssl-server-verify [none|required]
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’.
stats socket [address:port|
binds a unix socket to
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.2 “unix socket commands” 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.
stats timeout <timeout, in milliseconds>
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 }.
stats maxconn
by default, the stats socket is limited to 10 concurrent connections. it is
possible to change this value with “stats maxconn”.
uid
changes the process’ user id to
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”.
ulimit-n
sets the maximum number of per-process file-descriptors to
default, it is automatically computed, so it is recommended not to use this
option.
unix-bind [ prefix
[ group
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
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
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.
user
similar to “uid” but uses the uid of user name
see also “uid” and “group”.
node
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.
description
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.
51degrees-data-file
the path of the 51degrees data file to provide device detection services. the
file should be unzipped and accessible by haproxy with relevavnt permissions.
please note that this option is only available when haproxy has been
compiled with use_51degrees.
51degrees-property-name-list [
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.
51degrees-property-separator
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.
51degrees-cache-size
sets the size of the 51degrees converter cache to
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.
3.2. performance tuning
max-spread-checks
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.
maxconn
sets the maximum per-process number of concurrent connections to
is equivalent to the command-line argument “-n”. proxies will stop accepting
connections when this limit is reached. the “ulimit-n” parameter is
automatically adjusted according to this value. 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 maxconn until it works (slightly
below 500 in general). if this value is not set, it will default to the value
set in default_maxconn at build time (reported in haproxy -vv) if no memory
limit is enforced, or will be computed based on the memory limit, the buffer
size, memory allocated to compression, ssl cache size, and use or not of ssl
and the associated maxsslconn (which can also be automatic).
maxconnrate
sets the maximum per-process number of connections per second to
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.
maxcomprate
sets the maximum per-process input compression rate to
per second. for each session, if the maximum is reached, the compression
level will be decreased during the session. if the maximum is reached at the
beginning of a session, the session 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.
maxcompcpuusage
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. in
case of multiple processes (nbproc > 1), each process manages its individual
usage. 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.
maxpipes
sets the maximum per-process number of pipes to
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.
maxsessrate
sets the maximum per-process number of sessions per second to
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.
maxsslconn
sets the maximum per-process number of concurrent ssl connections to
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).
maxsslrate
sets the maximum per-process number of ssl sessions per second to
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.
maxzlibmem
sets the maximum amount of ram in megabytes per process usable by the zlib.
when the maximum amount is reached, future sessions 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.
noepoll
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”.
nokqueue
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”.
nopoll
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” and “noepoll”.
nosplice
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”.
nogetaddrinfo
disables the use of getaddrinfo(3) for name resolving. it is equivalent to
the command line argument “-dg”. deprecated gethostbyname(3) will be used.
spread-checks <0..50, in percent>
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.
tune.buffers.limit
sets a hard limit on the number of buffers which may be allocated per process.
the default value is zero which means unlimited. the minimum non-zero value
will always be greater than “tune.buffers.reserve” and should ideally always
be about twice as large. forcing this value can be particularly useful to
limit the amount of memory a process may take, while retaining a sane
behaviour. when this limit is reached, sessions which need a buffer wait for
another one to be released by another session. since buffers are dynamically
allocated and released, the waiting time is very short and not perceptible
provided that limits remain reasonable. in fact sometimes reducing the limit
may even increase performance by increasing the cpu cache’s efficiency. tests
have shown good results on average http traffic with a limit to 1/10 of the
expected global maxconn setting, which also significantly reduces memory
usage. the memory savings come from the fact that a number of connections
will not allocate 2*tune.bufsize. it is best not to touch this value unless
advised to do so by an haproxy core developer.
tune.buffers.reserve
sets the number of buffers which are pre-allocated and reserved for use only
during memory shortage conditions resulting in failed memory allocations. the
minimum value is 2 and is also the default. there is no reason a user would
want to change this value, it’s mostly aimed at haproxy core developers.
tune.bufsize
sets the buffer size to this size (in bytes). lower values allow more
sessions 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.
if 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).
tune.chksize
sets the check buffer size to this size (in bytes). higher values may help
find string or regex patterns in very large pages, though doing so may imply
more memory and cpu usage. the default value is 16384 and can be changed at
build time. it is not recommended to change this value, but to use better
checks whenever possible.
tune.comp.maxlevel
sets the maximum compression level. the compression level affects cpu
usage during compression. this value affects cpu usage during compression.
each session using compression initializes the compression algorithm with
this value. the default value is 1.
tune.http.cookielen
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.
tune.http.maxhdr
sets the maximum number of headers in a request. when a request comes with a
number of headers greater than this value (including the first line), it is
rejected with a “400 bad request” status code. similarly, too large responses
are blocked with “502 bad gateway”. 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. keep in mind that each
new header consumes 32bits of memory for each session, so don’t push this
limit too high.
tune.idletimer
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 (eg: read a page before
clicking). there should be not reason for changing this value. please check
tune.ssl.maxrecord below.
tune.lua.forced-yield
this directive forces the lua engine to execute a yield each
instructions executed. this permits interruptng a long script and allows the
haproxy scheduler to process other tasks like accepting connections or
forwarding traffic. the default value is 10000 instructions. if haproxy often
executes some lua code but more reactivity 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
tune.lua.maxmem
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.
tune.lua.session-timeout
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 has a
priority over other timeouts. for example, if this timeout is set to 4s and
you run a 5s sleep, the code will be interrupted with an error after waiting
4s.
tune.lua.task-timeout
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.
tune.maxaccept
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
give better performance at high connection rates. however in multi-process
modes, keeping a bit of fairness between processes generally is better to
increase performance. 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 64. 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.
tune.maxpollevents
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.
tune.maxrewrite
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.
tune.pattern.cache-size
sets the size of the pattern lookup cache to
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 on 32-bit systems and 8 mb on 64-bit systems. 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.
tune.pipesize
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.
tune.rcvbuf.client
tune.rcvbuf.server
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 autotune this value depending on the amount of available memory.
however it can sometimes help to set it to very low values (eg: 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.
tune.sndbuf.client
tune.sndbuf.server
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 autotune this value depending on the amount of available memory.
however it can sometimes help to set it to very low values (eg: 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.
tune.ssl.cachesize
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. 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
and are shared between all processes if “nbproc” is greater than 1. setting
this value to 0 disables the ssl session cache.
tune.ssl.force-private-cache
this boolean 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.
tune.ssl.lifetime
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.
tune.ssl.maxrecord
sets the maximum amount of bytes passed to ssl_write() at a time. 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).
tune.ssl.default-dh-param
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. default value if 1024. 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.
tune.ssl.ssl-ctx-cache-size
sets the size of the cache used to store generated certificates to
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.
tune.vars.global-max-size
tune.vars.reqres-max-size
tune.vars.sess-max-size
tune.vars.txn-max-size
these four tunes helps to manage the allowed amount of memory used by the
variables system. “global” limits the memory for all the systems. “sess” limit
the memory by session, “txn” limits the memory by transaction and “reqres”
limits the memory for each request or response processing. during the
accounting, “sess” embbed “txn” and “txn” embed “reqres”.
by example, we considers that “tune.vars.sess-max-size” is fixed to 100,
“tune.vars.txn-max-size” is fixed to 100, “tune.vars.reqres-max-size” is
also fixed to 100. if we create a variable “txn.var” that contains 100 bytes,
we cannot create any more variable in the other contexts.
tune.zlib.memlevel
sets the memlevel parameter in zlib initialization for each session. 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.
tune.zlib.windowsize
sets the window size (the size of the history buffer) as a parameter of the
zlib initialization for each session. 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.
3.3. debugging
debug
enables debug mode which dumps to stdout all exchanges, and disables forking
into background. it is the equivalent of the command-line argument “-d”. it
should never be used in a production configuration since it may prevent full
system startup.
quiet
do not display any message during startup. it is equivalent to the command-
line argument “-q”.
3.4. userlists
it is possible to control access to frontend/backend/listen sections or to
http stats by allowing only authenticated and authorized users. to do this,
it is required to create at least one userlist and to define users.
userlist
creates new userlist with name
used to store authentication & authorization data for independent customers.
group
adds group
attach users to this group by using a comma separated list of names
proceeded by “users” keyword.
user
[groups
adds user
insecure (unencrypted) passwords can be used. encrypted passwords are
evaluated using the crypt(3) function so depending of the system’s
capabilities, different algorithms are supported. for example modern glibc
based linux system supports md5, sha-256, sha-512 and of course classic,
des-based method of encrypting passwords.
example:
userlist l1
group g1 users tiger,scott
group g2 users xdb,scott
user tiger password $6$k6y3o.ep$jlkbx9za9667qe4(...)xhswrv6j.c0/d7cv91
user scott insecure-password elgato
user xdb insecure-password hello
userlist l2
group g1
group g2
user tiger password $6$k6y3o.ep$jlkbx(...)xhswrv6j.c0/d7cv91 groups g1
user scott insecure-password elgato groups g1,g2
user xdb insecure-password hello groups g2
please note that both lists are functionally identical.
3.5. peers
it is possible to propagate entries of any data-types in stick-tables between
several haproxy instances over tcp connections in a multi-master fashion. each
instance pushes its local updates and insertions to remote peers. the pushed
values overwrite remote ones without aggregation. interrupted exchanges are
automatically detected and recovered from the last known point.
in addition, during a soft restart, the old process connects to the new one
using such a tcp connection to push all its entries before the new process
tries to connect to other peers. that ensures very fast replication during a
reload, it typically takes a fraction of a second even for large tables.
note that server ids are used to identify servers remotely, so it is important
that configurations look similar or at least that the same ids are forced on
each server on all participants.
peers
creates a new peer list with name
which is referenced by one or more stick-tables.
disabled
disables a peers section. it disables both listening and any synchronization
related to this section. this is provided to disable synchronization of stick
tables without having to comment out all “peers” references.
enable
this re-enables a disabled peers section which was previously disabled.
peer
defines a peer inside a peers section.
if
using “-l” command line option), haproxy will listen for incoming remote peer
connection on
to join the remote peer, and
identify and validate the remote peer on the server side.
during a soft restart, local peer
connect the new one and initiate a complete replication (teaching process).
it is strongly recommended to have the exact same peers declaration on all
peers and to only rely on the “-l” command line argument to change the local
peer name. this makes it easier to maintain coherent configuration files
across all peers.
you may want to reference some environment variables in the address
parameter, see section 2.3 about environment variables.
example:
peers mypeers
peer haproxy1 192.168.0.1:1024
peer haproxy2 192.168.0.2:1024
peer haproxy3 10.2.0.1:1024
backend mybackend
mode tcp
balance roundrobin
stick-table type ip size 20k peers mypeers
stick on src
server srv1 192.168.0.30:80
server srv2 192.168.0.31:80
3.6. mailers
it is possible to send email alerts when the state of servers changes.
if configured email alerts are sent to each mailer that is configured
in a mailers section. email is sent to mailers using smtp.
mailer
creates a new mailer list with the name
independent section which is referenced by one or more proxies.
mailer
defines a mailer inside a mailers section.
example:
mailers mymailers
mailer smtp1 192.168.0.1:587
mailer smtp2 192.168.0.2:587
backend mybackend
mode tcp
balance roundrobin
email-alert mailers mymailers
email-alert from test1@horms.org
email-alert to test2@horms.org
server srv1 192.168.0.30:80
server srv2 192.168.0.31:80
4. proxies
proxy configuration can be located in a set of sections :
- defaults [
] - frontend
- backend
- listen
a “defaults” section sets default parameters for all other sections following
its declaration. those default parameters are reset by the next “defaults”
section. see below for the list of parameters which can be set in a “defaults”
section. the name is optional but its use is encouraged for better readability.
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.
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, it just caused troubles in the
logs. since the introduction of content switching, it is mandatory that two
proxies with overlapping capabilities (frontend/backend) have different names.
however, it is still permitted that a frontend and a backend share the same
name, as this configuration seems to be commonly encountered.
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 5 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.tun: tunnel (“option http-tunnel”) : this was the default mode for versions
1.0 to 1.5-dev21 : only the first request and response are processed, and
everything else is forwarded with no analysis at all. this mode should not
be used as it creates lots of trouble with logging and http processing.pcl: passive close (“option httpclose”) : exactly the same as tunnel mode,
but with “connection: close” appended in both directions to try to make
both ends close after the first request/response exchange.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.fcl: forced close (“option forceclose”) : the connection is actively closed
after the end of the response.
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 force close is the strongest.
backend mode
| kal | tun | pcl | scl | fcl
----+-----+-----+-----+-----+----
kal | kal | tun | pcl | scl | fcl
----+-----+-----+-----+-----+----
tun | tun | tun | pcl | scl | fcl
frontend —-+—–+—–+—–+—–+—-
mode pcl | pcl | pcl | pcl | fcl | fcl
—-+—–+—–+—–+—–+—-
scl | scl | scl | fcl | scl | fcl
—-+—–+—–+—–+—–+—-
fcl | fcl | fcl | fcl | fcl | fcl
4.1. proxy keywords matrix
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, eg. “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.
keyword defaults frontend listen backend
————————————+———-+———-+———+———
acl - x x x
appsession - - x x
backlog x x x -
balance x - x x
bind - x x -
bind-process x x x x
block - x x x
capture cookie - x x -
capture request header - x x -
capture response header - x x -
clitimeout (deprecated) x x x -
compression x x x x
contimeout (deprecated) x - x x
cookie x - x x
declare capture - x x -
default-server x - x x
default_backend x x x -
description - x x x
disabled x x x x
dispatch - - x x
email-alert from x x x x
email-alert level x x x x
email-alert mailers x x x x
email-alert myhostname x x x x
email-alert to x x x x
enabled x x x x
errorfile x x x x
errorloc x x x x
errorloc302 x x x x
– keyword ————————– defaults - frontend - listen – backend -
errorloc303 x x x x
force-persist - x x x
fullconn x - x x
grace x x x x
hash-type x - x x
http-check disable-on-404 x - x x
http-check expect - - x x
http-check send-state x - x x
http-request - x x x
http-response - x x x
http-send-name-header - - x x
id - x x x
ignore-persist - x x x
log () x x x x
log-format x x x -
log-tag x x x x
max-keep-alive-queue x - x x
maxconn x x x -
mode x x x x
monitor fail - x x -
monitor-net x x x -
monitor-uri x x x -
option abortonclose () x - x x
option accept-invalid-http-request () x x x -
option accept-invalid-http-response () x - x x
option allbackups () x - x x
option checkcache () x - x x
option clitcpka () x x x -
option contstats () x x x -
option dontlog-normal () x x x -
option dontlognull () x x x -
option forceclose () x x x x
– keyword ————————– defaults - frontend - listen – backend -
option forwardfor x x x x
option http-buffer-request () x x x x
option http-ignore-probes () x x x -
option http-keep-alive () x x x x
option http-no-delay () x x x x
option http-pretend-keepalive () x x x x
option http-server-close () x x x x
option http-tunnel () x x x x
option http-use-proxy-header () x x x -
option httpchk x - x x
option httpclose () x x x x
option httplog x x x x
option http_proxy () x x x x
option independent-streams () x x x x
option ldap-check x - x x
option external-check x - x x
option log-health-checks () x - x x
option log-separate-errors () x x x -
option logasap () x x x -
option mysql-check x - x x
option pgsql-check x - x x
option nolinger () x x x x
option originalto x x x x
option persist () x - x x
option redispatch () x - x x
option redis-check x - x x
option smtpchk x - x x
option socket-stats () x x x -
option splice-auto () x x x x
option splice-request () x x x x
option splice-response () x x x x
option srvtcpka () x - x x
option ssl-hello-chk x - x x
– keyword ————————– defaults - frontend - listen – backend -
option tcp-check x - x x
option tcp-smart-accept () x x x -
option tcp-smart-connect () x - x x
option tcpka x x x x
option tcplog x x x x
option transparent () x - x x
external-check command x - x x
external-check path x - x x
persist rdp-cookie x - x x
rate-limit sessions x x x -
redirect - x x x
redisp (deprecated) x - x x
redispatch (deprecated) x - x x
reqadd - x x x
reqallow - x x x
reqdel - x x x
reqdeny - x x x
reqiallow - x x x
reqidel - x x x
reqideny - x x x
reqipass - x x x
reqirep - x x x
reqitarpit - x x x
reqpass - x x x
reqrep - x x x
– keyword ————————– defaults - frontend - listen – backend -
reqtarpit - x x x
retries x - x x
rspadd - x x x
rspdel - x x x
rspdeny - x x x
rspidel - x x x
rspideny - x x x
rspirep - x x x
rsprep - x x x
server - - x x
source x - x x
srvtimeout (deprecated) x - x x
stats admin - - x x
stats auth x - x x
stats enable x - x x
stats hide-version x - x x
stats http-request - - x x
stats realm x - x x
stats refresh x - x x
stats scope x - x x
stats show-desc x - x x
stats show-legends x - x x
stats show-node x - x x
stats uri x - x x
– keyword ————————– defaults - frontend - listen – backend -
stick match - - x x
stick on - - x x
stick store-request - - x x
stick store-response - - x x
stick-table - - x x
tcp-check connect - - x x
tcp-check expect - - x x
tcp-check send - - x x
tcp-check send-binary - - x x
tcp-request connection - x x -
tcp-request content - x x x
tcp-request inspect-delay - x x x
tcp-response content - - x x
tcp-response inspect-delay - - x x
timeout check x - x x
timeout client x x x -
timeout client-fin x x x -
timeout clitimeout (deprecated) x x x -
timeout connect x - x x
timeout contimeout (deprecated) x - x x
timeout http-keep-alive x x x x
timeout http-request x x x x
timeout queue x - x x
timeout server x - x x
timeout server-fin x - x x
timeout srvtimeout (deprecated) x - x x
timeout tarpit x x x x
timeout tunnel x - x x
transparent (deprecated) x - x x
unique-id-format x x x -
unique-id-header x x x -
use_backend - x x -
use-server - - x x
————————————+———-+———-+———+———
keyword defaults frontend listen backend
4.2. alphabetically sorted keywords reference
this section provides a description of each keyword and its usage.
acl
declare or complete an access list.
may be used in sections : defaults | frontend | listen | backend
no | yes | yes | yes
example:
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.
appsession
[request-learn] [prefix] [mode <path-parameters|query-string>]
define session stickiness on an existing application cookie.
may be used in sections : defaults | frontend | listen | backend
no | no | yes | yes
arguments :
haproxy will have to learn for each new session.
<length> this is the max number of characters that will be memorized and
checked in each cookie value.
<holdtime> this is the time after which the cookie will be removed from
memory if unused. if no unit is specified, this time is in
milliseconds.
request-learn
if this option is specified, then haproxy will be able to learn
the cookie found in the request in case the server does not
specify any in response. this is typically what happens with
phpsessid cookies, or when haproxy's session expires before
the application's session and the correct server is selected.
it is recommended to specify this option to improve reliability.
prefix when this option is specified, haproxy will match on the cookie
prefix (or url parameter prefix). the appsession value is the
data following this prefix.
example :
appsession aspsessionid len 64 timeout 3h prefix
this will match the cookie aspsessionidxxxx=xxxxx,
the appsession value will be xxxx=xxxxx.
mode this option allows to change the url parser mode.
2 modes are currently supported :
- path-parameters :
the parser looks for the appsession in the path parameters
part (each parameter is separated by a semi-colon), which is
convenient for jsessionid for example.
this is the default mode if the option is not set.
- query-string :
in this mode, the parser will look for the appsession in the
query string.
when an application cookie is defined in a backend, haproxy will check when
the server sets such a cookie, and will store its value in a table, and
associate it with the server’s identifier. up to
the value will be retained. on each connection, haproxy will look for this
cookie both in the “cookie:” headers, and as a url parameter (depending on
the mode used). if a known value is found, the client will be directed to the
server associated with this value. otherwise, the load balancing algorithm is
applied. cookies are automatically removed from memory when they have been
unused for a duration longer than
the definition of an application cookie is limited to one per backend.
note : consider not using this feature in multi-process mode (nbproc > 1)
unless you know what you do : memory is not shared between the
processes, which can result in random behaviours.
example :
appsession jsessionid len 52 timeout 3h
see also : “cookie”, “capture cookie”, “balance”, “stick”, “stick-table”,
“ignore-persist”, “nbproc” and “bind-process”.
backlog
give hints to the system about the approximate listen backlog desired size
may be used in sections : defaults | frontend | listen | backend
yes | yes | yes | no
arguments :
system, it may represent the number of already acknowledged
connections, of non-acknowledged ones, or both.
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).
see also : “maxconn” and the target operating system’s tuning guide.
balance
balance url_param [check_post]
define the load balancing algorithm to be used in a backend.
may be used in sections : defaults | frontend | listen | backend
yes | no | yes | yes
arguments :
balancing. this only applies when no persistence information
is available, or when a connection is redispatched to another
server.
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.
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%).
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.
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.
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".
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.
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".
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".
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 rdp_cookie pattern fetch function.
<arguments> is an optional list of arguments which may be needed by some
algorithms. right now, only "url_param" and "uri" support an
optional argument.
the load balancing algorithm of a backend is set to roundrobin when no other
algorithm, mode nor option have been set. the algorithm may only be set once
for each backend.
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
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 reqideny 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 (rfc2616 3.6.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.
see also : “dispatch”, “cookie”, “appsession”, “transparent”, “hash-type” and
“http_proxy”.
bind [
]:bind /
define one or several listening addresses and/or ports in a frontend.
may be used in sections : defaults | frontend | listen | backend
no | yes | yes | no
arguments :
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 ‘::’.
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).
note: since abstract sockets are not “rebindable”, they
do not cope well with multi-process mode during
soft-restart, so it is better to avoid them if
nbproc is greater than 1. the effect is that if the
new process fails to start, only one of the old ones
will be able to rebind to the socket.
- ‘fd@
parent. the fd must be bound and may or may not already
be listening.
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.
example :
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}"
see also : “source”, “option forwardfor”, “unix-bind” and the proxy protocol
documentation, and section 5 about bind options.
bind-process [ all | odd | even | <number 1-64>[-<number 1-64>] ] …
limit visibility of an instance to a certain set of processes numbers.
may be used in sections : defaults | frontend | listen | backend
yes | yes | yes | yes
arguments :
all all process will see this instance. this is the default. it
may be used to override a default value.
odd this instance will be enabled on processes 1,3,5,...63\. this
option may be combined with other numbers.
even this instance will be enabled on processes 2,4,6,...64\. this
option may be combined with other numbers. do not use it
with less than 2 processes otherwise some instances might be
missing from all processes.
number the instance will be enabled on this process number or range,
whose values must all be between 1 and 32 or 64 depending on
the machine's word size. if a proxy is bound to process
numbers greater than the configured global.nbproc, it will
either be forced to process #1 if a single process was
specified, or to all processes otherwise.
this keyword limits binding of certain instances to certain processes. this
is useful in order not to have too many processes listening to the same
ports. for instance, on a dual-core machine, it might make sense to set
‘nbproc 2’ in the global section, then distributes the listeners among ‘odd’
and ‘even’ instances.
at the moment, it is not possible to reference more than 32 or 64 processes
using this keyword, but this should be more than enough for most setups.
please note that ‘all’ really means all processes regardless of the machine’s
word size, and is not limited to the first 32 or 64.
each “bind” line may further be limited to a subset of the proxy’s processes,
please consult the “process” bind keyword in section 5.1.
when a frontend has no explicit “bind-process” line, it tries to bind to all
the processes referenced by its “bind” lines. that means that frontends can
easily adapt to their listeners’ processes.
if some backends are referenced by frontends bound to other processes, the
backend automatically inherits the frontend’s processes.
example :
listen app_ip1
bind 10.0.0.1:80
bind-process odd
listen app_ip2
bind 10.0.0.2:80
bind-process even
listen management
bind 10.0.0.3:80
bind-process 1 2 3 4
listen management
bind 10.0.0.4:80
bind-process 1-4
see also : “nbproc” in global section, and “process” in section 5.1.
block { if | unless }
block a layer 7 request if/unless a condition is matched
may be used in sections : defaults | frontend | listen | backend
no | yes | yes | yes
the http request will be blocked very early in the layer 7 processing
if/unless
is blocked. the condition has to reference acls (see section 7). this is
typically used to deny access to certain sensitive resources if some
conditions are met or not met. there is no fixed limit to the number of
“block” statements per instance.
example:
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
block if invalid_src || local_dst
see section 7 about acl usage.
capture cookie
capture and log a cookie in the request and in the response.
may be used in sections : defaults | frontend | listen | backend
no | yes | yes | no
arguments :
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 (eg: aspsessionxxxxx).
<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.
example:
capture cookie aspsession len 32
see also : “capture request header”, “capture response header” as well as
section 8 about logging.
capture request header
capture and log the last occurrence of the specified request header.
may be used in sections : defaults | frontend | listen | backend
no | yes | yes | no
arguments :
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 session.
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.
example:
capture request header host len 15
capture request header x-forwarded-for len 15
capture request header referrer len 15
see also : “capture cookie”, “capture response header” as well as section 8
about logging.
capture response header
capture and log the last occurrence of the specified response header.
may be used in sections : defaults | frontend | listen | backend
no | yes | yes | no
arguments :
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 session.
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.
example:
capture response header content-length len 9
capture response header location len 15
see also : “capture cookie”, “capture request header” as well as section 8
about logging.
clitimeout
set the maximum inactivity time on the client side.
may be used in sections : defaults | frontend | listen | backend
yes | yes | yes | no
arguments :
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. 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
(eg: 4 or 5 seconds).
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 results in accumulation of expired sessions in
the system if the system’s timeouts are not configured either.
this parameter is provided for compatibility but is currently deprecated.
please use “timeout client” instead.
see also : “timeout client”, “timeout http-request”, “timeout server”, and
“srvtimeout”.
compression algo
compression type
compression offload
enable http compression.
may be used in sections : defaults | frontend | listen | backend
yes | yes | yes | yes
arguments :
algo is followed by the list of supported compression algorithms.
type is followed by the list of mime types that will be compressed.
offload makes haproxy work as a compression offloader only (see notes).
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 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 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 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.
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. note: for now, the “offload” setting is
ignored when set in a defaults section.
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
* http status code is not 200
* response header “transfer-encoding” contains “chunked” (temporary
workaround)
* 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)
note: the compression does not rewrite etag headers, and does not emit the
warning header.
examples :
compression algo gzip
compression type text/html text/plain
contimeout
set the maximum time to wait for a connection attempt to a server to succeed.
may be used in sections : defaults | frontend | listen | backend
yes | no | yes | yes
arguments :
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 (eg: 4 or 5 seconds). by default, the
connect timeout also presets the queue timeout to the same value if this one
has not been specified. historically, the contimeout was also used to set the
tarpit timeout in a listen section, which is not possible in a pure frontend.
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 results in accumulation of failed sessions in
the system if the system’s timeouts are not configured either.
this parameter is provided for backwards compatibility but is currently
deprecated. please use “timeout connect”, “timeout queue” or “timeout tarpit”
instead.
see also : “timeout connect”, “timeout queue”, “timeout tarpit”,
“timeout server”, “contimeout”.
cookie
[ postonly ] [ preserve ] [ httponly ] [ secure ]
[ domain
enable cookie-based persistence in a backend.
may be used in sections : defaults | frontend | listen | backend
yes | no | yes | yes
arguments :
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 (eg:
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 only
works in http close mode. unless the application behaviour 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 remove 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 requires the http close 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 (eg: 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 (eg: 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 (eg: after a farm size change). this
is stronger than the maxidle method in that it forces a
redispatch after some absolute delay.
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.
examples :
cookie jsessionid prefix
cookie srv insert indirect nocache
cookie srv insert postonly indirect
cookie srv insert indirect nocache maxidle 30m maxlife 8h
see also : “appsession”, “balance source”, “capture cookie”, “server”
and “ignore-persist”.
declare capture [ request | response ] len
declares a capture slot.
may be used in sections : defaults | frontend | listen | backend
no | yes | yes | no
arguments:
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.
see also: “capture-req”, “capture-res” (sample converters),
“http-request capture” and “http-response capture”.
default-server [param*]
change default options for a server in a backend
may be used in sections : defaults | frontend | listen | backend
yes | no | yes | yes
arguments:
<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.
example :
default-server inter 1000 weight 13
see also: “server” and section 5 about server options
default_backend
specify the backend to use when no “use_backend” rule has been matched.
may be used in sections : defaults | frontend | listen | backend
yes | yes | yes | no
arguments :
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.
example :
use_backend dynamic if url_dyn
use_backend static if url_css url_img extension_img
default_backend dynamic
see also : “use_backend”
description
describe a listen, frontend or backend.
may be used in sections : defaults | frontend | listen | backend
no | yes | yes | yes
arguments : string
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
disabled
disable a proxy, frontend or backend.
may be used in sections : defaults | frontend | listen | backend
yes | yes | yes | yes
arguments : none
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.
see also : “enabled”
dispatch
:set a default server address
may be used in sections : defaults | frontend | listen | backend
no | no | yes | yes
arguments :
<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.
see also : “server”
enabled
enable a proxy, frontend or backend.
may be used in sections : defaults | frontend | listen | backend
yes | yes | yes | yes
arguments : none
the “enabled” keyword is used to explicitly enable an instance, when the
defaults has been set to “disabled”. this is very rarely used.
see also : “disabled”
errorfile
return a file contents instead of errors generated by haproxy
may be used in sections : defaults | frontend | listen | backend
yes | yes | yes | yes
arguments :
is the http status code. currently, haproxy is capable of
generating codes 200, 400, 403, 405, 408, 429, 500, 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 returned verbatim on the tcp socket. this allows any trick such
as redirections to another url or site, as well as tricks to clean cookies,
force enable or disable caching, etc… the package provides default error
files returning the same contents as default errors.
the files should not exceed the configured buffer size (bufsize), which
generally is 8 or 16 kb, otherwise they will be truncated. it is also wise
not to put any reference to local contents (eg: 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. for better http compliance, it is
recommended that all header lines end with cr-lf and not lf alone.
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.
see also : “errorloc”, “errorloc302”, “errorloc303”
example :
errorfile 400 /etc/haproxy/errorfiles/400badreq.http
errorfile 408 /dev/null # workaround chrome pre-connect bug
errorfile 403 /etc/haproxy/errorfiles/403forbid.http
errorfile 503 /etc/haproxy/errorfiles/503sorry.http
errorloc
errorloc302
return an http redirection to a url instead of errors generated by haproxy
may be used in sections : defaults | frontend | listen | backend
yes | yes | yes | yes
arguments :
is the http status code. currently, haproxy is capable of
generating codes 200, 400, 403, 408, 500, 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 (eg: 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
workaround 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.
see also : “errorfile”, “errorloc303”
errorloc303
return an http redirection to a url instead of errors generated by haproxy
may be used in sections : defaults | frontend | listen | backend
yes | yes | yes | yes
arguments :
is the http status code. currently, haproxy is capable of
generating codes 400, 403, 408, 500, 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 (eg: 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.
see also : “errorfile”, “errorloc”, “errorloc302”
email-alert from
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 sections: defaults | frontend | listen | backend
yes | yes | yes | yes
arguments :
<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.
see also : “email-alert level”, “email-alert mailers”,
“email-alert myhostname”, “email-alert to”, section 3.6 about mailers.
email-alert level
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 sections: defaults | frontend | listen | backend
yes | yes | yes | yes
arguments :
<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
is alert or lower - a paused server is marked as down and
is notice or lower - a server is marked as up or enters the drain state and
is notice or lower - “option log-health-checks” is enabled,
is info or lower,
and a health check status update occurs
see also : “email-alert from”, “email-alert mailers”,
“email-alert myhostname”, “email-alert to”,
section 3.6 about mailers.
email-alert mailers
declare the mailers to be used when sending email alerts
may be used in sections: defaults | frontend | listen | backend
yes | yes | yes | yes
arguments :
<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.
see also : “email-alert from”, “email-alert level”, “email-alert myhostname”,
“email-alert to”, section 3.6 about mailers.
email-alert myhostname
declare the to hostname address to be used when communicating with
mailers.
may be used in sections: defaults | frontend | listen | backend
yes | yes | yes | yes
arguments :
<emailaddr> is the to email address to use when sending email alerts
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.
see also : “email-alert from”, “email-alert level”, “email-alert mailers”,
“email-alert to”, section 3.6 about mailers.
email-alert to
declare both the recipent 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 sections: defaults | frontend | listen | backend
yes | yes | yes | yes
arguments :
<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.
see also : “email-alert from”, “email-alert level”, “email-alert mailers”,
“email-alert myhostname”, section 3.6 about mailers.
force-persist { if | unless }
declare a condition to force persistence on down servers
may be used in sections: defaults | frontend | listen | backend
no | yes | 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.
see also : “option redispatch”, “ignore-persist”, “persist”,
and section 7 about acl usage.
fullconn
specify at what backend load the servers will reach their maxconn
may be used in sections : defaults | frontend | listen | backend
yes | no | yes | yes
arguments :
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
never more than
values when the backend has less than
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.
example :
# 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
see also : “maxconn”, “server”
grace
this may be used to ensure that the services disappear in a certain order.
this was designed so that frontends which are dedicated to monitoring by an
external equipment fail immediately while other ones remain up for the time
needed by the equipment to detect the failure.
note that currently, there is very little benefit in using this parameter,
and it may in fact complicate the soft-reconfiguration process more than
simplify it.
hash-type
specify a method to use for mapping hashes to servers
may be used in sections : defaults | frontend | listen | backend
yes | no | yes | yes
arguments :
the
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.
<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.
see also : “balance”, “server”
http-check disable-on-404
enable a maintenance mode upon http/404 response to health-checks
may be used in sections : defaults | frontend | listen | backend
yes | no | yes | yes
arguments : none
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.
see also : “option httpchk”, “http-check expect”
http-check expect [!]
make http health checks consider response contents or specific status codes
may be used in sections : defaults | frontend | listen | backend
yes | no | yes | yes
arguments :
response. the keyword may be one of “status”, “rstatus”,
“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 or a regular
expression. if the 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 <string> : test the exact string match for the http status code.
a health check response will be considered valid if the
response's status code is exactly this string. 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.
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 (eg: 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 (eg: a stack trace).
it is important to note that the responses will be limited to a certain size
defined by the global “tune.chksize” 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.
also “http-check expect” doesn’t support http keep-alive. keep in mind that it
will automatically append a “connection: close” header, meaning that this
header should not be present in the request provided by “option httpchk”.
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.
examples :
# only accept status 200 as valid
http-check expect status 200
# 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>
see also : “option httpchk”, “http-check disable-on-404”
http-check send-state
enable emission of a state header with http health checks
may be used in sections : defaults | frontend | listen | backend
yes | no | yes | yes
arguments : none
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 “
no specific order some values available in the stats interface :
- a variable “address”, containing the address of the backend server.
this corresponds to the 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
see also : “option httpchk”, “http-check disable-on-404”
http-request { allow | deny | tarpit | auth [realm may be used in sections: defaults | frontend | listen | backend the http-request statement defines a set of rules which apply to layer 7 the first keyword is the rule’s action. currently supported actions include : there is no limit to the number of http-request statements per instance. it is important to know that http-request rules are processed very early in example: example: example: example: example: see also : “stats http-request”, section 3.4 about userlists and section 7 http-response { allow | deny | add-header may be used in sections: defaults | frontend | listen | backend the http-response statement defines a set of rules which apply to layer 7 the first keyword is the rule’s action. currently supported actions include : there is no limit to the number of http-response statements per instance. it is important to know that http-response rules are processed very early in example: example: see also : “http-request”, section 3.4 about userlists and section 7 about http-send-name-header [ may be used in sections: defaults | frontend | listen | backend arguments : the “http-send-name-header” statement causes the name of the target see also : “server” id set a persistent id for the proxy. this id must be unique and positive. ignore-persist { if | unless } by default, when cookie persistence is enabled, every requests containing the “ignore-persist” statement allows one to declare various acl-based combined with “appsession”, it can also help reduce haproxy memory usage, as the persistence is ignored when an “if” condition is met, or unless an see also : “force-persist”, “cookie”, and section 7 about acl usage. log global prefix : arguments : it is important to keep in mind that it is the frontend which decides what to however, backend log declaration define how and where servers status changes note : according to rfc3164, messages are truncated to 1024 bytes before example : log-format this directive specifies the log format string that will be used for all logs log-tag sets the tag field in the syslog header to this string. it defaults to the max-keep-alive-queue http keep-alive tries to reuse the same server connection whenever possible, the purpose of this setting is to set a threshold on the number of queued note that this has no impact on responses which are maintained to the same see also : “option http-server-close”, “option prefer-last-server”, server maxconn if the system supports it, it can be useful on big sites to raise this limit also, when by default, this value is set to 2000. see also : “server”, global section’s “maxconn”, “fullconn” mode { tcp|http|health } when doing content switching, it is mandatory that the frontend and the example : see also : “monitor”, “monitor-net” monitor fail { if | unless } this statement adds a condition which can force the response to a monitor example: see also : “monitor-net”, “monitor-uri”, “errorfile”, “errorloc” monitor-net in tcp mode, any connection coming from a source matching in http mode, a connection coming from a source matching monitor requests are processed very early, just after tcp-request connection last, please note that only one “monitor-net” statement can be specified in example : see also : “monitor fail”, “monitor-uri” monitor-uri when an http request referencing monitor requests are processed very early. it is not possible to block nor example : see also : “monitor fail”, “monitor-net” option abortonclose in presence of very high loads, the servers will take some time to respond. as there is no way to distinguish between a full stop and a simple output in haproxy, the user can choose the desired behaviour using the option if this option has been enabled in a “defaults” section, it can be disabled see also : “timeout queue” and server’s “maxconn” and “maxqueue” parameters option accept-invalid-http-request by default, haproxy complies with rfc7230 in terms of message parsing. this this option should never be enabled by default as it hides application bugs when this option is enabled, erroneous header names will still be accepted in if this option has been enabled in a “defaults” section, it can be disabled see also : “option accept-invalid-http-response” and “show errors” on the option accept-invalid-http-response by default, haproxy complies with rfc7230 in terms of message parsing. this this option should never be enabled by default as it hides application bugs when this option is enabled, erroneous header names will still be accepted in if this option has been enabled in a “defaults” section, it can be disabled see also : “option accept-invalid-http-request” and “show errors” on the option allbackups by default, the first operational backup server gets all traffic when normal this option is mostly used with static server farms dedicated to return a if this option has been enabled in a “defaults” section, it can be disabled option checkcache some high-level frameworks set application cookies everywhere and do not the option “checkcache” enables deep inspection of all server responses for if a response doesn’t respect these requirements, then it will be blocked due to the high impact on the application, the application should be tested if this option has been enabled in a “defaults” section, it can be disabled option clitcpka when there is a firewall or any session-aware component between a client and enabling socket-level tcp keep-alives makes the system regularly send packets it is important to understand that keep-alive packets are neither emitted nor 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 if this option has been enabled in a “defaults” section, it can be disabled see also : “option srvtcpka”, “option tcpka” option contstats by default, counters used for statistics calculation are incremented option dontlog-normal there are large sites dealing with several thousand connections per second it is strongly discouraged to use this option as most of the time, the key to see also : “log”, “dontlognull”, “log-separate-errors” and section 8 about option dontlognull in certain environments, there are components which will regularly connect to it is generally recommended not to use this option in uncontrolled if this option has been enabled in a “defaults” section, it can be disabled see also : “log”, “http-ignore-probes”, “monitor-net”, “monitor-uri”, and option forceclose some http servers do not necessarily close the connections when they receive when this happens, it is possible to use “option forceclose”. it will this option may also be combined with “option http-pretend-keepalive”, which this option disables and replaces any previous “option httpclose”, “option if this option has been enabled in a “defaults” section, it can be disabled see also : “option httpclose” and “option http-pretend-keepalive” option forwardfor [ except since haproxy works in reverse-proxy mode, the servers see its ip address as the keyword “header” may be used to supply a different header name to replace sometimes, a same haproxy instance may be shared between a direct client alternatively, the keyword “if-none” states that the header will only be this option may be specified either in the frontend or in the backend. if at examples : see also : “option httpclose”, “option http-server-close”, option http-buffer-request it is sometimes desirable to wait for the body of an http request before see also : “option http-no-delay” option http-ignore-probes recently some browsers started to implement a “pre-connect” feature that way the empty connection is silently ignored. note that it is better if this option has been enabled in a “defaults” section, it can be disabled see also : “log”, “dontlognull”, “errorfile”, and section 8 about logging. option http-keep-alive by default haproxy operates in keep-alive mode with regards to persistent setting “option http-keep-alive” enables http keep-alive mode on the client- this last case can happen when the server is a fast static server of cache. if the client request has to go to another backend or another server due to in general it is preferred to use “option http-server-close” with application at the moment, logs will not indicate whether requests came from the same this option disables and replaces any previous “option httpclose”, “option see also : “option forceclose”, “option http-server-close”, option http-no-delay in http, each payload is unidirectional and has no notion of interactivity. when “option http-no-delay” is present in either the frontend or the backend see also : “option http-buffer-request” option http-pretend-keepalive when running with “option http-server-close” or “option forceclose”, haproxy by setting “option http-pretend-keepalive”, haproxy will make the server it is recommended not to enable this option by default, because most servers this option may be set both in a frontend and in a backend. it is enabled if if this option has been enabled in a “defaults” section, it can be disabled see also : “option forceclose”, “option http-server-close”, and option http-server-close by default haproxy operates in keep-alive mode with regards to persistent at the moment, logs will not indicate whether requests came from the same this option may be set both in a frontend and in a backend. it is enabled if if this option has been enabled in a “defaults” section, it can be disabled see also : “option forceclose”, “option http-pretend-keepalive”, option http-tunnel by default haproxy operates in keep-alive mode with regards to persistent option “http-tunnel” disables any http processing past the first request and if this option has been enabled in a “defaults” section, it can be disabled see also : “option forceclose”, “option http-server-close”, option http-use-proxy-header while rfc2616 explicitly states that http/1.1 agents must use the by setting this option in a frontend, haproxy can automatically switch to use also, when this option is set, a request which requires authentication will this option should normally never be used, except in front of a proxy. see also : “option httpclose”, “option forceclose” and “option option httpchk by default, server health checks only consist in trying to establish a tcp the port and interval are specified in the server configuration. this option does not necessarily require an http backend, it also works with examples : see also : “option ssl-hello-chk”, “option smtpchk”, “option mysql-check”, option httpclose by default haproxy operates in keep-alive mode with regards to persistent if “option httpclose” is set, haproxy will work in http tunnel mode and check it seldom happens that some servers incorrectly ignore this header and do not this option may be set both in a frontend and in a backend. it is enabled if if this option has been enabled in a “defaults” section, it can be disabled see also : “option forceclose”, “option http-server-close” and option httplog [ clf ] by default, the log output format is very poor, as it only contains the this option may be set either in the frontend or the backend. specifying only “option httplog” will automatically clear the ‘clf’ mode see also : section 8 about logging. option http_proxy it sometimes happens that people need a pure http proxy which understands no host address resolution is performed, so this only works when pure ip if this option has been enabled in a “defaults” section, it can be disabled example : see also : “option httpclose” option independent-streams by default, when data is sent over a socket, both the write timeout and the while this default behaviour is desirable for almost all applications, there when this option is set on the frontend, it will disable read timeout updates note: older versions used to call this setting “option independent-streams” see also : “timeout client”, “timeout server” and “timeout tunnel” option ldap-check it is possible to test that the server correctly talks ldapv3 instead of just the server is considered valid only when the ldap response contains success logging of bind requests is server dependent see your documentation how to example : see also : “option httpchk” option external-check it is possible to test the health of a server using an external command. requires the “external-check” global to be set. see also : “external-check”, “external-check command”, “external-check path” option log-health-checks by default, failed health check are logged if server is up and successful when this option is enabled, any change of the health check status or to note that status changes not caused by health checks (eg: enable/disable on see also: “option httpchk”, “option ldap-check”, “option mysql-check”, option log-separate-errors sometimes looking for errors in logs is not easy. this option makes haproxy using this option, large sites dealing with several thousand connections per see also : “log”, “dontlognull”, “dontlog-normal” and section 8 about option logasap by default, http requests are logged upon termination so that the total examples : see also : “option httplog”, “capture response header”, and section 8 about option mysql-check [ user if you specify a username, the check consists of sending two mysql packet, if you don’t specify a username (it is deprecated and not recommended), the remember that this does not check database presence nor database consistency. 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 see also: “option httpchk” option nolinger when clients or servers abort connections in a dirty way (eg: they are when this happens, it is possible to activate “option nolinger” which forces for this reason, it is not recommended to use this option when not absolutely this option may be used both on frontends and backends, depending on the side if this option has been enabled in a “defaults” section, it can be disabled option originalto [ except since haproxy can work in transparent mode, every request from a client can the keyword “header” may be used to supply a different header name to replace sometimes, a same haproxy instance may be shared between a direct client this option may be specified either in the frontend or in the backend. if at examples : see also : “option httpclose”, “option http-server-close”, option persist when an http request reaches a backend with a cookie which references a dead if this option has been enabled in a “defaults” section, it can be disabled see also : “option redispatch”, “retries”, “force-persist” option pgsql-check [ user the check sends a postgresql startupmessage and waits for either see also: “option httpchk” option prefer-last-server when the load balancing algorithm in use is not deterministic, and a previous if this option has been enabled in a “defaults” section, it can be disabled see also: “option http-keep-alive” option redispatch in http mode, if a server designated by a cookie is down, clients may specifying “option redispatch” will allow the proxy to break their it also allows to retry connections to another server in case of multiple this form is the preferred form, which replaces both the “redispatch” and if this option has been enabled in a “defaults” section, it can be disabled see also : “redispatch”, “retries”, “force-persist” option redis-check it is possible to test that the server correctly talks redis protocol instead example : see also : “option httpchk” option smtpchk when “option smtpchk” is set, the health checks will consist in tcp this test is meant to be used with smtp servers or relays. depending on the most often, an incoming smtp server needs to see the client’s ip address for example : see also : “option httpchk”, “source” option socket-stats enable or disable collecting & providing separate statistics for each socket. arguments : none option splice-auto when this option is enabled either on a frontend or on a backend, haproxy important note: kernel-based tcp splicing is a linux-specific feature which example : if this option has been enabled in a “defaults” section, it can be disabled see also : “option splice-request”, “option splice-response”, and global option splice-request when this option is enabled either on a frontend or on a backend, haproxy important note: see “option splice-auto” for usage limitations. example : if this option has been enabled in a “defaults” section, it can be disabled see also : “option splice-auto”, “option splice-response”, and global options option splice-response when this option is enabled either on a frontend or on a backend, haproxy important note: see “option splice-auto” for usage limitations. example : if this option has been enabled in a “defaults” section, it can be disabled see also : “option splice-auto”, “option splice-request”, and global options option srvtcpka when there is a firewall or any session-aware component between a client and enabling socket-level tcp keep-alives makes the system regularly send packets it is important to understand that keep-alive packets are neither emitted nor 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 if this option has been enabled in a “defaults” section, it can be disabled see also : “option clitcpka”, “option tcpka” option ssl-hello-chk when some ssl-based protocols are relayed in tcp mode through haproxy, it is all servers tested till there correctly reply to sslv3 client hello messages, note that this check works even when ssl support was not built into haproxy see also: “option httpchk”, “check-ssl” option tcp-check this health check method is intended to be combined with “tcp-check” command tcp checks currently support 4 modes of operations : examples : see also : “tcp-check expect”, “tcp-check send” option tcp-smart-accept when an http connection request comes in, the system acknowledges it on for this reason, in http mode, haproxy automatically asks the system to avoid during complex network debugging sessions, it may be desirable to disable it is also possible to force it for non-http proxies by simply specifying it is recommended to avoid forcing this option in a defaults section. in case see also : “option tcp-smart-connect” option tcp-smart-connect on certain systems (at least linux), haproxy can ask the kernel not to this feature is enabled when “option tcp-smart-connect” is set in a backend. it only makes sense to enable it with protocols where the client speaks first if this option has been enabled in a “defaults” section, it can be disabled see also : “option tcp-smart-accept” option tcpka when there is a firewall or any session-aware component between a client and enabling socket-level tcp keep-alives makes the system regularly send packets it is important to understand that keep-alive packets are neither emitted nor 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 see also : “option clitcpka”, “option srvtcpka” option tcplog by default, the log output format is very poor, as it only contains the this option may be set either in the frontend or the backend. see also : “option httplog”, and section 8 about logging. option transparent this option was introduced in order to provide layer 7 persistence to layer 3 note that contrary to a common belief, this option does not make haproxy see also: the “usesrc” argument of the “source” keyword, and the external-check command arguments : the arguments passed to the to the command are: the some values are also provided through environment variables. environment variables : if the command executed and exits with a zero status then the check is example : see also : “external-check”, “option external-check”, “external-check path” external-check path arguments : the default path is “”. example : see also : “external-check”, “option external-check”, persist rdp-cookie this statement enables persistence based on an rdp cookie. the rdp cookie note that this only makes sense in a tcp backend, but for this to work, the also, it is important to understand that the terminal server will emit this example : see also : “balance rdp-cookie”, “tcp-request”, the “req_rdp_cookie” acl and rate-limit sessions when the frontend reaches the specified number of new sessions per second, it this feature is particularly efficient at blocking connection-based attacks example : limit the connection rate on smtp to 10 per second max note : when the maximum rate is reached, the frontend’s status is not changed see also : the “backlog” keyword and the “fe_sess_rate” acl criterion. redirect location if/unless the condition is matched, the http request will lead to a redirect arguments : example: move the login url only to https. example: send redirects for request for articles without a ‘/‘. example: redirect all http traffic to https when ssl is handled by haproxy. example: append ‘www.’ prefix in front of all hosts not having it see section 7 about acl usage. redisp (deprecated) in http mode, if a server designated by a cookie is down, clients may specifying “redispatch” will allow the proxy to break their persistence and it also allows to retry last connection to another server in case of multiple this form is deprecated, do not use it in any new configuration, use the new see also : “option redispatch” reqadd a new line consisting in header transformations only apply to traffic which passes through haproxy, example : add “x-proto: ssl” to requests coming via port 81 see also: “rspadd”, section 6 about http header manipulation, and section 7 reqallow a request containing any line which matches extended regular expression it is easier, faster and more powerful to use acls to write access policies. example : see also: “reqdeny”, “block”, section 6 about http header manipulation, and reqdel any header line matching extended regular expression header transformations only apply to traffic which passes through haproxy, example : see also: “reqadd”, “reqrep”, “rspdel”, section 6 about http header reqdeny a request containing any line which matches extended regular expression a denied request will generate an “http 403 forbidden” response once the it is easier, faster and more powerful to use acls to write access policies. example : see also: “reqallow”, “rspdeny”, “block”, section 6 about http header reqpass a request containing any line which matches extended regular expression it is easier, faster and more powerful to use acls to write access policies. example : see also: “reqallow”, “reqdeny”, “block”, section 6 about http header reqrep any line matching extended regular expression header transformations only apply to traffic which passes through haproxy, example : see also: “reqadd”, “reqdel”, “rsprep”, “tune.bufsize”, section 6 about reqtarpit a request containing any line which matches extended regular expression the goal of the tarpit is to slow down robots attacking servers with examples : see also: “reqallow”, “reqdeny”, “reqpass”, section 6 about http header retries it is important to understand that this value applies to the number of in order to avoid immediate reconnections to a server which is restarting, when “option redispatch” is set, the last retry may be performed on another see also : “option redispatch” rspadd a new line consisting in header transformations only apply to traffic which passes through haproxy, see also: “reqadd”, section 6 about http header manipulation, and section 7 rspdel any header line matching extended regular expression header transformations only apply to traffic which passes through haproxy, example : see also: “rspadd”, “rsprep”, “reqdel”, section 6 about http header rspdeny a response containing any line which matches extended regular expression main use of this keyword is to prevent sensitive information leak and to it is easier, faster and more powerful to use acls to write access policies. example : see also: “reqdeny”, “acl”, “block”, section 6 about http header manipulation rsprep any line matching extended regular expression header transformations only apply to traffic which passes through haproxy, example : see also: “rspadd”, “rspdel”, “reqrep”, section 6 about http header server examples : see also: “default-server”, “http-send-name-header” and section 5 about source the “source” keyword is useful in complex environments where a specific an extension which is available on certain patched linux kernels may be used in this “full transparent proxy” mode, it is possible to force a specific ip note that depending on the transparent proxy technology used, it may be this option sets the default source for all servers in the backend. it may in order to work, “usesrc” requires root privileges. examples : see also : the “source” server option in section 5, the tproxy patches for srvtimeout the inactivity timeout applies when the server is expected to acknowledge or the value is specified in milliseconds by default, but can be in any other this parameter is specific to backends, but can be specified once for all in this parameter is provided for compatibility but is currently deprecated. see also : “timeout server”, “timeout tunnel”, “timeout client” and stats admin { if | unless } this statement enables the statistics admin level if/unless a condition is the admin level allows to enable/disable servers from the web interface. by note : consider not using this feature in multi-process mode (nbproc > 1) currently, the post request is limited to the buffer size minus the reserved example : example : example : see also : “stats enable”, “stats auth”, “stats http-request”, “nbproc”, stats auth this statement enables statistics with default settings, and restricts access since the authentication method is http basic authentication, the passwords it is also possible to reduce the scope of the proxies which appear in the though this statement alone is enough to enable statistics reporting, it is example : see also : “stats enable”, “stats realm”, “stats scope”, “stats uri” stats enable this statement enables statistics reporting with default settings defined though this statement alone is enough to enable statistics reporting, it is example : see also : “stats auth”, “stats realm”, “stats uri” stats hide-version by default, the stats page reports some useful status information along with though this statement alone is enough to enable statistics reporting, it is example : see also : “stats auth”, “stats enable”, “stats realm”, “stats uri” stats http-request { allow | deny | auth [realm may be used in sections: defaults | frontend | listen | backend as “http-request”, these set of options allow to fine control access to there is no fixed limit to the number of http-request statements per see also : “http-request”, section 3.4 about userlists and section 7 stats realm the realm is read as a single word, so any spaces in it should be escaped this statement is useful only in conjunction with “stats auth” since it is though this statement alone is enough to enable statistics reporting, it is example : see also : “stats auth”, “stats enable”, “stats uri” stats refresh this statement is useful on monitoring displays with a permanent page though this statement alone is enough to enable statistics reporting, it is example : see also : “stats auth”, “stats enable”, “stats realm”, “stats uri” stats scope { when this statement is specified, only the sections enumerated with this though this statement alone is enough to enable statistics reporting, it is example : see also : “stats auth”, “stats enable”, “stats realm”, “stats uri” stats show-desc [ this statement is useful for users that offer shared services to their though this statement alone is enough to enable statistics reporting, it is example : see also: “show-node”, “stats enable”, “stats uri” and “description” in stats show-legends enable reporting additional information on the statistics page : though this statement alone is enough to enable statistics reporting, it is see also: “stats enable”, “stats uri”. stats show-node [ this statement is useful for users that offer shared services to their though this statement alone is enough to enable statistics reporting, it is example: see also: “show-desc”, “stats enable”, “stats uri”, and “node” in global stats uri the statistics uri is intercepted on the relayed traffic, so it appears as a the default uri compiled in haproxy is “/haproxy?stats”, but this may be it is sometimes very convenient to use “/“ as the uri prefix, and put that though this statement alone is enough to enable statistics reporting, it is example : see also : “stats auth”, “stats enable”, “stats realm” stick match arguments : some protocols or applications require complex stickiness rules and cannot the table has to be declared using the “stick-table” statement. it must be of it is possible to restrict the conditions where a “stick match” statement there is no limit on the number of “stick match” statements. the first that the stick rules are checked after the persistence cookies, so they will not note : consider not using this feature in multi-process mode (nbproc > 1) example : see also : “stick-table”, “stick on”, “nbproc”, “bind-process” and section 7 stick on note : this form is exactly equivalent to “stick match” followed by note : consider not using this feature in multi-process mode (nbproc > 1) examples : see also : “stick match”, “stick store-request”, “nbproc” and “bind-process”. stick store-request arguments : some protocols or applications require complex stickiness rules and cannot the table has to be declared using the “stick-table” statement. it must be of it is possible to restrict the conditions where a “stick store-request” there is no limit on the number of “stick store-request” statements, but the “store-request” rules are evaluated once the server connection has been note : consider not using this feature in multi-process mode (nbproc > 1) example : see also : “stick-table”, “stick on”, “nbproc”, “bind-process” and section 7 stick-table type {ip | integer | string [len arguments : the data types that can be stored with an entry are the following : there is only one stick-table per proxy. at the moment of writing this doc, it is important to understand that stickiness based on learning information last, memory requirements may be important when storing many data types. example: see also : “stick match”, “stick on”, “stick store-request”, section 2.2 stick store-response arguments : some protocols or applications require complex stickiness rules and cannot the table has to be declared using the “stick-table” statement. it must be of it is possible to restrict the conditions where a “stick store-response” there is no limit on the number of “stick store-response” statements, but the table will contain the real server that processed the request. example : see also : “stick-table”, “stick on”, and section 7 about acls and pattern tcp-check connect [params*] when an application lies on more than a single tcp port or when haproxy when there are no tcp port configured on the server line neither server port in a tcp-check ruleset a ‘connect’ is required, it is also mandatory to start parameters : see also : “option tcp-check”, “tcp-check send”, “tcp-check expect” tcp-check expect [!] arguments : the available matches are intentionally similar to their http-check cousins : it is important to note that the responses will be limited to a certain size examples : see also : “option tcp-check”, “tcp-check connect”, “tcp-check send”, tcp-check send examples : see also : “option tcp-check”, “tcp-check connect”, “tcp-check expect”, tcp-check send-binary examples : see also : “option tcp-check”, “tcp-check connect”, “tcp-check expect”, tcp-request connection immediately after acceptance of a new incoming connection, it is possible to the “tcp-request connection” rules are evaluated in their exact declaration four types of actions are supported : note that the “if/unless” condition is optional. if no condition is set on example: accept all connections from white-listed hosts, reject too fast example: accept all connections from white-listed hosts, count all other example: enable the proxy protocol for traffic coming from all known proxies. see section 7 about acl usage. see also : “tcp-request content”, “stick-table” tcp-request content a request’s contents can be analysed at an early stage of request processing the first difference between these rules and “tcp-request connection” rules content-based rules are evaluated in their exact declaration order. if no four types of actions are supported : they have the same meaning as their counter-parts in “tcp-request connection” while there is nothing mandatory about it, it is recommended to use the note that the “if/unless” condition is optional. if no condition is set on it is perfectly possible to match layer 7 contents with “tcp-request content” tracking layer7 information is also possible provided that the information the “lua” keyword is followed by a lua function name. it is used to run a lua the “set-var” is used to set the content of a variable. the variable is example: example: example: example: example: example: track per-frontend and per-backend counters, block abusers at the see section 7 about acl usage. see also : “tcp-request connection”, “tcp-request inspect-delay” tcp-request inspect-delay people using haproxy primarily as a tcp relay are often worried about the tcp content inspection applies very early when a connection reaches a note that when performing content inspection, haproxy will evaluate the whole as soon as a rule matches, the request is released and continues as usual. if for most protocols, it is enough to set it to a few seconds, as most clients see also : “tcp-request content accept”, “tcp-request content reject”, tcp-response content response contents can be analysed at an early stage of response processing most often, these decisions will consider a protocol recognition or validity. content-based rules are evaluated in their exact declaration order. if no two types of actions are supported : note that the “if/unless” condition is optional. if no condition is set on it is perfectly possible to match layer 7 contents with “tcp-response the “lua” keyword is followed by a lua function name. it is used to run a lua the “set-var” is used to set the content of a variable. the variable is example: see section 7 about acl usage. see also : “tcp-request content”, “tcp-response inspect-delay” tcp-response inspect-delay see also : “tcp-response content”, “tcp-request inspect-delay”. timeout check may be used in sections: defaults | frontend | listen | backend if set, haproxy uses min(“timeout connect”, “inter”) as a connect timeout if “timeout check” is not set haproxy uses “inter” for complete check in most cases check request is much simpler and faster to handle than normal this parameter is specific to backends, but can be specified once for all in see also: “timeout connect”, “timeout queue”, “timeout server”, timeout client the inactivity timeout applies when the client is expected to acknowledge or this parameter is specific to frontends, but can be specified once for all in this parameter replaces the old, deprecated “clitimeout”. it is recommended see also : “clitimeout”, “timeout server”, “timeout tunnel”. timeout client-fin the inactivity timeout applies when the client is expected to acknowledge or this parameter is specific to frontends, but can be specified once for all in see also : “timeout client”, “timeout server-fin”, and “timeout tunnel”. timeout connect if the server is located on the same lan as haproxy, the connection should be this parameter is specific to backends, but can be specified once for all in this parameter replaces the old, deprecated “contimeout”. it is recommended see also: “timeout check”, “timeout queue”, “timeout server”, “contimeout”, timeout http-keep-alive by default, the time to wait for a new request in case of keep-alive is set the “http-keep-alive” timeout covers these needs. it will define how long to there is also another difference between the two timeouts : when a connection in general it is optimal to set this value to a few tens to hundreds of if this parameter is not set, the “http-request” timeout applies, and if both see also : “timeout http-request”, “timeout client”. timeout http-request in order to offer dos protection, it may be required to lower the maximum note that this timeout only applies to the header part of the request, and generally it is enough to set it to a few seconds, as most clients send the if this parameter is not set, the client timeout still applies between each see also : “errorfile”, “http-ignore-probes”, “timeout http-keep-alive”, and timeout queue when a server’s maxconn is reached, connections are left pending in a queue the “timeout queue” statement allows to fix the maximum time for a request to see also : “timeout connect”, “contimeout”. timeout server the inactivity timeout applies when the server is expected to acknowledge or the value is specified in milliseconds by default, but can be in any other this parameter is specific to backends, but can be specified once for all in this parameter replaces the old, deprecated “srvtimeout”. it is recommended see also : “srvtimeout”, “timeout client” and “timeout tunnel”. timeout server-fin the inactivity timeout applies when the server is expected to acknowledge or this parameter is specific to backends, but can be specified once for all in see also : “timeout client-fin”, “timeout server”, and “timeout tunnel”. timeout tarpit when a connection is tarpitted using “reqtarpit”, it is maintained open with the value is specified in milliseconds by default, but can be in any other see also : “timeout connect”, “contimeout”. timeout tunnel the tunnel timeout applies when a bidirectional connection is established since this timeout is usually used in conjunction with long-lived connections, the value is specified in milliseconds by default, but can be in any other this parameter is specific to backends, but can be specified once for all in example : see also : “timeout client”, “timeout client-fin”, “timeout server”. transparent (deprecated) this keyword was introduced in order to provide layer 7 persistence to layer the “transparent” keyword is deprecated, use “option transparent” instead. note that contrary to a common belief, this option does not make haproxy see also: “option transparent” unique-id-format this keyword creates a id for each request using the custom log format. a the format should be composed from elements that are guaranteed to be it is recommended to use hexadecimal notation for many fields since it example: see also: “unique-id-header” unique-id-header add a unique-id header in the http request sent to the server, using the example: use_backend when doing content-switching, connections arrive on a frontend and are then there may be as many “use_backend” rules as desired. all of these rules are in the first form, the backend will be used if the condition is met. in the note that it is possible to switch from a tcp frontend to an http backend. in when it is worth mentioning that “use_backend” rules with an explicit name are see also: “default_backend”, “tcp-request”, “fullconn”, “log-format”, and use-server by default, connections which arrive to a backend are load-balanced across sometimes it is desirable to forward a particular request to a specific if a rule designates a server which is down, and “option persist” is not used in the first form, the server will be used if the condition is met. in the note that even if a rule is matched, cookie processing is still performed but the “use-server” statement works both in http and tcp mode. this makes it example : see also: “use_backend”, section 5 about server and section 7 about acls. the “bind”, “server” and “default-server” keywords support a number of settings the “bind” keyword supports a certain number of settings which are all passed the currently supported settings are the following ones. accept-proxy alpn backlog ecdhe ca-file ca-ignore-err [all| ca-sign-file ca-sign-passphrase ciphers crl-file crt if the openssl used supports diffie-hellman, parameters present in this file if a directory name is used instead of a pem file, then all files found in if no sni is provided by the client or if the ssl library does not support 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 for each pem file, haproxy checks for the presence of file at the same path for each pem file, haproxy also checks for the presence of file at the same crt-ignore-err crt-list wildcards are supported in the sni filter. negative filter are also supported, defer-accept force-sslv3 force-tlsv10 force-tlsv11 force-tlsv12 generate-certificates creating a ssl certificate is an expensive operation, so a lru cache is used gid group id interface level maxconn mode mss name nice no-sslv3 no-tls-tickets no-tlsv10 no-tlsv11 no-tlsv12 npn process [ all | odd | even | <number 1-64>[-<number 1-64>] ] ssl strict-sni tcp-ut tfo tls-ticket-keys transparent v4v6 v6only uid user verify [none|optional|required] the “server” and “default-server” keywords support a certain number of settings server the currently supported settings are the following ones. addr <ipv4|ipv6> supported in default-server: no agent-check an ascii representation of a positive integer percentage, e.g. “75%”. the word “ready”. this will turn the server’s administrative state to the the word “drain”. this will turn the server’s administrative state to the the word “maint”. this will turn the server’s administrative state to the the words “down”, “failed”, or “stopped”, optionally followed by a the word “up” sets back the server’s operating state as up if health checks parameters which are not advertised by the agent are not changed. for failure to connect to the agent is not considered an error as connectivity requires the “agent-port” parameter to be set. see also the “agent-inter” supported in default-server: no agent-inter just as with every other time-based parameter, it may be entered in any see also the “agent-check” and “agent-port” parameters. supported in default-server: yes agent-port see also the “agent-check” and “agent-inter” parameters. supported in default-server: yes backup supported in default-server: no ca-file supported in default-server: no check supported in default-server: no check-send-proxy supported in default-server: no check-ssl supported in default-server: no ciphers supported in default-server: no cookie supported in default-server: no crl-file supported in default-server: no crt supported in default-server: no disabled supported in default-server: no error-limit supported in default-server: yes see also the “check”, “error-limit” and “on-error”. fall supported in default-server: yes force-sslv3 supported in default-server: no force-tlsv10 supported in default-server: no force-tlsv11 supported in default-server: no force-tlsv12 supported in default-server: no id supported in default-server: no inter just as with every other time-based parameter, they can be entered in any supported in default-server: yes maxconn supported in default-server: yes maxqueue supported in default-server: yes minconn supported in default-server: yes no-ssl-reuse supported in default-server: no no-sslv3 supported in default-server: no no-tls-tickets supported in default-server: no no-tlsv10 supported in default-server: no no-tlsv11 supported in default-server: no no-tlsv12 supported in default-server: no non-stick supported in default-server: no observe supported in default-server: no see also the “check”, “on-error” and “error-limit”. on-error supported in default-server: yes see also the “check”, “observe” and “error-limit”. on-marked-down actions are disabled by default supported in default-server: yes on-marked-up actions are disabled by default supported in default-server: yes port supported in default-server: yes redir example : server srv1 192.168.1.1:80 redir http://image1.mydomain.com check supported in default-server: no rise supported in default-server: yes resolve-prefer default value: ipv4 example: server s1 app1.domain.com:80 resolvers mydns resolve-prefer ipv6 resolvers example: server s1 app1.domain.com:80 resolvers mydns see also chapter 5.3 send-proxy supported in default-server: no send-proxy-v2 supported in default-server: no send-proxy-v2-ssl supported in default-server: no send-proxy-v2-ssl-cn supported in default-server: no slowstart maxconn: the number of connections accepted by the server will grow from 1 weight: when the backend uses a dynamic weighted algorithm, the weight the slowstart never applies when haproxy starts, otherwise it would cause supported in default-server: yes sni supported in default-server: no source additionally, the “source” statement on a server line allows one to specify a supported in default-server: no ssl supported in default-server: no track [ supported in default-server: no verify [none|required] supported in default-server: no verifyhost supported in default-server: no weight supported in default-server: yes haproxy allows using a host name to be resolved to find out what is the server as we’ve seen in introduction, name resolution in haproxy occurs at two 1. when starting up, haproxy parses the server line definition and matches a 2. at run time, when haproxy gets prepared to run a health check on a server, a few other events can trigger a name resolution at run time: a few things important to notice: all the name servers are queried in the mean time. haproxy will process the a resolution is considered as invalid (nx, timeout, refused), when all the this section is dedicated to host information related to name resolution in resolvers a resolvers section accept the following parameters: nameserver hold default value is 10s for “valid”. note: since the name resolution is triggered by the health checks, a new resolve_retries timeout example of a resolvers section (with default values): resolvers mydns in http mode, it is possible to rewrite, add or delete some of the request and if haproxy encounters an “informational response” (status code 1xx), it is able this section covers common usage of the following keywords, described in detail with all these keywords, the same conventions are used. the \t for a tab the the these keywords are not always convenient to allow/deny based on header lines are always considered as a whole. it is not possible to reference the first line is always considered as a header, which makes it possible to for performances reasons, the number of characters added to a request or to keywords beginning with “reqi” and “rspi” are the same as their counterpart when a request passes through a frontend then a backend, all req* rules req* statements are applied after “block” statements, so that “block” is haproxy is capable of extracting data from request or response streams, from the use of access control lists (acl) provides a flexible solution to perform the actions generally consist in blocking a request, selecting a backend, or in order to define a test, the “acl” keyword is used. the syntax is : acl this creates a new acl acl names must be formed from upper and lower case letters, digits, ‘-‘ (dash), there is no enforced limit to the number of acls. the unused ones do not affect the criterion generally is the name of a sample fetch method, or one of its acl sample fetch methods return data which can be of the following types : converters transform any of these data into any of these. for example, some each sample or converter returns data of a specific type, specified with its +———————+—————–+ note that in order to match a binary samples, it is mandatory to specify a the acl engine can match these types against patterns of the following types : the following acl flags are currently supported : -i : ignore case during matching of all subsequent patterns. the “-f” flag is followed by the name of a file from which all lines will be the “-m” flag allows an acl to use a map file. if this flag is set, the file is the “-u” flag forces the unique id of the acl. this unique id is used with the also, note that the “-i” flag applies to subsequent entries and not to entries in this example, each line of “exact-ua.lst” will be exactly matched against the “-m” flag is used to select a specific pattern matching method on the input the “-n” flag forbids the dns resolutions. it is used with the load of ip files. there are some restrictions however. not all methods can be used with all “found” : only check if the requested sample could be found in the stream, “bool” : check the value as a boolean. it can only be applied to fetches “int” : match the value as an integer. it can be used with integer and “ip” : match the value as an ipv4 or ipv6 address. it is compatible “bin” : match the contents against an hexadecimal string representing a “len” : match the sample’s length as an integer. this may be used with “str” : exact match : match the contents against a string. this may be “sub” : substring match : check that the contents contain at least one of “reg” : regex match : match the contents against a list of regular “beg” : prefix match : check that the contents begin like the provided “end” : suffix match : check that the contents end like the provided “dir” : subdir match : check that a slash-delimited portion of the “dom” : domain match : check that a dot-delimited portion of the contents for example, to quickly detect the presence of cookie “jsessionid” in an http in order to apply a regular expression on the 500 first bytes of data in the on systems where the regex library is much slower when using “-i”, it is all acl-specific criteria imply a default matching method. most often, these if an alternate match is specified using “-m” on an acl-specific criterion, the table below summarizes the compatibility matrix between sample or converter in order to match a boolean, no value is needed and all values are ignored. boolean matching may also be enforced using “-m bool” on fetch methods which integer matching applies by default to integer fetch methods. it can also be integer matching also supports integer ranges and operators. note that integer for instance, “1024:65535” is a valid range to represent a range of as a special case, some acl functions support decimal numbers which are in fact for an easier usage, comparison operators are also supported. note that using available operators for integer matching are : eq : true if the tested value equals at least one value for instance, the following acl matches any negative content-length header : acl negative-length hdr_val(content-length) lt 0 this one matches ssl versions between 3.0 and 3.1 (inclusive) : acl sslv3 req_ssl_ver 3:3.1 string matching applies to string or binary fetch methods, and exists in 6 exact match (-m str) : the extracted string must exactly match the substring match (-m sub) : the patterns are looked up inside the prefix match (-m beg) : the patterns are compared with the beginning of suffix match (-m end) : the patterns are compared with the end of the subdir match (-m sub) : the patterns are looked up inside the extracted domain match (-m dom) : the patterns are looked up inside the extracted string matching applies to verbatim strings as they are passed, with the just like with string matching, regex matching applies to verbatim strings as it is possible to match some extracted samples against a binary block which may example : ipv4 addresses values can be specified either as plain addresses or with a ipv6 may be entered in their usual form, with or without a netmask appended. haproxy is also able to match ipv4 addresses with ipv6 addresses in the some actions are only performed upon a valid condition. a condition is a a condition is formed as a disjunctive form: [!]acl1 [!]acl2 … [!]acln { or [!]acl1 [!]acl2 … [!]acln } … such conditions are generally used after an “if” or “unless” statement, for instance, to block http requests to the “*” url with methods other than acl missing_cl hdr_cnt(content-length) eq 0 to select a different backend for requests to static contents on the “www” site acl url_static path_beg /static /images /img /css use_backend static if host_static or host_www url_static it is also possible to form rules using “anonymous acls”. those are unnamed acl the following rule : can also be written that way : it is generally not recommended to use this construct because it’s a lot easier with named acls : with anonymous acls : see section 4.2 for detailed help on the “block” and “use_backend” keywords. historically, sample fetch methods were only used to retrieve data to match this section details all available sample fetch methods and their output type. the acl derivatives are also indicated when available, with their respective as indicated in the sample type versus matching compatibility matrix above, some of these keywords support one or multiple mandatory arguments, and one or thus, the syntax of a standard sample fetch method is one of the following : sample fetch methods may be combined with transformations to be applied on top these transformations are enumerated as a series of specific keywords after the a certain category of converters are bitwise and arithmetic operators which the currently available list of transformation keywords include : add( and( base64 bool bytes( cpl crc32([ da-csv( example: debug div( djb2([ even field( hex http_date([ in_table( ipmask( json([ the utf-8 json encoding can produce a “too long value” error when the utf-8 this converter is particularly useful for building properly escaped json for example: input request from client 127.0.0.1: output log: language( example : lower ltime( example : map( it is important to avoid overlapping between the keys : ip addresses and the following array contains the list of all map functions avalaible sorted by input type | match method | output type str | output type int | output type ip the file contains one key + value per line. lines which start with ‘#’ are example : mod( mul( neg not odd or( regsub( example : capture-req( see also: “declare capture”, “http-request capture”, capture-res( see also: “declare capture”, “http-request capture”, sdbm([ set-var() sub( table_bytes_in_rate( table_bytes_out_rate( table_conn_cnt( table_conn_cur( table_conn_rate( table_gpc0( table_gpc0_rate( table_http_err_cnt( table_http_err_rate( table_http_req_cnt( table_http_req_rate( table_kbytes_in( table_kbytes_out( table_server_id( table_sess_cnt( table_sess_rate( table_trackers( upper url_dec utime( example : word( wt6([ xor( a first set of sample fetch methods applies to internal information which does always_false : boolean always_true : boolean avg_queue([ be_conn([ be_sess_rate([ example : bin( bool( connslots([ the basic idea here is to be able to measure the number of connection “slots” ‘connslots’ = number of available server connection slots, + number of note that while “fe_conn” may be used, “connslots” comes in especially other caveats and notes: at this point in time, the code does not take care date([ example : env( examples : fe_conn([ fe_sess_rate([ example : int( ipv4( ipv6( meth( nbproc : integer nbsrv([ proc : integer queue([ rand([ srv_conn([ srv_is_up([ srv_sess_rate([ example : stopping : boolean str( table_avl([ table_cnt([ var( the layer 4 usually describes just the transport layer which in haproxy is be_id : integer dst : ip dst_conn : integer dst_port : integer fe_id : integer sc_bytes_in_rate( sc_bytes_out_rate( sc_clr_gpc0( sc_conn_cnt( sc_conn_cur( sc_conn_rate( sc_get_gpc0( sc_gpc0_rate( sc_http_err_cnt( sc_http_err_rate( sc_http_req_cnt( sc_http_req_rate( sc_inc_gpc0( sc_kbytes_in( sc_kbytes_out( sc_sess_cnt( sc_sess_rate( sc_tracked( sc_trackers( so_id : integer src : ip example: src_bytes_in_rate([ src_bytes_out_rate([ src_clr_gpc0([ src_conn_cnt([ src_conn_cur([ src_conn_rate([ src_get_gpc0([ src_gpc0_rate([ src_http_err_cnt([ src_http_err_rate([ src_http_req_cnt([ src_http_req_rate([ src_inc_gpc0([ src_kbytes_in([ src_kbytes_out([ src_port : integer src_sess_cnt([ src_sess_rate([ src_updt_conn_cnt([ example : srv_id : integer the layer 5 usually describes just the session layer which in haproxy is ssl_bc : boolean ssl_bc_alg_keysize : integer ssl_bc_cipher : string ssl_bc_protocol : string ssl_bc_unique_id : binary ssl_bc_session_id : binary ssl_bc_use_keysize : integer ssl_c_ca_err : integer ssl_c_ca_err_depth : integer ssl_c_der : binary ssl_c_err : integer ssl_c_i_dn([ ssl_c_key_alg : string ssl_c_notafter : string ssl_c_notbefore : string ssl_c_s_dn([ ssl_c_serial : binary ssl_c_sha1 : binary ssl_c_sig_alg : string ssl_c_used : boolean ssl_c_verify : integer ssl_c_version : integer ssl_f_der : binary ssl_f_i_dn([ ssl_f_key_alg : string ssl_f_notafter : string ssl_f_notbefore : string ssl_f_s_dn([ ssl_f_serial : binary ssl_f_sha1 : binary ssl_f_sig_alg : string ssl_f_version : integer ssl_fc : boolean example : ssl_fc_alg_keysize : integer ssl_fc_alpn : string ssl_fc_cipher : string ssl_fc_has_crt : boolean ssl_fc_has_sni : boolean ssl_fc_is_resumed: boolean ssl_fc_npn : string ssl_fc_protocol : string ssl_fc_unique_id : binary ssl_fc_session_id : binary ssl_fc_sni : string this fetch is different from “req_ssl_sni” above in that it applies to the acl derivatives : ssl_fc_use_keysize : integer fetching samples from buffer contents is a bit different from the previous payload( payload_lv( req.len : integer req.payload( acl alternatives : req.payload_lv( acl alternatives : example : please consult the example from the “stick store-response” keyword. req.proto_http : boolean example: req.rdp_cookie([ this differs from “balance rdp-cookie” in that any balancing algorithm may be acl derivatives : example : see also : “balance rdp-cookie”, “persist rdp-cookie”, “tcp-request” and the req.rdp_cookie_cnt([name]) : integer acl derivatives : req.ssl_ec_ext : boolean req.ssl_hello_type : integer req.ssl_sni : string acl derivatives : examples : res.ssl_hello_type : integer req.ssl_ver : integer acl derivatives : res.len : integer res.payload( res.payload_lv( example : please consult the example from the “stick store-response” keyword. wait_end : boolean examples : it is possible to fetch samples from http contents, requests and responses. base : string acl derivatives : base32 : integer base32+src : binary capture.req.hdr( capture.req.method : string capture.req.uri : string capture.req.ver : string capture.res.hdr( capture.res.ver : string req.body : binary req.body_param([ req.body_len : integer req.body_size : integer req.cook([ acl derivatives : req.cook_cnt([ req.cook_val([ cookie([ hdr([ req.fhdr( req.fhdr_cnt([ req.hdr([ acl derivatives :
add-header
capture
del-header
replace-header
replace-value
set-method
set-uri
add-acl(
del-acl(
del-map(
set-map(
set-var()
{ track-sc0 | track-sc1 | track-sc2 } ] |
lua
}
[ { if | unless }
access control for layer 7 requests
no | yes | yes | yes
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 is true.
- “allow” : this stops the evaluation of the rules and lets the request
pass the check. no further “http-request” rules are evaluated.- "deny" : this stops the evaluation of the rules and immediately rejects
the request and emits an http 403 error. no further "http-request" rules
are evaluated.
- "tarpit" : 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, an http error 500 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.
- "auth" : 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).
- "redirect" : 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 can be processed in the middle of other
"http-request" rules and that these rules use the "log-format" strings.
see the "redirect" keyword for the rule's syntax.
- "add-header" appends an http header field whose name is specified in
<name> and whose value is defined by <fmt> which follows the log-format
rules (see custom log format in section 8.2.4). this is particularly
useful to pass connection-specific information to the server (eg: 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.
- "set-header" does the same as "add-header" except that the header name
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. note that the new value is computed before the removal so
it is possible to concatenate a value to an existing header.
- "del-header" removes all http header fields whose name is specified in
<name>.
- "replace-header" matches the regular expression in all occurrences of
header field <name> according to <match-regex>, and replaces them with
the <replace-fmt> argument. format characters are allowed in replace-fmt
and work like in <fmt> arguments in "add-header". the match is only
case-sensitive. it is important to understand that this action only
considers whole header lines, regardless of the number of values they
may contain. this usage is suited to headers naturally containing commas
in their value, such as if-modified-since and so on.
example:
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
- "replace-value" 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
header.
example:
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
- "set-method" 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.
- "set-path" 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 "set-query" and "set-uri".
example :
# prepend the host name before the path
http-request set-path /%[hdr(host)]%[path]
- "set-query" 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 "set-query" and "set-uri".
example :
# replace "%3d" with "=" in the query string
http-request set-query %[query,regsub(%3d,=,g)]
- "set-uri" 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. see also "set-path" and
"set-query".
- "set-nice" sets the "nice" factor of the current request 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.
- "set-log-level" 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.
- "set-tos" is used to set the tos or dscp field value of packets sent to
the client to the value passed in <tos> on platforms which support this.
this value represents the whole 8 bits of the ip tos field, and can be
expressed both in decimal or hexadecimal format (prefixed by "0x"). note
that only the 6 higher bits are used in dscp or tos, and the two lower
bits are always 0\. this can be used to adjust some routing behaviour on
border routers based on some information from the request. see rfc 2474,
2597, 3260 and 4594 for more information.
- "set-mark" is used to set the netfilter mark on all packets sent to the
client to the value passed in <mark> on platforms which support it. this
value is an unsigned 32 bit value which can be matched by netfilter and
by the routing table. it can be expressed both in decimal or hexadecimal
format (prefixed by "0x"). this 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.
- "add-acl" 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 log-format rules, to collect content of the new entry. it
performs a lookup in the acl before insertion, to avoid duplicated (or
more) values. this lookup is done by a linear search and can be expensive
with large lists! it is the equivalent of the "add acl" command from the
stats socket, but can be triggered by an http request.
- "del-acl" 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 log-format rules, 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.
- "del-map" is used to delete an entry from a map. the map must be loaded
from a file (even a dummy empty file). the file name of the map to be
updated is passed between parentheses. it takes one argument: <key fmt>,
which follows log-format rules, 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.
- "set-map" is used to add a new entry into a map. the map must be loaded
from a file (even a dummy empty file). the file name of the map to be
updated is passed between parentheses. it takes 2 arguments: <key fmt>,
which follows log-format rules, used to collect map key, and <value fmt>,
which follows 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. this lookup is done by a linear search and can be expensive
with large lists! it is the equivalent of the "set map" command from the
stats socket, but can be triggered by an http request.
- capture <sample> [ len <length> | id <id> ] :
captures sample expression <sample> from the request buffer, and converts
it to a string of at most <len> characters. the resulting string is
stored into the next request "capture" slot, 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 rules
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
session life. please check section 7.3 (fetching samples) and "capture
request 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.
- { track-sc0 | track-sc1 | track-sc2 } <key> [table <table>] :
enables tracking of sticky counters from current request. these rules
do not stop evaluation and do not change default action. three sets of
counters may be simultaneously tracked by the same connection. 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.
these actions take one or two arguments :
<key> is mandatory, and is a sample expression rule as described
in section 7.3\. it describes what elements of the incoming
request or connection will be analysed, 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.
- "lua" is used to run a lua function if the action is executed. the single
parameter is the name of the function to run. the prototype of the
function is documented in the api documentation.
- set-var(<var-name>) <expr> :
is used to set the contents of a variable. the variable is declared
inline.
<var-name> the name of the variable starts by an indication about its
scope. the allowed scopes are:
"sess" : the variable is shared with all the session,
"txn" : the variable is shared with all the transaction
(request and response)
"req" : the variable is shared only during the request
processing
"res" : the variable is shared only during the response
processing.
this prefix is followed by a name. the separator is a '.'.
the name may only contain characters 'a-z', 'a-z', '0-9',
and '_'.
<expr> is a standard haproxy expression formed by a sample-fetch
followed by some converters.
example:
http-request set-var(req.my_var) req.fhdr(user-agent),lower
- set-src <expr> :
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.
<expr> is a standard haproxy expression formed by a sample-fetch
followed by some converters.
example:
http-request set-src hdr(x-forwarded-for)
http-request set-src src,ipmask(24)
when set-src is successful, the source port is set to 0.
the http processing, just after “block” rules and before “reqdel” or “reqrep”
rules. that way, headers added by “add-header”/“set-header” are visible by
almost all further acl 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 auth_ok http_auth_group(l1) g1
http-request auth unless auth_ok
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]
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]
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
about acl usage.
capture
set-header
replace-header
replace-value
set-log-level
add-acl(
del-acl(
del-map(
set-map(
set-var(
lua
}
[ { if | unless }
access control for layer 7 responses
no | yes | yes | yes
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 is true. since these rules apply on responses, the backend
rules are applied first, followed by the frontend’s rules.
- “allow” : this stops the evaluation of the rules and lets the response
pass the check. no further “http-response” rules are evaluated for the
current section.- "deny" : this stops the evaluation of the rules and immediately rejects
the response and emits an http 502 error. no further "http-response"
rules are evaluated.
- "add-header" appends an http header field whose name is specified in
<name> and whose value is defined by <fmt> which follows the log-format
rules (see custom log format in section 8.2.4). this may be used to send
a cookie to a client for example, or to pass some internal information.
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.
- "set-header" does the same as "add-header" except that the header name
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.
- "del-header" removes all http header fields whose name is specified in
<name>.
- "replace-header" matches the regular expression in all occurrences of
header field <name> according to <match-regex>, and replaces them with
the <replace-fmt> argument. format characters are allowed in replace-fmt
and work like in <fmt> arguments in "add-header". the match is only
case-sensitive. it is important to understand that this action only
considers whole header lines, regardless of the number of values they
may contain. this usage is suited to headers naturally containing commas
in their value, such as set-cookie, expires and so on.
example:
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.
- "replace-value" 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
header.
example:
http-response replace-value cache-control ^public$ private
applied to:
cache-control: max-age=3600, public
outputs:
cache-control: max-age=3600, private
- "set-nice" sets the "nice" factor of the current request 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.
- "set-log-level" 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.
- "set-tos" is used to set the tos or dscp field value of packets sent to
the client to the value passed in <tos> on platforms which support this.
this value represents the whole 8 bits of the ip tos field, and can be
expressed both in decimal or hexadecimal format (prefixed by "0x"). note
that only the 6 higher bits are used in dscp or tos, and the two lower
bits are always 0\. this can be used to adjust some routing behaviour on
border routers based on some information from the request. see rfc 2474,
2597, 3260 and 4594 for more information.
- "set-mark" is used to set the netfilter mark on all packets sent to the
client to the value passed in <mark> on platforms which support it. this
value is an unsigned 32 bit value which can be matched by netfilter and
by the routing table. it can be expressed both in decimal or hexadecimal
format (prefixed by "0x"). this 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.
- "add-acl" 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 log-format rules, to collect content of the new entry. it
performs a lookup in the acl before insertion, to avoid duplicated (or
more) values. this lookup is done by a linear search and can be expensive
with large lists! it is the equivalent of the "add acl" command from the
stats socket, but can be triggered by an http response.
- "del-acl" 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 log-format rules, 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 response.
- "del-map" is used to delete an entry from a map. the map must be loaded
from a file (even a dummy empty file). the file name of the map to be
updated is passed between parentheses. it takes one argument: <key fmt>,
which follows log-format rules, 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 response.
- "set-map" is used to add a new entry into a map. the map must be loaded
from a file (even a dummy empty file). the file name of the map to be
updated is passed between parentheses. it takes 2 arguments: <key fmt>,
which follows log-format rules, used to collect map key, and <value fmt>,
which follows 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. this lookup is done by a linear search and can be expensive
with large lists! it is the equivalent of the "set map" command from the
stats socket, but can be triggered by an http response.
- "lua" is used to run a lua function if the action is executed. the single
parameter is the name of the function to run. the prototype of the
function is documented in the api documentation.
- capture <sample> id <id> :
captures sample expression <sample> from the response buffer, and converts
it to a string. the resulting string is stored into the next request
"capture" slot, 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 rules to feed it into headers or
anything. please check section 7.3 (fetching samples) and "capture
response header" for more information.
the keyword "id" is the id of the capture slot which is used for storing
the string. the capture slot must be defined in an associated frontend.
this is useful to run captures in backends. the slot id can be declared by
a previous directive "http-response capture" or with the "declare capture"
keyword.
- "redirect" : this performs an http redirection based on a redirect rule.
this supports a format string similarly to "http-request redirect" rules,
with the exception that only the "location" type of redirect is possible
on the response. see the "redirect" keyword for the rule's syntax. when
a redirect rule is applied during a response, connections to the server
are closed so that no data can be forwarded from the server to the client.
- set-var(<var-name>) expr:
is used to set the contents of a variable. the variable is declared
inline.
<var-name> the name of the variable starts by an indication about its
scope. the allowed scopes are:
"sess" : the variable is shared with all the session,
"txn" : the variable is shared with all the transaction
(request and response)
"req" : the variable is shared only during the request
processing
"res" : the variable is shared only during the response
processing.
this prefix is followed by a name. the separator is a '.'.
the name may only contain characters 'a-z', 'a-z', '0-9',
and '_'.
<expr> is a standard haproxy expression formed by a sample-fetch
followed by some converters.
example:
http-response set-var(sess.last_redir) res.hdr(location)
the http processing, before “reqdel” or “reqrep” rules. that way, headers
added by “add-header”/“set-header” are visible by almost all further acl
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
acl usage.
add the server name to a request. use the header string given by
yes | no | yes | yes<header> the header string to use to send the server name
server to be added to the headers of an http request. the name
is added with the header string proved.
set a persistent id to a proxy.
may be used in sections : defaults | frontend | listen | backend
no | yes | yes | yes
arguments : none
an unused id will automatically be assigned if unset. the first assigned
value will be 1. this id is currently only returned in statistics.
declare a condition to ignore persistence
may be used in sections: defaults | frontend | listen | backend
no | yes | yes | yes
the cookie are unconditionally persistent (assuming the target server is up
and running).
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 appsession table won’t grow if persistence is ignored.
“unless” condition is met.
log
no log
enable per-instance logging of events and traffic.
may be used in sections : defaults | frontend | listen | backend
yes | yes | yes | yes
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
entries found in the “global” section. only one “log global”
statement may be used per instance, and this form takes no other
parameter.
<address> 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 writeable).
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-formated logs may require larger values.
<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
<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
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”.
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.
being emitted.
log global
log 127.0.0.1:514 local0 notice # only send important events
log 127.0.0.1:514 local0 notice notice # same but limit output level
log “${local_syslog}:514” local0 notice # send to local server
specifies the log format string to use for traffic logs
may be used in sections: defaults | frontend | listen | backend
yes | yes | yes | no
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.4 which covers the log format
string in depth.
specifies the log tag to use for all outgoing logs
may be used in sections: defaults | frontend | listen | backend
yes | yes | yes | yes
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 sections: defaults | frontend | listen | backend
yes | no | yes | yes
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.
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 (eg: 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.
server consecutively to a 401 response. they will still go to the same server
even if they have to be queued.
“maxconn” and cookie persistence.
fix the maximum number of concurrent connections on a frontend
may be used in sections : defaults | frontend | listen | backend
yes | yes | yes | no
arguments :
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.
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 8kb each, as well as some other data resulting in about 17 kb of ram being
consumed per established connection. that means that a medium system equipped
with 1gb of ram can withstand around 40000-50000 concurrent connections if
properly tuned.
are not sized to accept such loads, and for this reason it is generally wise
to assign them some reasonable connection limits.
set the running mode or protocol of the instance
may be used in sections : defaults | frontend | listen | backend
yes | yes | yes | yes
arguments :
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.
health the instance will work in "health" mode. it will just reply "ok"
to incoming connections and close the connection. alternatively,
if the "httpchk" option is set, "http/1.0 200 ok" will be sent
instead. nothing will be logged in either case. this mode is used
to reply to external components health checks. this mode is
deprecated and should not be used anymore as it is possible to do
the same and even better by combining tcp or http modes with the
"monitor" keyword.
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 sections : defaults | frontend | listen | backend
no | yes | yes | no
arguments :
if
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.
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
the connection to be immediately closed without any log. this allows another
equipment to probe the port and verify that it is still listening, without
forwarding the connection to a remote server.
accepted, the following response will be sent without waiting for a request,
then the connection will be closed : “http/1.0 200 ok”. 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 this
response is sent in raw format, without any transformation. this is important
as it means that it will not be ssl-encrypted on ssl listeners.
acls which are the only ones able to block them. these connections are short
lived and never wait for any data from the client. they cannot be logged, and
it is the intended purpose. they are only used to report haproxy’s health to
an upper component, nothing more. please note that “monitor fail” rules do
not apply to connections intercepted by “monitor-net”.
a frontend. if more than one is found, only the last one will be considered.
# addresses .252 and .253 are just probing us.
frontend www
monitor-net 192.168.0.252/31
intercept a uri used by external components’ monitor requests
may be used in sections : defaults | frontend | listen | backend
yes | yes | yes | no
arguments :
health status instead of forwarding the request.
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.
divert them using acls. they cannot be logged either, and it is the intended
purpose. 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).
# use /haproxy_test to report haproxy’s status
frontend www
mode http
monitor-uri /haproxy_test
no option abortonclose
enable or disable early dropping of aborted requests pending in queues.
may be used in sections : defaults | frontend | listen | backend
yes | no | yes | yes
arguments : none
the per-instance connection queue will inflate, and the response time will
increase respective to the size of the queue times the average per-session
response time. when clients will wait for more than a few seconds, they will
often hit the “stop” button on their browser, leaving a useless request in
the queue, and slowing down other users, and the servers as well, because the
request will eventually be served, then aborted at the first error
encountered while delivering the response.
close on the client side, http agents should be conservative and consider
that the client might only have closed its output channel while waiting for
the response. however, this introduces risks of congestion when lots of users
do the same, and is completely useless nowadays because probably no client at
all will close the session while waiting for the response. some http agents
support this behaviour (squid, apache, haproxy), and others do not (tux, most
hardware-based load balancers). so the probability for a closed input channel
to represent a user hitting the “stop” button is close to 100%, and the risk
of being the single component to break rare but valid traffic is extremely
low, which adds to the temptation to be able to abort a session early while
still not served and not pollute the servers.
“abortonclose”. by default (without the option) the behaviour is http
compliant and aborted requests will be served. but when the option is
specified, a session with an incoming channel closed will be aborted while
it is still possible, either pending in the queue for a connection slot, or
during the connection establishment if the server has not yet acknowledged
the connection request. this considerably reduces the queue size and the load
on saturated servers when users are tempted to click on stop, which in turn
reduces the response time for other users.
in a specific instance by prepending the “no” keyword before it.
no option accept-invalid-http-request
enable or disable relaxing of http request parsing
may be used in sections : defaults | frontend | listen | backend
yes | yes | yes | no
arguments : none
means that invalid characters in header names are not permitted and cause an
error to be returned to the client. this is the desired behaviour as such
forbidden characters are essentially used to build attacks exploiting server
weaknesses, and bypass security filtering. sometimes, a buggy browser or
server will emit invalid header names for whatever reason (configuration,
implementation) and the issue will not be immediately fixed. in such a case,
it is possible to relax haproxy’s header name parser to accept any character
even if that does not make sense, by specifying this option. similarly, 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
not allowed at all. haproxy always blocks a number of them (0..32, 127). the
remaining ones are blocked by default unless this option is enabled. this
option also relaxes the test on the http version, it allows http/0.9 requests
to pass through (no version specified) and multiple digits for both the major
and the minor version.
and open security breaches. it should only be deployed after a problem has
been confirmed.
requests, but the complete request will be captured in order to permit later
analysis using the “show errors” request on the unix stats socket. similarly,
requests containing invalid chars in the uri part will be logged. doing this
also helps confirming that the issue has been solved.
in a specific instance by prepending the “no” keyword before it.
stats socket.
no option accept-invalid-http-response
enable or disable relaxing of http response parsing
may be used in sections : defaults | frontend | listen | backend
yes | no | yes | yes
arguments : none
means that invalid characters in header names are not permitted and cause an
error to be returned to the client. this is the desired behaviour as such
forbidden characters are essentially used to build attacks exploiting server
weaknesses, and bypass security filtering. sometimes, a buggy browser or
server will emit invalid header names for whatever reason (configuration,
implementation) and the issue will not be immediately fixed. in such a case,
it is possible to relax haproxy’s header name parser to accept any character
even if that does not make sense, by specifying this option. this option also
relaxes the test on the http version format, it allows multiple digits for
both the major and the minor version.
and open security breaches. it should only be deployed after a problem has
been confirmed.
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.
in a specific instance by prepending the “no” keyword before it.
stats socket.
no option allbackups
use either all backup servers at a time or only the first one
may be used in sections : defaults | frontend | listen | backend
yes | no | yes | yes
arguments : none
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.
“sorry” page when an application is completely offline.
in a specific instance by prepending the “no” keyword before it.
no option checkcache
analyze all server responses and block responses with cacheable cookies
may be used in sections : defaults | frontend | listen | backend
yes | no | yes | yes
arguments : none
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.
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, 206, 300, 301, 410,
provided that the server has not set a “cache-control: public” header ;
- all those that come from a post request, provided that the server has not
set a ‘cache-control: public’ header ;
- 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)
just as if it was from an “rspdeny” filter, 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.
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 behaviours.
in a specific instance by prepending the “no” keyword before it.
no option clitcpka
enable or disable the sending of tcp keepalive packets on the client side
may be used in sections : defaults | frontend | listen | backend
yes | yes | yes | no
arguments : none
a server, and when the protocol involves very long sessions with long idle
periods (eg: remote desktops), there is a risk that one of the intermediate
components decides to expire a session which has remained idle for too long.
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.
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.
client side of a connection, which should help when session expirations are
noticed between haproxy and a client.
in a specific instance by prepending the “no” keyword before it.
enable continuous traffic statistics updates
may be used in sections : defaults | frontend | listen | backend
yes | yes | yes | no
arguments : none
only when a session 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 continuously,
during a whole session. recounting touches a hotpath directly so
it is not enabled by default, as it has small performance impact (~0.5%).
no option dontlog-normal
enable or disable logging of normal, successful connections
may be used in sections : defaults | frontend | listen | backend
yes | yes | yes | no
arguments : none
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.
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.
logging.
no option dontlognull
enable or disable logging of null connections
may be used in sections : defaults | frontend | listen | backend
yes | yes | yes | no
arguments : none
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.
environments (eg: internet), otherwise scans and other malicious activities
would not be logged.
in a specific instance by prepending the “no” keyword before it.
section 8 about logging.
no option forceclose
enable or disable active connection closing after response is transferred.
may be used in sections : defaults | frontend | listen | backend
yes | yes | yes | yes
arguments : none
the “connection: close” set by “option httpclose”, and if the client does not
close either, then the connection remains open till the timeout expires. this
causes high number of simultaneous connections on the servers and shows high
global session times in the logs.
actively close the outgoing server channel as soon as the server has finished
to respond and release some resources earlier than with “option httpclose”.
will disable sending of the “connection: close” header, but will still cause
the connection to be closed once the whole response is received.
http-server-close”, “option http-keep-alive”, or “option http-tunnel”.
in a specific instance by prepending the “no” keyword before it.
enable insertion of the x-forwarded-for header to requests sent to servers
may be used in sections : defaults | frontend | listen | backend
yes | yes | yes | yes
arguments :
matching
header name.
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 default “x-forwarded-for”. this can be useful where you might already
have a “x-forwarded-for” header from a different application (eg: stunnel),
and you need preserve it. also if your backend server doesn’t use the
“x-forwarded-for” header and requires different one (eg: zeus web servers
require “x-cluster-client-ip”).
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.
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.
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
“option forceclose”, “option http-keep-alive”
no option http-buffer-request
enable or disable waiting for whole http request body before proceeding
may be used in sections : defaults | frontend | listen | backend
yes | yes | yes | yes
arguments : none
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, or the first chunk is
complete in case of chunked encoding. it can have undesired side effects with
some applications abusing http by expecting unbufferred transmissions between
the frontend and the backend, so this should definitely not be used by
default.
no option http-ignore-probes
enable or disable logging of null connections and request timeouts
may be used in sections : defaults | frontend | listen | backend
yes | yes | yes | no
arguments : none
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
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.
in a specific instance by prepending the “no” keyword before it.
no option http-keep-alive
enable or disable http keep-alive from client to server
may be used in sections : defaults | frontend | listen | backend
yes | yes | yes | yes
arguments : none
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. this mode may be changed by several options such as
“option http-server-close”, “option forceclose”, “option httpclose” or
“option http-tunnel”. this option allows to set back the keep-alive mode,
which can be useful when another mode was used in a defaults section.
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 (eg: 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.
in this case, the server will need to be properly tuned to support high enough
connection counts because connections will last until the client sends another
request.
content switching or the load balancing algorithm, the idle connection will
immediately be closed and a new one re-opened. option “prefer-last-server” is
available to try optimize server selection so that if the server currently
attached to an idle connection is usable, it will be used.
servers, and some static servers might benefit from “option http-keep-alive”.
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.
http-server-close”, “option forceclose” or “option http-tunnel”. when backend
and frontend options differ, all of these 4 options have precedence over
“option http-keep-alive”.
“option prefer-last-server”, “option http-pretend-keepalive”,
“option httpclose”, and “1.1. the http transaction model”.
no option http-no-delay
instruct the system to favor low interactive delays over performance in http
may be used in sections : defaults | frontend | listen | backend
yes | yes | yes | yes
arguments : none
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.
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.
no option http-pretend-keepalive
define whether haproxy will announce keepalive to the server or not
may be used in sections : defaults | frontend | listen | backend
yes | yes | yes | yes
arguments : none
adds a “connection: close” header to the 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 immediate effect is that this prevents haproxy from
maintaining the client connection alive. a second effect is that a client or
a cache could receive an incomplete response without being aware of it, and
consider the response complete.
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
“forceclose” option. that way the client gets a normal response and the
connection is correctly closed on the server side.
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.
at least one of the frontend or backend holding a connection has it enabled.
this option may be combined with “option httpclose”, which will cause
keepalive to be announced to the server and close to be announced to the
client. this practice is discouraged though.
in a specific instance by prepending the “no” keyword before it.
“option http-keep-alive”
no option http-server-close
enable or disable http connection closing on the server side
may be used in sections : defaults | frontend | listen | backend
yes | yes | yes | yes
arguments : none
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. this mode may be changed by several options such
as “option http-server-close”, “option forceclose”, “option httpclose” or
“option http-tunnel”. 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 forceclose”.
it also permits non-keepalive capable servers to be served in keep-alive mode
to the clients if they conform to the requirements of rfc2616. 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”.
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.
at least one of the frontend or backend holding a connection has it enabled.
it disables and replaces any previous “option httpclose”, “option forceclose”,
“option http-tunnel” or “option http-keep-alive”. please check section 4
(“proxies”) to see how this option combines with others when frontend and
backend options differ.
in a specific instance by prepending the “no” keyword before it.
“option httpclose”, “option http-keep-alive”, and
“1.1. the http transaction model”.
no option http-tunnel
disable or enable http connection processing after first transaction
may be used in sections : defaults | frontend | listen | backend
yes | yes | yes | yes
arguments : none
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. this mode may be changed by several options such
as “option http-server-close”, “option forceclose”, “option httpclose” or
“option http-tunnel”.
the first response. this is the mode which was used by default in versions
1.0 to 1.5-dev21. it is the mode with the lowest processing overhead, which
is normally not needed anymore unless in very specific cases such as when
using an in-house protocol that looks like http but is not compatible, or
just to log one request per client in order to reduce log size. note that
everything which works at the http level, including header parsing/addition,
cookie processing or content switching will only work for the first request
and will be ignored after the first response.
in a specific instance by prepending the “no” keyword before it.
“option httpclose”, “option http-keep-alive”, and
“1.1. the http transaction model”.
no option http-use-proxy-header
make use of non-standard proxy-connection header instead of connection
may be used in sections : defaults | frontend | listen | backend
yes | yes | yes | no
arguments : none
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.
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 ‘*’. the
choice of header only affects requests passing through proxies making use of
one of the “httpclose”, “forceclose” and “http-server-close” options. note
that this option can only be specified in a frontend and will affect the
request along its whole life.
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.
http-server-close”.
option httpchk
option httpchk
option httpchk
enable http protocol to check on the servers health
may be used in sections : defaults | frontend | listen | backend
yes | no | yes | yes
arguments :
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, and as a trick, it is possible to pass it
after "\r\n" following the version string.
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.
plain tcp backends. this is particularly useful to check simple scripts bound
to some dedicated ports using the inetd daemon.
# 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\r\nhost:\ www
server apache1 192.168.1.1:443 check port 80
“option pgsql-check”, “http-check” and the “check”, “port” and
“inter” server options.
no option httpclose
enable or disable passive http connection closing
may be used in sections : defaults | frontend | listen | backend
yes | yes | yes | yes
arguments : none
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. this mode may be changed by several options such
as “option http-server-close”, “option forceclose”, “option httpclose” or
“option http-tunnel”.
if a “connection: close” header is already set in each direction, and will
add one if missing. each end should react to this by actively closing the tcp
connection after each transfer, thus resulting in a switch to the http close
mode. any “connection” header different from “close” will also be removed.
note that this option is deprecated since what it does is very cheap but not
reliable. using “option http-server-close” or “option forceclose” is strongly
recommended instead.
close the connection even though they reply “connection: close”. for this
reason, they are not compatible with older http 1.0 browsers. if this happens
it is possible to use the “option forceclose” which actively closes the
request connection once the server responds. option “forceclose” also
releases the server connection earlier because it does not have to wait for
the client to acknowledge it.
at least one of the frontend or backend holding a connection has it enabled.
it disables and replaces any previous “option http-server-close”,
“option forceclose”, “option http-keep-alive” or “option http-tunnel”. please
check section 4 (“proxies”) to see how this option combines with others when
frontend and backend options differ.
in a specific instance by prepending the “no” keyword before it.
“1.1. the http transaction model”.
enable logging of http request, session state and timers
may be used in sections : defaults | frontend | listen | backend
yes | yes | yes | yes
arguments :
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 analyser which only support the clf format and which is not
extensible.
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 session
status, the connections numbers, the captured headers and cookies, the
frontend, backend and server name, and of course the source address and
ports.
if it was set by default.
no option http_proxy
enable or disable plain http proxy mode
may be used in sections : defaults | frontend | listen | backend
yes | yes | yes | yes
arguments : none
basic proxy requests without caching nor any fancy feature. in this case,
it may be worth setting up an haproxy instance with the “option http_proxy”
set. in this mode, no server is declared, and the connection is forwarded to
the ip address and port found in the url after the “http://“ scheme.
addresses are passed. since this option’s usage perimeter is rather limited,
it will probably be used only by experts who know they need exactly it. last,
if the clients are susceptible of sending keep-alive requests, it will be
needed to add “option httpclose” to ensure that all requests will correctly
be analyzed.
in a specific instance by prepending the “no” keyword before it.
# this backend understands http proxy requests and forwards them directly.
backend direct_forward
option httpclose
option http_proxy
no option independent-streams
enable or disable independent timeout processing for both directions
may be used in sections : defaults | frontend | listen | backend
yes | yes | yes | yes
arguments : none
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.
exists a situation where it is desirable to disable it, and only refresh the
read timeout if there are incoming data. this happens on sessions 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.
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.
with a spelling mistake. this spelling is still supported but
deprecated.
use ldapv3 health checks for server testing
may be used in sections : defaults | frontend | listen | backend
yes | no | yes | yes
arguments : none
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.
resultcode (http://tools.ietf.org/html/rfc4511#section-4.1.9).
configure it.
option ldap-check
use external processes for server health checks
may be used in sections : defaults | frontend | listen | backend
yes | no | yes | yes
this is achieved by running the executable set using “external-check
command”.
no option log-health-checks
enable or disable logging of health checks status updates
may be used in sections : defaults | frontend | listen | backend
yes | no | yes | yes
arguments : none
health checks are logged if server is down, so the amount of additional
information is limited.
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.
the cli) are intentionally not logged by this option.
“option pgsql-check”, “option redis-check”, “option smtpchk”,
“option tcp-check”, “log” and section 8 about logging.
no option log-separate-errors
change log level for non-completely successful connections
may be used in sections : defaults | frontend | listen | backend
yes | yes | yes | no
arguments : none
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.
second may log normal traffic to a rotating buffer and only archive smaller
error logs.
logging.
no option logasap
enable or disable early logging of http requests
may be used in sections : defaults | frontend | listen | backend
yes | yes | yes | no
arguments : none
transfer time and the number of bytes appear in the logs. when large objects
are being transferred, it may take a while before the request appears in the
logs. using “option logasap”, the request gets logged as soon as the server
sends the complete headers. the only missing information in the logs will be
the total number of bytes which will indicate everything except the amount
of data transferred, and the total time which will not take the transfer
time into account. in such a situation, it’s a 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"
logging.
use mysql health checks for server testing
may be used in sections : defaults | frontend | listen | backend
yes | no | yes | yes
arguments :
server.
post-41 send post v4.1 client compatible checks
one client authentication packet, and one quit packet, to correctly close
mysql session. we then parse the mysql handshake initialisation 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 adding an authorization
in the mysql table, like this : use mysql;
insert into user (host,user) values ('<ip_of_haproxy>','<username>');
flush privileges;
check only consists in parsing the mysql handshake initialisation 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.
to do this, you can use an external check with xinetd for example.
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 cttproxy feature to be compiled in, and the mysql server
to route the client via the machine hosting haproxy.
no option nolinger
enable or disable immediate session resource cleaning after close
may be used in sections: defaults | frontend | listen | backend
yes | yes | yes | yes
arguments : none
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.
the system to immediately remove any socket’s pending data on close. thus,
the session is instantly purged from the system’s tables. this usually has
side effects such as increased number of tcp resets due to old retransmits
getting immediately rejected. some firewalls may sometimes complain about
this too.
needed. you know that you need it when you have thousands of fin_wait1
sessions on your system (time_wait ones do not count).
where it is required. use it on the frontend for clients, and on the backend
for servers.
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 sections : defaults | frontend | listen | backend
yes | yes | yes | yes
arguments :
matching
header name.
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 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.
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.
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
“option forceclose”
no option persist
enable or disable forced persistence on down servers
may be used in sections: defaults | frontend | listen | backend
yes | no | yes | yes
arguments : none
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.
in a specific instance by prepending the “no” keyword before it.
use postgresql health checks for server testing
may be used in sections : defaults | frontend | listen | backend
yes | no | yes | yes
arguments :
postgresql server.
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”.
no option prefer-last-server
allow multiple load balanced requests to remain on the same server
may be used in sections: defaults | frontend | listen | backend
yes | no | yes | yes
arguments : none
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). 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.
in a specific instance by prepending the “no” keyword before it.
option redispatch
no option redispatch
enable or disable session redistribution in case of connection failure
may be used in sections: defaults | frontend | listen | backend
yes | no | yes | yes
arguments :
occur when retrying connections. positive value p indicates a
redispatch is desired on every pth retry, and negative value
n indicate a redispath is desired on the nth retry prior to the
last retry. for example, the default of -1 preserves the
historical behaviour 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.
definitely stick to it because they cannot flush the cookie, so they will not
be able to access the service anymore.
persistence and redistribute them to a working server.
connection failures. of course, it requires having “retries” set to a nonzero
value.
“redisp” keywords.
in a specific instance by prepending the “no” keyword before it.
use redis health checks for server testing
may be used in sections : defaults | frontend | listen | backend
yes | no | yes | yes
arguments : none
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
option smtpchk
use smtp health checks for server testing
may be used in sections : defaults | frontend | listen | backend
yes | no | yes | yes
arguments :
be either “helo” (for smtp) or “ehlo” (for estmp). 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.
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.
request, it is possible that some servers do not log each connection attempt,
so you may want to experiment to improve the behaviour. using telnet on port
25 is often easier than adjusting the configuration.
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 cttproxy feature to be compiled in.
option smtpchk helo mydomain.org
no option socket-stats
may be used in sections : defaults | frontend | listen | backend
yes | yes | yes | no
no option splice-auto
enable or disable automatic kernel acceleration on sockets in both directions
may be used in sections : defaults | frontend | listen | backend
yes | yes | yes | yes
arguments : none
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.
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
in a specific instance by prepending the “no” keyword before it.
options “nosplice” and “maxpipes”
no option splice-request
enable or disable automatic kernel acceleration on sockets for requests
may be used in sections : defaults | frontend | listen | backend
yes | yes | yes | yes
arguments : none
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.
option splice-request
in a specific instance by prepending the “no” keyword before it.
“nosplice” and “maxpipes”
no option splice-response
enable or disable automatic kernel acceleration on sockets for responses
may be used in sections : defaults | frontend | listen | backend
yes | yes | yes | yes
arguments : none
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.
option splice-response
in a specific instance by prepending the “no” keyword before it.
“nosplice” and “maxpipes”
no option srvtcpka
enable or disable the sending of tcp keepalive packets on the server side
may be used in sections : defaults | frontend | listen | backend
yes | no | yes | yes
arguments : none
a server, and when the protocol involves very long sessions with long idle
periods (eg: remote desktops), there is a risk that one of the intermediate
components decides to expire a session which has remained idle for too long.
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.
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.
server side of a connection, which should help when session expirations are
noticed between haproxy and a server.
in a specific instance by prepending the “no” keyword before it.
use sslv3 client hello health checks for server testing
may be used in sections : defaults | frontend | listen | backend
yes | no | yes | yes
arguments : none
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.
and most servers tested do not even log the requests containing only hello
messages, which is appreciable.
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 sections: defaults | frontend | listen | backend
yes | no | yes | yes
lists in order to support send/expect types of health check sequences.
- 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 analysed. 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
analysed.
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.
# perform a pop check (analyse only server’s banner)
option tcp-check
tcp-check expect string +ok\ pop3\ ready comment pop\ protocol # perform an imap check (analyse 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 analyse the response 3 times)
option tcp-check
tcp-check comment ping\ phase
tcp-check send ping\r\n
tcp-check expect +ponge
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 analyse 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
no option tcp-smart-accept
enable or disable the saving of one ack packet during the accept sequence
may be used in sections : defaults | frontend | listen | backend
yes | yes | yes | no
arguments : none
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.
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.
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 behaviour by specifying “no option tcp-smart-accept”.
“option tcp-smart-accept”. for instance, it can make sense with some services
such as smtp where the server speaks first.
of doubt, consider setting it back to automatic values by prepending the
“default” keyword before it, or disabling it using the “no” keyword.
no option tcp-smart-connect
enable or disable the saving of one ack packet during the connect sequence
may be used in sections : defaults | frontend | listen | backend
yes | no | yes | yes
arguments : none
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.
it is not enabled by default because it makes network troubleshooting more
complex.
such as http. in other situations, if there is no data to send in place of
the ack, a normal ack is sent.
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 sections : defaults | frontend | listen | backend
yes | yes | yes | yes
arguments : none
a server, and when the protocol involves very long sessions with long idle
periods (eg: remote desktops), there is a risk that one of the intermediate
components decides to expire a session which has remained idle for too long.
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.
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.
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 session state and timers
may be used in sections : defaults | frontend | listen | backend
yes | yes | yes | yes
arguments : none
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 session 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.
no option transparent
enable client-side transparent proxying
may be used in sections : defaults | frontend | listen | backend
yes | no | yes | yes
arguments : none
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.
present the client’s ip to the server when establishing the connection.
“transparent” option of the “bind” keyword.
executable to run when performing an external-check
may be used in sections : defaults | frontend | listen | backend
yes | no | yes | yes
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
possible to determine a listener, and both
will have the string value “not_used”.
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).
path the path environment variable used when executing
the command may be set using "external-check path".
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 sections : defaults | frontend | listen | backend
yes | no | yes | yes
external-check path “/usr/bin:/bin”
“external-check command”
persist rdp-cookie(
enable rdp cookie-based persistence
may be used in sections : defaults | frontend | listen | backend
yes | no | yes | yes
arguments :
default cookie name “msts” will be used. there currently is no
valid reason to change this name.
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 analysed
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.
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.
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
the rdp_cookie pattern fetch function.
set a limit on the number of new sessions accepted per second on a frontend
may be used in sections : defaults | frontend | listen | backend
yes | yes | yes | no
arguments :
of new sessions per second to accept on the frontend.
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.
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.
listen smtp
mode tcp
bind :25
rate-limit sessions 10
server 127.0.0.1:1025
but its sockets appear as “waiting” in the statistics if the
“socket-stats” option is enabled.]
response. if no condition is specified, the redirect applies unconditionally.
the http “location” header. when used in an “http-request” rule,
dynamic values (see custom log format in section 8.2.4).<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 log-format
rules and can include some dynamic values (see custom log format
in section 8.2.4).
<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 log-format rules and can include some dynamic values (see
custom log format in section 8.2.4).
<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 permanently" 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 behaviour 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.
- "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.
- "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.
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
acl missing_slash path_reg ^/article/[^/]*$
redirect code 301 prefix / drop-query append-slash if missing_slash
redirect scheme https if !{ ssl_fc }
http-request redirect code 301 location www.%[hdr(host)]%[req.uri]
unless { hdr_beg(host) -i www }
redispatch (deprecated)
enable or disable session redistribution in case of connection failure
may be used in sections: defaults | frontend | listen | backend
yes | no | yes | yes
arguments : none
definitely stick to it because they cannot flush the cookie, so they will not
be able to access the service anymore.
redistribute them to a working server.
connection failures. of course, it requires having “retries” set to a nonzero
value.
“option redispatch” instead.
add a header at the end of the http request
may be used in sections : defaults | frontend | listen | backend
no | yes | yes | yes
arguments :
must be escaped using a backslash (‘'). please refer to section
6 about http header manipulation for more information.<cond> is an optional matching condition built from acls. it makes it
possible to ignore this rule when other conditions are not met.
the last header of an http request.
and not to traffic generated by haproxy, such as health-checks or error
responses.
acl is-ssl dst_port 81
reqadd x-proto:\ ssl if is-ssl
about acls.
reqiallow
definitely allow an http request if a line matches a regular expression
may be used in sections : defaults | frontend | listen | backend
no | yes | yes | yes
arguments :
request line. this is an extended regular expression. parenthesis
grouping is supported and no preliminary backslash is required.
any space or known delimiter must be escaped using a backslash
(‘'). the pattern applies to a full line at a time. the
“reqallow” keyword strictly matches case while “reqiallow”
ignores case.<cond> is an optional matching condition built from acls. it makes it
possible to ignore this rule when other conditions are not met.
result in a deny. the test applies both to the request line and to request
headers. keep in mind that urls in request line are case-sensitive while
header names are not.
reqdeny, reqallow and reqpass should be avoided in new designs.
# allow www.* but refuse *.local
reqiallow ^host:\ www.
reqideny ^host:\ .*.local
section 7 about acls.
reqidel
delete all headers matching a regular expression in an http request
may be used in sections : defaults | frontend | listen | backend
no | yes | yes | yes
arguments :
request line. this is an extended regular expression. parenthesis
grouping is supported and no preliminary backslash is required.
any space or known delimiter must be escaped using a backslash
(‘'). the pattern applies to a full line at a time. the “reqdel”
keyword strictly matches case while “reqidel” ignores case.<cond> is an optional matching condition built from acls. it makes it
possible to ignore this rule when other conditions are not met.
will be completely deleted. most common use of this is to remove unwanted
and/or dangerous headers or cookies from a request before passing it to the
next servers.
and not to traffic generated by haproxy, such as health-checks or error
responses. keep in mind that header names are not case-sensitive.
# remove x-forwarded-for header and server cookie
reqidel ^x-forwarded-for:.*
reqidel ^cookie:.*server=
manipulation, and section 7 about acls.
reqideny
deny an http request if a line matches a regular expression
may be used in sections : defaults | frontend | listen | backend
no | yes | yes | yes
arguments :
request line. this is an extended regular expression. parenthesis
grouping is supported and no preliminary backslash is required.
any space or known delimiter must be escaped using a backslash
(‘'). the pattern applies to a full line at a time. the
“reqdeny” keyword strictly matches case while “reqideny” ignores
case.<cond> is an optional matching condition built from acls. it makes it
possible to ignore this rule when other conditions are not met.
result in an allow. the test applies both to the request line and to request
headers. keep in mind that urls in request line are case-sensitive while
header names are not.
complete request has been parsed. this is consistent with what is practiced
using acls.
reqdeny, reqallow and reqpass should be avoided in new designs.
# refuse .local, then allow www.
reqideny ^host:\ .*.local
reqiallow ^host:\ www.
manipulation, and section 7 about acls.
reqipass
ignore any http request line matching a regular expression in next rules
may be used in sections : defaults | frontend | listen | backend
no | yes | yes | yes
arguments :
request line. this is an extended regular expression. parenthesis
grouping is supported and no preliminary backslash is required.
any space or known delimiter must be escaped using a backslash
(‘'). the pattern applies to a full line at a time. the
“reqpass” keyword strictly matches case while “reqipass” ignores
case.<cond> is an optional matching condition built from acls. it makes it
possible to ignore this rule when other conditions are not met.
the test applies both to the request line and to request headers. keep in
mind that urls in request line are case-sensitive while header names are not.
reqdeny, reqallow and reqpass should be avoided in new designs.
# refuse .local, then allow www., but ignore “www.private.local"
reqipass ^host:\ www.private\.local
reqideny ^host:\ .*.local
reqiallow ^host:\ www.
manipulation, and section 7 about acls.
reqirep
replace a regular expression with a string in an http request line
may be used in sections : defaults | frontend | listen | backend
no | yes | yes | yes
arguments :
request line. this is an extended regular expression. parenthesis
grouping is supported and no preliminary backslash is required.
any space or known delimiter must be escaped using a backslash
(‘'). the pattern applies to a full line at a time. the “reqrep”
keyword strictly matches case while “reqirep” ignores case.<string> is the complete line to be added. any space or known delimiter
must be escaped using a backslash ('\'). references to matched
pattern groups are possible using the common \n form, with n
being a single digit between 0 and 9\. please refer to section
6 about http header manipulation for more information.
<cond> is an optional matching condition built from acls. it makes it
possible to ignore this rule when other conditions are not met.
the request line and header lines) will be completely replaced with
most common use of this is to rewrite urls or domain names in “host” headers.
and not to traffic generated by haproxy, such as health-checks or error
responses. note that for increased readability, it is suggested to add enough
spaces between the request and the response. keep in mind that urls in
request line are case-sensitive while header names are not.
# replace “/static/“ with “/“ at the beginning of any request path.
reqrep ^([^\ :])\ /static/(.) \1\ /\2
# replace “www.mydomain.com" with “www” in the host name.
reqirep ^host:\ www.mydomain.com host:\ www
http header manipulation, and section 7 about acls.
reqitarpit
tarpit an http request containing a line matching a regular expression
may be used in sections : defaults | frontend | listen | backend
no | yes | yes | yes
arguments :
request line. this is an extended regular expression. parenthesis
grouping is supported and no preliminary backslash is required.
any space or known delimiter must be escaped using a backslash
(‘'). the pattern applies to a full line at a time. the
“reqtarpit” keyword strictly matches case while “reqitarpit”
ignores case.<cond> is an optional matching condition built from acls. it makes it
possible to ignore this rule when other conditions are not met.
be kept open for a pre-defined time, then will return an http error 500 so
that the attacker does not suspect it has been tarpitted. the status 500 will
be reported in the logs, but the completion flags will indicate “pt”. the
delay is defined by “timeout tarpit”, or “timeout connect” if the former is
not set.
identifiable requests. many robots limit their outgoing number of connections
and stay connected waiting for a reply which can take several minutes to
come. depending on the environment and attack, it may be particularly
efficient at reducing the load on the network and firewalls.
# ignore user-agents reporting any flavour of “mozilla” or “msie”, but
# block all others.
reqipass ^user-agent:.*(mozilla|msie)
reqitarpit ^user-agent: # block bad guys
acl badguys src 10.1.0.3 172.16.13.20/28
reqitarpit . if badguys
manipulation, and section 7 about acls.
set the number of retries to perform on a server after a connection failure
may be used in sections: defaults | frontend | listen | backend
yes | no | yes | yes
arguments :
a server when a connection either is refused or times out. the
default value is 3.
connection attempts, not full requests. when a connection has effectively
been established to a server, there will be no more retry.
a turn-around timer of min(“timeout connect”, one second) is applied before
a retry occurs.
server even if a cookie references a different server.
add a header at the end of the http response
may be used in sections : defaults | frontend | listen | backend
no | yes | yes | yes
arguments :
must be escaped using a backslash (‘'). please refer to section
6 about http header manipulation for more information.<cond> is an optional matching condition built from acls. it makes it
possible to ignore this rule when other conditions are not met.
the last header of an http response.
and not to traffic generated by haproxy, such as health-checks or error
responses.
about acls.
rspidel
delete all headers matching a regular expression in an http response
may be used in sections : defaults | frontend | listen | backend
no | yes | yes | yes
arguments :
response line. this is an extended regular expression, so
parenthesis grouping is supported and no preliminary backslash
is required. any space or known delimiter must be escaped using
a backslash (‘'). the pattern applies to a full line at a time.
the “rspdel” keyword strictly matches case while “rspidel”
ignores case.<cond> is an optional matching condition built from acls. it makes it
possible to ignore this rule when other conditions are not met.
will be completely deleted. most common use of this is to remove unwanted
and/or sensitive headers or cookies from a response before passing it to the
client.
and not to traffic generated by haproxy, such as health-checks or error
responses. keep in mind that header names are not case-sensitive.
# remove the server header from responses
rspidel ^server:.*
manipulation, and section 7 about acls.
rspideny
block an http response if a line matches a regular expression
may be used in sections : defaults | frontend | listen | backend
no | yes | yes | yes
arguments :
response line. this is an extended regular expression, so
parenthesis grouping is supported and no preliminary backslash
is required. any space or known delimiter must be escaped using
a backslash (‘'). the pattern applies to a full line at a time.
the “rspdeny” keyword strictly matches case while “rspideny”
ignores case.<cond> is an optional matching condition built from acls. it makes it
possible to ignore this rule when other conditions are not met.
response line and to response headers. keep in mind that header names are not
case-sensitive.
block the response before it reaches the client. if a response is denied, it
will be replaced with an http 502 error so that the client never retrieves
any sensitive data.
rspdeny should be avoided in new designs.
# ensure that no content type matching ms-word will leak
rspideny ^content-type:.*/ms-word
and section 7 about acls.
rspirep
replace a regular expression with a string in an http response line
may be used in sections : defaults | frontend | listen | backend
no | yes | yes | yes
arguments :
response line. this is an extended regular expression, so
parenthesis grouping is supported and no preliminary backslash
is required. any space or known delimiter must be escaped using
a backslash (‘'). the pattern applies to a full line at a time.
the “rsprep” keyword strictly matches case while “rspirep”
ignores case.<string> is the complete line to be added. any space or known delimiter
must be escaped using a backslash ('\'). references to matched
pattern groups are possible using the common \n form, with n
being a single digit between 0 and 9\. please refer to section
6 about http header manipulation for more information.
<cond> is an optional matching condition built from acls. it makes it
possible to ignore this rule when other conditions are not met.
the response line and header lines) will be completely replaced with
and not to traffic generated by haproxy, such as health-checks or error
responses. note that for increased readability, it is suggested to add enough
spaces between the request and the response. keep in mind that header names
are not case-sensitive.
# replace “location: 127.0.0.1:8080” with “location: www.mydomain.com"
rspirep ^location:\ 127.0.0.1:8080 location:\ www.mydomain.com
manipulation, and section 7 about acls.
declare a server in a backend
may be used in sections : defaults | frontend | listen | backend
no | no | yes | yes
arguments :
appear in logs and alerts. if “http-send-name-header” is
set, it will be added to the request header sent to the server.<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)
you may want to reference some environment variables in the
address parameter, see section 2.3 about environment
variables.
<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”
server options
source
source
set the source address for outgoing connections
may be used in sections : defaults | frontend | listen | backend
yes | no | yes | yes
arguments :
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)
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.
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.
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.
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.
required to force the source address. in fact, cttproxy version 2 requires an
ip address in
ip address because it creates nat entries which much match the exact outgoing
address. tproxy version 4 and some other kernel patches which work in pure
forwarding mode generally will not have this limitation.
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.
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)
the linux kernel on www.balabit.com, the “bind” keyword.
set the maximum inactivity time on the server side.
may be used in sections : defaults | frontend | listen | backend
yes | no | yes | yes
arguments :
can be in any other unit if the number is suffixed by the unit,
as explained at the top of this document.
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.
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 (eg: 4 or 5 seconds minimum).
“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 results in accumulation of expired sessions in
the system if the system’s timeouts are not configured either.
please use “timeout server” instead.
“clitimeout”.
enable statistics admin level if/unless a condition is matched
may be used in sections : defaults | frontend | listen | backend
no | yes | yes | yes
matched.
default, statistics page is read-only for security reasons.
unless you know what you do : memory is not shared between the
processes, which can result in random behaviours.
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.
# 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 haproxybackend 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
“bind-process”, section 3.4 about userlists and section 7 about
acl usage.
enable statistics with authentication and grant access to an account
may be used in sections : defaults | frontend | listen | backend
yes | yes | yes | yes
arguments :
<passwd> is the cleartext password associated to this user
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”.
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.
report using “stats scope”.
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 sections : defaults | frontend | listen | backend
yes | yes | yes | yes
arguments : none
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
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 sections : defaults | frontend | listen | backend
yes | yes | yes | yes
arguments : none
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.
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
[ { if | unless }
access control for statistics
no | no | yes | yes
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.
instance.
about acl usage.
enable statistics and set authentication realm
may be used in sections : defaults | frontend | listen | backend
yes | yes | yes | yes
arguments :
the browser. the browser uses it to display it in the pop-up
inviting the user to enter a valid username and password.
using a backslash (‘').
only related to authentication.
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 sections : defaults | frontend | listen | backend
yes | yes | yes | yes
arguments :
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.
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
he wants automatic refresh of the page or not.
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 sections : defaults | frontend | listen | backend
yes | yes | yes | yes
arguments :
reported. the special name “.” (a single dot) designates the
section in which the statement appears.
statement will appear in the report. all other ones will be hidden. 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.
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 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.
customers, where node or description should be different for each customer.
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
global section.
enable reporting additional information on the statistics page
may be used in sections : defaults | frontend | listen | backend
yes | yes | yes | yes
arguments : none
- cap: capabilities (proxy)
- mode: one of tcp, http or health (proxy)
- id: snmp id (proxy, socket, server)
- ip (socket, server)
- cookie (backend, server)
recommended to set all other settings in order to avoid relying on default
unobvious parameters. default behaviour is not to show this information.
enable reporting of a host name on the statistics page.
may be used in sections : defaults | frontend | listen | backend
yes | yes | yes | yes
arguments:
node name from global section is automatically used instead.
customers, where node or description might be different on a stats page
provided for each customer. default behaviour is not to show host name.
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
section.
enable statistics and define the uri prefix to access them
may be used in sections : defaults | frontend | listen | backend
yes | yes | yes | yes
arguments :
prefix may contain a question mark (‘?’) to indicate part of a
query string.
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.
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.
statement in a “listen” instance of its own. that makes it easy to dedicate
an address or a port to statistics only.
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
] [{if | unless}
define a request pattern matching condition to stick a user to a server
may be used in sections : defaults | frontend | listen | backend
no | no | yes | yes
describes what elements of the incoming request or connection
will be analysed 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.
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.
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.
will apply, using “if” or “unless” followed by a condition. see section 7 for
acl based conditions.
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.
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.
unless you know what you do : memory is not shared between the
processes, which can result in random behaviours.
# 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:110backend smtp
mode tcp
balance roundrobin
stick match src table pop
server s1 192.168.1.1:25
server s2 192.168.1.1:25
about acls and samples fetching.] [{if | unless}
define a request pattern to associate a user to a server
may be used in sections : defaults | frontend | listen | backend
no | no | yes | yes
“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.
unless you know what you do : memory is not shared between the
processes, which can result in random behaviours.
# 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
] [{if | unless}
define a request pattern used to create an entry in a stickiness table
may be used in sections : defaults | frontend | listen | backend
no | no | yes | yes
describes what elements of the incoming request or connection
will be analysed, 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.
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.
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.
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 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.
established, so that the table will contain the real server that processed
the request.
unless you know what you do : memory is not shared between the
processes, which can result in random behaviours.
# 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:110backend smtp
mode tcp
balance roundrobin
stick match src table pop
server s1 192.168.1.1:25
server s2 192.168.1.1:25
about acls and sample fetching.
size
[store
configure the stickiness table for the current section
may be used in sections : defaults | frontend | listen | backend
no | yes | yes | yes
ip a table declared with “type ip” will only store ipv4 addresses.
this form is very compact (about 50 bytes per entry) and allows
very fast entry lookup and stores with almost no overhead. this
is mainly used to store client source ip addresses.ipv6 a table declared with "type ipv6" will only store ipv6 addresses.
this form is very compact (about 60 bytes per entry) and allows
very fast entry lookup and stores with almost no overhead. this
is mainly used to store client source ip addresses.
integer a table declared with "type integer" will store 32bit integers
which can represent a client identifier found in a request for
instance.
string a table declared with "type string" will store substrings of up
to <len> characters. if the string provided by the pattern
extractor is larger than <len>, it will be truncated before
being stored. during matching, at most <len> characters will be
compared between the string in the table and the extracted
pattern. when not specified, the string is automatically limited
to 32 characters.
binary a table declared with "type binary" will store binary blocks
of <len> bytes. if the block provided by the pattern
extractor is larger than <len>, it will be truncated before
being stored. if the block provided by the sample expression
is shorter than <len>, it will be padded by 0\. when not
specified, the block is automatically limited to 32 bytes.
<length> is the maximum number of characters that will be stored in a
"string" type table (see type "string" above). or the number
of bytes of the block in "binary" type table. be careful when
changing this parameter as memory usage will proportionally
increase.
<size> is the maximum number of entries that can fit in the table. this
value directly impacts memory usage. count approximately
50 bytes per entry, plus the size of a string if any. the size
supports suffixes "k", "m", "g" for 2^10, 2^20 and 2^30 factors.
[nopurge] indicates that we refuse to purge older entries when the table
is full. when not specified and the table is full when haproxy
wants to store an entry in it, it will flush a few of the oldest
entries in order to release some space for the new ones. this is
most often the desired behaviour. in some specific cases, it
be desirable to refuse new entries instead of purging the older
ones. that may be the case when the amount of data to store is
far above the hardware limits and we prefer not to offer access
to new clients than to reject the ones already connected. when
using this parameter, be sure to properly set the "expire"
parameter (see below).
<peersect> is the name of the peers section to use for replication. entries
which associate keys to server ids are kept synchronized with
the remote peers declared in this section. all entries are also
automatically learned from the local peer (old process) during a
soft restart.
note : each peers section may be referenced only by tables
belonging to the same unique process.
<expire> defines the maximum duration of an entry in the table since it
was last created, refreshed or matched. the expiration delay is
defined using the standard time format, similarly as the various
timeouts. the maximum duration is slightly above 24 days. see
section 2.2 for more information. if this delay is not specified,
the session won't automatically expire, but older entries will
be removed once full. be sure not to use the "nopurge" parameter
if not expiration delay is specified.
may be used by acls in order to control various criteria related
to the activity of the client matching the stick-table. for each
item specified here, the size of each entry will be inflated so
that the additional data can fit. several data types may be
stored with an entry. multiple data types may be specified after
the “store” keyword, as a comma-separated list. alternatively,
it is possible to repeat the “store” keyword followed by one or
several data types. except for the “server_id” type which is
automatically detected and enabled, all data types must be
explicitly declared to be stored. if an acl references a data
type which is not stored, the acl will simply not match. some
data types require an argument which must be passed just after
the type between parenthesis. see below for the supported data
types and their arguments.
- server_id : this is an integer which holds the numeric id of the server a
request was assigned to. it is used by the “stick match”, “stick store”,
and “stick on” rules. it is automatically enabled when referenced.- gpc0 : first general purpose counter. it is a positive 32-bit integer
integer which may be used for anything. most of the time it will be used
to put a special tag on some entries, for instance to note that a
specific behaviour was detected and must be known for future matches.
- gpc0_rate(<period>) : increment rate of the first general purpose counter
over a period. it is a positive 32-bit integer integer which may be used
for anything. just like <gpc0>, it counts events, but instead of keeping
a cumulative count, it maintains the rate at which the counter is
incremented. most of the time it will be used to measure the frequency of
occurrence of certain events (eg: requests to a specific url).
- conn_cnt : connection count. it is a positive 32-bit integer which counts
the absolute number of connections received from clients which matched
this entry. it does not mean the connections were accepted, just that
they were received.
- conn_cur : current connections. it is a positive 32-bit integer which
stores the concurrent connection counts for the entry. it is incremented
once an incoming connection matches the entry, and decremented once the
connection leaves. that way it is possible to know at any time the exact
number of concurrent connections for an entry.
- conn_rate(<period>) : frequency counter (takes 12 bytes). it takes an
integer parameter <period> which indicates in milliseconds the length
of the period over which the average is measured. it reports the average
incoming connection rate over that period, in connections per period. the
result is an integer which can be matched using acls.
- sess_cnt : session count. it is a positive 32-bit integer which counts
the absolute number of sessions received from clients which matched this
entry. a session is a connection that was accepted by the layer 4 rules.
- sess_rate(<period>) : frequency counter (takes 12 bytes). it takes an
integer parameter <period> which indicates in milliseconds the length
of the period over which the average is measured. it reports the average
incoming session rate over that period, in sessions per period. the
result is an integer which can be matched using acls.
- http_req_cnt : http request count. it is a positive 32-bit integer which
counts the absolute number of http requests received from clients which
matched this entry. it does not matter whether they are valid requests or
not. note that this is different from sessions when keep-alive is used on
the client side.
- http_req_rate(<period>) : frequency counter (takes 12 bytes). it takes an
integer parameter <period> which indicates in milliseconds the length
of the period over which the average is measured. it reports the average
http request rate over that period, in requests per period. the result is
an integer which can be matched using acls. it does not matter whether
they are valid requests or not. note that this is different from sessions
when keep-alive is used on the client side.
- http_err_cnt : http error count. it is a positive 32-bit integer which
counts the absolute number of http requests errors induced by clients
which matched this entry. errors are counted on invalid and truncated
requests, as well as on denied or tarpitted requests, and on failed
authentications. if the server responds with 4xx, then the request is
also counted as an error since it's an error triggered by the client
(eg: vulnerability scan).
- http_err_rate(<period>) : frequency counter (takes 12 bytes). it takes an
integer parameter <period> which indicates in milliseconds the length
of the period over which the average is measured. it reports the average
http request error rate over that period, in requests per period (see
http_err_cnt above for what is accounted as an error). the result is an
integer which can be matched using acls.
- bytes_in_cnt : client to server byte count. it is a positive 64-bit
integer which counts the cumulated amount of bytes received from clients
which matched this entry. headers are included in the count. this may be
used to limit abuse of upload features on photo or video servers.
- bytes_in_rate(<period>) : frequency counter (takes 12 bytes). it takes an
integer parameter <period> which indicates in milliseconds the length
of the period over which the average is measured. it reports the average
incoming bytes rate over that period, in bytes per period. it may be used
to detect users which upload too much and too fast. warning: with large
uploads, it is possible that the amount of uploaded data will be counted
once upon termination, thus causing spikes in the average transfer speed
instead of having a smooth one. this may partially be smoothed with
"option contstats" though this is not perfect yet. use of byte_in_cnt is
recommended for better fairness.
- bytes_out_cnt : server to client byte count. it is a positive 64-bit
integer which counts the cumulated amount of bytes sent to clients which
matched this entry. headers are included in the count. this may be used
to limit abuse of bots sucking the whole site.
- bytes_out_rate(<period>) : frequency counter (takes 12 bytes). it takes
an integer parameter <period> which indicates in milliseconds the length
of the period over which the average is measured. it reports the average
outgoing bytes rate over that period, in bytes per period. it may be used
to detect users which download too much and too fast. warning: with large
transfers, it is possible that the amount of transferred data will be
counted once upon termination, thus causing spikes in the average
transfer speed instead of having a smooth one. this may partially be
smoothed with "option contstats" though this is not perfect yet. use of
byte_out_cnt is recommended for better fairness.
it does not seem useful to have multiple tables per proxy. if this happens
to be required, simply create a dummy backend with a stick-table in it and
reference it.
has some limitations, including the fact that all learned associations are
lost upon restart. in general it can be good as a complement but not always
as an exclusive stickiness.
indeed, storing all indicators above at once in each entry requires 116 bytes
per entry, or 116 mb for a 1-million entries table. this is definitely not
something that can be ignored.
# keep track of counters of up to 1 million ip addresses over 5 minutes
# and store a general purpose counter and the average connection rate
# computed over a sliding window of 30 seconds.
stick-table type ip size 1m expire 5m store gpc0,conn_rate(30s)
about time format and section 7 about acls.] [{if | unless}
define a request pattern used to create an entry in a stickiness table
may be used in sections : defaults | frontend | listen | backend
no | no | yes | yes
describes what elements of the response or connection will
be analysed, 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.
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.
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.
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 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.
# 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 rep_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 payload_lv(43,1) if clienthello
# learn on response if server hello.
stick store-response payload_lv(43,1) if serverhello
server s1 192.168.1.1:443
server s2 192.168.1.1:443
extraction.
opens a new connection
may be used in sections: defaults | frontend | listen | backend
no | no | yes | yes
load-balance many services in a single backend, it makes sense to probe all
the services individually before considering a server as operational.
directive, then the ‘tcp-check connect port
of the sequence.
the ruleset with a ‘connect’ rule. purpose is to ensure admin know what they
do.
they are optional and can be used to describe how haproxy should open and
use the tcp connection.port 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.
send-proxy send a proxy protocol string
ssl opens a ciphered connection
examples:
# 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
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 analysed during a generic health check
may be used in sections: defaults | frontend | listen | backend
no | no | yes | yes
response. the keyword may be one of “string”, “rstring” or
binary.
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 serie 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.
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.
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.
defined by the global “tune.chksize” 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 +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
“tcp-check send-binary”, “http-check expect”, tune.chksize
specify a string to be sent as a question during a generic health check
may be used in sections: defaults | frontend | listen | backend
no | no | yes | yes<data> : the data to be sent as a question during a generic health check
session. for now, <data> must be a string.
# look for the redis master server
option tcp-check
tcp-check send info\ replication\r\n
tcp-check expect string role:master
“tcp-check send-binary”, tune.chksize
specify an hexa digits string to be sent as a binary question during a raw
tcp health check
may be used in sections: defaults | frontend | listen | backend
no | no | yes | yes<data> : the data to be sent as a question during a generic health check
session. for now, <data> must be a string.
<hexastring> : 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 send binary data to ask on binary protocols.
# redis check in binary
option tcp-check
tcp-check send-binary 50494e470d0a # ping\r\n
tcp-check expect binary 2b504f4e47 # +pong
“tcp-check send”, tune.chksize
perform an action on an incoming connection depending on a layer 4 condition
may be used in sections : defaults | frontend | listen | backend
no | yes | yes | no
arguments :
actions include : “accept”, “reject”, “track-sc0”, “track-sc1”,
“track-sc2”, and “expect-proxy”. see below for more details.<condition> is a standard layer4-only acl-based condition (see section 7).
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.
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.
- accept :
accepts the connection if the condition is true (when used with “if”)
or false (when used with “unless”). the first such rule executed ends
the rules evaluation.- reject :
rejects the connection if the condition is true (when used with "if")
or false (when used with "unless"). the first such rule executed ends
the rules evaluation. 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.
- expect-proxy layer4 :
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.
- capture <sample> len <length> :
this only applies to "tcp-request content" rules. it captures sample
expression <sample> from the request buffer, and converts it to a
string of at most <len> characters. the resulting string is stored into
the next request "capture" slot, 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 rules 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
session life. please check section 7.3 (fetching samples) and "capture
request header" for more information.
- { track-sc0 | track-sc1 | track-sc2 } <key> [table <table>] :
enables tracking of sticky counters from current connection. these
rules do not stop evaluation and do not change default action. 3 sets
of counters may be simultaneously tracked by the same connection. 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.
these actions take one or two arguments :
<key> is mandatory, and is a sample expression rule as described
in section 7.3\. it describes what elements of the incoming
request or connection will be analysed, extracted, combined,
and used to select which table entry to update the counters.
note that "tcp-request connection" cannot use content-based
fetches.
<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. for example, connection counters will not be updated when
tracking layer 7 information, since the connection event happens before
layer7 information is extracted.
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.
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.
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
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 }
tcp-request connection expect-proxy layer4 if { src -f proxies.lst }
perform an action on a new session depending on a layer 4-7 condition
may be used in sections : defaults | frontend | listen | backend
no | yes | yes | yes
arguments :
actions include : “accept”, “reject”, “track-sc0”, “track-sc1”,
“track-sc2”, “capture” and “lua”. see “tcp-request connection”
above for their signification.<condition> is a standard layer 4-7 acl-based condition (see section 7).
called “tcp content inspection”. during this stage, acl-based rules are
evaluated every time the request contents are updated, until either an
“accept” or a “reject” rule matches, or the tcp request inspection delay
expires with no matching rule.
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.
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.
- accept : the request is accepted
- reject : the request is rejected and the connection is closed
- capture : the specified sample expression is captured
- { track-sc0 | track-sc1 | track-sc2 } ]
- lua
- set-var(
so please refer to that section for a complete description.
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 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.
rules, 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
backend connected to from an http frontend, it is guaranteed that http
contents will always be immediately present when the rule is evaluated first.
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.
function if the action is executed. the single parameter is the name of the
function to run. the prototype of the function is documented in the api
documentation.
declared inline.<var-name> the name of the variable starts by an indication about its scope.
the allowed scopes are:
"sess" : the variable is shared with all the session,
"txn" : the variable is shared with all the transaction
(request and response)
"req" : the variable is shared only during the request
processing
"res" : the variable is shared only during the response
processing.
this prefix is followed by a name. the separator is a '.'.
the name may only contain characters 'a-z', 'a-z', '0-9' and '_'.
<expr> is a standard haproxy expression formed by a sample-fetch
followed by some converters.
tcp-request content set-var(sess.my_var) src
# accept http requests containing a host header saying “example.com”
# and reject everything else.
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
# 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 from x-forwarded-for
tcp-request inspect-delay 10s
tcp-request content track-sc0 hdr(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
frontend when the backend detects abuse. frontend http
# use general purpose couter 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 gt 0
tcp-request content track-sc1 src
tcp-request content reject if click_too_fast mark_as_abuser
set the maximum allowed time to wait for data during content inspection
may be used in sections : defaults | frontend | listen | backend
no | yes | yes | yes
arguments :
can be in any other unit if the number is suffixed by the unit,
as explained at the top of this document.
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.
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.
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.
the timeout is reached and no rule matches, the default policy will be to let
it pass through unaffected.
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 (eg: smtp), or to wait for a client to talk before passing
data to the server (eg: 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.
“timeout client”.
perform an action on a session response depending on a layer 4-7 condition
may be used in sections : defaults | frontend | listen | backend
no | no | yes | yes
arguments :
actions include : “accept”, “close”, “reject”, “lua”.<condition> is a standard layer 4-7 acl-based condition (see section 7).
called “tcp content inspection”. during this stage, acl-based rules are
evaluated every time the response contents are updated, until either an
“accept”, “close” or a “reject” rule matches, or a tcp response inspection
delay is set and expires with no matching rule.
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.
- accept :
accepts the response if the condition is true (when used with “if”)
or false (when used with “unless”). the first such rule executed ends
the rules evaluation.- close :
immediately closes the connection with the server if the condition is
true (when used with "if"), or false (when used with "unless"). the
first such rule executed ends the rules evaluation. 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.
- reject :
rejects the response if the condition is true (when used with "if")
or false (when used with "unless"). the first such rule executed ends
the rules evaluation. rejected session are immediately closed.
- lua <function>
executes lua.
- set-var(<var-name>) <expr>
sets a variable.
the action, it is simply performed unconditionally. that can be useful for
for changing the default action to a reject.
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.
function if the action is executed. the single parameter is the name of the
function to run. the prototype of the function is documented in the api
documentation.
declared inline.<var-name> the name of the variable starts by an indication about its scope.
the allowed scopes are:
"sess" : the variable is shared with all the session,
"txn" : the variable is shared with all the transaction
(request and response)
"req" : the variable is shared only during the request
processing
"res" : the variable is shared only during the response
processing.
this prefix is followed by a name. the separator is a '.'.
the name may only contain characters 'a-z', 'a-z', '0-9' and '_'.
<expr> is a standard haproxy expression formed by a sample-fetch
followed by some converters.
tcp-request content set-var(sess.my_var) src
set the maximum allowed time to wait for a response during content inspection
may be used in sections : defaults | frontend | listen | backend
no | no | yes | yes
arguments :
can be in any other unit if the number is suffixed by the unit,
as explained at the top of this document.
set additional check timeout, but only after a connection has been already
established.
yes | no | yes | yes
arguments:
can be in any other unit if the number is suffixed by the unit,
as explained at the top of this document.
for check and “timeout check” as an additional read timeout. the “min” is
used so that people running with very long “timeout connect” (eg. 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).
timeout (connect + read) exactly like all <1.3.15 version.
requests and people may want to kick out laggy servers so this timeout should
be smaller than “timeout server”.
“defaults” sections. this is in fact one of the easiest solutions not to
forget about it.
“timeout tarpit”.
timeout clitimeout
set the maximum inactivity time on the client side.
may be used in sections : defaults | frontend | listen | backend
yes | yes | yes | no
arguments :
can be in any other unit if the number is suffixed by the unit,
as explained at the top of this document.
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. 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
(eg: 4 or 5 seconds). if some long-lived sessions are mixed with short-lived
sessions (eg: 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.
“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 results in accumulation of expired sessions in
the system if the system’s timeouts are not configured either.
to use it to write new configurations. the form “timeout clitimeout” is
provided only by backwards compatibility but its use is strongly discouraged.
set the inactivity timeout on the client side for half-closed connections.
may be used in sections : defaults | frontend | listen | backend
yes | yes | yes | no
arguments :
can be in any other unit if the number is suffixed by the unit,
as explained at the top of this document.
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.
“defaults” sections. by default it is not set, so half-closed connections
will use the other timeouts (timeout.client or timeout.tunnel).
timeout contimeout
set the maximum time to wait for a connection attempt to a server to succeed.
may be used in sections : defaults | frontend | listen | backend
yes | no | yes | yes
arguments :
can be in any other unit if the number is suffixed by the unit,
as explained at the top of this document.
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 (eg: 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.
“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 results in accumulation of failed sessions in
the system if the system’s timeouts are not configured either.
to use it to write new configurations. the form “timeout contimeout” is
provided only by backwards compatibility but its use is strongly discouraged.
“timeout tarpit”.
set the maximum allowed time to wait for a new http request to appear
may be used in sections : defaults | frontend | listen | backend
yes | yes | yes | yes
arguments :
can be in any other unit if the number is suffixed by the unit,
as explained at the top of this document.
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.
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.
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
connection to complete, a http 408 error is returned.
milliseconds, to allow users to fetch all objects of a page at once but
without waiting for further clicks. also, if set to a very small value (eg:
1 millisecond) it will probably only accept pipelined requests but not the
non-pipelined ones. it may be a nice trade-off for very large sites running
with tens to hundreds of thousands of clients.
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 sections : defaults | frontend | listen | backend
yes | yes | yes | yes
arguments :
can be in any other unit if the number is suffixed by the unit,
as explained at the top of this document.
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 behaviour, 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.
not to any data. as soon as the empty line is received, this timeout is not
used anymore. it is used again on keep-alive connections to wait for a second
request if “timeout http-keep-alive” is not set.
full request immediately upon connection. add 3 or more seconds to cover tcp
retransmits but that’s all. setting it to very low values (eg: 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.
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.
“timeout client”.
set the maximum time to wait in the queue for a connection slot to be free
may be used in sections : defaults | frontend | listen | backend
yes | no | yes | yes
arguments :
can be in any other unit if the number is suffixed by the unit,
as explained at the top of this document.
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.
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.
timeout srvtimeout
set the maximum inactivity time on the server side.
may be used in sections : defaults | frontend | listen | backend
yes | no | yes | yes
arguments :
can be in any other unit if the number is suffixed by the unit,
as explained at the top of this document.
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.
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 (eg: 4 or 5 seconds minimum). if some long-lived sessions are mixed
with short-lived sessions (eg: websocket and http), it’s worth considering
“timeout tunnel”, which overrides “timeout client” and “timeout server” for
tunnels.
“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 results in accumulation of expired sessions in
the system if the system’s timeouts are not configured either.
to use it to write new configurations. the form “timeout srvtimeout” is
provided only by backwards compatibility but its use is strongly discouraged.
set the inactivity timeout on the server side for half-closed connections.
may be used in sections : defaults | frontend | listen | backend
yes | no | yes | yes
arguments :
can be in any other unit if the number is suffixed by the unit,
as explained at the top of this document.
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.
“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 sections : defaults | frontend | listen | backend
yes | yes | yes | yes
arguments :
can be in any other unit if the number is suffixed by the unit,
as explained at the top of this document.
no activity for a certain amount of time, then closed. “timeout tarpit”
defines how long it will be maintained open.
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 sections : defaults | frontend | listen | backend
yes | no | yes | yes
arguments :
can be in any other unit if the number is suffixed by the unit,
as explained at the top of this document.
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
analyser remains attached to either connection (eg: tcp content rules are
accepted). in http, this timeout is used when a connection is upgraded (eg:
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.
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.
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 (eg: 4 or 5 seconds minimum).
“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 sections : defaults | frontend | listen | backend
yes | no | yes | yes
arguments : none
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.
present the client’s ip to the server when establishing the connection.
generate a unique id for each request.
may be used in sections : defaults | frontend | listen | backend
yes | yes | yes | no
arguments :
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 tag the log-format string.
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.
makes them more compact and saves space in logs. 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 sections : defaults | frontend | listen | backend
yes | yes | yes | no
arguments :
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 sections : defaults | frontend | listen | backend
no | yes | yes | no
arguments :
“log-format” string resolving to a backend name.<condition> is a condition composed of acls, as described in section 7\. if
it is omitted, the rule is unconditionally applied.
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 (eg:
source address validation) or combined with a “tcp-request” rule to wait for
some payload.
evaluated in their declaration order, and the first one which matches will
assign the backend.
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.
if no default backend is defined, 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.
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.
error is reported if the specified backend does not exist. if
a log-format string 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.
used to detect the association between frontends and backends to compute the
backend’s “fullconn” setting. this cannot be done for dynamic names.
section 7 about acls.
use-server
only use a specific server if/unless an acl-based condition is matched.
may be used in sections : defaults | frontend | listen | backend
no | no | yes | yes
arguments :
<condition> is a condition composed of acls, as described in section 7.
the available servers according to the configured algorithm, unless a
persistence mechanism such as a cookie is used and found in the request.
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.
and no force-persist rule was validated, it is ignored and evaluation goes on
with the next rules until one matches.
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.
does not assign the server. this allows prefixed cookies to have their prefix
stripped.
suitable for use with content-based inspection. for instance, a server could
be selected in a farm according to the tls sni field. 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:587 weight 0
use-server imap if { req_ssl_sni -i imap.example.com }
server mail 192.168.0.1:993 weight 0
# all the rest is forwarded to this server
server default 192.168.0.2:443 check5. bind and server options
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.5.1. bind options
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.
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.
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 build with support for tls
extensions enabled (check with haproxy -vv). the alpn extension replaces the
initial npn extension.
sets the socket’s backlog to this value. if unspecified, 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 sets
the named curve (rfc 4492) used to generate ecdh ephemeral keys. by default,
used named curve is prime256v1.
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.
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.
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 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. the format of the string is defined
in “man 1 ciphers” from openssl man pages, and can be for instance a string
such as “aes:all:!anull:!enull:+rc4:@strength” (without quotes).
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.
this setting is only available when support for openssl was built in. 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.
are loaded.
that directory will be loaded in alphabetic order unless their name ends with
‘.issuer’, ‘.ocsp’ or ‘.sctl’ (reserved extensions). 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 (eg: *.example.org matches
www.example.org but not www.sub.example.org).
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.
include haproxy when obtaining a certificate. if this happens be sure to
choose a webserver 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).
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.
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.
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. 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 list of sni filter per
certificate, with the following format for each line : <crtfile> [[!]<snifilter> ...]
only useful in combination with a wildcard filter to exclude a particular sni.
the certificates will be presented to clients who provide a valid tls server
name indication field matching one of the sni filters. if no sni filter is
specified, the cn and alt subjects are used. this directive may be specified
multiple times. see the “crt” option for more information. the default
certificate is still needed to meet openssl expectations. if it is not used,
the ‘strict-sni’ option may be used.
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 (eg: 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 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 “no-tlsv*” and “no-sslv3”.
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 “no-tlsv*” and “no-sslv3”.
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 “no-tlsv*”, and “no-sslv3”.
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 “no-tlsv*”, and “no-sslv3”.
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’). if an error occurs, the default certificate is
used, else the ‘strict-sni’ option is set.
it can also be used when haproxy is configured as a reverse proxy to ease the
deployment of an architecture with many backends.
to store forged certificates (see ‘tune.ssl.ssl-ctx-cache-size’). it
increases the haproxy’s memroy 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.
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.
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.
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.
read, and no change is allowed. it would make sense on systems where it
is not easy to restrict access to the socket.
be read, and only non-sensitive changes are permitted (eg: clear max
counters).
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.
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.
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”. see also “force-tls*”,
and “force-sslv3”.
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”.
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”. see also
“force-tlsv*”, and “force-sslv3”.
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”. see also
“force-tlsv*”, and “force-sslv3”.
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”. see also
“force-tlsv*”, and “force-sslv3”.
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 build 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).
this restricts the list of processes on which this listener is allowed to
run. it does not enforce any process but eliminates those which do not match.
if the frontend uses a “bind-process” setting, the intersection between the
two is applied. if in the end the listener is not allowed to run on any
remaining process, a warning is emitted, and the listener will either run on
the first process of the listener if a single process was specified, or on
all of its processes if multiple processes were specified. for the unlikely
case where several ranges are needed, this directive may be repeated. the
main purpose of this directive is to be used with the stats sockets and have
one different socket per process. the second purpose is to have multiple bind
lines sharing the same ip:port but not the same process in a listener, so
that the system can distribute the incoming connections into multiple queues
and allow a smoother inter-process load balancing. currently linux 3.9 and
above is known for supporting this. see also “bind-process” and “nbproc”.
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.
this setting is only available when support for openssl was built in. the
ssl/tls negotiation is allow only if the client provided an sni which match
a certificate. the default certificate is not used.
see the “crt” option for more information.
sets the tcp user timeout for all incoming connections instanciated 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 acknoledgement 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.
sets the tls ticket keys file to load the keys from. the keys need to be 48
bytes long, encoded with base64 (ex. openssl rand -base64 48). 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.
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.
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.
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’.5.2. server and default-server options
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:
default-server [settings …]
using the “addr” parameter, it becomes possible to use a different ip address
to send health-checks. 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.
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.
the string is made of a series of words delimited by spaces, tabs or commas
in any order, optionally terminated by ‘\r’ and/or ‘\n’, each consisting of :
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).
ready mode, thus cancelling any drain or maint state
drain mode, thus it will not accept any new connections other than those
that are accepted via persistence.
maint mode, thus it will not accept any new connections at all, and health
checks will be stopped.
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 (eg: missing process,
or port not responding).
also report that the service is accessible.
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.
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 workaround a bogus agent if needed.
parameter.
the “agent-inter” parameter sets the interval between two agent checks
to
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.
the “agent-port” parameter sets the tcp port used for agent checks.
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 “allbackups”
option.
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.
this option enables health checks on the server. by default, a server is
always considered available. if “check” is set, the server is available when
accepting periodic tcp connections, to ensure that it is really able to serve
requests. the default address and port to send the tests to are those of the
server, and the default source is the same as the one defined in the
backend. it is possible to change the address using the “addr” parameter, the
port using the “port” parameter, the source address using the “source”
address, and the interval and timers using the “inter”, “rise” and “fall”
parameters. the request method is define in the backend using the “httpchk”,
“smtpchk”, “mysql-check”, “pgsql-check” and “ssl-hello-chk” options. please
refer to those options and parameters for more information.
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.
this option forces encryption of all health checks over ssl, regardless of
whether the server uses ssl or not for the normal traffic. this is generally
used when an explicit “port” or “addr” directive is specified and ssl health
checks are not inherited. it is important to understand that this option
inserts an ssl transport layer below the checks, so that a simple tcp connect
check becomes an ssl connect, which replaces the old ssl-hello-chk. the most
common use is to send https checks by combining “httpchk” with ssl checks.
all ssl settings are common to health checks and traffic (eg: ciphers).
see the “ssl” option for more information.
this option sets the string describing the list of cipher algorithms that is
is negotiated during the ssl/tls handshake with the server. the format of the
string is defined in “man 1 ciphers”. when ssl is used to communicate with
servers on the local network, it is common to see a weaker set of algorithms
than what is used over the internet. doing so reduces cpu usage on both the
server and haproxy while still keeping it compatible with deployed software.
some algorithms such as rc4-sha1 are reasonably cheap. if no security at all
is needed and just connectivity, using des can be appropriate.
the “cookie” parameter sets the cookie value assigned to the server to
operational server possessing the same value will be selected. in return, in
cookie insertion or rewrite modes, this value will be assigned to the cookie
sent to the client. there is nothing wrong in having several servers sharing
the same cookie value, and it is in fact somewhat common between normal and
backup servers. see also the “cookie” keyword in backend section.
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 server’s certificate.
this setting is only available when support for openssl was built in.
it designates a pem file from which to load both a certificate and the
associated private key. this file can be built by concatenating both pem
files into one. this certificate will be sent if the server send a client
certificate request.
the “disabled” keyword starts the server in the “disabled” state. that means
that it is marked down in maintenance mode, and no connection other than the
ones allowed by persist mode will reach it. it is very well suited to setup
new servers, because normal traffic will never reach them, while it is still
possible to test the service by making use of the force-persist mechanism.
if health observing is enabled, the “error-limit” parameter specifies the
number of consecutive errors that triggers event selected by the “on-error”
option. by default it is set to 10 consecutive errors.
the “fall” parameter states that a server will be considered as dead after
unspecified. see also the “check”, “inter” and “rise” parameters.
this option enforces use of sslv3 only when ssl is used to communicate with
the server. sslv3 is generally less expensive than the tls counterparts for
high connection rates. this option is also available on global statement
“ssl-default-server-options”. see also “no-tlsv*”, “no-sslv3”.
this option enforces use of tlsv1.0 only when ssl is used to communicate with
the server. this option is also available on global statement
“ssl-default-server-options”. see also “no-tlsv*”, “no-sslv3”.
this option enforces use of tlsv1.1 only when ssl is used to communicate with
the server. this option is also available on global statement
“ssl-default-server-options”. see also “no-tlsv*”, “no-sslv3”.
this option enforces use of tlsv1.2 only when ssl is used to communicate with
the server. this option is also available on global statement
“ssl-default-server-options”. see also “no-tlsv*”, “no-sslv3”.
set a persistent id for the server. this id must be positive and unique for
the proxy. an unused id will automatically be assigned if unset. the first
assigned value will be 1. this id is currently only returned in statistics.
fastinter
downinter
the “inter” parameter sets the interval between two consecutive health checks
to
it is also possible to use “fastinter” and “downinter” to optimize delays
between checks depending on the server state : server state | interval used
---------------------------------+-----------------------------------------
up 100% (non-transitional) | "inter"
---------------------------------+-----------------------------------------
transitionally up (going down), |
transitionally down (going up), | "fastinter" if set, "inter" otherwise.
or yet unchecked. |
---------------------------------+-----------------------------------------
down 100% (non-transitional) | "downinter" if set, "inter" otherwise.
---------------------------------+-----------------------------------------
other explicit unit among { us, ms, s, m, h, d }. the “inter” parameter also
serves as a timeout for health checks sent to servers if “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.
the “maxconn” parameter specifies the maximal number of concurrent
connections that will be sent to this server. if the number of incoming
concurrent requests goes higher than this value, they will be queued, waiting
for a connection to be released. this parameter is very important as it can
save fragile servers from going down under extreme loads. if a “minconn”
parameter is specified, the limit becomes dynamic. the default value is “0”
which means unlimited. see also the “minconn” and “maxqueue” parameters, and
the backend’s “fullconn” keyword.
the “maxqueue” parameter specifies the maximal number of connections which
will wait in the queue for this server. if this limit is reached, next
requests will be redispatched to other servers instead of indefinitely
waiting to be served. this will break persistence but may allow people to
quickly re-log in when the server they try to connect to is dying. the
default value is “0” which means the queue is unlimited. see also the
“maxconn” and “minconn” parameters.
when the “minconn” parameter is set, the maxconn limit becomes a dynamic
limit following the backend’s load. the server will always accept at least
the ramp between both values when the backend has less than
concurrent connections. this makes it possible to limit the load on the
server during normal loads, but push it further for important loads without
overloading the server during exceptional loads. see also the “maxconn”
and “maxqueue” parameters, as well as the “fullconn” backend keyword.
this option disables ssl session reuse when ssl is used to communicate with
the server. it will force the server to perform a full handshake for every
new connection. it’s probably only useful for benchmarking, troubleshooting,
and for paranoid users.
this option disables support for sslv3 when ssl is used to communicate with
the server. note that sslv2 is disabled in the code and cannot be enabled
using any configuration option. see also “force-sslv3”, “force-tlsv*”.
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 for servers. this option
is also available on global statement “ssl-default-server-options”.
this option disables support for tlsv1.0 when ssl is used to communicate with
the server. note that sslv2 is disabled in the code and cannot be enabled
using any configuration option. tlsv1 is more expensive than sslv3 so it
often makes sense to disable it when communicating with local servers. this
option is also available on global statement “ssl-default-server-options”.
see also “force-sslv3”, “force-tlsv*”.
this option disables support for tlsv1.1 when ssl is used to communicate with
the server. note that sslv2 is disabled in the code and cannot be enabled
using any configuration option. tlsv1 is more expensive than sslv3 so it
often makes sense to disable it when communicating with local servers. this
option is also available on global statement “ssl-default-server-options”.
see also “force-sslv3”, “force-tlsv*”.
this option disables support for tlsv1.2 when ssl is used to communicate with
the server. note that sslv2 is disabled in the code and cannot be enabled
using any configuration option. tlsv1 is more expensive than sslv3 so it
often makes sense to disable it when communicating with local servers. this
option is also available on global statement “ssl-default-server-options”.
see also “force-sslv3”, “force-tlsv*”.
never add connections allocated to this sever to a stick-table.
this may be used in conjunction with backup to ensure that
stick-table persistence is disabled for backup servers.
this option enables health adjusting based on observing communication with
the server. by default this functionality is disabled and enabling it also
requires to enable health checks. there are two supported modes: “layer4” and
“layer7”. in layer4 mode, only successful/unsuccessful tcp connections are
significant. in layer7, which is only allowed for http proxies, responses
received from server are verified, like valid/wrong http code, unparsable
headers, a timeout, etc. valid status codes include 100 to 499, 501 and 505.
select what should happen when enough consecutive errors are detected.
currently, four modes are available:
check will mark a server down, forces fastinter
modify what occurs when a server is marked down.
currently one action is available:
all connections to the server are immediately terminated when the server
goes down. it might be used if the health check detects more complex cases
than a simple connection status, and long timeouts would cause the service
to remain unresponsive for too long a time. for instance, a health check
might detect that a database is stuck and that there’s no chance to reuse
existing connections anymore. connections killed this way are logged with
a ‘d’ termination code (for “down”).
modify what occurs when a server is marked up.
currently one action is available:
done only if the server is not in backup state and if it is not disabled
(it must have an effective weight > 0). this can be used sometimes to force
an active server to take all the traffic back after recovery when dealing
with long sessions (eg: ldap, sql, …). doing this can cause more trouble
than it tries to solve (eg: incomplete transactions), so use this feature
with extreme care. sessions killed because a server comes up are logged
with an ‘u’ termination code (for “up”).
using the “port” parameter, it becomes possible to use a different port to
send health-checks. on some servers, it may be desirable to dedicate a port
to a specific component able to perform complex tests which are more suitable
to health-checks than the application. it is common to run a simple script in
inetd for instance. this parameter is ignored if the “check” parameter is not
set. see also the “addr” parameter.
the “redir” parameter enables the redirection mode for all get and head
requests addressing this server. this means that instead of having haproxy
forward the request to the server, it will send an “http 302” response with
the “location” header composed of this prefix immediately followed by the
requested uri beginning at the leading ‘/‘ of the path component. that means
that no trailing slash should be used after
will be rejected, and all non-get or head requests will be normally served by
the server. note that since the response is completely forged, no header
mangling nor cookie insertion is possible in the response. however, cookies in
requests are still analysed, making this solution completely usable to direct
users to a remote location in case of local disaster. main use consists in
increasing bandwidth for static servers by having the clients directly
connect to them. note: never use a relative location here, it would cause a
loop between the client and haproxy!
the “rise” parameter states that a server will be considered as operational
after
if unspecified. see also the “check”, “inter” and “fall” parameters.
when dns resolution is enabled for a server and multiple ip addresses from
different families are returned, haproxy will prefer using an ip address
from the family mentioned in the “resolve-prefer” parameter.
available families: “ipv4” and “ipv6”
points to an existing “resolvers” section to resolve current server’s
hostname.
the “send-proxy” parameter enforces use of the proxy protocol over any
connection established to this server. the proxy protocol informs the other
end about the layer 3/4 addresses of the incoming connection, so that it can
know the client’s address or the public address it accessed to, whatever the
upper layer protocol. for connections accepted by an “accept-proxy” listener,
the advertised address will be used. only tcpv4 and tcpv6 address families
are supported. other families such as unix sockets, will report an unknown
family. servers using this option can fully be chained to another instance of
haproxy listening with an “accept-proxy” setting. this setting must not be
used if the server isn’t aware of the protocol. when health checks are sent
to the server, the proxy protocol is automatically used when this option is
set, unless there is an explicit “port” or “addr” directive, in which case an
explicit “check-send-proxy” directive would also be needed to use the proxy
protocol. see also the “accept-proxy” option of the “bind” keyword.
the “send-proxy-v2” parameter enforces use of the proxy protocol version 2
over any connection established to this server. the proxy protocol informs
the other end about the layer 3/4 addresses of the incoming connection, so
that it can know the client’s address or the public address it accessed to,
whatever the upper layer protocol. this setting must not be used if the
server isn’t aware of this version of the protocol. see also the “send-proxy”
option of the “bind” keyword.
the “send-proxy-v2-ssl” parameter enforces use of the proxy protocol version
2 over any connection established to this server. the proxy protocol informs
the other end about the layer 3/4 addresses of the incoming connection, so
that it can know the client’s address or the public address it accessed to,
whatever the upper layer protocol. in addition, the ssl information extension
of the proxy protocol is added to the proxy protocol header. this setting
must not be used if the server isn’t aware of this version of the protocol.
see also the “send-proxy-v2” option of the “bind” keyword.
the “send-proxy-v2-ssl” parameter enforces use of the proxy protocol version
2 over any connection established to this server. the proxy protocol informs
the other end about the layer 3/4 addresses of the incoming connection, so
that it can know the client’s address or the public address it accessed to,
whatever the upper layer protocol. in addition, the ssl information extension
of the proxy protocol, along along with the common name from the subject of
the client certificate (if any), is added to the proxy protocol header. this
setting must not be used if the server isn’t aware of this version of the
protocol. see also the “send-proxy-v2” option of the “bind” keyword.
the “slowstart” parameter for a server accepts a value in milliseconds which
indicates after how long a server which has just come back up will run at
full speed. just as with every other time-based parameter, it can be entered
in any other explicit unit among { us, ms, s, m, h, d }. the speed grows
linearly from 0 to 100% during this time. the limitation applies to two
parameters :
to 100% of the usual dynamic limit defined by (minconn,maxconn,fullconn).
grows linearly from 1 to 100%. in this case, the weight is updated at every
health-check. for this reason, it is important that the “inter” parameter
is smaller than the “slowstart”, in order to maximize the number of steps.
trouble to running servers. it only applies when a server has been previously
seen as failed.
the “sni” parameter evaluates the sample fetch expression, converts it to a
string and uses the result as the host name sent in the sni tls extension to
the server. a typical use case is to send the sni received from the client in
a bridged https scenario, using the “ssl_fc_sni” sample fetch for the
expression, though alternatives such as req.hdr(host) can also make sense.
source
source
the “source” parameter sets the source address which will be used when
connecting to the server. it follows the exact same parameters and principle
as the backend “source” keyword, except that it only applies to the server
referencing it. please consult the “source” keyword for details.
source port range by indicating the lower and higher bounds delimited by a
dash (‘-‘). some operating systems might require a valid ip address when a
source port range is specified. it is permitted to have the same ip/range for
several servers. doing so makes it possible to bypass the maximum of 64k
total concurrent connections. the limit will then reach 64k connections per
server.
this option enables ssl ciphering on outgoing connections to the server. it
is critical to verify server certificates using “verify” when using ssl to
connect to servers, otherwise the communication is prone to trivial man in
the-middle attacks rendering ssl useless. when this option is used, health
checks are automatically sent in ssl too unless there is a “port” or an
“addr” directive indicating the check should be sent to a different location.
see the “check-ssl” option to force ssl health checks.
this option enables ability to set the current state of the server by tracking
another one. it is possible to track a server which itself tracks another
server, provided that at the end of the chain, a server has health checks
enabled. if
used, it has to be enabled on both proxies.
this setting is only available when support for openssl was built in. if set
to ‘none’, server certificate is not verified. in the other case, the
certificate provided by the server is verified using cas from ‘ca-file’
and optional crls from ‘crl-file’. if ‘ssl_server_verify’ is not specified
in global section, this is the default. on verify failure the handshake
is aborted. it is critically important to verify server certificates when
using ssl to connect to servers, otherwise the communication is prone to
trivial man-in-the-middle attacks rendering ssl totally useless.
this setting is only available when support for openssl was built in, and
only takes effect if ‘verify required’ is also specified. when set, the
hostnames in the subject and subjectalternatenames of the certificate
provided by the server are checked. if none of the hostnames in the
certificate match the specified hostname, the handshake is aborted. the
hostnames in the server-provided certificate may include wildcards.
the “weight” parameter is used to adjust the server’s weight relative to
other servers. all servers will receive a load proportional to their weight
relative to the sum of all weights, so the higher the weight, the higher the
load. the default weight is 1, and the maximal value is 256. a value of 0
means the server will not participate in load-balancing but will still accept
persistent connections. if this parameter is used to distribute the load
according to server’s capacity, it is recommended to start with values which
can both grow and shrink, for instance between 10 and 100 to leave enough
room above and below for later adjustments.5.3. server ip address resolution using dns
ip address. by default, haproxy resolves the name when parsing the
configuration, at startup.
this is not sufficient in some cases, such as in amazon where a server’s ip
can change after a reboot or an elb virtual ip can change based on current
workload.
this chapter describes how haproxy can be configured to process server’s name
resolution at run time.
whether run time server name resolution has been enable or not, haproxy will
carry on doing the first resolution when parsing the configuration.5.3.1. global overview
different steps of the process life:
host name. it uses libc functions to get the host name resolved. this
resolution relies on /etc/resolv.conf file.
it verifies if the current name resolution is still considered as valid.
if not, it processes a new resolution, in parallel of the health check.
because the server has a new ip address. so we need to trigger a name
resolution to know this new ip.
first valid response.
servers return an error.5.3.2. the resolvers section
haproxy.
there can be as many as resolvers section as needed. each section can contain
many name servers.
creates a new name server list labelled
dns server description:
defines
on last resolution
answer was in
resolution is triggered after
the healch check.
defines the number
giving up.
default value: 3
defines timeouts related to name resolution
events available are:
- retry: time between two dns queries, when no response have
been received.
default value: 1s
nameserver dns1 10.0.0.1:53
nameserver dns2 10.0.0.2:53
resolve_retries 3
timeout retry 1s
hold valid 10s6. http header manipulation
response headers based on regular expressions. it is also possible to block a
request or a response if a particular header matches a regular expression,
which is enough to stop most elementary protocol attacks, and to protect
against information leak from the internal network.
to process all rsp* rules which can allow, deny, rewrite or delete a header,
but it will refuse to add a header to any such messages as this is not
http-compliant. the reason for still processing headers in such responses is to
stop and/or fix any possible information leak which may happen, for instance
because another downstream equipment would unconditionally add a header, or if
a server name appears there. when such messages are seen, normal processing
still occurs on the next non-informational messages.
in section 4.2 :
is a posix extended regular expression (regex) which supports grouping through
parenthesis (without the backslash). spaces and other delimiters must be
prefixed with a backslash (‘') to avoid confusion with a field delimiter.
other characters may be prefixed with a backslash to change their meaning :
\r for a carriage return (cr)
\n for a new line (lf)
\ to mark a space and differentiate it from a delimiter
# to mark a sharp and differentiate it from a comment
\ to use a backslash in a regex
\\ to use a backslash in the text (*2 for regex, *2 for haproxy)
\xxx to write the ascii hex code xx as in the c language
portion of text matching the regex. it can make use of the special characters
above, and can reference a substring which is delimited by parenthesis in the
regex, by writing a backslash (‘') immediately followed by one digit from 0 to
9 indicating the group position (0 designating the entire line). this practice
is very common to users of the “sed” program.
after the last header line. it can also use special character sequences above.notes related to these keywords :
contents. it is strongly recommended to use acls with the “block” keyword
instead, resulting in far more flexible and manageable rules.
a header name only or a value only. this is important because of the way
headers are written (notably the number of spaces after the colon).
rewrite or filter http requests uris or response codes, but in turn makes
it harder to distinguish between headers and request line. the regex prefix
^[^\ \t][\ \t] matches any http method followed by a space, and the prefix
^[^ \t:]: matches any header name followed by a colon.
a response is limited at build time to values between 1 and 4 kb. this
should normally be far more than enough for most usages. if it is too short
on occasional usages, it is possible to gain some space by removing some
useless headers before adding new ones.
without the ‘i’ letter except that they ignore case when matching patterns.
from the frontend will be evaluated, then all req* rules from the backend
will be evaluated. the reverse path is applied to responses.
always the first one, but before “use_backend” in order to permit rewriting
before switching.7. using acls and fetching samples
client or server information, from tables, environmental information etc…
the action of extracting such data is called fetching a sample. once retrieved,
these samples may be used for various purposes such as a key to a stick-table,
but most common usages consist in matching them against predefined constant
data called patterns.7.1. acl basics
content switching and generally to take decisions based on content extracted
from the request, the response or any environmental status. the principle is
simple :
adding a header.
those tests apply to the portion of request/response specified in
and may be adjusted with optional flags [flags]. some criteria also support
an operator which may be specified before the set of values. optionally some
conversion operators may be applied to the sample, and they will be specified
as a comma-delimited list of keywords just after the first keyword. the values
are of the type supported by the criterion, and are separated by spaces.
‘_’ (underscore) , ‘.’ (dot) and ‘:’ (colon). acl names are case-sensitive,
which means that “my_acl” and “my_acl” are two different acls.
performance, they just consume a small amount of memory.
specific declinations. the default test method is implied by the output type of
this sample fetch method. the acl declinations can describe alternate matching
methods of a same sample fetch method. the sample fetch methods are the only
ones supporting a conversion.
converters might convert a string to a lower-case string while other ones
would turn a string to an ipv4 address, or apply a netmask to an ip address.
the resulting sample is of the type of the last converter applied to the list,
which defaults to the type of the sample fetch method.
keyword in this documentation. when an acl is declared using a standard sample
fetch method, certain types automatically involved a default matching method
which are summarized in the table below :
| sample or converter | default |
| output type | matching method |
+———————+—————–+
| boolean | bool |
+———————+—————–+
| integer | int |
+———————+—————–+
| ip | ip |
+———————+—————–+
| string | str |
+———————+—————–+
| binary | none, use “-m” |
+———————+—————–+
matching method, see below.
-f : load patterns from a file.
-m : use a specific pattern matching method
-n : forbid the dns resolutions
-m : load the file pointed by -f like a map file.
-u : force the unique id of the acl
– : force end of flags. useful when a string looks like one of the flags.
read as individual values. it is even possible to pass multiple “-f” arguments
if the patterns are to be loaded from multiple files. empty lines as well as
lines beginning with a sharp (‘#’) will be ignored. all leading spaces and tabs
will be stripped. if it is absolutely necessary to insert a valid pattern
beginning with a sharp, just prefix it with a space so that it is not taken for
a comment. depending on the data type and match method, haproxy may load the
lines into a binary tree, allowing very fast lookups. this is true for ipv4 and
exact string matching. in this case, duplicates will automatically be removed.
parsed as two column file. the first column contains the patterns used by the
acl, and the second column contain the samples. the sample can be used later by
a map. this can be useful in some rare cases where an acl would just be used to
check for the existence of a pattern in a map before a mapping is applied.
socket interface to identify acl and dynamically change its values. note that a
file is always identified by its name even if an id is set.
loaded from files preceding it. for instance :acl valid-ua hdr(user-agent) -f exact-ua.lst -i -f generic-ua.lst test
the “user-agent” header of the request. then each line of “generic-ua” will be
case-insensitively matched. then the word “test” will be insensitively matched
as well.
sample. all acl-specific criteria imply a pattern matching method and generally
do not need this flag. however, this flag is useful with generic sample fetch
methods to describe how they’re going to be matched against the patterns. this
is required for sample fetches which return data type for which there is no
obvious matching method (eg: string or binary). when “-m” is specified and
followed by a pattern matching method name, this method is used instead of the
default one for the criterion. this makes it possible to match contents in ways
that were not initially planned, or with sample fetch methods which return a
string. the matching method also affects the way the patterns are parsed.
by default, if the parser cannot parse ip address it considers that the parsed
string is maybe a domain name and try dns resolution. the flag “-n” disable this
resolution. it is useful for detecting malformed ip lists. note that if the dns
server is not reachable, the haproxy configuration parsing may last many minutes
waiting fir the timeout. during this time no error messages are displayed. the
flag “-n” disable this behavior. note also that during the runtime, this
function is disabled for the dynamic acl modifications.
sample fetch methods. also, if “-m” is used in conjunction with “-f”, it must
be placed first. the pattern matching method must be one of the following :
but do not compare it against any pattern. it is recommended not
to pass any pattern to avoid confusion. this matching method is
particularly useful to detect presence of certain contents such
as headers, cookies, etc... even if they are empty and without
comparing them to anything nor counting them.
which return a boolean or integer value, and takes no pattern.
value zero or false does not match, all other values do match.
boolean samples. boolean false is integer 0, true is integer 1.
with ip address samples only, so it is implied and never needed.
binary sequence. this may be used with binary or string samples.
binary or string samples.
used with binary or string samples.
the provided string patterns. this may be used with binary or
string samples.
expressions. this may be used with binary or string samples.
string patterns. this may be used with binary or string samples.
string patterns. this may be used with binary or string samples.
contents exactly matches one of the provided string patterns.
this may be used with binary or string samples.
exactly match one of the provided string patterns. this may be
used with binary or string samples.
request, it is possible to do :acl jsess_present cook(jsessionid) -m found
buffer, one would use the following acl :acl script_tag payload(0,500) -m reg -i <script>
possible to convert the sample to lowercase before matching, like this :acl script_tag payload(0,500),lower -m reg <script>
criteria are composed by concatenating the name of the original sample fetch
method and the matching method. for example, “hdr_beg” applies the “beg” match
to samples retrieved using the “hdr” fetch method. since all acl-specific
criteria rely on a sample fetch method, it is always possible instead to use
the original sample fetch method and the explicit matching method using “-m”.
the matching method is simply applied to the underlying sample fetch method.
for example, all acls below are exact equivalent :acl short_form hdr_beg(host) www.
acl alternate1 hdr_beg(host) -m beg www.
acl alternate2 hdr_dom(host) -m beg www.
acl alternate3 hdr(host) -m beg www.
types and the pattern types to fetch against. it indicates for each compatible
combination the name of the matching method to be used, surrounded with angle
brackets “>” and “<” when the method is the default one and will work by
default without “-m”. +-------------------------------------------------+
| input sample type |
+----------------------+---------+---------+---------+---------+---------+
| pattern type | boolean | integer | ip | string | binary |
+----------------------+---------+---------+---------+---------+---------+
| none (presence only) | found | found | found | found | found |
+----------------------+---------+---------+---------+---------+---------+
| none (boolean value) |> bool <| bool | | bool | |
+----------------------+---------+---------+---------+---------+---------+
| integer (value) | int |> int <| int | int | |
+----------------------+---------+---------+---------+---------+---------+
| integer (length) | len | len | len | len | len |
+----------------------+---------+---------+---------+---------+---------+
| ip address | | |> ip <| ip | ip |
+----------------------+---------+---------+---------+---------+---------+
| exact string | str | str | str |> str <| str |
+----------------------+---------+---------+---------+---------+---------+
| prefix | beg | beg | beg | beg | beg |
+----------------------+---------+---------+---------+---------+---------+
| suffix | end | end | end | end | end |
+----------------------+---------+---------+---------+---------+---------+
| substring | sub | sub | sub | sub | sub |
+----------------------+---------+---------+---------+---------+---------+
| subdir | dir | dir | dir | dir | dir |
+----------------------+---------+---------+---------+---------+---------+
| domain | dom | dom | dom | dom | dom |
+----------------------+---------+---------+---------+---------+---------+
| regex | reg | reg | reg | reg | reg |
+----------------------+---------+---------+---------+---------+---------+
| hex block | | | | bin | bin |
+----------------------+---------+---------+---------+---------+---------+
7.1.1. matching booleans
boolean matching is used by default for all fetch methods of type “boolean”.
when boolean matching is used, the fetched value is returned as-is, which means
that a boolean “true” will always match and a boolean “false” will never match.
return an integer value. then, integer value 0 is converted to the boolean
“false” and all other values are converted to “true”.7.1.2. matching integers
enforced on boolean fetches using “-m int”. in this case, “false” is converted
to the integer 0, and “true” is converted to the integer 1.
matching only applies to positive values. a range is a value expressed with a
lower and an upper bound separated with a colon, both of which may be omitted.
unprivileged ports, and “1024:” would also work. “0:1023” is a valid
representation of privileged ports, and “:1023” would also work.
two integers separated by a dot. this is used with some version checks for
instance. all integer properties apply to those decimal numbers, including
ranges and operators.
operators with ranges does not make much sense and is strongly discouraged.
similarly, it does not make much sense to perform order comparisons with a set
of values.
ge : true if the tested value is greater than or equal to at least one value
gt : true if the tested value is greater than at least one value
le : true if the tested value is less than or equal to at least one value
lt : true if the tested value is less than at least one value7.1.3. matching strings
different forms :
patterns ;
extracted string, and the acl matches if any of them is found inside ;
the extracted string, and the acl matches if any of them matches.
extracted string, and the acl matches if any of them matches.
string, delimited with slashes (“/“), and the acl matches if any of them
matches.
string, delimited with dots (“.”), and the acl matches if any of them
matches.
exception of the backslash (“") which makes it possible to escape some
characters such as the space. if the “-i” flag is passed before the first
string, then the matching will be performed ignoring the case. in order
to match the string “-i”, either set it second, or pass the “–” flag
before the first string. same applies of course to match the string “–”.7.1.4. matching regular expressions (regexes)
they are passed, with the exception of the backslash (“") which makes it
possible to escape some characters such as the space. if the “-i” flag is
passed before the first regex, then the matching will be performed ignoring
the case. in order to match the string “-i”, either set it second, or pass
the “–” flag before the first string. same principle applies of course to
match the string “–”.7.1.5. matching arbitrary data blocks
not safely be represented as a string. for this, the patterns must be passed as
a series of hexadecimal digits in an even number, when the match method is set
to binary. each sequence of two digits will represent a byte. the hexadecimal
digits may be used upper or lower case.
# match “hello\n” in the input stream (\x48 \x65 \x6c \x6c \x6f \x0a)
acl hello payload(0,6) -m bin 48656c6c6f0a7.1.6. matching ipv4 and ipv6 addresses
netmask appended, in which case the ipv4 address matches whenever it is
within the network. plain addresses may also be replaced with a resolvable
host name, but this practice is generally discouraged as it makes it more
difficult to read and debug configurations. if hostnames are used, you should
at least ensure that they are present in /etc/hosts so that the configuration
does not depend on any random dns match at the moment the configuration is
parsed.
only bit counts are accepted for ipv6 netmasks. in order to avoid any risk of
trouble with randomly resolved ip addresses, host names are never allowed in
ipv6 patterns.
following situations :
in ipv4 using the supplied mask if any.
in ipv6 using the supplied mask if any.
using the pattern’s mask if the ipv6 address matches with 2002:ipv4::,
::ipv4 or ::ffff:ipv4, otherwise it fails.
converted to ipv6 by prefixing ::ffff: in front of it, then the match is
applied in ipv6 using the supplied ipv6 mask.7.2. using acls to form conditions
combination of acls with operators. 3 operators are supported :
indicating when the condition will trigger the action.
“options”, as well as post requests without content-length, and get or head
requests with a content-length greater than 0, and finally every request which
is not either get/head/post/options !
block if http_url_star !meth_options || meth_post missing_cl
block if meth_get http_content
block unless meth_get or meth_post or meth_options
and to every request on the “img”, “video”, “download” and “ftp” hosts :
acl url_static path_end .gif .png .jpg .css .js
acl host_www hdr_beg(host) -i www
acl host_static hdr_beg(host) -i img. video. download. ftp.now use backend “static” for all static-only hosts, and for static urls
of host “www”. use backend “www” for the rest.
use_backend www if host_www
expressions that are built on the fly without needing to be declared. they must
be enclosed between braces, with a space before and after each brace (because
the braces must be seen as independent words). example : acl missing_cl hdr_cnt(content-length) eq 0
block if meth_post missing_cl
block if meth_post { hdr_cnt(content-length) eq 0 }
to leave errors in the configuration when written that way. however, for very
simple rules matching only one source ip address for instance, it can make more
sense to use them than to declare acls with random names. another example of
good use is the following : acl site_dead nbsrv(dynamic) lt 2
acl site_dead nbsrv(static) lt 2
monitor fail if site_dead
monitor fail if { nbsrv(dynamic) lt 2 } || { nbsrv(static) lt 2 }
7.3. fetching samples
against patterns using acls. with the arrival of stick-tables, a new class of
sample fetch methods was created, most often sharing the same syntax as their
acl counterpart. these sample fetch methods are also known as “fetches”. as
of now, acls and fetches have converged. all acl fetch methods have been made
available as fetch methods, and acls may use any sample fetch method as well.
some sample fetch methods have deprecated aliases that are used to maintain
compatibility with existing configurations. they are then explicitly marked as
deprecated and should not be used in new setups.
matching methods. these ones all have a well defined default pattern matching
method, so it is never necessary (though allowed) to pass the “-m” option to
indicate how the sample will be matched using acls.
when using a generic sample fetch method in an acl, the “-m” option is
mandatory unless the sample type is one of boolean, integer, ipv4 or ipv6. when
the same keyword exists as an acl keyword and as a standard fetch method, the
acl engine will automatically pick the acl-only one by default.
multiple optional arguments. these arguments are strongly typed and are checked
when the configuration is parsed so that there is no risk of running with an
incorrect argument (eg: an unresolved backend name). fetch function arguments
are passed between parenthesis and are delimited by commas. when an argument
is optional, it will be indicated below between square brackets (‘[ ]’). when
all arguments are optional, the parenthesis may be omitted.
7.3.1. converters
of the fetched sample (also called “converters”). these combinations form what
is called “sample expressions” and the result is a “sample”. initially this
was only supported by “stick on” and “stick store-request” directives but this
has now be extended to all places where samples may be used (acls, log-format,
unique-id-format, add-header, …).
sample fetch method. these keywords may equally be appended immediately after
the fetch keyword’s argument, delimited by a comma. these keywords can also
support some arguments (eg: a netmask) which must be passed in parenthesis.
support performing basic operations on integers. some bitwise operations are
supported (and, or, xor, cpl) and some arithmetic operations are supported
(add, sub, mul, div, mod, neg). some comparators are provided (odd, even, not,
bool) which make it possible to report a match without having to write an acl.
adds
result as a signed integer.
name. the name of the variable starts by an indication about its scope. the
allowed scopes are:
“sess” : the variable is shared with all the session,
“txn” : the variable is shared with all the transaction (request and
response),
“req” : the variable is shared only during the request processing,
“res” : the variable is shared only during the response processing.
this prefix is followed by a name. the separator is a ‘.’. the name may only
contain characters ‘a-z’, ‘a-z’, ‘0-9’ and ‘_’.
performs a bitwise “and” between
integer, and returns the result as an signed integer.
numeric value or a variable name. the name of the variable starts by an
indication about its scope. the allowed scopes are:
“sess” : the variable is shared with all the session,
“txn” : the variable is shared with all the transaction (request and
response),
“req” : the variable is shared only during the request processing,
“res” : the variable is shared only during the response processing.
this prefix is followed by a name. the separator is a ‘.’. the name may only
contain characters ‘a-z’, ‘a-z’, ‘0-9’ and ‘_’.
converts a binary input sample to a base64 string. it is used to log or
transfer binary content in a way that can be reliably transferred (eg:
an ssl id can be copied in a header).
returns a boolean true if the input value of type signed integer is
non-null, otherwise returns false. used in conjunction with and(), it can be
used to report true/false for bit testing on input values (eg: verify the
presence of a flag).
extracts some bytes from an input binary sample. the result is a binary
sample starting at an offset (in bytes) of the original sample and
optionnaly truncated at the given length.
takes the input value of type signed integer, applies a ones-complement
(flips all bits) and returns the result as an signed integer.
hashes a binary input sample into an unsigned 32-bit quantity using the crc32
hash function. optionally, it is possible to apply a full avalanche hash
function to the output if the optional
converter uses the same functions as used by the various hash-based load
balancing algorithms, so it will provide exactly the same results. it is
provided for compatibility with other software which want a crc32 to be
computed on some input keys, so it follows the most common implementation as
found in ethernet, gzip, png, etc… it is slower than the other algorithms
but may provide a better or at least less predictable distribution. it must
not be used for security purposes as a 32-bit hash is trivial to break. see
also “djb2”, “sdbm”, “wt6” and the “hash-type” directive.
asks the deviceatlas converter to identify the user agent string passed on
input, and to emit a string made of the concatenation of the properties
enumerated in argument, delimited by the separator defined by the global
keyword “deviceatlas-property-separator”, or by default the pipe character
(‘|’). there’s a limit of 5 different properties imposed by the haproxy
configuration language.
frontend www
bind *:8881
default_backend servers
http-request set-header x-deviceatlas-data %[req.fhdr(user-agent),da-csv(primaryhardwaretype,osname,osversion,browsername,browserversion)]
this converter is used as debug tool. it dumps on screen the content and the
type of the input sample. the sample is returned as is on its output. this
converter only exists when haproxy was built with debugging enabled.
divides the input value of type signed integer by
result as an signed integer. if
integer is returned (typically 2^63-1).
variable name. the name of the variable starts by an indication about it
scope. the scope allowed are:
“sess” : the variable is shared with all the session,
“txn” : the variable is shared with all the transaction (request and
response),
“req” : the variable is shared only during the request processing,
“res” : the variable is shared only during the response processing.
this prefix is followed by a name. the separator is a ‘.’. the name may only
contain characters ‘a-z’, ‘a-z’, ‘0-9’ and ‘_’.
hashes a binary input sample into an unsigned 32-bit quantity using the djb2
hash function. optionally, it is possible to apply a full avalanche hash
function to the output if the optional
converter uses the same functions as used by the various hash-based load
balancing algorithms, so it will provide exactly the same results. it is
mostly intended for debugging, but can be used as a stick-table entry to
collect rough statistics. it must not be used for security purposes as a
32-bit hash is trivial to break. see also “crc32”, “sdbm”, “wt6” and the
“hash-type” directive.
returns a boolean true if the input value of type signed integer is even
otherwise returns false. it is functionally equivalent to “not,and(1),bool”.
extracts the substring at the given index considering given delimiters from
an input string. indexes start at 1 and delimiters are a string formatted
list of chars.
converts a binary input sample to an hex string containing two hex digits per
input byte. it is used to log or transfer hex dumps of some binary input data
in a way that can be reliably transferred (eg: an ssl id can be copied in a
header).
converts an integer supposed to contain a date since epoch to a string
representing this date in a format suitable for use in http header fields. if
an offset value is specified, then it is a number of seconds that is added to
the date before the conversion is operated. this is particularly useful to
emit date header fields, expires values in responses when combined with a
positive offset, or last-modified values when the offset is negative.)
uses the string representation of the input sample to perform a look up in
the specified table. if the key is not found in the table, a boolean false
is returned. otherwise a boolean true is returned. this can be used to verify
the presence of a certain key in a table tracking some elements (eg: whether
or not a source ip address or an authorization header was already seen).
apply a mask to an ipv4 address, and use the result for lookups and storage.
this can be used to make all hosts within a certain mask to share the same
table entries and as such use the same server. the mask can be passed in
dotted form (eg: 255.255.255.0) or in cidr form (eg: 24).
escapes the input string and produces an ascii ouput string ready to use as a
json string. the converter tries to decode the input string according to the
“utf8ps”. the “ascii” decoder never fails. the “utf8” decoder detects 3 types
of errors:
bytes, …)
character is greater than 0xffff because the json string escape specification
only authorizes 4 hex digits for the value encoding. the utf-8 decoder exists
in 4 variants designated by a combination of two suffix letters : “p” for
“permissive” and “s” for “silently ignore”. the behaviors of the decoders
are :
error ;
characters corresponding to the other errors.
logging to servers which consume json-formated traffic logs.
capture request header user-agent len 150
capture request header host len 15
log-format {“ip”:”%[src]”,”user-agent”:”%[capture.req.hdr(1),json]”}
get / http/1.0
user-agent: very “ugly” ua 1/2
{“ip”:”127.0.0.1”,”user-agent”:”very "ugly" ua 1/2”}
returns the value with the highest q-factor from a list as extracted from the
“accept-language” header using “req.fhdr”. values with no q-factor have a
q-factor of 1. values with a q-factor of 0 are dropped. only values which
belong to the list of semi-colon delimited
argument
given list and a default value is provided, it is returned. note that language
names may have a variant after a dash (‘-‘). if this variant is present in the
list, it will be matched, but if it is not, only the base language is checked.
the match is case-sensitive, and the output string is always one of those
provided in arguments. the ordering of arguments is meaningless, only the
ordering of the values in the request counts, as the first value among
multiple sharing the same q-factor is used.# this configuration switches to the backend matching a
# given language based on the request :
acl es req.fhdr(accept-language),language(es;fr;en) -m str es
acl fr req.fhdr(accept-language),language(es;fr;en) -m str fr
acl en req.fhdr(accept-language),language(es;fr;en) -m str en
use_backend spanish if es
use_backend french if fr
use_backend english if en
default_backend choose_your_language
convert a string sample to lower case. this can only be placed after a string
sample fetch function or after a transformation keyword returning a string
type. the result is of type string.
converts an integer supposed to contain a date since epoch to a string
representing this date in local time using a format defined by the
string using strftime(3). the purpose is to allow any date format to be used
in logs. an optional
(positive or negative). see the strftime() man page for the format supported
by your operating system. see also the utime converter. # emit two colons, one with the local time and another with ip:port
# eg: 20140710162350 127.0.0.1:57325
log-format %[date,ltime(%y%m%d%h%m%s)]\ %ci:%cp
map_
map_
search the input value from
and return the associated value converted to the type
input value cannot be found in the
acts as if no input value could be fetched. if the
defaults to “str”. likewise, if the
“str”. for convenience, the “map” keyword is an alias for “map_str” and maps a
string to another string.
strings are stored in trees, so the first of the finest match will be used.
other keys are stored in lists, so the first matching occurrence will be used.
input type, match type and output type.
———–+————–+—————–+—————–+—————
str | str | map_str | map_str_int | map_str_ip
———–+————–+—————–+—————–+—————
str | beg | map_beg | map_beg_int | map_end_ip
———–+————–+—————–+—————–+—————
str | sub | map_sub | map_sub_int | map_sub_ip
———–+————–+—————–+—————–+—————
str | dir | map_dir | map_dir_int | map_dir_ip
———–+————–+—————–+—————–+—————
str | dom | map_dom | map_dom_int | map_dom_ip
———–+————–+—————–+—————–+—————
str | end | map_end | map_end_int | map_end_ip
———–+————–+—————–+—————–+—————
str | reg | map_reg | map_reg_int | map_reg_ip
———–+————–+—————–+—————–+—————
int | int | map_int | map_int_int | map_int_ip
———–+————–+—————–+—————–+—————
ip | ip | map_ip | map_ip_int | map_ip_ip
———–+————–+—————–+—————–+—————
ignored, just like empty lines. leading tabs and spaces are stripped. the key
is then the first “word” (series of non-space/tabs characters), and the value
is what follows this series of space/tab till the end of the line excluding
trailing spaces/tabs. # this is a comment and is ignored
2.22.246.0/23 united kingdom \n
<-><-----------><--><------------><---->
| | | | `- trailing spaces ignored
| | | `---------- value
| | `-------------------- middle spaces ignored
| `---------------------------- key
`------------------------------------ leading spaces ignored
divides the input value of type signed integer by
remainder as an signed integer. if
starts by an indication about its scope. the allowed scopes are:
“sess” : the variable is shared with all the session,
“txn” : the variable is shared with all the transaction (request and
response),
“req” : the variable is shared only during the request processing,
“res” : the variable is shared only during the response processing.
this prefix is followed by a name. the separator is a ‘.’. the name may only
contain characters ‘a-z’, ‘a-z’, ‘0-9’ and ‘_’.
multiplies the input value of type signed integer by
the product as an signed integer. in case of overflow, the largest possible
value for the sign is returned so that the operation doesn’t wrap around.
starts by an indication about its scope. the allowed scopes are:
“sess” : the variable is shared with all the session,
“txn” : the variable is shared with all the transaction (request and
response),
“req” : the variable is shared only during the request processing,
“res” : the variable is shared only during the response processing.
this prefix is followed by a name. the separator is a ‘.’. the name may only
contain characters ‘a-z’, ‘a-z’, ‘0-9’ and ‘_’.
takes the input value of type signed integer, computes the opposite value,
and returns the remainder as an signed integer. 0 is identity. this operator
is provided for reversed subtracts : in order to subtract the input from a
constant, simply perform a “neg,add(value)”.
returns a boolean false if the input value of type signed integer is
non-null, otherwise returns true. used in conjunction with and(), it can be
used to report true/false for bit testing on input values (eg: verify the
absence of a flag).
returns a boolean true if the input value of type signed integer is odd
otherwise returns false. it is functionally equivalent to “and(1),bool”.
performs a bitwise “or” between
integer, and returns the result as an signed integer.
numeric value or a variable name. the name of the variable starts by an
indication about its scope. the allowed scopes are:
“sess” : the variable is shared with all the session,
“txn” : the variable is shared with all the transaction (request and
response),
“req” : the variable is shared only during the request processing,
“res” : the variable is shared only during the response processing.
this prefix is followed by a name. the separator is a ‘.’. the name may only
contain characters ‘a-z’, ‘a-z’, ‘0-9’ and ‘_’.
applies a regex-based substitution to the input string. it does the same
operation as the well-known “sed” utility with “s/
default it will replace in the input string the first occurrence of the
largest part matching the regular expression
string
the flag “g” in the third argument
regex case insensitive by adding the flag “i” in
string, it is made up from the concatenation of all desired flags. thus if
both “i” and “g” are desired, using “gi” or “ig” will have the same effect.
it is important to note that due to the current limitations of the
configuration parser, some characters such as closing parenthesis or comma
are not possible to use in the arguments. the first use of this converter is
to replace certain characters or sequence of characters with other ones. # de-duplicate "/" in header "x-path".
# input: x-path: /////a///b/c/xzxyz/
# output: x-path: /a/b/c/xzxyz/
http-request set-header x-path %[hdr(x-path),regsub(/+,/,g)]
capture the string entry in the request slot
is. if the slot doesn’t exist, the capture fails silently.
“http-response capture”, “req.hdr.capture” and
“res.hdr.capture” (sample fetches).
capture the string entry in the response slot
is. if the slot doesn’t exist, the capture fails silently.
“http-response capture”, “req.hdr.capture” and
“res.hdr.capture” (sample fetches).
hashes a binary input sample into an unsigned 32-bit quantity using the sdbm
hash function. optionally, it is possible to apply a full avalanche hash
function to the output if the optional
converter uses the same functions as used by the various hash-based load
balancing algorithms, so it will provide exactly the same results. it is
mostly intended for debugging, but can be used as a stick-table entry to
collect rough statistics. it must not be used for security purposes as a
32-bit hash is trivial to break. see also “crc32”, “djb2”, “wt6” and the
“hash-type” directive.
sets a variable with the input content and return the content on the output as
is. the variable keep the value and the associated input type. the name of the
variable starts by an indication about it scope. the scope allowed are:
“sess” : the variable is shared with all the session,
“txn” : the variable is shared with all the transaction (request and
response),
“req” : the variable is shared only during the request processing,
“res” : the variable is shared only during the response processing.
this prefix is followed by a name. the separator is a ‘.’. the name may only
contain characters ‘a-z’, ‘a-z’, ‘0-9’ and ‘_’.
subtracts
the result as an signed integer. note: in order to subtract the input from
a constant, simply perform a “neg,add(value)”.
or a variable name. the name of the variable starts by an indication about its
scope. the allowed scopes are:
“sess” : the variable is shared with all the session,
“txn” : the variable is shared with all the transaction (request and
response),
“req” : the variable is shared only during the request processing,
“res” : the variable is shared only during the response processing.
this prefix is followed by a name. the separator is a ‘.’. the name may only
contain characters ‘a-z’, ‘a-z’, ‘0-9’ and ‘_’.)
uses the string representation of the input sample to perform a look up in
the specified table. if the key is not found in the table, integer value zero
is returned. otherwise the converter returns the average client-to-server
bytes rate associated with the input sample in the designated table, measured
in amount of bytes over the period configured in the table. see also the
sc_bytes_in_rate sample fetch keyword.
)
uses the string representation of the input sample to perform a look up in
the specified table. if the key is not found in the table, integer value zero
is returned. otherwise the converter returns the average server-to-client
bytes rate associated with the input sample in the designated table, measured
in amount of bytes over the period configured in the table. see also the
sc_bytes_out_rate sample fetch keyword.
)
uses the string representation of the input sample to perform a look up in
the specified table. if the key is not found in the table, integer value zero
is returned. otherwise the converter returns the cumulated amount of incoming
connections associated with the input sample in the designated table. see
also the sc_conn_cnt sample fetch keyword.
)
uses the string representation of the input sample to perform a look up in
the specified table. if the key is not found in the table, integer value zero
is returned. otherwise the converter returns the current amount of concurrent
tracked connections associated with the input sample in the designated table.
see also the sc_conn_cur sample fetch keyword.
)
uses the string representation of the input sample to perform a look up in
the specified table. if the key is not found in the table, integer value zero
is returned. otherwise the converter returns the average incoming connection
rate associated with the input sample in the designated table. see also the
sc_conn_rate sample fetch keyword.
)
uses the string representation of the input sample to perform a look up in
the specified table. if the key is not found in the table, integer value zero
is returned. otherwise the converter returns the current value of the first
general purpose counter associated with the input sample in the designated
table. see also the sc_get_gpc0 sample fetch keyword.
)
uses the string representation of the input sample to perform a look up in
the specified table. if the key is not found in the table, integer value zero
is returned. otherwise the converter returns the frequency which the gpc0
counter was incremented over the configured period in the table, associated
with the input sample in the designated table. see also the sc_get_gpc0_rate
sample fetch keyword.
)
uses the string representation of the input sample to perform a look up in
the specified table. if the key is not found in the table, integer value zero
is returned. otherwise the converter returns the cumulated amount of http
errors associated with the input sample in the designated table. see also the
sc_http_err_cnt sample fetch keyword.
)
uses the string representation of the input sample to perform a look up in
the specified table. if the key is not found in the table, integer value zero
is returned. otherwise the average rate of http errors associated with the
input sample in the designated table, measured in amount of errors over the
period configured in the table. see also the sc_http_err_rate sample fetch
keyword.
)
uses the string representation of the input sample to perform a look up in
the specified table. if the key is not found in the table, integer value zero
is returned. otherwise the converter returns the cumulated amount of http
requests associated with the input sample in the designated table. see also
the sc_http_req_cnt sample fetch keyword.
)
uses the string representation of the input sample to perform a look up in
the specified table. if the key is not found in the table, integer value zero
is returned. otherwise the average rate of http requests associated with the
input sample in the designated table, measured in amount of requests over the
period configured in the table. see also the sc_http_req_rate sample fetch
keyword.
)
uses the string representation of the input sample to perform a look up in
the specified table. if the key is not found in the table, integer value zero
is returned. otherwise the converter returns the cumulated amount of client-
to-server data associated with the input sample in the designated table,
measured in kilobytes. the test is currently performed on 32-bit integers,
which limits values to 4 terabytes. see also the sc_kbytes_in sample fetch
keyword.
)
uses the string representation of the input sample to perform a look up in
the specified table. if the key is not found in the table, integer value zero
is returned. otherwise the converter returns the cumulated amount of server-
to-client data associated with the input sample in the designated table,
measured in kilobytes. the test is currently performed on 32-bit integers,
which limits values to 4 terabytes. see also the sc_kbytes_out sample fetch
keyword.
)
uses the string representation of the input sample to perform a look up in
the specified table. if the key is not found in the table, integer value zero
is returned. otherwise the converter returns the server id associated with
the input sample in the designated table. a server id is associated to a
sample by a “stick” rule when a connection to a server succeeds. a server id
zero means that no server is associated with this key.
)
uses the string representation of the input sample to perform a look up in
the specified table. if the key is not found in the table, integer value zero
is returned. otherwise the converter returns the cumulated amount of incoming
sessions associated with the input sample in the designated table. note that
a session here refers to an incoming connection being accepted by the
“tcp-request connection” rulesets. see also the sc_sess_cnt sample fetch
keyword.
)
uses the string representation of the input sample to perform a look up in
the specified table. if the key is not found in the table, integer value zero
is returned. otherwise the converter returns the average incoming session
rate associated with the input sample in the designated table. note that a
session here refers to an incoming connection being accepted by the
“tcp-request connection” rulesets. see also the sc_sess_rate sample fetch
keyword.
)
uses the string representation of the input sample to perform a look up in
the specified table. if the key is not found in the table, integer value zero
is returned. otherwise the converter returns the current amount of concurrent
connections tracking the same key as the input sample in the designated
table. it differs from table_conn_cur in that it does not rely on any stored
information but on the table’s reference count (the “use” value which is
returned by “show table” on the cli). this may sometimes be more suited for
layer7 tracking. it can be used to tell a server how many concurrent
connections there are from a given address for example. see also the
sc_trackers sample fetch keyword.
convert a string sample to upper case. this can only be placed after a string
sample fetch function or after a transformation keyword returning a string
type. the result is of type string.
takes an url-encoded string provided as input and returns the decoded
version as output. the input and the output are of type string.
converts an integer supposed to contain a date since epoch to a string
representing this date in utc time using a format defined by the
string using strftime(3). the purpose is to allow any date format to be used
in logs. an optional
(positive or negative). see the strftime() man page for the format supported
by your operating system. see also the ltime converter. # emit two colons, one with the utc time and another with ip:port
# eg: 20140710162350 127.0.0.1:57325
log-format %[date,utime(%y%m%d%h%m%s)]\ %ci:%cp
extracts the nth word considering given delimiters from an input string.
indexes start at 1 and delimiters are a string formatted list of chars.
hashes a binary input sample into an unsigned 32-bit quantity using the wt6
hash function. optionally, it is possible to apply a full avalanche hash
function to the output if the optional
converter uses the same functions as used by the various hash-based load
balancing algorithms, so it will provide exactly the same results. it is
mostly intended for debugging, but can be used as a stick-table entry to
collect rough statistics. it must not be used for security purposes as a
32-bit hash is trivial to break. see also “crc32”, “djb2”, “sdbm”, and the
“hash-type” directive.
performs a bitwise “xor” (exclusive or) between
of type signed integer, and returns the result as an signed integer.
starts by an indication about its scope. the allowed scopes are:
“sess” : the variable is shared with all the session,
“txn” : the variable is shared with all the transaction (request and
response),
“req” : the variable is shared only during the request processing,
“res” : the variable is shared only during the response processing.
this prefix is followed by a name. the separator is a ‘.’. the name may only
contain characters ‘a-z’, ‘a-z’, ‘0-9’ and ‘_’.7.3.2. fetching samples from internal states
not even relate to any client information. these ones are sometimes used with
“monitor-fail” directives to report an internal status to external watchers.
the sample fetch methods described in this section are usable anywhere.
always returns the boolean “false” value. it may be used with acls as a
temporary replacement for another one when adjusting configurations.
always returns the boolean “true” value. it may be used with acls as a
temporary replacement for another one when adjusting configurations.
returns the total number of queued connections of the designated backend
divided by the number of active servers. the current backend is used if no
backend is specified. this is very similar to “queue” except that the size of
the farm is considered, in order to give a more accurate measurement of the
time it may take for a new connection to be processed. the main usage is with
acl to return a sorry page to new users when it becomes certain they will get
a degraded service, or to pass to the backend servers in a header so that
they decide to work in degraded mode or to disable some functions to speed up
the processing a bit. note that in the event there would not be any active
server anymore, twice the number of queued connections would be considered as
the measured value. this is a fair estimate, as we expect one server to get
back soon anyway, but we still prefer to send new traffic to another backend
if in better shape. see also the “queue”, “be_conn”, and “be_sess_rate”
sample fetches.
applies to the number of currently established connections on the backend,
possibly including the connection being evaluated. if no backend name is
specified, the current one is used. but it is also possible to check another
backend. it can be used to use a specific farm when the nominal one is full.
see also the “fe_conn”, “queue” and “be_sess_rate” criteria.
returns an integer value corresponding to the sessions creation rate on the
backend, in number of new sessions per second. this is used with acls to
switch to an alternate backend when an expensive or fragile one reaches too
high a session rate, or to limit abuse of service (eg. prevent sucking of an
online dictionary). it can also be useful to add this element to logs using a
log-format directive.
# redirect to an error page if the dictionary is requested too often
backend dynamic
mode http
acl being_scanned be_sess_rate gt 100
redirect location /denied.html if being_scanned
returns a binary chain. the input is the hexadecimal representation
of the string.
returns a boolean value.
‘false’ and ‘0’ are the same. ‘true’ and ‘1’ are the same.
returns an integer value corresponding to the number of connection slots
still available in the backend, by totaling the maximum amount of
connections on all servers and the maximum queue size. this is probably only
used with acls.
still available (connection + queue), so that anything beyond that (intended
usage; see “use_backend” keyword) can be redirected to a different backend.
available server queue slots.
useful when you have a case of traffic going to one single ip, splitting into
multiple backends (perhaps using acls to do name-based load balancing) and
you want to be able to differentiate between different backends, and their
available “connslots”. also, whereas “nbsrv” only measures servers that are
actually down, this fetch is more fine-grained and looks into the number of
available connection slots as well. see also “queue” and “avg_queue”.
of dynamic connections. also, if any of the server maxconn, or maxqueue is 0,
then this fetch clearly does not make sense, in which case the value returned
will be -1.
returns the current date as the epoch (number of seconds since 01/01/1970).
if an offset value is specified, then it is a number of seconds that is added
to the current date before returning the value. this is particularly useful
to compute relative dates, as both positive and negative offsets are allowed.
it is useful combined with the http_date converter. # set an expires header to now+1 hour in every response
http-response set-header expires %[date(3600),http_date]
returns a string containing the value of environment variable
reminder, environment variables are per-process and are sampled when the
process starts. this can be useful to pass some information to a next hop
server, or with acls to take specific action when the process is started a
certain way.
# pass the via header to next hop with the local hostname in it
http-request add-header via 1.1\ %[env(hostname)] # reject cookie-less requests when the stop environment variable is set
http-request deny if !{ cook(sessionid) -m found } { env(stop) -m found }
returns the number of currently established connections on the frontend,
possibly including the connection being evaluated. if no frontend name is
specified, the current one is used. but it is also possible to check another
frontend. it can be used to return a sorry page before hard-blocking, or to
use a specific backend to drain new requests when the farm is considered
full. this is mostly used with acls but can also be used to pass some
statistics to servers in http headers. see also the “dst_conn”, “be_conn”,
“fe_sess_rate” fetches.
returns an integer value corresponding to the sessions creation rate on the
frontend, in number of new sessions per second. this is used with acls to
limit the incoming session rate to an acceptable range in order to prevent
abuse of service at the earliest moment, for example when combined with other
layer 4 acls in order to force the clients to wait a bit for the rate to go
down below the limit. it can also be useful to add this element to logs using
a log-format directive. see also the “rate-limit sessions” directive for use
in frontends.
# this frontend limits incoming mails to 10/s with a max of 100
# concurrent connections. we accept any connection below 10/s, and
# force excess clients to wait for 100 ms. since clients are limited to
# 100 max, there cannot be more than 10 incoming mails per second.
frontend mail
bind :25
mode tcp
maxconn 100
acl too_fast fe_sess_rate ge 10
tcp-request inspect-delay 100ms
tcp-request content accept if ! too_fast
tcp-request content accept if wait_end
returns a signed integer.
returns an ipv4.
returns an ipv6.
returns a method.
returns an integer value corresponding to the number of processes that were
started (it equals the global “nbproc” setting). this is useful for logging
and debugging purposes.
returns an integer value corresponding to the number of usable servers of
either the current backend or the named backend. this is mostly used with
acls but can also be useful when added to logs. this is normally used to
switch to an alternate backend when the number of servers is too low to
to handle some load. it is useful to report a failure when combined with
“monitor fail”.
returns an integer value corresponding to the position of the process calling
the function, between 1 and global.nbproc. this is useful for logging and
debugging purposes.
returns the total number of queued connections of the designated backend,
including all the connections in server queues. if no backend name is
specified, the current one is used, but it is also possible to check another
one. this is useful with acls or to pass statistics to backend servers. this
can be used to take actions when queuing goes above a known level, generally
indicating a surge of traffic or a massive slowdown on the servers. one
possible action could be to reject new users but still accept old ones. see
also the “avg_queue”, “be_conn”, and “be_sess_rate” fetches.
returns a random integer value within a range of
starting at zero. if the range is not specified, it defaults to 2^32, which
gives numbers between 0 and 4294967295. it can be useful to pass some values
needed to take some routing decisions for example, or just for debugging
purposes. this random must not be used for security purposes.
returns an integer value corresponding to the number of currently established
connections on the designated server, possibly including the connection being
evaluated. if
current backend. it can be used to use a specific farm when one server is
full, or to inform the server about our view of the number of active
connections with it. see also the “fe_conn”, “be_conn” and “queue” fetch
methods.
returns true when the designated server is up, and false when it is either
down or in maintenance mode. if
looked up in the current backend. it is mainly used to take action based on
an external status reported via a health check (eg: a geographical site’s
availability). another possible use which is more of a hack consists in
using dummy servers as boolean variables that can be enabled or disabled from
the cli, so that rules depending on those acls can be tweaked in realtime.
returns an integer corresponding to the sessions creation rate on the
designated server, in number of new sessions per second. if
omitted, then the server is looked up in the current backend. this is mostly
used with acls but can make sense with logs too. this is used to switch to an
alternate backend when an expensive or fragile one reaches too high a session
rate, or to limit abuse of service (eg. prevent latent requests from
overloading servers).
# redirect to a separate back
acl srv1_full srv_sess_rate(be1/srv1) gt 50
acl srv2_full srv_sess_rate(be1/srv2) gt 50
use_backend be2 if srv1_full or srv2_full
returns true if the process calling the function is currently stopping. this
can be useful for logging, or for relaxing certain checks or helping close
certain connections upon graceful shutdown.
returns a string.]) : integer
returns the total number of available entries in the current proxy’s
stick-table or in the designated stick-table. see also table_cnt.
]) : integer
returns the total number of entries currently in use in the current proxy’s
stick-table or in the designated stick-table. see also src_conn_cnt and
table_avl for other entry counting methods.
returns a variable with the stored type. if the variable is not set, the
sample fetch fails. the name of the variable starts by an indication about its
scope. the scope allowed are:
“sess” : the variable is shared with all the session,
“txn” : the variable is shared with all the transaction (request and
response),
“req” : the variable is shared only during the request processing,
“res” : the variable is shared only during the response processing.
this prefix is followed by a name. the separator is a ‘.’. the name may only
contain characters ‘a-z’, ‘a-z’, ‘0-9’ and ‘_’.7.3.3. fetching samples at layer 4
closest to the connection, where no content is yet made available. the fetch
methods described here are usable as low as the “tcp-request connection” rule
sets unless they require some future information. those generally include
tcp/ip addresses and ports, as well as elements from stick-tables related to
the incoming connection. for retrieving a value from a sticky counters, the
counter number can be explicitly set as 0, 1, or 2 using the pre-defined
“sc0_”, “sc1_”, or “sc2_” prefix, or it can be specified as the first integer
argument when using the “sc_” prefix. an optional table may be specified with
the “sc*” form, in which case the currently tracked key will be looked up into
this alternate table instead of the table currently being tracked.
returns an integer containing the current backend’s id. it can be used in
frontends with responses to check which backend processed the request.
this is the destination ipv4 address of the connection on the client side,
which is the address the client connected to. it can be useful when running
in transparent mode. it is of type ip and works on both ipv4 and ipv6 tables.
on ipv6 tables, ipv4 address is mapped to its ipv6 equivalent, according to
rfc 4291.
returns an integer value corresponding to the number of currently established
connections on the same socket including the one being evaluated. it is
normally used with acls but can as well be used to pass the information to
servers in an http header or in logs. it can be used to either return a sorry
page before hard-blocking, or to use a specific backend to drain new requests
when the socket is considered saturated. this offers the ability to assign
different limits to different listening ports or addresses. see also the
“fe_conn” and “be_conn” fetches.
returns an integer value corresponding to the destination tcp port of the
connection on the client side, which is the port the client connected to.
this might be used when running in transparent mode, when assigning dynamic
ports to some clients for a whole application session, to stick all users to
a same server, or to pass the destination port information to a server using
an http header.
returns an integer containing the current frontend’s id. it can be used in
backends to check from which backend it was called, or to stick all users
coming via a same frontend to the same server.]) : integer
sc0_bytes_in_rate([]) : integer
sc1_bytes_in_rate([]) : integer
sc2_bytes_in_rate([]) : integer
returns the average client-to-server bytes rate from the currently tracked
counters, measured in amount of bytes over the period configured in the
table. see also src_bytes_in_rate.
]) : integer
sc0_bytes_out_rate([]) : integer
sc1_bytes_out_rate([]) : integer
sc2_bytes_out_rate([]) : integer
returns the average server-to-client bytes rate from the currently tracked
counters, measured in amount of bytes over the period configured in the
table. see also src_bytes_out_rate.
]) : integer
sc0_clr_gpc0([]) : integer
sc1_clr_gpc0([]) : integer
sc2_clr_gpc0([]) : integer
clears the first general purpose counter associated to the currently tracked
counters, and returns its previous value. before the first invocation, the
stored value is zero, so first invocation will always return zero. this is
typically used as a second acl in an expression in order to mark a connection
when a first acl was verified :
# block if 5 consecutive requests continue to come faster than 10 sess
# per second, and reset the counter as soon as the traffic slows down.
acl abuse sc0_http_req_rate gt 10
acl kill sc0_inc_gpc0 gt 5
acl save sc0_clr_gpc0 ge 0
tcp-request connection accept if !abuse save
tcp-request connection reject if abuse kill
]) : integer
sc0_conn_cnt([]) : integer
sc1_conn_cnt([]) : integer
sc2_conn_cnt([]) : integer
returns the cumulated number of incoming connections from currently tracked
counters. see also src_conn_cnt.
]) : integer
sc0_conn_cur([]) : integer
sc1_conn_cur([]) : integer
sc2_conn_cur([]) : integer
returns the current amount of concurrent connections tracking the same
tracked counters. this number is automatically incremented when tracking
begins and decremented when tracking stops. see also src_conn_cur.
]) : integer
sc0_conn_rate([]) : integer
sc1_conn_rate([]) : integer
sc2_conn_rate([]) : integer
returns the average connection rate from the currently tracked counters,
measured in amount of connections over the period configured in the table.
see also src_conn_rate.
]) : integer
sc0_get_gpc0([]) : integer
sc1_get_gpc0([]) : integer
sc2_get_gpc0([]) : integer
returns the value of the first general purpose counter associated to the
currently tracked counters. see also src_get_gpc0 and sc/sc0/sc1/sc2_inc_gpc0.
]) : integer
sc0_gpc0_rate([]) : integer
sc1_gpc0_rate([]) : integer
sc2_gpc0_rate([]) : integer
returns the average increment rate of the first general purpose counter
associated to the currently tracked counters. it reports the frequency
which the gpc0 counter was incremented over the configured period. see also
src_gpc0_rate, sc/sc0/sc1/sc2_get_gpc0, and sc/sc0/sc1/sc2_inc_gpc0. note
that the “gpc0_rate” counter must be stored in the stick-table for a value to
be returned, as “gpc0” only holds the event count.
]) : integer
sc0_http_err_cnt([]) : integer
sc1_http_err_cnt([]) : integer
sc2_http_err_cnt([]) : integer
returns the cumulated number of http errors from the currently tracked
counters. this includes the both request errors and 4xx error responses.
see also src_http_err_cnt.
]) : integer
sc0_http_err_rate([]) : integer
sc1_http_err_rate([]) : integer
sc2_http_err_rate([]) : integer
returns the average rate of http errors from the currently tracked counters,
measured in amount of errors over the period configured in the table. this
includes the both request errors and 4xx error responses. see also
src_http_err_rate.
]) : integer
sc0_http_req_cnt([]) : integer
sc1_http_req_cnt([]) : integer
sc2_http_req_cnt([]) : integer
returns the cumulated number of http requests from the currently tracked
counters. this includes every started request, valid or not. see also
src_http_req_cnt.
]) : integer
sc0_http_req_rate([]) : integer
sc1_http_req_rate([]) : integer
sc2_http_req_rate([]) : integer
returns the average rate of http requests from the currently tracked
counters, measured in amount of requests over the period configured in
the table. this includes every started request, valid or not. see also
src_http_req_rate.
]) : integer
sc0_inc_gpc0([]) : integer
sc1_inc_gpc0([]) : integer
sc2_inc_gpc0([]) : integer
increments the first general purpose counter associated to the currently
tracked counters, and returns its new value. before the first invocation,
the stored value is zero, so first invocation will increase it to 1 and will
return 1. this is typically used as a second acl in an expression in order
to mark a connection when a first acl was verified :
acl abuse sc0_http_req_rate gt 10
acl kill sc0_inc_gpc0 gt 0
tcp-request connection reject if abuse kill
]) : integer
sc0_kbytes_in([]) : integer
sc1_kbytes_in([]) : integer
sc2_kbytes_in([]) : integer
returns the total amount of client-to-server data from the currently tracked
counters, measured in kilobytes. the test is currently performed on 32-bit
integers, which limits values to 4 terabytes. see also src_kbytes_in.
]) : integer
sc0_kbytes_out([]) : integer
sc1_kbytes_out([]) : integer
sc2_kbytes_out([]) : integer
returns the total amount of server-to-client data from the currently tracked
counters, measured in kilobytes. the test is currently performed on 32-bit
integers, which limits values to 4 terabytes. see also src_kbytes_out.
]) : integer
sc0_sess_cnt([]) : integer
sc1_sess_cnt([]) : integer
sc2_sess_cnt([]) : integer
returns the cumulated number of incoming connections that were transformed
into sessions, which means that they were accepted by a “tcp-request
connection” rule, from the currently tracked counters. a backend may count
more sessions than connections because each connection could result in many
backend sessions if some http keep-alive is performed over the connection
with the client. see also src_sess_cnt.
]) : integer
sc0_sess_rate([]) : integer
sc1_sess_rate([]) : integer
sc2_sess_rate([]) : integer
returns the average session rate from the currently tracked counters,
measured in amount of sessions over the period configured in the table. a
session is a connection that got past the early “tcp-request connection”
rules. a backend may count more sessions than connections because each
connection could result in many backend sessions if some http keep-alive is
performed over the connection with the client. see also src_sess_rate.
]) : boolean
sc0_tracked([]) : boolean
sc1_tracked([]) : boolean
sc2_tracked([]) : boolean
returns true if the designated session counter is currently being tracked by
the current session. this can be useful when deciding whether or not we want
to set some values in a header passed to the server.
]) : integer
sc0_trackers([]) : integer
sc1_trackers([]) : integer
sc2_trackers([]) : integer
returns the current amount of concurrent connections tracking the same
tracked counters. this number is automatically incremented when tracking
begins and decremented when tracking stops. it differs from sc0_conn_cur in
that it does not rely on any stored information but on the table’s reference
count (the “use” value which is returned by “show table” on the cli). this
may sometimes be more suited for layer7 tracking. it can be used to tell a
server how many concurrent connections there are from a given address for
example.
returns an integer containing the current listening socket’s id. it is useful
in frontends involving many “bind” lines, or to stick all users coming via a
same socket to the same server.
this is the source ipv4 address of the client of the session. it is of type
ip and works on both ipv4 and ipv6 tables. on ipv6 tables, ipv4 addresses are
mapped to their ipv6 equivalent, according to rfc 4291. note that it is the
tcp-level source address which is used, and not the address of a client
behind a proxy. however if the “accept-proxy” bind directive is used, it can
be the address of a client behind another proxy-protocol compatible component
for all rule sets except “tcp-request connection” which sees the real address.
# add an http header in requests with the originating address’ country
http-request set-header x-country %[src,map_ip(geoip.lst)]]) : integer
returns the average bytes rate from the incoming connection’s source address
in the current proxy’s stick-table or in the designated stick-table, measured
in amount of bytes over the period configured in the table. if the address is
not found, zero is returned. see also sc/sc0/sc1/sc2_bytes_in_rate.
]) : integer
returns the average bytes rate to the incoming connection’s source address in
the current proxy’s stick-table or in the designated stick-table, measured in
amount of bytes over the period configured in the table. if the address is
not found, zero is returned. see also sc/sc0/sc1/sc2_bytes_out_rate.
]) : integer
clears the first general purpose counter associated to the incoming
connection’s source address in the current proxy’s stick-table or in the
designated stick-table, and returns its previous value. if the address is not
found, an entry is created and 0 is returned. this is typically used as a
second acl in an expression in order to mark a connection when a first acl
was verified :
# block if 5 consecutive requests continue to come faster than 10 sess
# per second, and reset the counter as soon as the traffic slows down.
acl abuse src_http_req_rate gt 10
acl kill src_inc_gpc0 gt 5
acl save src_clr_gpc0 ge 0
tcp-request connection accept if !abuse save
tcp-request connection reject if abuse kill
]) : integer
returns the cumulated number of connections initiated from the current
incoming connection’s source address in the current proxy’s stick-table or in
the designated stick-table. if the address is not found, zero is returned.
see also sc/sc0/sc1/sc2_conn_cnt.
]) : integer
returns the current amount of concurrent connections initiated from the
current incoming connection’s source address in the current proxy’s
stick-table or in the designated stick-table. if the address is not found,
zero is returned. see also sc/sc0/sc1/sc2_conn_cur.
]) : integer
returns the average connection rate from the incoming connection’s source
address in the current proxy’s stick-table or in the designated stick-table,
measured in amount of connections over the period configured in the table. if
the address is not found, zero is returned. see also sc/sc0/sc1/sc2_conn_rate.
]) : integer
returns the value of the first general purpose counter associated to the
incoming connection’s source address in the current proxy’s stick-table or in
the designated stick-table. if the address is not found, zero is returned.
see also sc/sc0/sc1/sc2_get_gpc0 and src_inc_gpc0.
]) : integer
returns the average increment rate of the first general purpose counter
associated to the incoming connection’s source address in the current proxy’s
stick-table or in the designated stick-table. it reports the frequency
which the gpc0 counter was incremented over the configured period. see also
sc/sc0/sc1/sc2_gpc0_rate, src_get_gpc0, and sc/sc0/sc1/sc2_inc_gpc0. note
that the “gpc0_rate” counter must be stored in the stick-table for a value to
be returned, as “gpc0” only holds the event count.
]) : integer
returns the cumulated number of http errors from the incoming connection’s
source address in the current proxy’s stick-table or in the designated
stick-table. this includes the both request errors and 4xx error responses.
see also sc/sc0/sc1/sc2_http_err_cnt. if the address is not found, zero is
returned.
]) : integer
returns the average rate of http errors from the incoming connection’s source
address in the current proxy’s stick-table or in the designated stick-table,
measured in amount of errors over the period configured in the table. this
includes the both request errors and 4xx error responses. if the address is
not found, zero is returned. see also sc/sc0/sc1/sc2_http_err_rate.
]) : integer
returns the cumulated number of http requests from the incoming connection’s
source address in the current proxy’s stick-table or in the designated stick-
table. this includes every started request, valid or not. if the address is
not found, zero is returned. see also sc/sc0/sc1/sc2_http_req_cnt.
]) : integer
returns the average rate of http requests from the incoming connection’s
source address in the current proxy’s stick-table or in the designated stick-
table, measured in amount of requests over the period configured in the
table. this includes every started request, valid or not. if the address is
not found, zero is returned. see also sc/sc0/sc1/sc2_http_req_rate.
]) : integer
increments the first general purpose counter associated to the incoming
connection’s source address in the current proxy’s stick-table or in the
designated stick-table, and returns its new value. if the address is not
found, an entry is created and 1 is returned. see also sc0/sc2/sc2_inc_gpc0.
this is typically used as a second acl in an expression in order to mark a
connection when a first acl was verified :
acl abuse src_http_req_rate gt 10
acl kill src_inc_gpc0 gt 0
tcp-request connection reject if abuse kill
]) : integer
returns the total amount of data received from the incoming connection’s
source address in the current proxy’s stick-table or in the designated
stick-table, measured in kilobytes. if the address is not found, zero is
returned. the test is currently performed on 32-bit integers, which limits
values to 4 terabytes. see also sc/sc0/sc1/sc2_kbytes_in.
]) : integer
returns the total amount of data sent to the incoming connection’s source
address in the current proxy’s stick-table or in the designated stick-table,
measured in kilobytes. if the address is not found, zero is returned. the
test is currently performed on 32-bit integers, which limits values to 4
terabytes. see also sc/sc0/sc1/sc2_kbytes_out.
returns an integer value corresponding to the tcp source port of the
connection on the client side, which is the port the client connected from.
usage of this function is very limited as modern protocols do not care much
about source ports nowadays.]) : integer
returns the cumulated number of connections initiated from the incoming
connection’s source ipv4 address in the current proxy’s stick-table or in the
designated stick-table, that were transformed into sessions, which means that
they were accepted by “tcp-request” rules. if the address is not found, zero
is returned. see also sc/sc0/sc1/sc2_sess_cnt.
]) : integer
returns the average session rate from the incoming connection’s source
address in the current proxy’s stick-table or in the designated stick-table,
measured in amount of sessions over the period configured in the table. a
session is a connection that went past the early “tcp-request” rules. if the
address is not found, zero is returned. see also sc/sc0/sc1/sc2_sess_rate.
]) : integer
creates or updates the entry associated to the incoming connection’s source
address in the current proxy’s stick-table or in the designated stick-table.
this table must be configured to store the “conn_cnt” data type, otherwise
the match will be ignored. the current count is incremented by one, and the
expiration timer refreshed. the updated count is returned, so this match
can’t return zero. this was used to reject service abusers based on their
source address. note: it is recommended to use the more complete “track-sc*”
actions in “tcp-request” rules instead.
# this frontend limits incoming ssh connections to 3 per 10 second for
# each source address, and rejects excess connections until a 10 second
# silence is observed. at most 20 addresses are tracked.
listen ssh
bind :22
mode tcp
maxconn 100
stick-table type ip size 20 expire 10s store conn_cnt
tcp-request content reject if { src_updt_conn_cnt gt 3 }
server local 127.0.0.1:22
returns an integer containing the server’s id when processing the response.
while it’s almost only used with acls, it may be used for logging or
debugging.7.3.4. fetching samples at layer 5
closest to the session once all the connection handshakes are finished, but
when no content is yet made available. the fetch methods described here are
usable as low as the “tcp-request content” rule sets unless they require some
future information. those generally include the results of ssl negotiations.
returns true when the back connection was made via an ssl/tls transport
layer and is locally deciphered. this means the outgoing connection was made
other a server with the “ssl” option.
returns the symmetric cipher key size supported in bits when the outgoing
connection was made over an ssl/tls transport layer.
returns the name of the used cipher when the outgoing connection was made
over an ssl/tls transport layer.
returns the name of the used protocol when the outgoing connection was made
over an ssl/tls transport layer.
when the outgoing connection was made over an ssl/tls transport layer,
returns the tls unique id as defined in rfc5929 section 3. the unique id
can be encoded to base64 using the converter: “ssl_bc_unique_id,base64”.
returns the ssl id of the back connection when the outgoing connection was
made over an ssl/tls transport layer. it is useful to log if we want to know
if session was reused or not.
returns the symmetric cipher key size used in bits when the outgoing
connection was made over an ssl/tls transport layer.
when the incoming connection was made over an ssl/tls transport layer,
returns the id of the first error detected during verification of the client
certificate at depth > 0, or 0 if no error was encountered during this
verification process. please refer to your ssl library’s documentation to
find the exhaustive list of error codes.
when the incoming connection was made over an ssl/tls transport layer,
returns the depth in the ca chain of the first error detected during the
verification of the client certificate. if no error is encountered, 0 is
returned.
returns the der formatted certificate presented by the client when the
incoming connection was made over an ssl/tls transport layer. when used for
an acl, the value(s) to match against can be passed in hexadecimal form.
when the incoming connection was made over an ssl/tls transport layer,
returns the id of the first error detected during verification at depth 0, or
0 if no error was encountered during this verification process. please refer
to your ssl library’s documentation to find the exhaustive list of error
codes.
when the incoming connection was made over an ssl/tls transport layer,
returns the full distinguished name of the issuer of the certificate
presented by the client when no
first given entry found from the beginning of the dn. if a positive/negative
occurrence number is specified as the optional second argument, it returns
the value of the nth given entry value from the beginning/end of the dn.
for instance, “ssl_c_i_dn(ou,2)” the second organization unit, and
“ssl_c_i_dn(cn)” retrieves the common name.
returns the name of the algorithm used to generate the key of the certificate
presented by the client when the incoming connection was made over an ssl/tls
transport layer.
returns the end date presented by the client as a formatted string
yymmddhhmmss[z] when the incoming connection was made over an ssl/tls
transport layer.
returns the start date presented by the client as a formatted string
yymmddhhmmss[z] when the incoming connection was made over an ssl/tls
transport layer.
when the incoming connection was made over an ssl/tls transport layer,
returns the full distinguished name of the subject of the certificate
presented by the client when no
first given entry found from the beginning of the dn. if a positive/negative
occurrence number is specified as the optional second argument, it returns
the value of the nth given entry value from the beginning/end of the dn.
for instance, “ssl_c_s_dn(ou,2)” the second organization unit, and
“ssl_c_s_dn(cn)” retrieves the common name.
returns the serial of the certificate presented by the client when the
incoming connection was made over an ssl/tls transport layer. when used for
an acl, the value(s) to match against can be passed in hexadecimal form.
returns the sha-1 fingerprint of the certificate presented by the client when
the incoming connection was made over an ssl/tls transport layer. this can be
used to stick a client to a server, or to pass this information to a server.
note that the output is binary, so if you want to pass that signature to the
server, you need to encode it in hex or base64, such as in the example below: http-request set-header x-ssl-client-sha1 %[ssl_c_sha1,hex]
returns the name of the algorithm used to sign the certificate presented by
the client when the incoming connection was made over an ssl/tls transport
layer.
returns true if current ssl session uses a client certificate even if current
connection uses ssl session resumption. see also “ssl_fc_has_crt”.
returns the verify result error id when the incoming connection was made over
an ssl/tls transport layer, otherwise zero if no error is encountered. please
refer to your ssl library’s documentation for an exhaustive list of error
codes.
returns the version of the certificate presented by the client when the
incoming connection was made over an ssl/tls transport layer.
returns the der formatted certificate presented by the frontend when the
incoming connection was made over an ssl/tls transport layer. when used for
an acl, the value(s) to match against can be passed in hexadecimal form.
when the incoming connection was made over an ssl/tls transport layer,
returns the full distinguished name of the issuer of the certificate
presented by the frontend when no
first given entry found from the beginning of the dn. if a positive/negative
occurrence number is specified as the optional second argument, it returns
the value of the nth given entry value from the beginning/end of the dn.
for instance, “ssl_f_i_dn(ou,2)” the second organization unit, and
“ssl_f_i_dn(cn)” retrieves the common name.
returns the name of the algorithm used to generate the key of the certificate
presented by the frontend when the incoming connection was made over an
ssl/tls transport layer.
returns the end date presented by the frontend as a formatted string
yymmddhhmmss[z] when the incoming connection was made over an ssl/tls
transport layer.
returns the start date presented by the frontend as a formatted string
yymmddhhmmss[z] when the incoming connection was made over an ssl/tls
transport layer.
when the incoming connection was made over an ssl/tls transport layer,
returns the full distinguished name of the subject of the certificate
presented by the frontend when no
first given entry found from the beginning of the dn. if a positive/negative
occurrence number is specified as the optional second argument, it returns
the value of the nth given entry value from the beginning/end of the dn.
for instance, “ssl_f_s_dn(ou,2)” the second organization unit, and
“ssl_f_s_dn(cn)” retrieves the common name.
returns the serial of the certificate presented by the frontend when the
incoming connection was made over an ssl/tls transport layer. when used for
an acl, the value(s) to match against can be passed in hexadecimal form.
returns the sha-1 fingerprint of the certificate presented by the frontend
when the incoming connection was made over an ssl/tls transport layer. this
can be used to know which certificate was chosen using sni.
returns the name of the algorithm used to sign the certificate presented by
the frontend when the incoming connection was made over an ssl/tls transport
layer.
returns the version of the certificate presented by the frontend when the
incoming connection was made over an ssl/tls transport layer.
returns true when the front connection was made via an ssl/tls transport
layer and is locally deciphered. this means it has matched a socket declared
with a “bind” line having the “ssl” option.
# this passes “x-proto: https” to servers when client connects over ssl
listen http-https
bind :80
bind :443 ssl crt /etc/haproxy.pem
http-request add-header x-proto https if { ssl_fc }
returns the symmetric cipher key size supported in bits when the incoming
connection was made over an ssl/tls transport layer.
this extracts the application layer protocol negotiation field from an
incoming connection made via a tls transport layer and locally deciphered by
haproxy. the result is a string containing the protocol name advertised by
the client. the ssl library must have been built with support for tls
extensions enabled (check haproxy -vv). note that the tls alpn extension is
not advertised unless the “alpn” keyword on the “bind” line specifies a
protocol list. also, nothing forces the client to pick a protocol from this
list, any other one may be requested. the tls alpn extension is meant to
replace the tls npn extension. see also “ssl_fc_npn”.
returns the name of the used cipher when the incoming connection was made
over an ssl/tls transport layer.
returns true if a client certificate is present in an incoming connection over
ssl/tls transport layer. useful if ‘verify’ statement is set to ‘optional’.
note: on ssl session resumption with session id or tls ticket, client
certificate is not present in the current connection but may be retrieved
from the cache or the ticket. so prefer “ssl_c_used” if you want to check if
current ssl session uses a client certificate.
this checks for the presence of a server name indication tls extension (sni)
in an incoming connection was made over an ssl/tls transport layer. returns
true when the incoming connection presents a tls sni field. this requires
that the ssl library is build with support for tls extensions enabled (check
haproxy -vv).
returns true if the ssl/tls session has been resumed through the use of
ssl session cache or tls tickets.
this extracts the next protocol negotiation field from an incoming connection
made via a tls transport layer and locally deciphered by haproxy. the result
is a string containing the protocol name advertised by the client. the ssl
library must have been built with support for tls extensions enabled (check
haproxy -vv). note that the tls npn extension is not advertised unless the
“npn” keyword on the “bind” line specifies a protocol list. also, nothing
forces the client to pick a protocol from this list, any other one may be
requested. please note that the tls npn extension was replaced with alpn.
returns the name of the used protocol when the incoming connection was made
over an ssl/tls transport layer.
when the incoming connection was made over an ssl/tls transport layer,
returns the tls unique id as defined in rfc5929 section 3. the unique id
can be encoded to base64 using the converter: “ssl_bc_unique_id,base64”.
returns the ssl id of the front connection when the incoming connection was
made over an ssl/tls transport layer. it is useful to stick a given client to
a server. it is important to note that some browsers refresh their session id
every few minutes.
this extracts the server name indication tls extension (sni) field from an
incoming connection made via an ssl/tls transport layer and locally
deciphered by haproxy. the result (when present) typically is a string
matching the https host name (253 chars or less). the ssl library must have
been built with support for tls extensions enabled (check haproxy -vv).
connection being deciphered by haproxy and not to ssl contents being blindly
forwarded. see also “ssl_fc_sni_end” and “ssl_fc_sni_reg” below. this
requires that the ssl library is build with support for tls extensions
enabled (check haproxy -vv).
ssl_fc_sni_end : suffix match
ssl_fc_sni_reg : regex match
returns the symmetric cipher key size used in bits when the incoming
connection was made over an ssl/tls transport layer.7.3.5. fetching samples from buffer contents (layer 6)
sample fetches above because the sampled data are ephemeral. these data can
only be used when they’re available and will be lost when they’re forwarded.
for this reason, samples fetched from buffer contents during a request cannot
be used in a response for example. even while the data are being fetched, they
can change. sometimes it is necessary to set some delays or combine multiple
sample fetch methods to ensure that the expected data are complete and usable,
for example through tcp request content inspection. please see the “tcp-request
content” keyword for more detailed information on the subject.
this is an alias for “req.payload” when used in the context of a request (eg:
“stick on”, “stick match”), and for “res.payload” when used in the context of
a response such as in “stick store response”.
this is an alias for “req.payload_lv” when used in the context of a request
(eg: “stick on”, “stick match”), and for “res.payload_lv” when used in the
context of a response such as in “stick store response”.
req_len : integer (deprecated)
returns an integer value corresponding to the number of bytes present in the
request buffer. this is mostly used in acl. it is important to understand
that this test does not return false as long as the buffer is changing. this
means that a check with equality to zero will almost always immediately match
at the beginning of the session, while a test for more data will wait for
that data to come in and return false only when haproxy is certain that no
more data will come in. this test was designed to be used with tcp request
content inspection.
this extracts a binary block of
in the request buffer. as a special case, if the
the the whole buffer from
with acls in order to check for the presence of some content in a buffer at
any location.
payload(
this extracts a binary block whose size is specified at
bytes, and which starts at
the request buffer. the
prepended with a ‘+’ or ‘-‘ sign.
payload_lv(
req_proto_http : boolean (deprecated)
returns true when data in the request buffer look like http and correctly
parses as such. it is the same parser as the common http request parser which
is used so there should be no surprises. the test does not match until the
request is complete, failed or timed out. this test may be used to report the
protocol in tcp logs, but the biggest use is to block tcp request analysis
until a complete http request is present in the buffer, for example to track
a header.
# track request counts per “base” (concatenation of host+url)
tcp-request inspect-delay 10s
tcp-request content reject if !http
tcp-request content track-sc0 base table req-rate
rdp_cookie([
when the request buffer looks like the rdp protocol, extracts the rdp cookie
cookie, as illustrated in the rdp protocol specification. the cookie name is
case insensitive. generally the “msts” cookie name will be used, as it can
contain the user name of the client connecting to the server if properly
configured on the client. the “mstshash” cookie is often used as well for
session stickiness to servers.
used and thus the distribution of clients to backend servers is not linked to
a hash of the rdp cookie. it is envisaged that using a balancing algorithm
such as “balance roundrobin” or “balance leastconn” will lead to a more even
distribution of clients to backend servers than the hash used by “balance
rdp-cookie”.
req_rdp_cookie([
listen tse-farm
bind 0.0.0.0: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
# persist based on the mstshash cookie
# this is only useful makes sense if
# balance rdp-cookie is not used
stick-table type string size 204800
stick on req.rdp_cookie(mstshash)
server srv1 1.1.1.1:3389
server srv1 1.1.1.2:3389
“req_rdp_cookie” acl.
rdp_cookie_cnt([name]) : integer (deprecated)
tries to parse the request buffer as rdp protocol, then returns an integer
corresponding to the number of rdp cookies found. if an optional cookie name
is passed, only cookies matching this name are considered. this is mostly
used in acl.
req_rdp_cookie_cnt([
returns a boolean identifying if client sent the supported elliptic curves
extension as defined in rfc4492, section 5.1. within the ssl clienthello
message. this can be used to present ecc compatible clients with ec certificate
and to use rsa for all others, on the same ip address. note that this only
applies to raw contents found in the request buffer and not to contents
deciphered via an ssl data layer, so this will not work with “bind” lines
having the “ssl” option.
req_ssl_hello_type : integer (deprecated)
returns an integer value containing the type of the ssl hello message found
in the request buffer if the buffer contains data that parse as a complete
ssl (v3 or superior) client hello message. note that this only applies to raw
contents found in the request buffer and not to contents deciphered via an
ssl data layer, so this will not work with “bind” lines having the “ssl”
option. this is mostly used in acl to detect presence of an ssl hello message
that is supposed to contain an ssl session id usable for stickiness.
req_ssl_sni : string (deprecated)
returns a string containing the value of the server name tls extension sent
by a client in a tls stream passing through the request buffer if the buffer
contains data that parse as a complete ssl (v3 or superior) client hello
message. note that this only applies to raw contents found in the request
buffer and not to contents deciphered via an ssl data layer, so this will not
work with “bind” lines having the “ssl” option. sni normally contains the
name of the host the client tries to connect to (for recent browsers). sni is
useful for allowing or denying access to certain hosts when ssl/tls is used
by the client. this test was designed to be used with tcp request content
inspection. if content switching is needed, it is recommended to first wait
for a complete client hello (type 1), like in the example below. see also
“ssl_fc_sni”.
req_ssl_sni : exact string match
# wait for a client hello for at most 5 seconds
tcp-request inspect-delay 5s
tcp-request content accept if { req_ssl_hello_type 1 }
use_backend bk_allow if { req_ssl_sni -f allowed_sites }
default_backend bk_sorry_page
rep_ssl_hello_type : integer (deprecated)
returns an integer value containing the type of the ssl hello message found
in the response buffer if the buffer contains data that parses as a complete
ssl (v3 or superior) hello message. note that this only applies to raw
contents found in the response buffer and not to contents deciphered via an
ssl data layer, so this will not work with “server” lines having the “ssl”
option. this is mostly used in acl to detect presence of an ssl hello message
that is supposed to contain an ssl session id usable for stickiness.
req_ssl_ver : integer (deprecated)
returns an integer value containing the version of the ssl/tls protocol of a
stream present in the request buffer. both sslv2 hello messages and sslv3
messages are supported. tlsv1 is announced as ssl version 3.1. the value is
composed of the major version multiplied by 65536, added to the minor
version. note that this only applies to raw contents found in the request
buffer and not to contents deciphered via an ssl data layer, so this will not
work with “bind” lines having the “ssl” option. the acl version of the test
matches against a decimal notation in the form major.minor (eg: 3.1). this
fetch is mostly used in acl.
req_ssl_ver : decimal match
returns an integer value corresponding to the number of bytes present in the
response buffer. this is mostly used in acl. it is important to understand
that this test does not return false as long as the buffer is changing. this
means that a check with equality to zero will almost always immediately match
at the beginning of the session, while a test for more data will wait for
that data to come in and return false only when haproxy is certain that no
more data will come in. this test was designed to be used with tcp response
content inspection.
this extracts a binary block of
in the response buffer. as a special case, if the
the the whole buffer from
with acls in order to check for the presence of some content in a buffer at
any location.
this extracts a binary block whose size is specified at
bytes, and which starts at
the response buffer. the
if prepended with a ‘+’ or ‘-‘ sign.
this fetch either returns true when the inspection period is over, or does
not fetch. it is only used in acls, in conjunction with content analysis to
avoid returning a wrong verdict early. it may also be used to delay some
actions, such as a delayed reject for some special addresses. since it either
stops the rules evaluation or immediately returns true, it is recommended to
use this acl as the last one in a rule. please note that the default acl
“wait_end” is always usable without prior declaration. this test was designed
to be used with tcp request content inspection.
# delay every incoming request by 2 seconds
tcp-request inspect-delay 2s
tcp-request content accept if wait_end # don't immediately tell bad guys they are rejected
tcp-request inspect-delay 10s
acl goodguys src 10.0.0.0/24
acl badguys src 10.0.1.0/24
tcp-request content accept if goodguys
tcp-request content reject if badguys wait_end
tcp-request content reject
7.3.6. fetching http samples (layer 7)
this application layer is also called layer 7. it is only possible to fetch the
data in this section when a full http request or response has been parsed from
its respective request or response buffer. this is always the case with all
http specific rules and for sections running with “mode http”. when using tcp
content inspection, it may be necessary to support an inspection delay in order
to let the request or response come in first. these fetches may require a bit
more cpu resources than the layer 4 ones, but not much since the request and
response are indexed.
this returns the concatenation of the first host header and the path part of
the request, which starts at the first slash and ends before the question
mark. it can be useful in virtual hosted environments to detect url abuses as
well as to improve shared caches efficiency. using this with a limited size
stick table also allows one to collect statistics about most commonly
requested objects by host/path. with acls it can allow simple content
switching rules involving the host and the path at the same time, such as
“www.example.com/favicon.ico". see also “path” and “uri”.
base : exact string match
base_beg : prefix match
base_dir : subdir match
base_dom : domain match
base_end : suffix match
base_len : length match
base_reg : regex match
base_sub : substring match
this returns a 32-bit hash of the value returned by the “base” fetch method
above. this is useful to track per-url activity on high traffic sites without
having to store all urls. instead a shorter hash is stored, saving a lot of
memory. the output type is an unsigned integer. the hash function used is
sdbm with full avalanche on the output. technically, base32 is exactly equal
to “base,sdbm(1)”.
this returns the concatenation of the base32 fetch above and the src fetch
below. the resulting type is of type binary, with a size of 8 or 20 bytes
depending on the source address family. this can be used to track per-ip,
per-url counters.
this extracts the content of the header captured by the “capture request
header”, idx is the position of the capture keyword in the configuration.
the first entry is an index of 0. see also: “capture request header”.
this extracts the method of an http request. it can be used in both request
and response. unlike “method”, it can be used in both request and response
because it’s allocated.
this extracts the request’s uri, which starts at the first slash and ends
before the first space in the request (without the host part). unlike “path”
and “url”, it can be used in both request and response because it’s
allocated.
this extracts the request’s http version and returns either “http/1.0” or
“http/1.1”. unlike “req.ver”, it can be used in both request, response, and
logs because it relies on a persistent flag.
this extracts the content of the header captured by the “capture response
header”, idx is the position of the capture keyword in the configuration.
the first entry is an index of 0.
see also: “capture response header”
this extracts the response’s http version and returns either “http/1.0” or
“http/1.1”. unlike “res.ver”, it can be used in logs because it relies on a
persistent flag.
this returns the http request’s available body as a block of data. it
requires that the request body has been buffered made available using
“option http-buffer-request”. in case of chunked-encoded body, currently only
the first chunk is analyzed.
this fetch assumes that the body of the post request is url-encoded. the user
can check if the “content-type” contains the value
“application/x-www-form-urlencoded”. this extracts the first occurrence of the
parameter
case-sensitive. if no name is given, any parameter will match, and the first
one will be returned. the result is a string corresponding to the value of the
parameter
performed). note that the acl version of this fetch iterates over multiple
parameters and will iteratively report all parameters values if no name is
given.
this returns the length of the http request’s available body in bytes. it may
be lower than the advertised length if the body is larger than the buffer. it
requires that the request body has been buffered made available using
“option http-buffer-request”.
this returns the advertised length of the http request’s body in bytes. it
will represent the advertised content-length header, or the size of the first
chunk in case of chunked encoding. in order to parse the chunks, it requires
that the request body has been buffered made available using
“option http-buffer-request”.
cook([
this extracts the last occurrence of the cookie name
header line from the request, and returns its value as string. if no name is
specified, the first cookie value is returned. when used with acls, all
matching cookies are evaluated. spaces around the name and the value are
ignored as requested by the cookie header specification (rfc6265). the cookie
name is case-sensitive. empty cookies are valid, so an empty cookie may very
well return an empty value if it is present. use the “found” match to detect
presence. use the res.cook() variant for response cookies sent by the server.
cook([
cook_beg([
cook_dir([
cook_dom([
cook_end([
cook_len([
cook_reg([
cook_sub([
cook_cnt([
returns an integer value representing the number of occurrences of the cookie
cook_val([
this extracts the last occurrence of the cookie name
header line from the request, and converts its value to an integer which is
returned. if no name is specified, the first cookie value is returned. when
used in acls, all matching names are iterated over until a value matches.
this extracts the last occurrence of the cookie name
header line from the request, or a “set-cookie” header from the response, and
returns its value as a string. a typical use is to get multiple clients
sharing a same profile use the same server. this can be similar to what
“appsession” does with the “request-learn” statement, but with support for
multi-peer synchronization and state keeping across restarts. if no name is
specified, the first cookie value is returned. this fetch should not be used
anymore and should be replaced by req.cook() or res.cook() instead as it
ambiguously uses the direction based on the context where it is used.
see also : “appsession”.
this is equivalent to req.hdr() when used on requests, and to res.hdr() when
used on responses. please refer to these respective fetches for more details.
in case of doubt about the fetch direction, please use the explicit ones.
note that contrary to the hdr() sample fetch method, the hdr_* acl keywords
unambiguously apply to the request headers.
this extracts the last occurrence of header
used from an acl, all occurrences are iterated over until a match is found.
optionally, a specific occurrence might be specified as a position number.
positive values indicate a position from the first occurrence, with 1 being
the first one. negative values indicate positions relative to the last one,
with -1 being the last one. it differs from req.hdr() in that any commas
present in the value are returned and are not used as delimiters. this is
sometimes useful with headers such as user-agent.
returns an integer value representing the number of occurrences of request
header field name
not specified. contrary to its req.hdr_cnt() cousin, this function returns
the number of full line headers and does not stop on commas.
this extracts the last occurrence of header
used from an acl, all occurrences are iterated over until a match is found.
optionally, a specific occurrence might be specified as a position number.
positive values indicate a position from the first occurrence, with 1 being
the first one. negative values indicate positions relative to the last one,
with -1 being the last one. a typical use is with the x-forwarded-for header
once converted to ip, associated with an ip stick-table. the function
considers any comma as a delimiter for distinct values. if full-line headers
are desired instead, use req.fhdr(). please carefully check rfc2616 to know
how certain headers are supposed to be parsed. also, some of them are case
insensitive (eg: connection).
hdr([
hdr_beg([
hdr_dir([
hdr_dom([
hdr_end([
hdr_len([
hdr_reg([