blob: f7f2bc57349a7bc7df8ec1c10f593a509381c939 [file] [log] [blame]
Willy Tarreau6a06a402007-07-15 20:15:28 +02001 ----------------------
Willy Tarreau8317b282014-04-23 01:49:41 +02002 HAProxy
Willy Tarreau6a06a402007-07-15 20:15:28 +02003 Configuration Manual
4 ----------------------
Willy Tarreau15480d72014-06-19 21:10:58 +02005 version 1.6
Willy Tarreau6a06a402007-07-15 20:15:28 +02006 willy tarreau
Willy Tarreaue7ae6562015-09-28 23:46:27 +02007 2015/09/28
Willy Tarreau6a06a402007-07-15 20:15:28 +02008
9
10This document covers the configuration language as implemented in the version
11specified above. It does not provide any hint, example or advice. For such
Willy Tarreau0ba27502007-12-24 16:55:16 +010012documentation, please refer to the Reference Manual or the Architecture Manual.
Willy Tarreauc57f0e22009-05-10 13:12:33 +020013The summary below is meant to help you search sections by name and navigate
14through the document.
Willy Tarreau6a06a402007-07-15 20:15:28 +020015
Willy Tarreauc57f0e22009-05-10 13:12:33 +020016Note to documentation contributors :
Jamie Gloudonaaa21002012-08-25 00:18:33 -040017 This document is formatted with 80 columns per line, with even number of
Willy Tarreauc57f0e22009-05-10 13:12:33 +020018 spaces for indentation and without tabs. Please follow these rules strictly
19 so that it remains easily printable everywhere. If a line needs to be
20 printed verbatim and does not fit, please end each line with a backslash
Willy Tarreau62a36c42010-08-17 15:53:10 +020021 ('\') and continue on next line, indented by two characters. It is also
22 sometimes useful to prefix all output lines (logs, console outs) with 3
23 closing angle brackets ('>>>') in order to help get the difference between
24 inputs and outputs when it can become ambiguous. If you add sections,
25 please update the summary below for easier searching.
Willy Tarreauc57f0e22009-05-10 13:12:33 +020026
27
28Summary
29-------
30
311. Quick reminder about HTTP
321.1. The HTTP transaction model
331.2. HTTP request
341.2.1. The Request line
351.2.2. The request headers
361.3. HTTP response
371.3.1. The Response line
381.3.2. The response headers
39
402. Configuring HAProxy
412.1. Configuration file format
William Lallemandf9873ba2015-05-05 17:37:14 +0200422.2. Quoting and escaping
William Lallemandb2f07452015-05-12 14:27:13 +0200432.3. Environment variables
442.4. Time format
452.5. Examples
Willy Tarreauc57f0e22009-05-10 13:12:33 +020046
473. Global parameters
483.1. Process management and security
493.2. Performance tuning
503.3. Debugging
Krzysztof Piotr Oledzki6b35ce12010-02-01 23:35:44 +0100513.4. Userlists
Cyril Bontédc4d9032012-04-08 21:57:39 +0200523.5. Peers
Willy Tarreauc57f0e22009-05-10 13:12:33 +020053
544. Proxies
554.1. Proxy keywords matrix
564.2. Alphabetically sorted keywords reference
57
Willy Tarreau086fbf52012-09-24 20:34:51 +0200585. Bind and Server options
595.1. Bind options
605.2. Server and default-server options
Baptiste Assmann1fa66662015-04-14 00:28:47 +0200615.3. Server DNS resolution
625.3.1. Global overview
635.3.2. The resolvers section
Willy Tarreauc57f0e22009-05-10 13:12:33 +020064
656. HTTP header manipulation
66
Willy Tarreau74ca5042013-06-11 23:12:07 +0200677. Using ACLs and fetching samples
687.1. ACL basics
697.1.1. Matching booleans
707.1.2. Matching integers
717.1.3. Matching strings
727.1.4. Matching regular expressions (regexes)
737.1.5. Matching arbitrary data blocks
747.1.6. Matching IPv4 and IPv6 addresses
757.2. Using ACLs to form conditions
767.3. Fetching samples
Thierry FOURNIER060762e2014-04-23 13:29:15 +0200777.3.1. Converters
787.3.2. Fetching samples from internal states
797.3.3. Fetching samples at Layer 4
807.3.4. Fetching samples at Layer 5
817.3.5. Fetching samples from buffer contents (Layer 6)
827.3.6. Fetching HTTP samples (Layer 7)
Willy Tarreau74ca5042013-06-11 23:12:07 +0200837.4. Pre-defined ACLs
Willy Tarreauc57f0e22009-05-10 13:12:33 +020084
858. Logging
868.1. Log levels
878.2. Log formats
888.2.1. Default log format
898.2.2. TCP log format
908.2.3. HTTP log format
William Lallemand48940402012-01-30 16:47:22 +0100918.2.4. Custom log format
Willy Tarreau5f51e1a2012-12-03 18:40:10 +0100928.2.5. Error log format
Willy Tarreauc57f0e22009-05-10 13:12:33 +0200938.3. Advanced logging options
948.3.1. Disabling logging of external tests
958.3.2. Logging before waiting for the session to terminate
968.3.3. Raising log level upon errors
978.3.4. Disabling logging of successful connections
988.4. Timing events
998.5. Session state at disconnection
1008.6. Non-printable characters
1018.7. Capturing HTTP cookies
1028.8. Capturing HTTP headers
1038.9. Examples of logs
104
1059. Statistics and monitoring
1069.1. CSV format
1079.2. Unix Socket commands
108
109
1101. Quick reminder about HTTP
111----------------------------
112
113When haproxy is running in HTTP mode, both the request and the response are
114fully analyzed and indexed, thus it becomes possible to build matching criteria
115on almost anything found in the contents.
116
117However, it is important to understand how HTTP requests and responses are
118formed, and how HAProxy decomposes them. It will then become easier to write
119correct rules and to debug existing configurations.
120
121
1221.1. The HTTP transaction model
123-------------------------------
124
125The HTTP protocol is transaction-driven. This means that each request will lead
Krzysztof Piotr Oledzkif8645332009-12-13 21:55:50 +0100126to one and only one response. Traditionally, a TCP connection is established
Willy Tarreauc57f0e22009-05-10 13:12:33 +0200127from the client to the server, a request is sent by the client on the
128connection, the server responds and the connection is closed. A new request
129will involve a new connection :
130
131 [CON1] [REQ1] ... [RESP1] [CLO1] [CON2] [REQ2] ... [RESP2] [CLO2] ...
132
133In this mode, called the "HTTP close" mode, there are as many connection
134establishments as there are HTTP transactions. Since the connection is closed
135by the server after the response, the client does not need to know the content
136length.
137
138Due to the transactional nature of the protocol, it was possible to improve it
139to avoid closing a connection between two subsequent transactions. In this mode
140however, it is mandatory that the server indicates the content length for each
141response so that the client does not wait indefinitely. For this, a special
142header is used: "Content-length". This mode is called the "keep-alive" mode :
143
144 [CON] [REQ1] ... [RESP1] [REQ2] ... [RESP2] [CLO] ...
145
146Its advantages are a reduced latency between transactions, and less processing
147power required on the server side. It is generally better than the close mode,
148but not always because the clients often limit their concurrent connections to
Patrick Mezard9ec2ec42010-06-12 17:02:45 +0200149a smaller value.
Willy Tarreauc57f0e22009-05-10 13:12:33 +0200150
151A last improvement in the communications is the pipelining mode. It still uses
152keep-alive, but the client does not wait for the first response to send the
153second request. This is useful for fetching large number of images composing a
154page :
155
156 [CON] [REQ1] [REQ2] ... [RESP1] [RESP2] [CLO] ...
157
158This can obviously have a tremendous benefit on performance because the network
159latency is eliminated between subsequent requests. Many HTTP agents do not
160correctly support pipelining since there is no way to associate a response with
161the corresponding request in HTTP. For this reason, it is mandatory for the
Cyril Bonté78caf842010-03-10 22:41:43 +0100162server to reply in the exact same order as the requests were received.
Willy Tarreauc57f0e22009-05-10 13:12:33 +0200163
Willy Tarreau70dffda2014-01-30 03:07:23 +0100164By default HAProxy operates in keep-alive mode with regards to persistent
165connections: for each connection it processes each request and response, and
166leaves the connection idle on both sides between the end of a response and the
167start of a new request.
Patrick Mezard9ec2ec42010-06-12 17:02:45 +0200168
Willy Tarreau70dffda2014-01-30 03:07:23 +0100169HAProxy supports 5 connection modes :
170 - keep alive : all requests and responses are processed (default)
171 - tunnel : only the first request and response are processed,
172 everything else is forwarded with no analysis.
173 - passive close : tunnel with "Connection: close" added in both directions.
174 - server close : the server-facing connection is closed after the response.
175 - forced close : the connection is actively closed after end of response.
176
Willy Tarreauc57f0e22009-05-10 13:12:33 +0200177
1781.2. HTTP request
179-----------------
180
181First, let's consider this HTTP request :
182
183 Line Contents
Willy Tarreaud72758d2010-01-12 10:42:19 +0100184 number
Willy Tarreauc57f0e22009-05-10 13:12:33 +0200185 1 GET /serv/login.php?lang=en&profile=2 HTTP/1.1
186 2 Host: www.mydomain.com
187 3 User-agent: my small browser
188 4 Accept: image/jpeg, image/gif
189 5 Accept: image/png
190
191
1921.2.1. The Request line
193-----------------------
194
195Line 1 is the "request line". It is always composed of 3 fields :
196
197 - a METHOD : GET
198 - a URI : /serv/login.php?lang=en&profile=2
199 - a version tag : HTTP/1.1
200
201All of them are delimited by what the standard calls LWS (linear white spaces),
202which are commonly spaces, but can also be tabs or line feeds/carriage returns
203followed by spaces/tabs. The method itself cannot contain any colon (':') and
204is limited to alphabetic letters. All those various combinations make it
205desirable that HAProxy performs the splitting itself rather than leaving it to
206the user to write a complex or inaccurate regular expression.
207
208The URI itself can have several forms :
209
210 - A "relative URI" :
211
212 /serv/login.php?lang=en&profile=2
213
214 It is a complete URL without the host part. This is generally what is
215 received by servers, reverse proxies and transparent proxies.
216
217 - An "absolute URI", also called a "URL" :
218
219 http://192.168.0.12:8080/serv/login.php?lang=en&profile=2
220
221 It is composed of a "scheme" (the protocol name followed by '://'), a host
222 name or address, optionally a colon (':') followed by a port number, then
223 a relative URI beginning at the first slash ('/') after the address part.
224 This is generally what proxies receive, but a server supporting HTTP/1.1
225 must accept this form too.
226
227 - a star ('*') : this form is only accepted in association with the OPTIONS
228 method and is not relayable. It is used to inquiry a next hop's
229 capabilities.
Willy Tarreaud72758d2010-01-12 10:42:19 +0100230
Willy Tarreauc57f0e22009-05-10 13:12:33 +0200231 - an address:port combination : 192.168.0.12:80
232 This is used with the CONNECT method, which is used to establish TCP
233 tunnels through HTTP proxies, generally for HTTPS, but sometimes for
234 other protocols too.
235
236In a relative URI, two sub-parts are identified. The part before the question
237mark is called the "path". It is typically the relative path to static objects
238on the server. The part after the question mark is called the "query string".
239It is mostly used with GET requests sent to dynamic scripts and is very
240specific to the language, framework or application in use.
241
242
2431.2.2. The request headers
244--------------------------
245
246The headers start at the second line. They are composed of a name at the
247beginning of the line, immediately followed by a colon (':'). Traditionally,
248an LWS is added after the colon but that's not required. Then come the values.
249Multiple identical headers may be folded into one single line, delimiting the
250values with commas, provided that their order is respected. This is commonly
251encountered in the "Cookie:" field. A header may span over multiple lines if
252the subsequent lines begin with an LWS. In the example in 1.2, lines 4 and 5
253define a total of 3 values for the "Accept:" header.
254
255Contrary to a common mis-conception, header names are not case-sensitive, and
256their values are not either if they refer to other header names (such as the
257"Connection:" header).
258
259The end of the headers is indicated by the first empty line. People often say
260that it's a double line feed, which is not exact, even if a double line feed
261is one valid form of empty line.
262
263Fortunately, HAProxy takes care of all these complex combinations when indexing
264headers, checking values and counting them, so there is no reason to worry
265about the way they could be written, but it is important not to accuse an
266application of being buggy if it does unusual, valid things.
267
268Important note:
269 As suggested by RFC2616, HAProxy normalizes headers by replacing line breaks
270 in the middle of headers by LWS in order to join multi-line headers. This
271 is necessary for proper analysis and helps less capable HTTP parsers to work
272 correctly and not to be fooled by such complex constructs.
273
274
2751.3. HTTP response
276------------------
277
278An HTTP response looks very much like an HTTP request. Both are called HTTP
279messages. Let's consider this HTTP response :
280
281 Line Contents
Willy Tarreaud72758d2010-01-12 10:42:19 +0100282 number
Willy Tarreauc57f0e22009-05-10 13:12:33 +0200283 1 HTTP/1.1 200 OK
284 2 Content-length: 350
285 3 Content-Type: text/html
286
Willy Tarreau816b9792009-09-15 21:25:21 +0200287As a special case, HTTP supports so called "Informational responses" as status
288codes 1xx. These messages are special in that they don't convey any part of the
289response, they're just used as sort of a signaling message to ask a client to
Willy Tarreau5843d1a2010-02-01 15:13:32 +0100290continue to post its request for instance. In the case of a status 100 response
291the requested information will be carried by the next non-100 response message
292following the informational one. This implies that multiple responses may be
293sent to a single request, and that this only works when keep-alive is enabled
294(1xx messages are HTTP/1.1 only). HAProxy handles these messages and is able to
295correctly forward and skip them, and only process the next non-100 response. As
296such, these messages are neither logged nor transformed, unless explicitly
297state otherwise. Status 101 messages indicate that the protocol is changing
298over the same connection and that haproxy must switch to tunnel mode, just as
299if a CONNECT had occurred. Then the Upgrade header would contain additional
300information about the type of protocol the connection is switching to.
Willy Tarreau816b9792009-09-15 21:25:21 +0200301
Willy Tarreauc57f0e22009-05-10 13:12:33 +0200302
3031.3.1. The Response line
304------------------------
305
306Line 1 is the "response line". It is always composed of 3 fields :
307
308 - a version tag : HTTP/1.1
309 - a status code : 200
310 - a reason : OK
311
312The status code is always 3-digit. The first digit indicates a general status :
Willy Tarreau816b9792009-09-15 21:25:21 +0200313 - 1xx = informational message to be skipped (eg: 100, 101)
Willy Tarreauc57f0e22009-05-10 13:12:33 +0200314 - 2xx = OK, content is following (eg: 200, 206)
315 - 3xx = OK, no content following (eg: 302, 304)
316 - 4xx = error caused by the client (eg: 401, 403, 404)
317 - 5xx = error caused by the server (eg: 500, 502, 503)
318
319Please refer to RFC2616 for the detailed meaning of all such codes. The
Willy Tarreaud72758d2010-01-12 10:42:19 +0100320"reason" field is just a hint, but is not parsed by clients. Anything can be
Willy Tarreauc57f0e22009-05-10 13:12:33 +0200321found there, but it's a common practice to respect the well-established
322messages. It can be composed of one or multiple words, such as "OK", "Found",
323or "Authentication Required".
324
325Haproxy may emit the following status codes by itself :
326
327 Code When / reason
328 200 access to stats page, and when replying to monitoring requests
329 301 when performing a redirection, depending on the configured code
330 302 when performing a redirection, depending on the configured code
331 303 when performing a redirection, depending on the configured code
Willy Tarreaub67fdc42013-03-29 19:28:11 +0100332 307 when performing a redirection, depending on the configured code
333 308 when performing a redirection, depending on the configured code
Willy Tarreauc57f0e22009-05-10 13:12:33 +0200334 400 for an invalid or too large request
335 401 when an authentication is required to perform the action (when
336 accessing the stats page)
337 403 when a request is forbidden by a "block" ACL or "reqdeny" filter
338 408 when the request timeout strikes before the request is complete
339 500 when haproxy encounters an unrecoverable internal error, such as a
340 memory allocation failure, which should never happen
341 502 when the server returns an empty, invalid or incomplete response, or
342 when an "rspdeny" filter blocks the response.
343 503 when no server was available to handle the request, or in response to
344 monitoring requests which match the "monitor fail" condition
345 504 when the response timeout strikes before the server responds
346
347The error 4xx and 5xx codes above may be customized (see "errorloc" in section
3484.2).
349
350
3511.3.2. The response headers
352---------------------------
353
354Response headers work exactly like request headers, and as such, HAProxy uses
355the same parsing function for both. Please refer to paragraph 1.2.2 for more
356details.
357
358
3592. Configuring HAProxy
360----------------------
361
3622.1. Configuration file format
363------------------------------
Willy Tarreau6a06a402007-07-15 20:15:28 +0200364
365HAProxy's configuration process involves 3 major sources of parameters :
366
367 - the arguments from the command-line, which always take precedence
368 - the "global" section, which sets process-wide parameters
369 - the proxies sections which can take form of "defaults", "listen",
370 "frontend" and "backend".
371
Willy Tarreau0ba27502007-12-24 16:55:16 +0100372The configuration file syntax consists in lines beginning with a keyword
373referenced in this manual, optionally followed by one or several parameters
William Lallemandf9873ba2015-05-05 17:37:14 +0200374delimited by spaces.
Willy Tarreau0ba27502007-12-24 16:55:16 +0100375
Willy Tarreauc57f0e22009-05-10 13:12:33 +0200376
William Lallemandf9873ba2015-05-05 17:37:14 +02003772.2. Quoting and escaping
378-------------------------
379
380HAProxy's configuration introduces a quoting and escaping system similar to
381many programming languages. The configuration file supports 3 types: escaping
382with a backslash, weak quoting with double quotes, and strong quoting with
383single quotes.
384
385If spaces have to be entered in strings, then they must be escaped by preceding
386them by a backslash ('\') or by quoting them. Backslashes also have to be
387escaped by doubling or strong quoting them.
388
389Escaping is achieved by preceding a special character by a backslash ('\'):
390
391 \ to mark a space and differentiate it from a delimiter
392 \# to mark a hash and differentiate it from a comment
393 \\ to use a backslash
394 \' to use a single quote and differentiate it from strong quoting
395 \" to use a double quote and differentiate it from weak quoting
396
397Weak quoting is achieved by using double quotes (""). Weak quoting prevents
398the interpretation of:
399
400 space as a parameter separator
401 ' single quote as a strong quoting delimiter
402 # hash as a comment start
403
William Lallemandb2f07452015-05-12 14:27:13 +0200404Weak quoting permits the interpretation of variables, if you want to use a non
405-interpreted dollar within a double quoted string, you should escape it with a
406backslash ("\$"), it does not work outside weak quoting.
407
408Interpretation of escaping and special characters are not prevented by weak
William Lallemandf9873ba2015-05-05 17:37:14 +0200409quoting.
410
411Strong quoting is achieved by using single quotes (''). Inside single quotes,
412nothing is interpreted, it's the efficient way to quote regexes.
413
414Quoted and escaped strings are replaced in memory by their interpreted
415equivalent, it allows you to perform concatenation.
416
417 Example:
418 # those are equivalents:
419 log-format %{+Q}o\ %t\ %s\ %{-Q}r
420 log-format "%{+Q}o %t %s %{-Q}r"
421 log-format '%{+Q}o %t %s %{-Q}r'
422 log-format "%{+Q}o %t"' %s %{-Q}r'
423 log-format "%{+Q}o %t"' %s'\ %{-Q}r
424
425 # those are equivalents:
426 reqrep "^([^\ :]*)\ /static/(.*)" \1\ /\2
427 reqrep "^([^ :]*)\ /static/(.*)" '\1 /\2'
428 reqrep "^([^ :]*)\ /static/(.*)" "\1 /\2"
429 reqrep "^([^ :]*)\ /static/(.*)" "\1\ /\2"
430
431
William Lallemandb2f07452015-05-12 14:27:13 +02004322.3. Environment variables
433--------------------------
434
435HAProxy's configuration supports environment variables. Those variables are
436interpreted only within double quotes. Variables are expanded during the
437configuration parsing. Variable names must be preceded by a dollar ("$") and
438optionally enclosed with braces ("{}") similarly to what is done in Bourne
439shell. Variable names can contain alphanumerical characters or the character
440underscore ("_") but should not start with a digit.
441
442 Example:
443
444 bind "fd@${FD_APP1}"
445
446 log "${LOCAL_SYSLOG}:514" local0 notice # send to local server
447
448 user "$HAPROXY_USER"
449
450
4512.4. Time format
Willy Tarreauc57f0e22009-05-10 13:12:33 +0200452----------------
453
Krzysztof Piotr Oledzkif8645332009-12-13 21:55:50 +0100454Some parameters involve values representing time, such as timeouts. These
Willy Tarreau0ba27502007-12-24 16:55:16 +0100455values are generally expressed in milliseconds (unless explicitly stated
456otherwise) but may be expressed in any other unit by suffixing the unit to the
457numeric value. It is important to consider this because it will not be repeated
458for every keyword. Supported units are :
459
460 - us : microseconds. 1 microsecond = 1/1000000 second
461 - ms : milliseconds. 1 millisecond = 1/1000 second. This is the default.
462 - s : seconds. 1s = 1000ms
463 - m : minutes. 1m = 60s = 60000ms
464 - h : hours. 1h = 60m = 3600s = 3600000ms
465 - d : days. 1d = 24h = 1440m = 86400s = 86400000ms
466
467
William Lallemandf9873ba2015-05-05 17:37:14 +02004682.4. Examples
Patrick Mezard35da19c2010-06-12 17:02:47 +0200469-------------
470
471 # Simple configuration for an HTTP proxy listening on port 80 on all
472 # interfaces and forwarding requests to a single backend "servers" with a
473 # single server "server1" listening on 127.0.0.1:8000
474 global
475 daemon
476 maxconn 256
477
478 defaults
479 mode http
480 timeout connect 5000ms
481 timeout client 50000ms
482 timeout server 50000ms
483
484 frontend http-in
485 bind *:80
486 default_backend servers
487
488 backend servers
489 server server1 127.0.0.1:8000 maxconn 32
490
491
492 # The same configuration defined with a single listen block. Shorter but
493 # less expressive, especially in HTTP mode.
494 global
495 daemon
496 maxconn 256
497
498 defaults
499 mode http
500 timeout connect 5000ms
501 timeout client 50000ms
502 timeout server 50000ms
503
504 listen http-in
505 bind *:80
506 server server1 127.0.0.1:8000 maxconn 32
507
508
509Assuming haproxy is in $PATH, test these configurations in a shell with:
510
Willy Tarreauccb289d2010-12-11 20:19:38 +0100511 $ sudo haproxy -f configuration.conf -c
Patrick Mezard35da19c2010-06-12 17:02:47 +0200512
513
Willy Tarreauc57f0e22009-05-10 13:12:33 +02005143. Global parameters
Willy Tarreau6a06a402007-07-15 20:15:28 +0200515--------------------
516
517Parameters in the "global" section are process-wide and often OS-specific. They
518are generally set once for all and do not need being changed once correct. Some
519of them have command-line equivalents.
520
521The following keywords are supported in the "global" section :
522
523 * Process management and security
Emeric Brunc8e8d122012-10-02 18:42:10 +0200524 - ca-base
Willy Tarreau6a06a402007-07-15 20:15:28 +0200525 - chroot
Emeric Brunc8e8d122012-10-02 18:42:10 +0200526 - crt-base
Willy Tarreau6a06a402007-07-15 20:15:28 +0200527 - daemon
Simon Horman98637e52014-06-20 12:30:16 +0900528 - external-check
Willy Tarreau6a06a402007-07-15 20:15:28 +0200529 - gid
530 - group
531 - log
Joe Williamsdf5b38f2010-12-29 17:05:48 +0100532 - log-send-hostname
Willy Tarreau6a06a402007-07-15 20:15:28 +0200533 - nbproc
534 - pidfile
535 - uid
536 - ulimit-n
537 - user
Willy Tarreaufbee7132007-10-18 13:53:22 +0200538 - stats
Emeric Brun850efd52014-01-29 12:24:34 +0100539 - ssl-server-verify
Krzysztof Piotr Oledzki48cb2ae2009-10-02 22:51:14 +0200540 - node
541 - description
Willy Tarreauceb24bc2010-11-09 12:46:41 +0100542 - unix-bind
Thomas Holmesdb04f192015-05-18 13:21:39 +0100543 - 51degrees-data-file
544 - 51degrees-property-name-list
Dragan Dosen93b38d92015-06-29 16:43:25 +0200545 - 51degrees-property-separator
Dragan Dosenae6d39a2015-06-29 16:43:27 +0200546 - 51degrees-cache-size
Willy Tarreaud72758d2010-01-12 10:42:19 +0100547
Willy Tarreau6a06a402007-07-15 20:15:28 +0200548 * Performance tuning
Willy Tarreau1746eec2014-04-25 10:46:47 +0200549 - max-spread-checks
Willy Tarreau6a06a402007-07-15 20:15:28 +0200550 - maxconn
Willy Tarreau81c25d02011-09-07 15:17:21 +0200551 - maxconnrate
William Lallemandd85f9172012-11-09 17:05:39 +0100552 - maxcomprate
William Lallemand072a2bf2012-11-20 17:01:01 +0100553 - maxcompcpuusage
Willy Tarreauff4f82d2009-02-06 11:28:13 +0100554 - maxpipes
Willy Tarreau93e7c002013-10-07 18:51:07 +0200555 - maxsessrate
Willy Tarreau403edff2012-09-06 11:58:37 +0200556 - maxsslconn
Willy Tarreaue43d5322013-10-07 20:01:52 +0200557 - maxsslrate
Willy Tarreau6a06a402007-07-15 20:15:28 +0200558 - noepoll
559 - nokqueue
560 - nopoll
Willy Tarreauff4f82d2009-02-06 11:28:13 +0100561 - nosplice
Jarno Huuskonen0e82b922014-04-12 18:22:19 +0300562 - nogetaddrinfo
Willy Tarreaufe255b72007-10-14 23:09:26 +0200563 - spread-checks
Baptiste Assmann5626f482015-08-23 10:00:10 +0200564 - server-state-base
Baptiste Assmannef1f0fc2015-08-23 10:06:39 +0200565 - server-state-file
Willy Tarreau27a674e2009-08-17 07:23:33 +0200566 - tune.bufsize
Willy Tarreau43961d52010-10-04 20:39:20 +0200567 - tune.chksize
William Lallemandf3747832012-11-09 12:33:10 +0100568 - tune.comp.maxlevel
Willy Tarreau193b8c62012-11-22 00:17:38 +0100569 - tune.http.cookielen
Willy Tarreauac1932d2011-10-24 19:14:41 +0200570 - tune.http.maxhdr
Willy Tarreau7e312732014-02-12 16:35:14 +0100571 - tune.idletimer
Thierry FOURNIER90da1912015-03-05 11:17:06 +0100572 - tune.lua.forced-yield
Willy Tarreau32f61e22015-03-18 17:54:59 +0100573 - tune.lua.maxmem
Thierry FOURNIER90da1912015-03-05 11:17:06 +0100574 - tune.lua.session-timeout
575 - tune.lua.task-timeout
Willy Tarreaua0250ba2008-01-06 11:22:57 +0100576 - tune.maxaccept
577 - tune.maxpollevents
Willy Tarreau27a674e2009-08-17 07:23:33 +0200578 - tune.maxrewrite
Willy Tarreauf3045d22015-04-29 16:24:50 +0200579 - tune.pattern.cache-size
Willy Tarreaubd9a0a72011-10-23 21:14:29 +0200580 - tune.pipesize
Willy Tarreaue803de22010-01-21 17:43:04 +0100581 - tune.rcvbuf.client
582 - tune.rcvbuf.server
583 - tune.sndbuf.client
584 - tune.sndbuf.server
Willy Tarreau6ec58db2012-11-16 16:32:15 +0100585 - tune.ssl.cachesize
Willy Tarreaubfd59462013-02-21 07:46:09 +0100586 - tune.ssl.lifetime
Emeric Brun8dc60392014-05-09 13:52:00 +0200587 - tune.ssl.force-private-cache
Willy Tarreaubfd59462013-02-21 07:46:09 +0100588 - tune.ssl.maxrecord
Remi Gacognef46cd6e2014-06-12 14:58:40 +0200589 - tune.ssl.default-dh-param
Christopher Faulet31af49d2015-06-09 17:29:50 +0200590 - tune.ssl.ssl-ctx-cache-size
Thierry FOURNIER4834bc72015-06-06 19:29:07 +0200591 - tune.vars.global-max-size
592 - tune.vars.reqres-max-size
593 - tune.vars.sess-max-size
594 - tune.vars.txn-max-size
William Lallemanda509e4c2012-11-07 16:54:34 +0100595 - tune.zlib.memlevel
596 - tune.zlib.windowsize
Willy Tarreaud72758d2010-01-12 10:42:19 +0100597
Willy Tarreau6a06a402007-07-15 20:15:28 +0200598 * Debugging
599 - debug
600 - quiet
Willy Tarreau6a06a402007-07-15 20:15:28 +0200601
602
Willy Tarreauc57f0e22009-05-10 13:12:33 +02006033.1. Process management and security
Willy Tarreau6a06a402007-07-15 20:15:28 +0200604------------------------------------
605
Emeric Brunc8e8d122012-10-02 18:42:10 +0200606ca-base <dir>
607 Assigns a default directory to fetch SSL CA certificates and CRLs from when a
Emeric Brunfd33a262012-10-11 16:28:27 +0200608 relative path is used with "ca-file" or "crl-file" directives. Absolute
609 locations specified in "ca-file" and "crl-file" prevail and ignore "ca-base".
Emeric Brunc8e8d122012-10-02 18:42:10 +0200610
Willy Tarreau6a06a402007-07-15 20:15:28 +0200611chroot <jail dir>
612 Changes current directory to <jail dir> and performs a chroot() there before
613 dropping privileges. This increases the security level in case an unknown
614 vulnerability would be exploited, since it would make it very hard for the
615 attacker to exploit the system. This only works when the process is started
616 with superuser privileges. It is important to ensure that <jail_dir> is both
617 empty and unwritable to anyone.
Willy Tarreaud72758d2010-01-12 10:42:19 +0100618
Willy Tarreaufc6c0322012-11-16 16:12:27 +0100619cpu-map <"all"|"odd"|"even"|process_num> <cpu-set>...
620 On Linux 2.6 and above, it is possible to bind a process to a specific CPU
621 set. This means that the process will never run on other CPUs. The "cpu-map"
622 directive specifies CPU sets for process sets. The first argument is the
Willy Tarreaua9db57e2013-01-18 11:29:29 +0100623 process number to bind. This process must have a number between 1 and 32 or
624 64, depending on the machine's word size, and any process IDs above nbproc
625 are ignored. It is possible to specify all processes at once using "all",
626 only odd numbers using "odd" or even numbers using "even", just like with the
627 "bind-process" directive. The second and forthcoming arguments are CPU sets.
628 Each CPU set is either a unique number between 0 and 31 or 63 or a range with
629 two such numbers delimited by a dash ('-'). Multiple CPU numbers or ranges
630 may be specified, and the processes will be allowed to bind to all of them.
631 Obviously, multiple "cpu-map" directives may be specified. Each "cpu-map"
632 directive will replace the previous ones when they overlap.
Willy Tarreaufc6c0322012-11-16 16:12:27 +0100633
Emeric Brunc8e8d122012-10-02 18:42:10 +0200634crt-base <dir>
635 Assigns a default directory to fetch SSL certificates from when a relative
636 path is used with "crtfile" directives. Absolute locations specified after
637 "crtfile" prevail and ignore "crt-base".
638
Willy Tarreau6a06a402007-07-15 20:15:28 +0200639daemon
640 Makes the process fork into background. This is the recommended mode of
641 operation. It is equivalent to the command line "-D" argument. It can be
642 disabled by the command line "-db" argument.
643
David Carlier8167f302015-06-01 13:50:06 +0200644deviceatlas-json-file <path>
645 Sets the path of the DeviceAtlas JSON data file to be loaded by the API.
646 The path must be a valid JSON data file and accessible by Haproxy process.
647
648deviceatlas-log-level <value>
649 Sets the level of informations returned by the API. This directive is
650 optional and set to 0 by default if not set.
651
652deviceatlas-separator <char>
653 Sets the character separator for the API properties results. This directive
654 is optional and set to | by default if not set.
655
David Carlier29b3ca32015-09-25 14:09:21 +0100656devicatlas-properties-cookie <name>
657 Sets the client cookie's name used for the detection if the DeviceAtlas Client-side
658 component was used during the request. This directive is optional and set to
659 DAPROPS by default if not set.
660
Simon Horman98637e52014-06-20 12:30:16 +0900661external-check
662 Allows the use of an external agent to perform health checks.
663 This is disabled by default as a security precaution.
664 See "option external-check".
665
Willy Tarreau6a06a402007-07-15 20:15:28 +0200666gid <number>
667 Changes the process' group ID to <number>. It is recommended that the group
668 ID is dedicated to HAProxy or to a small set of similar daemons. HAProxy must
669 be started with a user belonging to this group, or with superuser privileges.
Michael Schererab012dd2013-01-12 18:35:19 +0100670 Note that if haproxy is started from a user having supplementary groups, it
671 will only be able to drop these groups if started with superuser privileges.
Willy Tarreau6a06a402007-07-15 20:15:28 +0200672 See also "group" and "uid".
Willy Tarreaud72758d2010-01-12 10:42:19 +0100673
Willy Tarreau6a06a402007-07-15 20:15:28 +0200674group <group name>
675 Similar to "gid" but uses the GID of group name <group name> from /etc/group.
676 See also "gid" and "user".
Willy Tarreaud72758d2010-01-12 10:42:19 +0100677
Dragan Dosen7ad31542015-09-28 17:16:47 +0200678log <address> [len <length>] [format <format>] <facility> [max level [min level]]
Willy Tarreau6a06a402007-07-15 20:15:28 +0200679 Adds a global syslog server. Up to two global servers can be defined. They
680 will receive logs for startups and exits, as well as all logs from proxies
Robert Tsai81ae1952007-12-05 10:47:29 +0100681 configured with "log global".
682
683 <address> can be one of:
684
Willy Tarreau2769aa02007-12-27 18:26:09 +0100685 - An IPv4 address optionally followed by a colon and a UDP port. If
Robert Tsai81ae1952007-12-05 10:47:29 +0100686 no port is specified, 514 is used by default (the standard syslog
687 port).
688
David du Colombier24bb5f52011-03-17 10:40:23 +0100689 - An IPv6 address followed by a colon and optionally a UDP port. If
690 no port is specified, 514 is used by default (the standard syslog
691 port).
692
Robert Tsai81ae1952007-12-05 10:47:29 +0100693 - A filesystem path to a UNIX domain socket, keeping in mind
694 considerations for chroot (be sure the path is accessible inside
695 the chroot) and uid/gid (be sure the path is appropriately
696 writeable).
697
William Lallemandb2f07452015-05-12 14:27:13 +0200698 You may want to reference some environment variables in the address
699 parameter, see section 2.3 about environment variables.
Willy Tarreaudad36a32013-03-11 01:20:04 +0100700
Willy Tarreau18324f52014-06-27 18:10:07 +0200701 <length> is an optional maximum line length. Log lines larger than this value
702 will be truncated before being sent. The reason is that syslog
703 servers act differently on log line length. All servers support the
704 default value of 1024, but some servers simply drop larger lines
705 while others do log them. If a server supports long lines, it may
706 make sense to set this value here in order to avoid truncating long
707 lines. Similarly, if a server drops long lines, it is preferable to
708 truncate them before sending them. Accepted values are 80 to 65535
709 inclusive. The default value of 1024 is generally fine for all
710 standard usages. Some specific cases of long captures or
711 JSON-formated logs may require larger values.
712
Dragan Dosen7ad31542015-09-28 17:16:47 +0200713 <format> is the log format used when generating syslog messages. It may be
714 one of the following :
715
716 rfc3164 The RFC3164 syslog message format. This is the default.
717 (https://tools.ietf.org/html/rfc3164)
718
719 rfc5424 The RFC5424 syslog message format.
720 (https://tools.ietf.org/html/rfc5424)
721
Robert Tsai81ae1952007-12-05 10:47:29 +0100722 <facility> must be one of the 24 standard syslog facilities :
Willy Tarreau6a06a402007-07-15 20:15:28 +0200723
724 kern user mail daemon auth syslog lpr news
725 uucp cron auth2 ftp ntp audit alert cron2
726 local0 local1 local2 local3 local4 local5 local6 local7
727
728 An optional level can be specified to filter outgoing messages. By default,
Willy Tarreauf7edefa2009-05-10 17:20:05 +0200729 all messages are sent. If a maximum level is specified, only messages with a
730 severity at least as important as this level will be sent. An optional minimum
731 level can be specified. If it is set, logs emitted with a more severe level
732 than this one will be capped to this level. This is used to avoid sending
733 "emerg" messages on all terminals on some default syslog configurations.
734 Eight levels are known :
Willy Tarreau6a06a402007-07-15 20:15:28 +0200735
Cyril Bontédc4d9032012-04-08 21:57:39 +0200736 emerg alert crit err warning notice info debug
Willy Tarreau6a06a402007-07-15 20:15:28 +0200737
Joe Williamsdf5b38f2010-12-29 17:05:48 +0100738log-send-hostname [<string>]
739 Sets the hostname field in the syslog header. If optional "string" parameter
740 is set the header is set to the string contents, otherwise uses the hostname
741 of the system. Generally used if one is not relaying logs through an
742 intermediate syslog server or for simply customizing the hostname printed in
743 the logs.
744
Kevinm48936af2010-12-22 16:08:21 +0000745log-tag <string>
746 Sets the tag field in the syslog header to this string. It defaults to the
747 program name as launched from the command line, which usually is "haproxy".
748 Sometimes it can be useful to differentiate between multiple processes
Willy Tarreau094af4e2015-01-07 15:03:42 +0100749 running on the same host. See also the per-proxy "log-tag" directive.
Kevinm48936af2010-12-22 16:08:21 +0000750
Thierry FOURNIER90da1912015-03-05 11:17:06 +0100751lua-load <file>
752 This global directive loads and executes a Lua file. This directive can be
753 used multiple times.
754
Willy Tarreau6a06a402007-07-15 20:15:28 +0200755nbproc <number>
756 Creates <number> processes when going daemon. This requires the "daemon"
757 mode. By default, only one process is created, which is the recommended mode
758 of operation. For systems limited to small sets of file descriptors per
759 process, it may be needed to fork multiple daemons. USING MULTIPLE PROCESSES
760 IS HARDER TO DEBUG AND IS REALLY DISCOURAGED. See also "daemon".
761
762pidfile <pidfile>
763 Writes pids of all daemons into file <pidfile>. This option is equivalent to
764 the "-p" command line argument. The file must be accessible to the user
765 starting the process. See also "daemon".
766
Willy Tarreaua9db57e2013-01-18 11:29:29 +0100767stats bind-process [ all | odd | even | <number 1-64>[-<number 1-64>] ] ...
Willy Tarreau35b7b162012-10-22 23:17:18 +0200768 Limits the stats socket to a certain set of processes numbers. By default the
769 stats socket is bound to all processes, causing a warning to be emitted when
770 nbproc is greater than 1 because there is no way to select the target process
771 when connecting. However, by using this setting, it becomes possible to pin
772 the stats socket to a specific set of processes, typically the first one. The
773 warning will automatically be disabled when this setting is used, whatever
Willy Tarreaua9db57e2013-01-18 11:29:29 +0100774 the number of processes used. The maximum process ID depends on the machine's
Willy Tarreauae302532014-05-07 19:22:24 +0200775 word size (32 or 64). A better option consists in using the "process" setting
776 of the "stats socket" line to force the process on each line.
Willy Tarreau35b7b162012-10-22 23:17:18 +0200777
Baptiste Assmann5626f482015-08-23 10:00:10 +0200778server-state-base <directory>
779 Specifies the directory prefix to be prepended in front of all servers state
Baptiste Assmann01c6cc32015-08-23 11:45:29 +0200780 file names which do not start with a '/'. See also "server-state-file",
781 "load-server-state-from-file" and "server-state-file-name".
Baptiste Assmannef1f0fc2015-08-23 10:06:39 +0200782
783server-state-file <file>
784 Specifies the path to the file containing state of servers. If the path starts
785 with a slash ('/'), it is considered absolute, otherwise it is considered
786 relative to the directory specified using "server-state-base" (if set) or to
787 the current directory. Before reloading HAProxy, it is possible to save the
788 servers' current state using the stats command "show servers state". The
789 output of this command must be written in the file pointed by <file>. When
790 starting up, before handling traffic, HAProxy will read, load and apply state
791 for each server found in the file and available in its current running
Baptiste Assmann01c6cc32015-08-23 11:45:29 +0200792 configuration. See also "server-state-base" and "show servers state",
793 "load-server-state-from-file" and "server-state-file-name"
Baptiste Assmann5626f482015-08-23 10:00:10 +0200794
Willy Tarreau610f04b2014-02-13 11:36:41 +0100795ssl-default-bind-ciphers <ciphers>
796 This setting is only available when support for OpenSSL was built in. It sets
797 the default string describing the list of cipher algorithms ("cipher suite")
Jarno Huuskonen0e82b922014-04-12 18:22:19 +0300798 that are negotiated during the SSL/TLS handshake for all "bind" lines which
Willy Tarreau610f04b2014-02-13 11:36:41 +0100799 do not explicitly define theirs. The format of the string is defined in
800 "man 1 ciphers" from OpenSSL man pages, and can be for instance a string such
801 as "AES:ALL:!aNULL:!eNULL:+RC4:@STRENGTH" (without quotes). Please check the
802 "bind" keyword for more information.
803
Emeric Brun2c86cbf2014-10-30 15:56:50 +0100804ssl-default-bind-options [<option>]...
805 This setting is only available when support for OpenSSL was built in. It sets
806 default ssl-options to force on all "bind" lines. Please check the "bind"
807 keyword to see available options.
808
809 Example:
810 global
811 ssl-default-bind-options no-sslv3 no-tls-tickets
812
Willy Tarreau610f04b2014-02-13 11:36:41 +0100813ssl-default-server-ciphers <ciphers>
814 This setting is only available when support for OpenSSL was built in. It
815 sets the default string describing the list of cipher algorithms that are
Jarno Huuskonen0e82b922014-04-12 18:22:19 +0300816 negotiated during the SSL/TLS handshake with the server, for all "server"
Willy Tarreau610f04b2014-02-13 11:36:41 +0100817 lines which do not explicitly define theirs. The format of the string is
818 defined in "man 1 ciphers". Please check the "server" keyword for more
819 information.
820
Emeric Brun2c86cbf2014-10-30 15:56:50 +0100821ssl-default-server-options [<option>]...
822 This setting is only available when support for OpenSSL was built in. It sets
823 default ssl-options to force on all "server" lines. Please check the "server"
824 keyword to see available options.
825
Remi Gacogne47783ef2015-05-29 15:53:22 +0200826ssl-dh-param-file <file>
827 This setting is only available when support for OpenSSL was built in. It sets
828 the default DH parameters that are used during the SSL/TLS handshake when
829 ephemeral Diffie-Hellman (DHE) key exchange is used, for all "bind" lines
830 which do not explicitely define theirs. It will be overridden by custom DH
831 parameters found in a bind certificate file if any. If custom DH parameters
832 are not specified either by using ssl-dh-param-file or by setting them directly
833 in the certificate file, pre-generated DH parameters of the size specified
834 by tune.ssl.default-dh-param will be used. Custom parameters are known to be
835 more secure and therefore their use is recommended.
836 Custom DH parameters may be generated by using the OpenSSL command
837 "openssl dhparam <size>", where size should be at least 2048, as 1024-bit DH
838 parameters should not be considered secure anymore.
839
Emeric Brun850efd52014-01-29 12:24:34 +0100840ssl-server-verify [none|required]
841 The default behavior for SSL verify on servers side. If specified to 'none',
842 servers certificates are not verified. The default is 'required' except if
843 forced using cmdline option '-dV'.
844
Willy Tarreauabb175f2012-09-24 12:43:26 +0200845stats socket [<address:port>|<path>] [param*]
846 Binds a UNIX socket to <path> or a TCPv4/v6 address to <address:port>.
847 Connections to this socket will return various statistics outputs and even
848 allow some commands to be issued to change some runtime settings. Please
849 consult section 9.2 "Unix Socket commands" for more details.
Willy Tarreau6162db22009-10-10 17:13:00 +0200850
Willy Tarreauabb175f2012-09-24 12:43:26 +0200851 All parameters supported by "bind" lines are supported, for instance to
852 restrict access to some users or their access rights. Please consult
853 section 5.1 for more information.
Willy Tarreaufbee7132007-10-18 13:53:22 +0200854
855stats timeout <timeout, in milliseconds>
856 The default timeout on the stats socket is set to 10 seconds. It is possible
857 to change this value with "stats timeout". The value must be passed in
Willy Tarreaubefdff12007-12-02 22:27:38 +0100858 milliseconds, or be suffixed by a time unit among { us, ms, s, m, h, d }.
Willy Tarreaufbee7132007-10-18 13:53:22 +0200859
860stats maxconn <connections>
861 By default, the stats socket is limited to 10 concurrent connections. It is
862 possible to change this value with "stats maxconn".
863
Willy Tarreau6a06a402007-07-15 20:15:28 +0200864uid <number>
865 Changes the process' user ID to <number>. It is recommended that the user ID
866 is dedicated to HAProxy or to a small set of similar daemons. HAProxy must
867 be started with superuser privileges in order to be able to switch to another
868 one. See also "gid" and "user".
869
870ulimit-n <number>
871 Sets the maximum number of per-process file-descriptors to <number>. By
872 default, it is automatically computed, so it is recommended not to use this
873 option.
874
Willy Tarreauceb24bc2010-11-09 12:46:41 +0100875unix-bind [ prefix <prefix> ] [ mode <mode> ] [ user <user> ] [ uid <uid> ]
876 [ group <group> ] [ gid <gid> ]
877
878 Fixes common settings to UNIX listening sockets declared in "bind" statements.
879 This is mainly used to simplify declaration of those UNIX sockets and reduce
880 the risk of errors, since those settings are most commonly required but are
881 also process-specific. The <prefix> setting can be used to force all socket
882 path to be relative to that directory. This might be needed to access another
883 component's chroot. Note that those paths are resolved before haproxy chroots
884 itself, so they are absolute. The <mode>, <user>, <uid>, <group> and <gid>
885 all have the same meaning as their homonyms used by the "bind" statement. If
886 both are specified, the "bind" statement has priority, meaning that the
887 "unix-bind" settings may be seen as process-wide default settings.
888
Willy Tarreau6a06a402007-07-15 20:15:28 +0200889user <user name>
890 Similar to "uid" but uses the UID of user name <user name> from /etc/passwd.
891 See also "uid" and "group".
892
Krzysztof Piotr Oledzki48cb2ae2009-10-02 22:51:14 +0200893node <name>
894 Only letters, digits, hyphen and underscore are allowed, like in DNS names.
895
896 This statement is useful in HA configurations where two or more processes or
897 servers share the same IP address. By setting a different node-name on all
898 nodes, it becomes easy to immediately spot what server is handling the
899 traffic.
900
901description <text>
902 Add a text that describes the instance.
903
904 Please note that it is required to escape certain characters (# for example)
905 and this text is inserted into a html page so you should avoid using
906 "<" and ">" characters.
907
Thomas Holmesdb04f192015-05-18 13:21:39 +010090851degrees-data-file <file path>
909 The path of the 51Degrees data file to provide device detection services. The
910 file should be unzipped and accessible by HAProxy with relevavnt permissions.
911
Dragan Dosenae6d39a2015-06-29 16:43:27 +0200912 Please note that this option is only available when haproxy has been
Thomas Holmesdb04f192015-05-18 13:21:39 +0100913 compiled with USE_51DEGREES.
914
91551degrees-property-name-list [<string>]
916 A list of 51Degrees property names to be load from the dataset. A full list
917 of names is available on the 51Degrees website:
918 https://51degrees.com/resources/property-dictionary
919
Dragan Dosenae6d39a2015-06-29 16:43:27 +0200920 Please note that this option is only available when haproxy has been
Thomas Holmesdb04f192015-05-18 13:21:39 +0100921 compiled with USE_51DEGREES.
922
Dragan Dosen93b38d92015-06-29 16:43:25 +020092351degrees-property-separator <char>
Thomas Holmesdb04f192015-05-18 13:21:39 +0100924 A char that will be appended to every property value in a response header
925 containing 51Degrees results. If not set that will be set as ','.
926
Dragan Dosenae6d39a2015-06-29 16:43:27 +0200927 Please note that this option is only available when haproxy has been
928 compiled with USE_51DEGREES.
929
93051degrees-cache-size <number>
931 Sets the size of the 51Degrees converter cache to <number> entries. This
932 is an LRU cache which reminds previous device detections and their results.
933 By default, this cache is disabled.
934
935 Please note that this option is only available when haproxy has been
Thomas Holmesdb04f192015-05-18 13:21:39 +0100936 compiled with USE_51DEGREES.
937
Willy Tarreau6a06a402007-07-15 20:15:28 +0200938
Willy Tarreauc57f0e22009-05-10 13:12:33 +02009393.2. Performance tuning
Willy Tarreau6a06a402007-07-15 20:15:28 +0200940-----------------------
941
Willy Tarreau1746eec2014-04-25 10:46:47 +0200942max-spread-checks <delay in milliseconds>
943 By default, haproxy tries to spread the start of health checks across the
944 smallest health check interval of all the servers in a farm. The principle is
945 to avoid hammering services running on the same server. But when using large
946 check intervals (10 seconds or more), the last servers in the farm take some
947 time before starting to be tested, which can be a problem. This parameter is
948 used to enforce an upper bound on delay between the first and the last check,
949 even if the servers' check intervals are larger. When servers run with
950 shorter intervals, their intervals will be respected though.
951
Willy Tarreau6a06a402007-07-15 20:15:28 +0200952maxconn <number>
953 Sets the maximum per-process number of concurrent connections to <number>. It
954 is equivalent to the command-line argument "-n". Proxies will stop accepting
955 connections when this limit is reached. The "ulimit-n" parameter is
Willy Tarreau8274e102014-06-19 15:31:25 +0200956 automatically adjusted according to this value. See also "ulimit-n". Note:
957 the "select" poller cannot reliably use more than 1024 file descriptors on
958 some platforms. If your platform only supports select and reports "select
959 FAILED" on startup, you need to reduce maxconn until it works (slightly
Willy Tarreaud0256482015-01-15 21:45:22 +0100960 below 500 in general). If this value is not set, it will default to the value
961 set in DEFAULT_MAXCONN at build time (reported in haproxy -vv) if no memory
962 limit is enforced, or will be computed based on the memory limit, the buffer
963 size, memory allocated to compression, SSL cache size, and use or not of SSL
964 and the associated maxsslconn (which can also be automatic).
Willy Tarreau6a06a402007-07-15 20:15:28 +0200965
Willy Tarreau81c25d02011-09-07 15:17:21 +0200966maxconnrate <number>
967 Sets the maximum per-process number of connections per second to <number>.
968 Proxies will stop accepting connections when this limit is reached. It can be
969 used to limit the global capacity regardless of each frontend capacity. It is
970 important to note that this can only be used as a service protection measure,
971 as there will not necessarily be a fair share between frontends when the
972 limit is reached, so it's a good idea to also limit each frontend to some
973 value close to its expected share. Also, lowering tune.maxaccept can improve
974 fairness.
975
William Lallemandd85f9172012-11-09 17:05:39 +0100976maxcomprate <number>
977 Sets the maximum per-process input compression rate to <number> kilobytes
Jarno Huuskonen0e82b922014-04-12 18:22:19 +0300978 per second. For each session, if the maximum is reached, the compression
William Lallemandd85f9172012-11-09 17:05:39 +0100979 level will be decreased during the session. If the maximum is reached at the
980 beginning of a session, the session will not compress at all. If the maximum
981 is not reached, the compression level will be increased up to
982 tune.comp.maxlevel. A value of zero means there is no limit, this is the
983 default value.
984
William Lallemand072a2bf2012-11-20 17:01:01 +0100985maxcompcpuusage <number>
986 Sets the maximum CPU usage HAProxy can reach before stopping the compression
987 for new requests or decreasing the compression level of current requests.
988 It works like 'maxcomprate' but measures CPU usage instead of incoming data
989 bandwidth. The value is expressed in percent of the CPU used by haproxy. In
990 case of multiple processes (nbproc > 1), each process manages its individual
991 usage. A value of 100 disable the limit. The default value is 100. Setting
992 a lower value will prevent the compression work from slowing the whole
993 process down and from introducing high latencies.
994
Willy Tarreauff4f82d2009-02-06 11:28:13 +0100995maxpipes <number>
996 Sets the maximum per-process number of pipes to <number>. Currently, pipes
997 are only used by kernel-based tcp splicing. Since a pipe contains two file
998 descriptors, the "ulimit-n" value will be increased accordingly. The default
999 value is maxconn/4, which seems to be more than enough for most heavy usages.
1000 The splice code dynamically allocates and releases pipes, and can fall back
1001 to standard copy, so setting this value too low may only impact performance.
1002
Willy Tarreau93e7c002013-10-07 18:51:07 +02001003maxsessrate <number>
1004 Sets the maximum per-process number of sessions per second to <number>.
1005 Proxies will stop accepting connections when this limit is reached. It can be
1006 used to limit the global capacity regardless of each frontend capacity. It is
1007 important to note that this can only be used as a service protection measure,
1008 as there will not necessarily be a fair share between frontends when the
1009 limit is reached, so it's a good idea to also limit each frontend to some
1010 value close to its expected share. Also, lowering tune.maxaccept can improve
1011 fairness.
1012
Willy Tarreau403edff2012-09-06 11:58:37 +02001013maxsslconn <number>
1014 Sets the maximum per-process number of concurrent SSL connections to
1015 <number>. By default there is no SSL-specific limit, which means that the
1016 global maxconn setting will apply to all connections. Setting this limit
1017 avoids having openssl use too much memory and crash when malloc returns NULL
1018 (since it unfortunately does not reliably check for such conditions). Note
1019 that the limit applies both to incoming and outgoing connections, so one
1020 connection which is deciphered then ciphered accounts for 2 SSL connections.
Willy Tarreaud0256482015-01-15 21:45:22 +01001021 If this value is not set, but a memory limit is enforced, this value will be
1022 automatically computed based on the memory limit, maxconn, the buffer size,
1023 memory allocated to compression, SSL cache size, and use of SSL in either
1024 frontends, backends or both. If neither maxconn nor maxsslconn are specified
1025 when there is a memory limit, haproxy will automatically adjust these values
1026 so that 100% of the connections can be made over SSL with no risk, and will
1027 consider the sides where it is enabled (frontend, backend, both).
Willy Tarreau403edff2012-09-06 11:58:37 +02001028
Willy Tarreaue43d5322013-10-07 20:01:52 +02001029maxsslrate <number>
1030 Sets the maximum per-process number of SSL sessions per second to <number>.
1031 SSL listeners will stop accepting connections when this limit is reached. It
1032 can be used to limit the global SSL CPU usage regardless of each frontend
1033 capacity. It is important to note that this can only be used as a service
1034 protection measure, as there will not necessarily be a fair share between
1035 frontends when the limit is reached, so it's a good idea to also limit each
1036 frontend to some value close to its expected share. It is also important to
1037 note that the sessions are accounted before they enter the SSL stack and not
1038 after, which also protects the stack against bad handshakes. Also, lowering
1039 tune.maxaccept can improve fairness.
1040
William Lallemand9d5f5482012-11-07 16:12:57 +01001041maxzlibmem <number>
1042 Sets the maximum amount of RAM in megabytes per process usable by the zlib.
1043 When the maximum amount is reached, future sessions will not compress as long
1044 as RAM is unavailable. When sets to 0, there is no limit.
William Lallemande3a7d992012-11-20 11:25:20 +01001045 The default value is 0. The value is available in bytes on the UNIX socket
1046 with "show info" on the line "MaxZlibMemUsage", the memory used by zlib is
1047 "ZlibMemUsage" in bytes.
1048
Willy Tarreau6a06a402007-07-15 20:15:28 +02001049noepoll
1050 Disables the use of the "epoll" event polling system on Linux. It is
1051 equivalent to the command-line argument "-de". The next polling system
Willy Tarreaue9f49e72012-11-11 17:42:00 +01001052 used will generally be "poll". See also "nopoll".
Willy Tarreau6a06a402007-07-15 20:15:28 +02001053
1054nokqueue
1055 Disables the use of the "kqueue" event polling system on BSD. It is
1056 equivalent to the command-line argument "-dk". The next polling system
1057 used will generally be "poll". See also "nopoll".
1058
1059nopoll
1060 Disables the use of the "poll" event polling system. It is equivalent to the
1061 command-line argument "-dp". The next polling system used will be "select".
Willy Tarreau0ba27502007-12-24 16:55:16 +01001062 It should never be needed to disable "poll" since it's available on all
Willy Tarreaue9f49e72012-11-11 17:42:00 +01001063 platforms supported by HAProxy. See also "nokqueue" and "noepoll".
Willy Tarreau6a06a402007-07-15 20:15:28 +02001064
Willy Tarreauff4f82d2009-02-06 11:28:13 +01001065nosplice
1066 Disables the use of kernel tcp splicing between sockets on Linux. It is
1067 equivalent to the command line argument "-dS". Data will then be copied
1068 using conventional and more portable recv/send calls. Kernel tcp splicing is
Krzysztof Piotr Oledzkif8645332009-12-13 21:55:50 +01001069 limited to some very recent instances of kernel 2.6. Most versions between
Willy Tarreauff4f82d2009-02-06 11:28:13 +01001070 2.6.25 and 2.6.28 are buggy and will forward corrupted data, so they must not
1071 be used. This option makes it easier to globally disable kernel splicing in
1072 case of doubt. See also "option splice-auto", "option splice-request" and
1073 "option splice-response".
1074
Jarno Huuskonen0e82b922014-04-12 18:22:19 +03001075nogetaddrinfo
1076 Disables the use of getaddrinfo(3) for name resolving. It is equivalent to
1077 the command line argument "-dG". Deprecated gethostbyname(3) will be used.
1078
Willy Tarreaufe255b72007-10-14 23:09:26 +02001079spread-checks <0..50, in percent>
Simon Hormand60d6912013-11-25 10:46:36 +09001080 Sometimes it is desirable to avoid sending agent and health checks to
1081 servers at exact intervals, for instance when many logical servers are
1082 located on the same physical server. With the help of this parameter, it
1083 becomes possible to add some randomness in the check interval between 0
1084 and +/- 50%. A value between 2 and 5 seems to show good results. The
1085 default value remains at 0.
Willy Tarreaufe255b72007-10-14 23:09:26 +02001086
Willy Tarreau33cb0652014-12-23 22:52:37 +01001087tune.buffers.limit <number>
1088 Sets a hard limit on the number of buffers which may be allocated per process.
1089 The default value is zero which means unlimited. The minimum non-zero value
1090 will always be greater than "tune.buffers.reserve" and should ideally always
1091 be about twice as large. Forcing this value can be particularly useful to
1092 limit the amount of memory a process may take, while retaining a sane
1093 behaviour. When this limit is reached, sessions which need a buffer wait for
1094 another one to be released by another session. Since buffers are dynamically
1095 allocated and released, the waiting time is very short and not perceptible
1096 provided that limits remain reasonable. In fact sometimes reducing the limit
1097 may even increase performance by increasing the CPU cache's efficiency. Tests
1098 have shown good results on average HTTP traffic with a limit to 1/10 of the
1099 expected global maxconn setting, which also significantly reduces memory
1100 usage. The memory savings come from the fact that a number of connections
1101 will not allocate 2*tune.bufsize. It is best not to touch this value unless
1102 advised to do so by an haproxy core developer.
1103
Willy Tarreau1058ae72014-12-23 22:40:40 +01001104tune.buffers.reserve <number>
1105 Sets the number of buffers which are pre-allocated and reserved for use only
1106 during memory shortage conditions resulting in failed memory allocations. The
1107 minimum value is 2 and is also the default. There is no reason a user would
1108 want to change this value, it's mostly aimed at haproxy core developers.
1109
Willy Tarreau27a674e2009-08-17 07:23:33 +02001110tune.bufsize <number>
1111 Sets the buffer size to this size (in bytes). Lower values allow more
1112 sessions to coexist in the same amount of RAM, and higher values allow some
1113 applications with very large cookies to work. The default value is 16384 and
1114 can be changed at build time. It is strongly recommended not to change this
1115 from the default value, as very low values will break some services such as
1116 statistics, and values larger than default size will increase memory usage,
1117 possibly causing the system to run out of memory. At least the global maxconn
1118 parameter should be decreased by the same factor as this one is increased.
Dmitry Sivachenkof6f4f7b2012-10-21 18:10:25 +04001119 If HTTP request is larger than (tune.bufsize - tune.maxrewrite), haproxy will
1120 return HTTP 400 (Bad Request) error. Similarly if an HTTP response is larger
1121 than this size, haproxy will return HTTP 502 (Bad Gateway).
Willy Tarreau27a674e2009-08-17 07:23:33 +02001122
Willy Tarreau43961d52010-10-04 20:39:20 +02001123tune.chksize <number>
1124 Sets the check buffer size to this size (in bytes). Higher values may help
1125 find string or regex patterns in very large pages, though doing so may imply
1126 more memory and CPU usage. The default value is 16384 and can be changed at
1127 build time. It is not recommended to change this value, but to use better
1128 checks whenever possible.
1129
William Lallemandf3747832012-11-09 12:33:10 +01001130tune.comp.maxlevel <number>
1131 Sets the maximum compression level. The compression level affects CPU
1132 usage during compression. This value affects CPU usage during compression.
1133 Each session using compression initializes the compression algorithm with
1134 this value. The default value is 1.
1135
Willy Tarreau193b8c62012-11-22 00:17:38 +01001136tune.http.cookielen <number>
1137 Sets the maximum length of captured cookies. This is the maximum value that
1138 the "capture cookie xxx len yyy" will be allowed to take, and any upper value
1139 will automatically be truncated to this one. It is important not to set too
1140 high a value because all cookie captures still allocate this size whatever
1141 their configured value (they share a same pool). This value is per request
1142 per response, so the memory allocated is twice this value per connection.
1143 When not specified, the limit is set to 63 characters. It is recommended not
1144 to change this value.
1145
Willy Tarreauac1932d2011-10-24 19:14:41 +02001146tune.http.maxhdr <number>
1147 Sets the maximum number of headers in a request. When a request comes with a
1148 number of headers greater than this value (including the first line), it is
1149 rejected with a "400 Bad Request" status code. Similarly, too large responses
1150 are blocked with "502 Bad Gateway". The default value is 101, which is enough
1151 for all usages, considering that the widely deployed Apache server uses the
1152 same limit. It can be useful to push this limit further to temporarily allow
1153 a buggy application to work by the time it gets fixed. Keep in mind that each
1154 new header consumes 32bits of memory for each session, so don't push this
1155 limit too high.
1156
Willy Tarreau7e312732014-02-12 16:35:14 +01001157tune.idletimer <timeout>
1158 Sets the duration after which haproxy will consider that an empty buffer is
1159 probably associated with an idle stream. This is used to optimally adjust
1160 some packet sizes while forwarding large and small data alternatively. The
1161 decision to use splice() or to send large buffers in SSL is modulated by this
1162 parameter. The value is in milliseconds between 0 and 65535. A value of zero
1163 means that haproxy will not try to detect idle streams. The default is 1000,
1164 which seems to correctly detect end user pauses (eg: read a page before
1165 clicking). There should be not reason for changing this value. Please check
1166 tune.ssl.maxrecord below.
1167
Thierry FOURNIER90da1912015-03-05 11:17:06 +01001168tune.lua.forced-yield <number>
1169 This directive forces the Lua engine to execute a yield each <number> of
1170 instructions executed. This permits interruptng a long script and allows the
1171 HAProxy scheduler to process other tasks like accepting connections or
1172 forwarding traffic. The default value is 10000 instructions. If HAProxy often
1173 executes some Lua code but more reactivity is required, this value can be
1174 lowered. If the Lua code is quite long and its result is absolutely required
1175 to process the data, the <number> can be increased.
1176
Willy Tarreau32f61e22015-03-18 17:54:59 +01001177tune.lua.maxmem
1178 Sets the maximum amount of RAM in megabytes per process usable by Lua. By
1179 default it is zero which means unlimited. It is important to set a limit to
1180 ensure that a bug in a script will not result in the system running out of
1181 memory.
1182
Thierry FOURNIER90da1912015-03-05 11:17:06 +01001183tune.lua.session-timeout <timeout>
1184 This is the execution timeout for the Lua sessions. This is useful for
1185 preventing infinite loops or spending too much time in Lua. This timeout has a
1186 priority over other timeouts. For example, if this timeout is set to 4s and
1187 you run a 5s sleep, the code will be interrupted with an error after waiting
1188 4s.
1189
1190tune.lua.task-timeout <timeout>
1191 Purpose is the same as "tune.lua.session-timeout", but this timeout is
1192 dedicated to the tasks. By default, this timeout isn't set because a task may
1193 remain alive during of the lifetime of HAProxy. For example, a task used to
1194 check servers.
1195
Willy Tarreaua0250ba2008-01-06 11:22:57 +01001196tune.maxaccept <number>
Willy Tarreau16a21472012-11-19 12:39:59 +01001197 Sets the maximum number of consecutive connections a process may accept in a
1198 row before switching to other work. In single process mode, higher numbers
1199 give better performance at high connection rates. However in multi-process
1200 modes, keeping a bit of fairness between processes generally is better to
1201 increase performance. This value applies individually to each listener, so
1202 that the number of processes a listener is bound to is taken into account.
1203 This value defaults to 64. In multi-process mode, it is divided by twice
1204 the number of processes the listener is bound to. Setting this value to -1
1205 completely disables the limitation. It should normally not be needed to tweak
1206 this value.
Willy Tarreaua0250ba2008-01-06 11:22:57 +01001207
1208tune.maxpollevents <number>
1209 Sets the maximum amount of events that can be processed at once in a call to
1210 the polling system. The default value is adapted to the operating system. It
1211 has been noticed that reducing it below 200 tends to slightly decrease
1212 latency at the expense of network bandwidth, and increasing it above 200
1213 tends to trade latency for slightly increased bandwidth.
1214
Willy Tarreau27a674e2009-08-17 07:23:33 +02001215tune.maxrewrite <number>
1216 Sets the reserved buffer space to this size in bytes. The reserved space is
1217 used for header rewriting or appending. The first reads on sockets will never
1218 fill more than bufsize-maxrewrite. Historically it has defaulted to half of
1219 bufsize, though that does not make much sense since there are rarely large
1220 numbers of headers to add. Setting it too high prevents processing of large
1221 requests or responses. Setting it too low prevents addition of new headers
1222 to already large requests or to POST requests. It is generally wise to set it
1223 to about 1024. It is automatically readjusted to half of bufsize if it is
1224 larger than that. This means you don't have to worry about it when changing
1225 bufsize.
1226
Willy Tarreauf3045d22015-04-29 16:24:50 +02001227tune.pattern.cache-size <number>
1228 Sets the size of the pattern lookup cache to <number> entries. This is an LRU
1229 cache which reminds previous lookups and their results. It is used by ACLs
1230 and maps on slow pattern lookups, namely the ones using the "sub", "reg",
1231 "dir", "dom", "end", "bin" match methods as well as the case-insensitive
1232 strings. It applies to pattern expressions which means that it will be able
1233 to memorize the result of a lookup among all the patterns specified on a
1234 configuration line (including all those loaded from files). It automatically
1235 invalidates entries which are updated using HTTP actions or on the CLI. The
1236 default cache size is set to 10000 entries, which limits its footprint to
1237 about 5 MB on 32-bit systems and 8 MB on 64-bit systems. There is a very low
1238 risk of collision in this cache, which is in the order of the size of the
1239 cache divided by 2^64. Typically, at 10000 requests per second with the
1240 default cache size of 10000 entries, there's 1% chance that a brute force
1241 attack could cause a single collision after 60 years, or 0.1% after 6 years.
1242 This is considered much lower than the risk of a memory corruption caused by
1243 aging components. If this is not acceptable, the cache can be disabled by
1244 setting this parameter to 0.
1245
Willy Tarreaubd9a0a72011-10-23 21:14:29 +02001246tune.pipesize <number>
1247 Sets the kernel pipe buffer size to this size (in bytes). By default, pipes
1248 are the default size for the system. But sometimes when using TCP splicing,
1249 it can improve performance to increase pipe sizes, especially if it is
1250 suspected that pipes are not filled and that many calls to splice() are
1251 performed. This has an impact on the kernel's memory footprint, so this must
1252 not be changed if impacts are not understood.
1253
Willy Tarreaue803de22010-01-21 17:43:04 +01001254tune.rcvbuf.client <number>
1255tune.rcvbuf.server <number>
1256 Forces the kernel socket receive buffer size on the client or the server side
1257 to the specified value in bytes. This value applies to all TCP/HTTP frontends
1258 and backends. It should normally never be set, and the default size (0) lets
1259 the kernel autotune this value depending on the amount of available memory.
1260 However it can sometimes help to set it to very low values (eg: 4096) in
1261 order to save kernel memory by preventing it from buffering too large amounts
1262 of received data. Lower values will significantly increase CPU usage though.
1263
1264tune.sndbuf.client <number>
1265tune.sndbuf.server <number>
1266 Forces the kernel socket send buffer size on the client or the server side to
1267 the specified value in bytes. This value applies to all TCP/HTTP frontends
1268 and backends. It should normally never be set, and the default size (0) lets
1269 the kernel autotune this value depending on the amount of available memory.
1270 However it can sometimes help to set it to very low values (eg: 4096) in
1271 order to save kernel memory by preventing it from buffering too large amounts
1272 of received data. Lower values will significantly increase CPU usage though.
1273 Another use case is to prevent write timeouts with extremely slow clients due
1274 to the kernel waiting for a large part of the buffer to be read before
1275 notifying haproxy again.
1276
Willy Tarreau6ec58db2012-11-16 16:32:15 +01001277tune.ssl.cachesize <number>
Emeric Brunaf9619d2012-11-28 18:47:52 +01001278 Sets the size of the global SSL session cache, in a number of blocks. A block
1279 is large enough to contain an encoded session without peer certificate.
1280 An encoded session with peer certificate is stored in multiple blocks
Jarno Huuskonen0e82b922014-04-12 18:22:19 +03001281 depending on the size of the peer certificate. A block uses approximately
Emeric Brunaf9619d2012-11-28 18:47:52 +01001282 200 bytes of memory. The default value may be forced at build time, otherwise
1283 defaults to 20000. When the cache is full, the most idle entries are purged
1284 and reassigned. Higher values reduce the occurrence of such a purge, hence
1285 the number of CPU-intensive SSL handshakes by ensuring that all users keep
1286 their session as long as possible. All entries are pre-allocated upon startup
Emeric Brun22890a12012-12-28 14:41:32 +01001287 and are shared between all processes if "nbproc" is greater than 1. Setting
1288 this value to 0 disables the SSL session cache.
Willy Tarreau6ec58db2012-11-16 16:32:15 +01001289
Emeric Brun8dc60392014-05-09 13:52:00 +02001290tune.ssl.force-private-cache
1291 This boolean disables SSL session cache sharing between all processes. It
1292 should normally not be used since it will force many renegotiations due to
1293 clients hitting a random process. But it may be required on some operating
1294 systems where none of the SSL cache synchronization method may be used. In
1295 this case, adding a first layer of hash-based load balancing before the SSL
1296 layer might limit the impact of the lack of session sharing.
1297
Emeric Brun4f65bff2012-11-16 15:11:00 +01001298tune.ssl.lifetime <timeout>
1299 Sets how long a cached SSL session may remain valid. This time is expressed
Jarno Huuskonen0e82b922014-04-12 18:22:19 +03001300 in seconds and defaults to 300 (5 min). It is important to understand that it
Emeric Brun4f65bff2012-11-16 15:11:00 +01001301 does not guarantee that sessions will last that long, because if the cache is
1302 full, the longest idle sessions will be purged despite their configured
1303 lifetime. The real usefulness of this setting is to prevent sessions from
1304 being used for too long.
1305
Willy Tarreaubfd59462013-02-21 07:46:09 +01001306tune.ssl.maxrecord <number>
1307 Sets the maximum amount of bytes passed to SSL_write() at a time. Default
1308 value 0 means there is no limit. Over SSL/TLS, the client can decipher the
1309 data only once it has received a full record. With large records, it means
1310 that clients might have to download up to 16kB of data before starting to
1311 process them. Limiting the value can improve page load times on browsers
1312 located over high latency or low bandwidth networks. It is suggested to find
1313 optimal values which fit into 1 or 2 TCP segments (generally 1448 bytes over
1314 Ethernet with TCP timestamps enabled, or 1460 when timestamps are disabled),
1315 keeping in mind that SSL/TLS add some overhead. Typical values of 1419 and
1316 2859 gave good results during tests. Use "strace -e trace=write" to find the
Willy Tarreau7e312732014-02-12 16:35:14 +01001317 best value. Haproxy will automatically switch to this setting after an idle
1318 stream has been detected (see tune.idletimer above).
Willy Tarreaubfd59462013-02-21 07:46:09 +01001319
Remi Gacognef46cd6e2014-06-12 14:58:40 +02001320tune.ssl.default-dh-param <number>
1321 Sets the maximum size of the Diffie-Hellman parameters used for generating
1322 the ephemeral/temporary Diffie-Hellman key in case of DHE key exchange. The
1323 final size will try to match the size of the server's RSA (or DSA) key (e.g,
1324 a 2048 bits temporary DH key for a 2048 bits RSA key), but will not exceed
1325 this maximum value. Default value if 1024. Only 1024 or higher values are
1326 allowed. Higher values will increase the CPU load, and values greater than
1327 1024 bits are not supported by Java 7 and earlier clients. This value is not
Remi Gacogne47783ef2015-05-29 15:53:22 +02001328 used if static Diffie-Hellman parameters are supplied either directly
1329 in the certificate file or by using the ssl-dh-param-file parameter.
Remi Gacognef46cd6e2014-06-12 14:58:40 +02001330
Christopher Faulet31af49d2015-06-09 17:29:50 +02001331tune.ssl.ssl-ctx-cache-size <number>
1332 Sets the size of the cache used to store generated certificates to <number>
1333 entries. This is a LRU cache. Because generating a SSL certificate
1334 dynamically is expensive, they are cached. The default cache size is set to
1335 1000 entries.
1336
Thierry FOURNIER4834bc72015-06-06 19:29:07 +02001337tune.vars.global-max-size <size>
1338tune.vars.reqres-max-size <size>
1339tune.vars.sess-max-size <size>
1340tune.vars.txn-max-size <size>
1341 These four tunes helps to manage the allowed amount of memory used by the
1342 variables system. "global" limits the memory for all the systems. "sess" limit
1343 the memory by session, "txn" limits the memory by transaction and "reqres"
1344 limits the memory for each request or response processing. during the
1345 accounting, "sess" embbed "txn" and "txn" embed "reqres".
1346
1347 By example, we considers that "tune.vars.sess-max-size" is fixed to 100,
1348 "tune.vars.txn-max-size" is fixed to 100, "tune.vars.reqres-max-size" is
1349 also fixed to 100. If we create a variable "txn.var" that contains 100 bytes,
1350 we cannot create any more variable in the other contexts.
1351
William Lallemanda509e4c2012-11-07 16:54:34 +01001352tune.zlib.memlevel <number>
1353 Sets the memLevel parameter in zlib initialization for each session. It
Jarno Huuskonen0e82b922014-04-12 18:22:19 +03001354 defines how much memory should be allocated for the internal compression
William Lallemanda509e4c2012-11-07 16:54:34 +01001355 state. A value of 1 uses minimum memory but is slow and reduces compression
1356 ratio, a value of 9 uses maximum memory for optimal speed. Can be a value
1357 between 1 and 9. The default value is 8.
1358
1359tune.zlib.windowsize <number>
1360 Sets the window size (the size of the history buffer) as a parameter of the
1361 zlib initialization for each session. Larger values of this parameter result
1362 in better compression at the expense of memory usage. Can be a value between
1363 8 and 15. The default value is 15.
Willy Tarreau6a06a402007-07-15 20:15:28 +02001364
Willy Tarreauc57f0e22009-05-10 13:12:33 +020013653.3. Debugging
1366--------------
Willy Tarreau6a06a402007-07-15 20:15:28 +02001367
1368debug
1369 Enables debug mode which dumps to stdout all exchanges, and disables forking
1370 into background. It is the equivalent of the command-line argument "-d". It
1371 should never be used in a production configuration since it may prevent full
1372 system startup.
1373
1374quiet
1375 Do not display any message during startup. It is equivalent to the command-
1376 line argument "-q".
1377
Emeric Brunf099e792010-09-27 12:05:28 +02001378
Krzysztof Piotr Oledzki6b35ce12010-02-01 23:35:44 +010013793.4. Userlists
1380--------------
1381It is possible to control access to frontend/backend/listen sections or to
1382http stats by allowing only authenticated and authorized users. To do this,
1383it is required to create at least one userlist and to define users.
1384
1385userlist <listname>
Cyril Bonté78caf842010-03-10 22:41:43 +01001386 Creates new userlist with name <listname>. Many independent userlists can be
Krzysztof Piotr Oledzki6b35ce12010-02-01 23:35:44 +01001387 used to store authentication & authorization data for independent customers.
1388
1389group <groupname> [users <user>,<user>,(...)]
Cyril Bonté78caf842010-03-10 22:41:43 +01001390 Adds group <groupname> to the current userlist. It is also possible to
Krzysztof Piotr Oledzki6b35ce12010-02-01 23:35:44 +01001391 attach users to this group by using a comma separated list of names
1392 proceeded by "users" keyword.
1393
Cyril Bontéf0c60612010-02-06 14:44:47 +01001394user <username> [password|insecure-password <password>]
1395 [groups <group>,<group>,(...)]
Krzysztof Piotr Oledzki6b35ce12010-02-01 23:35:44 +01001396 Adds user <username> to the current userlist. Both secure (encrypted) and
1397 insecure (unencrypted) passwords can be used. Encrypted passwords are
Cyril Bonté78caf842010-03-10 22:41:43 +01001398 evaluated using the crypt(3) function so depending of the system's
1399 capabilities, different algorithms are supported. For example modern Glibc
Krzysztof Piotr Oledzki6b35ce12010-02-01 23:35:44 +01001400 based Linux system supports MD5, SHA-256, SHA-512 and of course classic,
Jarno Huuskonen0e82b922014-04-12 18:22:19 +03001401 DES-based method of encrypting passwords.
Krzysztof Piotr Oledzki6b35ce12010-02-01 23:35:44 +01001402
1403
1404 Example:
Cyril Bontéf0c60612010-02-06 14:44:47 +01001405 userlist L1
1406 group G1 users tiger,scott
1407 group G2 users xdb,scott
Krzysztof Piotr Oledzki6b35ce12010-02-01 23:35:44 +01001408
Cyril Bontéf0c60612010-02-06 14:44:47 +01001409 user tiger password $6$k6y3o.eP$JlKBx9za9667qe4(...)xHSwRv6J.C0/D7cV91
1410 user scott insecure-password elgato
1411 user xdb insecure-password hello
Krzysztof Piotr Oledzki6b35ce12010-02-01 23:35:44 +01001412
Cyril Bontéf0c60612010-02-06 14:44:47 +01001413 userlist L2
1414 group G1
1415 group G2
Krzysztof Piotr Oledzki6b35ce12010-02-01 23:35:44 +01001416
Cyril Bontéf0c60612010-02-06 14:44:47 +01001417 user tiger password $6$k6y3o.eP$JlKBx(...)xHSwRv6J.C0/D7cV91 groups G1
1418 user scott insecure-password elgato groups G1,G2
1419 user xdb insecure-password hello groups G2
Krzysztof Piotr Oledzki6b35ce12010-02-01 23:35:44 +01001420
1421 Please note that both lists are functionally identical.
Willy Tarreau6a06a402007-07-15 20:15:28 +02001422
Emeric Brunf099e792010-09-27 12:05:28 +02001423
14243.5. Peers
Cyril Bontédc4d9032012-04-08 21:57:39 +02001425----------
Emeric Brun94900952015-06-11 18:25:54 +02001426It is possible to propagate entries of any data-types in stick-tables between
1427several haproxy instances over TCP connections in a multi-master fashion. Each
1428instance pushes its local updates and insertions to remote peers. The pushed
1429values overwrite remote ones without aggregation. Interrupted exchanges are
1430automatically detected and recovered from the last known point.
1431In addition, during a soft restart, the old process connects to the new one
1432using such a TCP connection to push all its entries before the new process
1433tries to connect to other peers. That ensures very fast replication during a
1434reload, it typically takes a fraction of a second even for large tables.
1435Note that Server IDs are used to identify servers remotely, so it is important
1436that configurations look similar or at least that the same IDs are forced on
1437each server on all participants.
Emeric Brunf099e792010-09-27 12:05:28 +02001438
1439peers <peersect>
Jamie Gloudon801a0a32012-08-25 00:18:33 -04001440 Creates a new peer list with name <peersect>. It is an independent section,
Emeric Brunf099e792010-09-27 12:05:28 +02001441 which is referenced by one or more stick-tables.
1442
Willy Tarreau77e4bd12015-05-01 20:02:17 +02001443disabled
1444 Disables a peers section. It disables both listening and any synchronization
1445 related to this section. This is provided to disable synchronization of stick
1446 tables without having to comment out all "peers" references.
1447
1448enable
1449 This re-enables a disabled peers section which was previously disabled.
1450
Emeric Brunf099e792010-09-27 12:05:28 +02001451peer <peername> <ip>:<port>
1452 Defines a peer inside a peers section.
1453 If <peername> is set to the local peer name (by default hostname, or forced
1454 using "-L" command line option), haproxy will listen for incoming remote peer
1455 connection on <ip>:<port>. Otherwise, <ip>:<port> defines where to connect to
1456 to join the remote peer, and <peername> is used at the protocol level to
1457 identify and validate the remote peer on the server side.
1458
1459 During a soft restart, local peer <ip>:<port> is used by the old instance to
1460 connect the new one and initiate a complete replication (teaching process).
1461
1462 It is strongly recommended to have the exact same peers declaration on all
1463 peers and to only rely on the "-L" command line argument to change the local
1464 peer name. This makes it easier to maintain coherent configuration files
1465 across all peers.
1466
William Lallemandb2f07452015-05-12 14:27:13 +02001467 You may want to reference some environment variables in the address
1468 parameter, see section 2.3 about environment variables.
Willy Tarreaudad36a32013-03-11 01:20:04 +01001469
Cyril Bontédc4d9032012-04-08 21:57:39 +02001470 Example:
Emeric Brunf099e792010-09-27 12:05:28 +02001471 peers mypeers
Willy Tarreauf7b30a92010-12-06 22:59:17 +01001472 peer haproxy1 192.168.0.1:1024
1473 peer haproxy2 192.168.0.2:1024
1474 peer haproxy3 10.2.0.1:1024
Emeric Brunf099e792010-09-27 12:05:28 +02001475
1476 backend mybackend
1477 mode tcp
1478 balance roundrobin
1479 stick-table type ip size 20k peers mypeers
1480 stick on src
1481
Willy Tarreauf7b30a92010-12-06 22:59:17 +01001482 server srv1 192.168.0.30:80
1483 server srv2 192.168.0.31:80
Emeric Brunf099e792010-09-27 12:05:28 +02001484
1485
Simon Horman51a1cf62015-02-03 13:00:44 +090014863.6. Mailers
1487------------
1488It is possible to send email alerts when the state of servers changes.
1489If configured email alerts are sent to each mailer that is configured
1490in a mailers section. Email is sent to mailers using SMTP.
1491
Pieter Baauw386a1272015-08-16 15:26:24 +02001492mailers <mailersect>
Simon Horman51a1cf62015-02-03 13:00:44 +09001493 Creates a new mailer list with the name <mailersect>. It is an
1494 independent section which is referenced by one or more proxies.
1495
1496mailer <mailername> <ip>:<port>
1497 Defines a mailer inside a mailers section.
1498
1499 Example:
1500 mailers mymailers
1501 mailer smtp1 192.168.0.1:587
1502 mailer smtp2 192.168.0.2:587
1503
1504 backend mybackend
1505 mode tcp
1506 balance roundrobin
1507
1508 email-alert mailers mymailers
1509 email-alert from test1@horms.org
1510 email-alert to test2@horms.org
1511
1512 server srv1 192.168.0.30:80
1513 server srv2 192.168.0.31:80
1514
1515
Willy Tarreauc57f0e22009-05-10 13:12:33 +020015164. Proxies
Willy Tarreau6a06a402007-07-15 20:15:28 +02001517----------
Willy Tarreau0ba27502007-12-24 16:55:16 +01001518
Willy Tarreau6a06a402007-07-15 20:15:28 +02001519Proxy configuration can be located in a set of sections :
William Lallemand6e62fb62015-04-28 16:55:23 +02001520 - defaults [<name>]
Willy Tarreau6a06a402007-07-15 20:15:28 +02001521 - frontend <name>
1522 - backend <name>
1523 - listen <name>
1524
1525A "defaults" section sets default parameters for all other sections following
1526its declaration. Those default parameters are reset by the next "defaults"
1527section. See below for the list of parameters which can be set in a "defaults"
Willy Tarreau0ba27502007-12-24 16:55:16 +01001528section. The name is optional but its use is encouraged for better readability.
Willy Tarreau6a06a402007-07-15 20:15:28 +02001529
1530A "frontend" section describes a set of listening sockets accepting client
1531connections.
1532
1533A "backend" section describes a set of servers to which the proxy will connect
1534to forward incoming connections.
1535
1536A "listen" section defines a complete proxy with its frontend and backend
1537parts combined in one section. It is generally useful for TCP-only traffic.
1538
Willy Tarreau0ba27502007-12-24 16:55:16 +01001539All proxy names must be formed from upper and lower case letters, digits,
1540'-' (dash), '_' (underscore) , '.' (dot) and ':' (colon). ACL names are
1541case-sensitive, which means that "www" and "WWW" are two different proxies.
1542
1543Historically, all proxy names could overlap, it just caused troubles in the
1544logs. Since the introduction of content switching, it is mandatory that two
1545proxies with overlapping capabilities (frontend/backend) have different names.
1546However, it is still permitted that a frontend and a backend share the same
1547name, as this configuration seems to be commonly encountered.
1548
1549Right now, two major proxy modes are supported : "tcp", also known as layer 4,
1550and "http", also known as layer 7. In layer 4 mode, HAProxy simply forwards
Krzysztof Piotr Oledzkif8645332009-12-13 21:55:50 +01001551bidirectional traffic between two sides. In layer 7 mode, HAProxy analyzes the
Willy Tarreau0ba27502007-12-24 16:55:16 +01001552protocol, and can interact with it by allowing, blocking, switching, adding,
1553modifying, or removing arbitrary contents in requests or responses, based on
1554arbitrary criteria.
1555
Willy Tarreau70dffda2014-01-30 03:07:23 +01001556In HTTP mode, the processing applied to requests and responses flowing over
1557a connection depends in the combination of the frontend's HTTP options and
1558the backend's. HAProxy supports 5 connection modes :
1559
1560 - KAL : keep alive ("option http-keep-alive") which is the default mode : all
1561 requests and responses are processed, and connections remain open but idle
1562 between responses and new requests.
1563
1564 - TUN: tunnel ("option http-tunnel") : this was the default mode for versions
1565 1.0 to 1.5-dev21 : only the first request and response are processed, and
1566 everything else is forwarded with no analysis at all. This mode should not
1567 be used as it creates lots of trouble with logging and HTTP processing.
1568
1569 - PCL: passive close ("option httpclose") : exactly the same as tunnel mode,
1570 but with "Connection: close" appended in both directions to try to make
1571 both ends close after the first request/response exchange.
1572
1573 - SCL: server close ("option http-server-close") : the server-facing
1574 connection is closed after the end of the response is received, but the
1575 client-facing connection remains open.
1576
1577 - FCL: forced close ("option forceclose") : the connection is actively closed
1578 after the end of the response.
1579
1580The effective mode that will be applied to a connection passing through a
1581frontend and a backend can be determined by both proxy modes according to the
1582following matrix, but in short, the modes are symmetric, keep-alive is the
1583weakest option and force close is the strongest.
1584
1585 Backend mode
1586
1587 | KAL | TUN | PCL | SCL | FCL
1588 ----+-----+-----+-----+-----+----
1589 KAL | KAL | TUN | PCL | SCL | FCL
1590 ----+-----+-----+-----+-----+----
1591 TUN | TUN | TUN | PCL | SCL | FCL
1592 Frontend ----+-----+-----+-----+-----+----
1593 mode PCL | PCL | PCL | PCL | FCL | FCL
1594 ----+-----+-----+-----+-----+----
1595 SCL | SCL | SCL | FCL | SCL | FCL
1596 ----+-----+-----+-----+-----+----
1597 FCL | FCL | FCL | FCL | FCL | FCL
1598
Willy Tarreau0ba27502007-12-24 16:55:16 +01001599
Willy Tarreau70dffda2014-01-30 03:07:23 +01001600
Willy Tarreauc57f0e22009-05-10 13:12:33 +020016014.1. Proxy keywords matrix
1602--------------------------
Willy Tarreau0ba27502007-12-24 16:55:16 +01001603
Willy Tarreauc57f0e22009-05-10 13:12:33 +02001604The following list of keywords is supported. Most of them may only be used in a
1605limited set of section types. Some of them are marked as "deprecated" because
1606they are inherited from an old syntax which may be confusing or functionally
1607limited, and there are new recommended keywords to replace them. Keywords
Willy Tarreau5c6f7b32010-02-26 13:34:29 +01001608marked with "(*)" can be optionally inverted using the "no" prefix, eg. "no
Willy Tarreauc57f0e22009-05-10 13:12:33 +02001609option contstats". This makes sense when the option has been enabled by default
Willy Tarreau3842f002009-06-14 11:39:52 +02001610and must be disabled for a specific instance. Such options may also be prefixed
1611with "default" in order to restore default settings regardless of what has been
1612specified in a previous "defaults" section.
Willy Tarreau0ba27502007-12-24 16:55:16 +01001613
Willy Tarreau6a06a402007-07-15 20:15:28 +02001614
Willy Tarreau5c6f7b32010-02-26 13:34:29 +01001615 keyword defaults frontend listen backend
1616------------------------------------+----------+----------+---------+---------
1617acl - X X X
Willy Tarreau294d0f02015-08-10 19:40:12 +02001618appsession - - - -
Willy Tarreau5c6f7b32010-02-26 13:34:29 +01001619backlog X X X -
1620balance X - X X
1621bind - X X -
1622bind-process X X X X
1623block - X X X
1624capture cookie - X X -
1625capture request header - X X -
1626capture response header - X X -
1627clitimeout (deprecated) X X X -
William Lallemand82fe75c2012-10-23 10:25:10 +02001628compression X X X X
Willy Tarreau5c6f7b32010-02-26 13:34:29 +01001629contimeout (deprecated) X - X X
1630cookie X - X X
Thierry FOURNIERa0a1b752015-05-26 17:44:32 +02001631declare capture - X X -
Willy Tarreau5c6f7b32010-02-26 13:34:29 +01001632default-server X - X X
1633default_backend X X X -
1634description - X X X
1635disabled X X X X
1636dispatch - - X X
Simon Horman51a1cf62015-02-03 13:00:44 +09001637email-alert from X X X X
Simon Horman64e34162015-02-06 11:11:57 +09001638email-alert level X X X X
Simon Horman51a1cf62015-02-03 13:00:44 +09001639email-alert mailers X X X X
1640email-alert myhostname X X X X
1641email-alert to X X X X
Willy Tarreau5c6f7b32010-02-26 13:34:29 +01001642enabled X X X X
1643errorfile X X X X
1644errorloc X X X X
1645errorloc302 X X X X
1646-- keyword -------------------------- defaults - frontend - listen -- backend -
1647errorloc303 X X X X
Cyril Bonté0d4bf012010-04-25 23:21:46 +02001648force-persist - X X X
Willy Tarreau5c6f7b32010-02-26 13:34:29 +01001649fullconn X - X X
1650grace X X X X
1651hash-type X - X X
1652http-check disable-on-404 X - X X
Willy Tarreaubd741542010-03-16 18:46:54 +01001653http-check expect - - X X
Willy Tarreau7ab6aff2010-10-12 06:30:16 +02001654http-check send-state X - X X
Willy Tarreau5c6f7b32010-02-26 13:34:29 +01001655http-request - X X X
Willy Tarreaue365c0b2013-06-11 16:06:12 +02001656http-response - X X X
Willy Tarreau30631952015-08-06 15:05:24 +02001657http-reuse X - X X
Baptiste Assmann2c42ef52013-10-09 21:57:02 +02001658http-send-name-header - - X X
Willy Tarreau5c6f7b32010-02-26 13:34:29 +01001659id - X X X
Cyril Bonté0d4bf012010-04-25 23:21:46 +02001660ignore-persist - X X X
Baptiste Assmann01c6cc32015-08-23 11:45:29 +02001661load-server-state-from-file X - X X
William Lallemand0f99e342011-10-12 17:50:54 +02001662log (*) X X X X
Willy Tarreaufb4e7ea2015-01-07 14:55:17 +01001663log-format X X X -
Dragan Dosen7ad31542015-09-28 17:16:47 +02001664log-format-sd X X X -
Willy Tarreau094af4e2015-01-07 15:03:42 +01001665log-tag X X X X
Willy Tarreauc35362a2014-04-25 13:58:37 +02001666max-keep-alive-queue X - X X
Willy Tarreau5c6f7b32010-02-26 13:34:29 +01001667maxconn X X X -
1668mode X X X X
1669monitor fail - X X -
1670monitor-net X X X -
1671monitor-uri X X X -
1672option abortonclose (*) X - X X
1673option accept-invalid-http-request (*) X X X -
1674option accept-invalid-http-response (*) X - X X
1675option allbackups (*) X - X X
1676option checkcache (*) X - X X
1677option clitcpka (*) X X X -
1678option contstats (*) X X X -
1679option dontlog-normal (*) X X X -
1680option dontlognull (*) X X X -
1681option forceclose (*) X X X X
1682-- keyword -------------------------- defaults - frontend - listen -- backend -
1683option forwardfor X X X X
Willy Tarreau9fbe18e2015-05-01 22:42:08 +02001684option http-buffer-request (*) X X X X
Willy Tarreau82649f92015-05-01 22:40:51 +02001685option http-ignore-probes (*) X X X -
Willy Tarreau16bfb022010-01-16 19:48:41 +01001686option http-keep-alive (*) X X X X
Willy Tarreau96e31212011-05-30 18:10:30 +02001687option http-no-delay (*) X X X X
Willy Tarreau8a8e1d92010-04-05 16:15:16 +02001688option http-pretend-keepalive (*) X X X X
Willy Tarreau5c6f7b32010-02-26 13:34:29 +01001689option http-server-close (*) X X X X
Willy Tarreau02bce8b2014-01-30 00:15:28 +01001690option http-tunnel (*) X X X X
Willy Tarreau5c6f7b32010-02-26 13:34:29 +01001691option http-use-proxy-header (*) X X X -
1692option httpchk X - X X
1693option httpclose (*) X X X X
1694option httplog X X X X
1695option http_proxy (*) X X X X
Jamie Gloudon801a0a32012-08-25 00:18:33 -04001696option independent-streams (*) X X X X
Gabor Lekenyb4c81e42010-09-29 18:17:05 +02001697option ldap-check X - X X
Simon Horman98637e52014-06-20 12:30:16 +09001698option external-check X - X X
Willy Tarreau5c6f7b32010-02-26 13:34:29 +01001699option log-health-checks (*) X - X X
1700option log-separate-errors (*) X X X -
1701option logasap (*) X X X -
1702option mysql-check X - X X
Rauf Kuliyev38b41562011-01-04 15:14:13 +01001703option pgsql-check X - X X
Willy Tarreau5c6f7b32010-02-26 13:34:29 +01001704option nolinger (*) X X X X
1705option originalto X X X X
1706option persist (*) X - X X
1707option redispatch (*) X - X X
Hervé COMMOWICKec032d62011-08-05 16:23:48 +02001708option redis-check X - X X
Willy Tarreau5c6f7b32010-02-26 13:34:29 +01001709option smtpchk X - X X
1710option socket-stats (*) X X X -
1711option splice-auto (*) X X X X
1712option splice-request (*) X X X X
1713option splice-response (*) X X X X
1714option srvtcpka (*) X - X X
1715option ssl-hello-chk X - X X
1716-- keyword -------------------------- defaults - frontend - listen -- backend -
Willy Tarreaued179852013-12-16 01:07:00 +01001717option tcp-check X - X X
Willy Tarreau5c6f7b32010-02-26 13:34:29 +01001718option tcp-smart-accept (*) X X X -
1719option tcp-smart-connect (*) X - X X
1720option tcpka X X X X
1721option tcplog X X X X
1722option transparent (*) X - X X
Simon Horman98637e52014-06-20 12:30:16 +09001723external-check command X - X X
1724external-check path X - X X
Willy Tarreau5c6f7b32010-02-26 13:34:29 +01001725persist rdp-cookie X - X X
1726rate-limit sessions X X X -
1727redirect - X X X
1728redisp (deprecated) X - X X
1729redispatch (deprecated) X - X X
1730reqadd - X X X
1731reqallow - X X X
1732reqdel - X X X
1733reqdeny - X X X
1734reqiallow - X X X
1735reqidel - X X X
1736reqideny - X X X
1737reqipass - X X X
1738reqirep - X X X
Willy Tarreau5c6f7b32010-02-26 13:34:29 +01001739reqitarpit - X X X
1740reqpass - X X X
1741reqrep - X X X
1742-- keyword -------------------------- defaults - frontend - listen -- backend -
Willy Tarreau5c6f7b32010-02-26 13:34:29 +01001743reqtarpit - X X X
1744retries X - X X
1745rspadd - X X X
1746rspdel - X X X
1747rspdeny - X X X
1748rspidel - X X X
1749rspideny - X X X
1750rspirep - X X X
1751rsprep - X X X
1752server - - X X
Baptiste Assmann01c6cc32015-08-23 11:45:29 +02001753server-state-file-name X - X X
Willy Tarreau5c6f7b32010-02-26 13:34:29 +01001754source X - X X
1755srvtimeout (deprecated) X - X X
Cyril Bonté66c327d2010-10-12 00:14:37 +02001756stats admin - - X X
Willy Tarreau5c6f7b32010-02-26 13:34:29 +01001757stats auth X - X X
1758stats enable X - X X
1759stats hide-version X - X X
Cyril Bonté2be1b3f2010-09-30 23:46:30 +02001760stats http-request - - X X
Willy Tarreau5c6f7b32010-02-26 13:34:29 +01001761stats realm X - X X
1762stats refresh X - X X
1763stats scope X - X X
1764stats show-desc X - X X
1765stats show-legends X - X X
1766stats show-node X - X X
1767stats uri X - X X
1768-- keyword -------------------------- defaults - frontend - listen -- backend -
1769stick match - - X X
1770stick on - - X X
1771stick store-request - - X X
Willy Tarreaud8dc99f2011-07-01 11:33:25 +02001772stick store-response - - X X
Willy Tarreau5c6f7b32010-02-26 13:34:29 +01001773stick-table - - X X
Willy Tarreau938c7fe2014-04-25 14:21:39 +02001774tcp-check connect - - X X
1775tcp-check expect - - X X
1776tcp-check send - - X X
1777tcp-check send-binary - - X X
Willy Tarreaue9656522010-08-17 15:40:09 +02001778tcp-request connection - X X -
1779tcp-request content - X X X
Willy Tarreaua56235c2010-09-14 11:31:36 +02001780tcp-request inspect-delay - X X X
Emeric Brun0a3b67f2010-09-24 15:34:53 +02001781tcp-response content - - X X
1782tcp-response inspect-delay - - X X
Willy Tarreau5c6f7b32010-02-26 13:34:29 +01001783timeout check X - X X
1784timeout client X X X -
Willy Tarreau05cdd962014-05-10 14:30:07 +02001785timeout client-fin X X X -
Willy Tarreau5c6f7b32010-02-26 13:34:29 +01001786timeout clitimeout (deprecated) X X X -
1787timeout connect X - X X
1788timeout contimeout (deprecated) X - X X
1789timeout http-keep-alive X X X X
1790timeout http-request X X X X
1791timeout queue X - X X
1792timeout server X - X X
Willy Tarreau05cdd962014-05-10 14:30:07 +02001793timeout server-fin X - X X
Willy Tarreau5c6f7b32010-02-26 13:34:29 +01001794timeout srvtimeout (deprecated) X - X X
1795timeout tarpit X X X X
Willy Tarreauce887fd2012-05-12 12:50:00 +02001796timeout tunnel X - X X
Willy Tarreau5c6f7b32010-02-26 13:34:29 +01001797transparent (deprecated) X - X X
William Lallemanda73203e2012-03-12 12:48:57 +01001798unique-id-format X X X -
1799unique-id-header X X X -
Willy Tarreau5c6f7b32010-02-26 13:34:29 +01001800use_backend - X X -
Willy Tarreau4a5cade2012-04-05 21:09:48 +02001801use-server - - X X
Willy Tarreau5c6f7b32010-02-26 13:34:29 +01001802------------------------------------+----------+----------+---------+---------
1803 keyword defaults frontend listen backend
Willy Tarreau6a06a402007-07-15 20:15:28 +02001804
Willy Tarreau0ba27502007-12-24 16:55:16 +01001805
Willy Tarreauc57f0e22009-05-10 13:12:33 +020018064.2. Alphabetically sorted keywords reference
1807---------------------------------------------
Willy Tarreau0ba27502007-12-24 16:55:16 +01001808
1809This section provides a description of each keyword and its usage.
1810
1811
1812acl <aclname> <criterion> [flags] [operator] <value> ...
1813 Declare or complete an access list.
1814 May be used in sections : defaults | frontend | listen | backend
1815 no | yes | yes | yes
1816 Example:
1817 acl invalid_src src 0.0.0.0/7 224.0.0.0/3
1818 acl invalid_src src_port 0:1023
1819 acl local_dst hdr(host) -i localhost
1820
Willy Tarreauc57f0e22009-05-10 13:12:33 +02001821 See section 7 about ACL usage.
Willy Tarreau0ba27502007-12-24 16:55:16 +01001822
1823
Cyril Bontéb21570a2009-11-29 20:04:48 +01001824appsession <cookie> len <length> timeout <holdtime>
1825 [request-learn] [prefix] [mode <path-parameters|query-string>]
Willy Tarreau0ba27502007-12-24 16:55:16 +01001826 Define session stickiness on an existing application cookie.
1827 May be used in sections : defaults | frontend | listen | backend
1828 no | no | yes | yes
1829 Arguments :
1830 <cookie> this is the name of the cookie used by the application and which
1831 HAProxy will have to learn for each new session.
1832
Cyril Bontéb21570a2009-11-29 20:04:48 +01001833 <length> this is the max number of characters that will be memorized and
Willy Tarreau0ba27502007-12-24 16:55:16 +01001834 checked in each cookie value.
1835
1836 <holdtime> this is the time after which the cookie will be removed from
1837 memory if unused. If no unit is specified, this time is in
1838 milliseconds.
1839
Cyril Bontébf47aeb2009-10-15 00:15:40 +02001840 request-learn
1841 If this option is specified, then haproxy will be able to learn
1842 the cookie found in the request in case the server does not
1843 specify any in response. This is typically what happens with
1844 PHPSESSID cookies, or when haproxy's session expires before
1845 the application's session and the correct server is selected.
1846 It is recommended to specify this option to improve reliability.
1847
Cyril Bontéb21570a2009-11-29 20:04:48 +01001848 prefix When this option is specified, haproxy will match on the cookie
1849 prefix (or URL parameter prefix). The appsession value is the
1850 data following this prefix.
1851
1852 Example :
1853 appsession ASPSESSIONID len 64 timeout 3h prefix
1854
1855 This will match the cookie ASPSESSIONIDXXXX=XXXXX,
1856 the appsession value will be XXXX=XXXXX.
1857
1858 mode This option allows to change the URL parser mode.
1859 2 modes are currently supported :
1860 - path-parameters :
1861 The parser looks for the appsession in the path parameters
1862 part (each parameter is separated by a semi-colon), which is
1863 convenient for JSESSIONID for example.
1864 This is the default mode if the option is not set.
1865 - query-string :
1866 In this mode, the parser will look for the appsession in the
1867 query string.
1868
Willy Tarreau294d0f02015-08-10 19:40:12 +02001869 As of version 1.6, appsessions was removed. It is more flexible and more
1870 convenient to use stick-tables instead, and stick-tables support multi-master
1871 replication and data conservation across reloads, which appsessions did not.
Willy Tarreau0ba27502007-12-24 16:55:16 +01001872
Cyril Bonté02ff8ef2010-12-14 22:48:49 +01001873 See also : "cookie", "capture cookie", "balance", "stick", "stick-table",
1874 "ignore-persist", "nbproc" and "bind-process".
Willy Tarreau0ba27502007-12-24 16:55:16 +01001875
1876
Willy Tarreauc73ce2b2008-01-06 10:55:10 +01001877backlog <conns>
1878 Give hints to the system about the approximate listen backlog desired size
1879 May be used in sections : defaults | frontend | listen | backend
1880 yes | yes | yes | no
1881 Arguments :
1882 <conns> is the number of pending connections. Depending on the operating
1883 system, it may represent the number of already acknowledged
Cyril Bontédc4d9032012-04-08 21:57:39 +02001884 connections, of non-acknowledged ones, or both.
Willy Tarreauc73ce2b2008-01-06 10:55:10 +01001885
1886 In order to protect against SYN flood attacks, one solution is to increase
1887 the system's SYN backlog size. Depending on the system, sometimes it is just
1888 tunable via a system parameter, sometimes it is not adjustable at all, and
1889 sometimes the system relies on hints given by the application at the time of
1890 the listen() syscall. By default, HAProxy passes the frontend's maxconn value
1891 to the listen() syscall. On systems which can make use of this value, it can
1892 sometimes be useful to be able to specify a different value, hence this
1893 backlog parameter.
1894
1895 On Linux 2.4, the parameter is ignored by the system. On Linux 2.6, it is
1896 used as a hint and the system accepts up to the smallest greater power of
1897 two, and never more than some limits (usually 32768).
1898
1899 See also : "maxconn" and the target operating system's tuning guide.
1900
1901
Willy Tarreau0ba27502007-12-24 16:55:16 +01001902balance <algorithm> [ <arguments> ]
Willy Tarreau226071e2014-04-10 11:55:45 +02001903balance url_param <param> [check_post]
Willy Tarreau0ba27502007-12-24 16:55:16 +01001904 Define the load balancing algorithm to be used in a backend.
1905 May be used in sections : defaults | frontend | listen | backend
1906 yes | no | yes | yes
1907 Arguments :
1908 <algorithm> is the algorithm used to select a server when doing load
1909 balancing. This only applies when no persistence information
1910 is available, or when a connection is redispatched to another
1911 server. <algorithm> may be one of the following :
1912
1913 roundrobin Each server is used in turns, according to their weights.
1914 This is the smoothest and fairest algorithm when the server's
1915 processing time remains equally distributed. This algorithm
1916 is dynamic, which means that server weights may be adjusted
Willy Tarreau9757a382009-10-03 12:56:50 +02001917 on the fly for slow starts for instance. It is limited by
Godbacha34bdc02013-07-22 07:44:53 +08001918 design to 4095 active servers per backend. Note that in some
Willy Tarreau9757a382009-10-03 12:56:50 +02001919 large farms, when a server becomes up after having been down
1920 for a very short time, it may sometimes take a few hundreds
1921 requests for it to be re-integrated into the farm and start
1922 receiving traffic. This is normal, though very rare. It is
1923 indicated here in case you would have the chance to observe
1924 it, so that you don't worry.
1925
1926 static-rr Each server is used in turns, according to their weights.
1927 This algorithm is as similar to roundrobin except that it is
1928 static, which means that changing a server's weight on the
1929 fly will have no effect. On the other hand, it has no design
1930 limitation on the number of servers, and when a server goes
1931 up, it is always immediately reintroduced into the farm, once
1932 the full map is recomputed. It also uses slightly less CPU to
1933 run (around -1%).
Willy Tarreau0ba27502007-12-24 16:55:16 +01001934
Willy Tarreau2d2a7f82008-03-17 12:07:56 +01001935 leastconn The server with the lowest number of connections receives the
1936 connection. Round-robin is performed within groups of servers
1937 of the same load to ensure that all servers will be used. Use
1938 of this algorithm is recommended where very long sessions are
1939 expected, such as LDAP, SQL, TSE, etc... but is not very well
1940 suited for protocols using short sessions such as HTTP. This
1941 algorithm is dynamic, which means that server weights may be
1942 adjusted on the fly for slow starts for instance.
1943
Willy Tarreauf09c6602012-02-13 17:12:08 +01001944 first The first server with available connection slots receives the
Jarno Huuskonen0e82b922014-04-12 18:22:19 +03001945 connection. The servers are chosen from the lowest numeric
Willy Tarreauf09c6602012-02-13 17:12:08 +01001946 identifier to the highest (see server parameter "id"), which
1947 defaults to the server's position in the farm. Once a server
Willy Tarreau64559c52012-04-07 09:08:45 +02001948 reaches its maxconn value, the next server is used. It does
Willy Tarreauf09c6602012-02-13 17:12:08 +01001949 not make sense to use this algorithm without setting maxconn.
1950 The purpose of this algorithm is to always use the smallest
1951 number of servers so that extra servers can be powered off
1952 during non-intensive hours. This algorithm ignores the server
1953 weight, and brings more benefit to long session such as RDP
Willy Tarreau64559c52012-04-07 09:08:45 +02001954 or IMAP than HTTP, though it can be useful there too. In
1955 order to use this algorithm efficiently, it is recommended
1956 that a cloud controller regularly checks server usage to turn
1957 them off when unused, and regularly checks backend queue to
1958 turn new servers on when the queue inflates. Alternatively,
1959 using "http-check send-state" may inform servers on the load.
Willy Tarreauf09c6602012-02-13 17:12:08 +01001960
Willy Tarreau0ba27502007-12-24 16:55:16 +01001961 source The source IP address is hashed and divided by the total
1962 weight of the running servers to designate which server will
1963 receive the request. This ensures that the same client IP
1964 address will always reach the same server as long as no
1965 server goes down or up. If the hash result changes due to the
1966 number of running servers changing, many clients will be
1967 directed to a different server. This algorithm is generally
1968 used in TCP mode where no cookie may be inserted. It may also
Krzysztof Piotr Oledzkif8645332009-12-13 21:55:50 +01001969 be used on the Internet to provide a best-effort stickiness
Willy Tarreau0ba27502007-12-24 16:55:16 +01001970 to clients which refuse session cookies. This algorithm is
Willy Tarreau6b2e11b2009-10-01 07:52:15 +02001971 static by default, which means that changing a server's
1972 weight on the fly will have no effect, but this can be
1973 changed using "hash-type".
Willy Tarreau0ba27502007-12-24 16:55:16 +01001974
Oskar Stolc8dc41842012-05-19 10:19:54 +01001975 uri This algorithm hashes either the left part of the URI (before
1976 the question mark) or the whole URI (if the "whole" parameter
1977 is present) and divides the hash value by the total weight of
1978 the running servers. The result designates which server will
1979 receive the request. This ensures that the same URI will
1980 always be directed to the same server as long as no server
1981 goes up or down. This is used with proxy caches and
1982 anti-virus proxies in order to maximize the cache hit rate.
1983 Note that this algorithm may only be used in an HTTP backend.
1984 This algorithm is static by default, which means that
1985 changing a server's weight on the fly will have no effect,
1986 but this can be changed using "hash-type".
Willy Tarreau0ba27502007-12-24 16:55:16 +01001987
Oskar Stolc8dc41842012-05-19 10:19:54 +01001988 This algorithm supports two optional parameters "len" and
Marek Majkowski9c30fc12008-04-27 23:25:55 +02001989 "depth", both followed by a positive integer number. These
1990 options may be helpful when it is needed to balance servers
1991 based on the beginning of the URI only. The "len" parameter
1992 indicates that the algorithm should only consider that many
1993 characters at the beginning of the URI to compute the hash.
1994 Note that having "len" set to 1 rarely makes sense since most
1995 URIs start with a leading "/".
1996
1997 The "depth" parameter indicates the maximum directory depth
1998 to be used to compute the hash. One level is counted for each
1999 slash in the request. If both parameters are specified, the
2000 evaluation stops when either is reached.
2001
Willy Tarreau0ba27502007-12-24 16:55:16 +01002002 url_param The URL parameter specified in argument will be looked up in
matt.farnsworth@nokia.com1c2ab962008-04-14 20:47:37 +02002003 the query string of each HTTP GET request.
2004
2005 If the modifier "check_post" is used, then an HTTP POST
Cyril Bontédc4d9032012-04-08 21:57:39 +02002006 request entity will be searched for the parameter argument,
2007 when it is not found in a query string after a question mark
Willy Tarreau226071e2014-04-10 11:55:45 +02002008 ('?') in the URL. The message body will only start to be
2009 analyzed once either the advertised amount of data has been
2010 received or the request buffer is full. In the unlikely event
2011 that chunked encoding is used, only the first chunk is
Cyril Bontédc4d9032012-04-08 21:57:39 +02002012 scanned. Parameter values separated by a chunk boundary, may
Willy Tarreau226071e2014-04-10 11:55:45 +02002013 be randomly balanced if at all. This keyword used to support
2014 an optional <max_wait> parameter which is now ignored.
matt.farnsworth@nokia.com1c2ab962008-04-14 20:47:37 +02002015
2016 If the parameter is found followed by an equal sign ('=') and
2017 a value, then the value is hashed and divided by the total
2018 weight of the running servers. The result designates which
2019 server will receive the request.
2020
2021 This is used to track user identifiers in requests and ensure
2022 that a same user ID will always be sent to the same server as
2023 long as no server goes up or down. If no value is found or if
2024 the parameter is not found, then a round robin algorithm is
2025 applied. Note that this algorithm may only be used in an HTTP
Willy Tarreau6b2e11b2009-10-01 07:52:15 +02002026 backend. This algorithm is static by default, which means
2027 that changing a server's weight on the fly will have no
2028 effect, but this can be changed using "hash-type".
Willy Tarreau0ba27502007-12-24 16:55:16 +01002029
Cyril Bontédc4d9032012-04-08 21:57:39 +02002030 hdr(<name>) The HTTP header <name> will be looked up in each HTTP
2031 request. Just as with the equivalent ACL 'hdr()' function,
2032 the header name in parenthesis is not case sensitive. If the
2033 header is absent or if it does not contain any value, the
2034 roundrobin algorithm is applied instead.
Benoitaffb4812009-03-25 13:02:10 +01002035
Krzysztof Piotr Oledzkif8645332009-12-13 21:55:50 +01002036 An optional 'use_domain_only' parameter is available, for
Benoitaffb4812009-03-25 13:02:10 +01002037 reducing the hash algorithm to the main domain part with some
2038 specific headers such as 'Host'. For instance, in the Host
2039 value "haproxy.1wt.eu", only "1wt" will be considered.
2040
Willy Tarreau6b2e11b2009-10-01 07:52:15 +02002041 This algorithm is static by default, which means that
2042 changing a server's weight on the fly will have no effect,
2043 but this can be changed using "hash-type".
2044
Emeric Brun736aa232009-06-30 17:56:00 +02002045 rdp-cookie
Hervé COMMOWICKa3eb39c2011-08-05 18:48:51 +02002046 rdp-cookie(<name>)
Emeric Brun736aa232009-06-30 17:56:00 +02002047 The RDP cookie <name> (or "mstshash" if omitted) will be
2048 looked up and hashed for each incoming TCP request. Just as
2049 with the equivalent ACL 'req_rdp_cookie()' function, the name
2050 is not case-sensitive. This mechanism is useful as a degraded
2051 persistence mode, as it makes it possible to always send the
2052 same user (or the same session ID) to the same server. If the
Krzysztof Piotr Oledzkif8645332009-12-13 21:55:50 +01002053 cookie is not found, the normal roundrobin algorithm is
Emeric Brun736aa232009-06-30 17:56:00 +02002054 used instead.
2055
2056 Note that for this to work, the frontend must ensure that an
2057 RDP cookie is already present in the request buffer. For this
2058 you must use 'tcp-request content accept' rule combined with
2059 a 'req_rdp_cookie_cnt' ACL.
2060
Willy Tarreau6b2e11b2009-10-01 07:52:15 +02002061 This algorithm is static by default, which means that
2062 changing a server's weight on the fly will have no effect,
2063 but this can be changed using "hash-type".
2064
Cyril Bontédc4d9032012-04-08 21:57:39 +02002065 See also the rdp_cookie pattern fetch function.
Simon Hormanab814e02011-06-24 14:50:20 +09002066
Willy Tarreau0ba27502007-12-24 16:55:16 +01002067 <arguments> is an optional list of arguments which may be needed by some
Marek Majkowski9c30fc12008-04-27 23:25:55 +02002068 algorithms. Right now, only "url_param" and "uri" support an
2069 optional argument.
matt.farnsworth@nokia.com1c2ab962008-04-14 20:47:37 +02002070
Willy Tarreau3cd9af22009-03-15 14:06:41 +01002071 The load balancing algorithm of a backend is set to roundrobin when no other
2072 algorithm, mode nor option have been set. The algorithm may only be set once
2073 for each backend.
Willy Tarreau0ba27502007-12-24 16:55:16 +01002074
2075 Examples :
2076 balance roundrobin
2077 balance url_param userid
matt.farnsworth@nokia.com1c2ab962008-04-14 20:47:37 +02002078 balance url_param session_id check_post 64
Benoitaffb4812009-03-25 13:02:10 +01002079 balance hdr(User-Agent)
2080 balance hdr(host)
2081 balance hdr(Host) use_domain_only
matt.farnsworth@nokia.com1c2ab962008-04-14 20:47:37 +02002082
2083 Note: the following caveats and limitations on using the "check_post"
2084 extension with "url_param" must be considered :
2085
Krzysztof Piotr Oledzkif8645332009-12-13 21:55:50 +01002086 - all POST requests are eligible for consideration, because there is no way
matt.farnsworth@nokia.com1c2ab962008-04-14 20:47:37 +02002087 to determine if the parameters will be found in the body or entity which
2088 may contain binary data. Therefore another method may be required to
2089 restrict consideration of POST requests that have no URL parameters in
2090 the body. (see acl reqideny http_end)
2091
2092 - using a <max_wait> value larger than the request buffer size does not
2093 make sense and is useless. The buffer size is set at build time, and
2094 defaults to 16 kB.
2095
2096 - Content-Encoding is not supported, the parameter search will probably
2097 fail; and load balancing will fall back to Round Robin.
2098
2099 - Expect: 100-continue is not supported, load balancing will fall back to
2100 Round Robin.
2101
2102 - Transfer-Encoding (RFC2616 3.6.1) is only supported in the first chunk.
2103 If the entire parameter value is not present in the first chunk, the
2104 selection of server is undefined (actually, defined by how little
2105 actually appeared in the first chunk).
2106
2107 - This feature does not support generation of a 100, 411 or 501 response.
2108
2109 - In some cases, requesting "check_post" MAY attempt to scan the entire
Krzysztof Piotr Oledzkif8645332009-12-13 21:55:50 +01002110 contents of a message body. Scanning normally terminates when linear
matt.farnsworth@nokia.com1c2ab962008-04-14 20:47:37 +02002111 white space or control characters are found, indicating the end of what
2112 might be a URL parameter list. This is probably not a concern with SGML
2113 type message bodies.
Willy Tarreau0ba27502007-12-24 16:55:16 +01002114
Willy Tarreau294d0f02015-08-10 19:40:12 +02002115 See also : "dispatch", "cookie", "transparent", "hash-type" and "http_proxy".
Willy Tarreau0ba27502007-12-24 16:55:16 +01002116
2117
Willy Tarreaub6205fd2012-09-24 12:27:33 +02002118bind [<address>]:<port_range> [, ...] [param*]
2119bind /<path> [, ...] [param*]
Willy Tarreau0ba27502007-12-24 16:55:16 +01002120 Define one or several listening addresses and/or ports in a frontend.
2121 May be used in sections : defaults | frontend | listen | backend
2122 no | yes | yes | no
2123 Arguments :
Willy Tarreaub1e52e82008-01-13 14:49:51 +01002124 <address> is optional and can be a host name, an IPv4 address, an IPv6
2125 address, or '*'. It designates the address the frontend will
2126 listen on. If unset, all IPv4 addresses of the system will be
2127 listened on. The same will apply for '*' or the system's
David du Colombier9c938da2011-03-17 10:40:27 +01002128 special address "0.0.0.0". The IPv6 equivalent is '::'.
Willy Tarreau24709282013-03-10 21:32:12 +01002129 Optionally, an address family prefix may be used before the
2130 address to force the family regardless of the address format,
2131 which can be useful to specify a path to a unix socket with
2132 no slash ('/'). Currently supported prefixes are :
2133 - 'ipv4@' -> address is always IPv4
2134 - 'ipv6@' -> address is always IPv6
2135 - 'unix@' -> address is a path to a local unix socket
Willy Tarreau70f72e02014-07-08 00:37:50 +02002136 - 'abns@' -> address is in abstract namespace (Linux only).
2137 Note: since abstract sockets are not "rebindable", they
2138 do not cope well with multi-process mode during
2139 soft-restart, so it is better to avoid them if
2140 nbproc is greater than 1. The effect is that if the
2141 new process fails to start, only one of the old ones
2142 will be able to rebind to the socket.
Willy Tarreau40aa0702013-03-10 23:51:38 +01002143 - 'fd@<n>' -> use file descriptor <n> inherited from the
2144 parent. The fd must be bound and may or may not already
2145 be listening.
William Lallemandb2f07452015-05-12 14:27:13 +02002146 You may want to reference some environment variables in the
2147 address parameter, see section 2.3 about environment
2148 variables.
Willy Tarreaub1e52e82008-01-13 14:49:51 +01002149
Willy Tarreauc5011ca2010-03-22 11:53:56 +01002150 <port_range> is either a unique TCP port, or a port range for which the
2151 proxy will accept connections for the IP address specified
Willy Tarreauceb24bc2010-11-09 12:46:41 +01002152 above. The port is mandatory for TCP listeners. Note that in
2153 the case of an IPv6 address, the port is always the number
2154 after the last colon (':'). A range can either be :
Willy Tarreauc5011ca2010-03-22 11:53:56 +01002155 - a numerical port (ex: '80')
2156 - a dash-delimited ports range explicitly stating the lower
2157 and upper bounds (ex: '2000-2100') which are included in
2158 the range.
2159
2160 Particular care must be taken against port ranges, because
2161 every <address:port> couple consumes one socket (= a file
2162 descriptor), so it's easy to consume lots of descriptors
2163 with a simple range, and to run out of sockets. Also, each
2164 <address:port> couple must be used only once among all
2165 instances running on a same system. Please note that binding
2166 to ports lower than 1024 generally require particular
Jamie Gloudon801a0a32012-08-25 00:18:33 -04002167 privileges to start the program, which are independent of
Willy Tarreauc5011ca2010-03-22 11:53:56 +01002168 the 'uid' parameter.
Willy Tarreau0ba27502007-12-24 16:55:16 +01002169
Willy Tarreauceb24bc2010-11-09 12:46:41 +01002170 <path> is a UNIX socket path beginning with a slash ('/'). This is
2171 alternative to the TCP listening port. Haproxy will then
2172 receive UNIX connections on the socket located at this place.
2173 The path must begin with a slash and by default is absolute.
2174 It can be relative to the prefix defined by "unix-bind" in
2175 the global section. Note that the total length of the prefix
2176 followed by the socket path cannot exceed some system limits
2177 for UNIX sockets, which commonly are set to 107 characters.
2178
Willy Tarreaub6205fd2012-09-24 12:27:33 +02002179 <param*> is a list of parameters common to all sockets declared on the
2180 same line. These numerous parameters depend on OS and build
2181 options and have a complete section dedicated to them. Please
2182 refer to section 5 to for more details.
Willy Tarreaua0ee1d02012-09-10 09:01:23 +02002183
Willy Tarreau0ba27502007-12-24 16:55:16 +01002184 It is possible to specify a list of address:port combinations delimited by
2185 commas. The frontend will then listen on all of these addresses. There is no
2186 fixed limit to the number of addresses and ports which can be listened on in
2187 a frontend, as well as there is no limit to the number of "bind" statements
2188 in a frontend.
2189
2190 Example :
2191 listen http_proxy
2192 bind :80,:443
2193 bind 10.0.0.1:10080,10.0.0.1:10443
Willy Tarreauceb24bc2010-11-09 12:46:41 +01002194 bind /var/run/ssl-frontend.sock user root mode 600 accept-proxy
Willy Tarreau0ba27502007-12-24 16:55:16 +01002195
Willy Tarreaua0ee1d02012-09-10 09:01:23 +02002196 listen http_https_proxy
2197 bind :80
Cyril Bonté0d44fc62012-10-09 22:45:33 +02002198 bind :443 ssl crt /etc/haproxy/site.pem
Willy Tarreaua0ee1d02012-09-10 09:01:23 +02002199
Willy Tarreau24709282013-03-10 21:32:12 +01002200 listen http_https_proxy_explicit
2201 bind ipv6@:80
2202 bind ipv4@public_ssl:443 ssl crt /etc/haproxy/site.pem
2203 bind unix@ssl-frontend.sock user root mode 600 accept-proxy
2204
Willy Tarreaudad36a32013-03-11 01:20:04 +01002205 listen external_bind_app1
William Lallemandb2f07452015-05-12 14:27:13 +02002206 bind "fd@${FD_APP1}"
Willy Tarreaudad36a32013-03-11 01:20:04 +01002207
Willy Tarreau55dcaf62015-09-27 15:03:15 +02002208 Note: regarding Linux's abstract namespace sockets, HAProxy uses the whole
2209 sun_path length is used for the address length. Some other programs
2210 such as socat use the string length only by default. Pass the option
2211 ",unix-tightsocklen=0" to any abstract socket definition in socat to
2212 make it compatible with HAProxy's.
2213
Willy Tarreauceb24bc2010-11-09 12:46:41 +01002214 See also : "source", "option forwardfor", "unix-bind" and the PROXY protocol
Willy Tarreaub6205fd2012-09-24 12:27:33 +02002215 documentation, and section 5 about bind options.
Willy Tarreau0ba27502007-12-24 16:55:16 +01002216
2217
Willy Tarreaua9db57e2013-01-18 11:29:29 +01002218bind-process [ all | odd | even | <number 1-64>[-<number 1-64>] ] ...
Willy Tarreau0b9c02c2009-02-04 22:05:05 +01002219 Limit visibility of an instance to a certain set of processes numbers.
2220 May be used in sections : defaults | frontend | listen | backend
2221 yes | yes | yes | yes
2222 Arguments :
2223 all All process will see this instance. This is the default. It
2224 may be used to override a default value.
2225
Willy Tarreaua9db57e2013-01-18 11:29:29 +01002226 odd This instance will be enabled on processes 1,3,5,...63. This
Willy Tarreau0b9c02c2009-02-04 22:05:05 +01002227 option may be combined with other numbers.
2228
Willy Tarreaua9db57e2013-01-18 11:29:29 +01002229 even This instance will be enabled on processes 2,4,6,...64. This
Willy Tarreau0b9c02c2009-02-04 22:05:05 +01002230 option may be combined with other numbers. Do not use it
2231 with less than 2 processes otherwise some instances might be
2232 missing from all processes.
2233
Willy Tarreau110ecc12012-11-15 17:50:01 +01002234 number The instance will be enabled on this process number or range,
Willy Tarreaua9db57e2013-01-18 11:29:29 +01002235 whose values must all be between 1 and 32 or 64 depending on
Willy Tarreau102df612014-05-07 23:56:38 +02002236 the machine's word size. If a proxy is bound to process
2237 numbers greater than the configured global.nbproc, it will
2238 either be forced to process #1 if a single process was
2239 specified, or to all processes otherwise.
Willy Tarreau0b9c02c2009-02-04 22:05:05 +01002240
2241 This keyword limits binding of certain instances to certain processes. This
2242 is useful in order not to have too many processes listening to the same
2243 ports. For instance, on a dual-core machine, it might make sense to set
2244 'nbproc 2' in the global section, then distributes the listeners among 'odd'
2245 and 'even' instances.
2246
Willy Tarreaua9db57e2013-01-18 11:29:29 +01002247 At the moment, it is not possible to reference more than 32 or 64 processes
2248 using this keyword, but this should be more than enough for most setups.
2249 Please note that 'all' really means all processes regardless of the machine's
2250 word size, and is not limited to the first 32 or 64.
Willy Tarreau0b9c02c2009-02-04 22:05:05 +01002251
Willy Tarreau6ae1ba62014-05-07 19:01:58 +02002252 Each "bind" line may further be limited to a subset of the proxy's processes,
2253 please consult the "process" bind keyword in section 5.1.
2254
Willy Tarreaub369a042014-09-16 13:21:03 +02002255 When a frontend has no explicit "bind-process" line, it tries to bind to all
2256 the processes referenced by its "bind" lines. That means that frontends can
2257 easily adapt to their listeners' processes.
2258
Willy Tarreau0b9c02c2009-02-04 22:05:05 +01002259 If some backends are referenced by frontends bound to other processes, the
2260 backend automatically inherits the frontend's processes.
2261
2262 Example :
2263 listen app_ip1
2264 bind 10.0.0.1:80
Willy Tarreaubfcd3112010-10-23 11:22:08 +02002265 bind-process odd
Willy Tarreau0b9c02c2009-02-04 22:05:05 +01002266
2267 listen app_ip2
2268 bind 10.0.0.2:80
Willy Tarreaubfcd3112010-10-23 11:22:08 +02002269 bind-process even
Willy Tarreau0b9c02c2009-02-04 22:05:05 +01002270
2271 listen management
2272 bind 10.0.0.3:80
Willy Tarreaubfcd3112010-10-23 11:22:08 +02002273 bind-process 1 2 3 4
Willy Tarreau0b9c02c2009-02-04 22:05:05 +01002274
Willy Tarreau110ecc12012-11-15 17:50:01 +01002275 listen management
2276 bind 10.0.0.4:80
2277 bind-process 1-4
2278
Willy Tarreau6ae1ba62014-05-07 19:01:58 +02002279 See also : "nbproc" in global section, and "process" in section 5.1.
Willy Tarreau0b9c02c2009-02-04 22:05:05 +01002280
2281
Willy Tarreau0ba27502007-12-24 16:55:16 +01002282block { if | unless } <condition>
2283 Block a layer 7 request if/unless a condition is matched
2284 May be used in sections : defaults | frontend | listen | backend
2285 no | yes | yes | yes
2286
2287 The HTTP request will be blocked very early in the layer 7 processing
2288 if/unless <condition> is matched. A 403 error will be returned if the request
Willy Tarreauc57f0e22009-05-10 13:12:33 +02002289 is blocked. The condition has to reference ACLs (see section 7). This is
Willy Tarreau3c92c5f2011-08-28 09:45:47 +02002290 typically used to deny access to certain sensitive resources if some
Willy Tarreau0ba27502007-12-24 16:55:16 +01002291 conditions are met or not met. There is no fixed limit to the number of
2292 "block" statements per instance.
2293
2294 Example:
2295 acl invalid_src src 0.0.0.0/7 224.0.0.0/3
2296 acl invalid_src src_port 0:1023
2297 acl local_dst hdr(host) -i localhost
2298 block if invalid_src || local_dst
2299
Willy Tarreauc57f0e22009-05-10 13:12:33 +02002300 See section 7 about ACL usage.
Willy Tarreau0ba27502007-12-24 16:55:16 +01002301
2302
2303capture cookie <name> len <length>
2304 Capture and log a cookie in the request and in the response.
2305 May be used in sections : defaults | frontend | listen | backend
2306 no | yes | yes | no
2307 Arguments :
2308 <name> is the beginning of the name of the cookie to capture. In order
2309 to match the exact name, simply suffix the name with an equal
2310 sign ('='). The full name will appear in the logs, which is
2311 useful with application servers which adjust both the cookie name
2312 and value (eg: ASPSESSIONXXXXX).
2313
2314 <length> is the maximum number of characters to report in the logs, which
2315 include the cookie name, the equal sign and the value, all in the
2316 standard "name=value" form. The string will be truncated on the
2317 right if it exceeds <length>.
2318
2319 Only the first cookie is captured. Both the "cookie" request headers and the
2320 "set-cookie" response headers are monitored. This is particularly useful to
2321 check for application bugs causing session crossing or stealing between
2322 users, because generally the user's cookies can only change on a login page.
2323
2324 When the cookie was not presented by the client, the associated log column
2325 will report "-". When a request does not cause a cookie to be assigned by the
2326 server, a "-" is reported in the response column.
2327
2328 The capture is performed in the frontend only because it is necessary that
2329 the log format does not change for a given frontend depending on the
2330 backends. This may change in the future. Note that there can be only one
Willy Tarreau193b8c62012-11-22 00:17:38 +01002331 "capture cookie" statement in a frontend. The maximum capture length is set
2332 by the global "tune.http.cookielen" setting and defaults to 63 characters. It
2333 is not possible to specify a capture in a "defaults" section.
Willy Tarreau0ba27502007-12-24 16:55:16 +01002334
2335 Example:
2336 capture cookie ASPSESSION len 32
2337
2338 See also : "capture request header", "capture response header" as well as
Willy Tarreauc57f0e22009-05-10 13:12:33 +02002339 section 8 about logging.
Willy Tarreau0ba27502007-12-24 16:55:16 +01002340
2341
2342capture request header <name> len <length>
Willy Tarreau4460d032012-11-21 23:37:37 +01002343 Capture and log the last occurrence of the specified request header.
Willy Tarreau0ba27502007-12-24 16:55:16 +01002344 May be used in sections : defaults | frontend | listen | backend
2345 no | yes | yes | no
2346 Arguments :
2347 <name> is the name of the header to capture. The header names are not
Willy Tarreaud2a4aa22008-01-31 15:28:22 +01002348 case-sensitive, but it is a common practice to write them as they
Willy Tarreau0ba27502007-12-24 16:55:16 +01002349 appear in the requests, with the first letter of each word in
2350 upper case. The header name will not appear in the logs, only the
2351 value is reported, but the position in the logs is respected.
2352
2353 <length> is the maximum number of characters to extract from the value and
2354 report in the logs. The string will be truncated on the right if
2355 it exceeds <length>.
2356
Willy Tarreau4460d032012-11-21 23:37:37 +01002357 The complete value of the last occurrence of the header is captured. The
Willy Tarreau0ba27502007-12-24 16:55:16 +01002358 value will be added to the logs between braces ('{}'). If multiple headers
2359 are captured, they will be delimited by a vertical bar ('|') and will appear
Willy Tarreaucc6c8912009-02-22 10:53:55 +01002360 in the same order they were declared in the configuration. Non-existent
2361 headers will be logged just as an empty string. Common uses for request
2362 header captures include the "Host" field in virtual hosting environments, the
2363 "Content-length" when uploads are supported, "User-agent" to quickly
Krzysztof Piotr Oledzkif8645332009-12-13 21:55:50 +01002364 differentiate between real users and robots, and "X-Forwarded-For" in proxied
Willy Tarreaucc6c8912009-02-22 10:53:55 +01002365 environments to find where the request came from.
2366
2367 Note that when capturing headers such as "User-agent", some spaces may be
2368 logged, making the log analysis more difficult. Thus be careful about what
2369 you log if you know your log parser is not smart enough to rely on the
2370 braces.
Willy Tarreau0ba27502007-12-24 16:55:16 +01002371
Willy Tarreau0900abb2012-11-22 00:21:46 +01002372 There is no limit to the number of captured request headers nor to their
2373 length, though it is wise to keep them low to limit memory usage per session.
2374 In order to keep log format consistent for a same frontend, header captures
2375 can only be declared in a frontend. It is not possible to specify a capture
2376 in a "defaults" section.
Willy Tarreau0ba27502007-12-24 16:55:16 +01002377
2378 Example:
2379 capture request header Host len 15
2380 capture request header X-Forwarded-For len 15
2381 capture request header Referrer len 15
2382
Willy Tarreauc57f0e22009-05-10 13:12:33 +02002383 See also : "capture cookie", "capture response header" as well as section 8
Willy Tarreau0ba27502007-12-24 16:55:16 +01002384 about logging.
2385
2386
2387capture response header <name> len <length>
Willy Tarreau4460d032012-11-21 23:37:37 +01002388 Capture and log the last occurrence of the specified response header.
Willy Tarreau0ba27502007-12-24 16:55:16 +01002389 May be used in sections : defaults | frontend | listen | backend
2390 no | yes | yes | no
2391 Arguments :
2392 <name> is the name of the header to capture. The header names are not
Willy Tarreaud2a4aa22008-01-31 15:28:22 +01002393 case-sensitive, but it is a common practice to write them as they
Willy Tarreau0ba27502007-12-24 16:55:16 +01002394 appear in the response, with the first letter of each word in
2395 upper case. The header name will not appear in the logs, only the
2396 value is reported, but the position in the logs is respected.
2397
2398 <length> is the maximum number of characters to extract from the value and
2399 report in the logs. The string will be truncated on the right if
2400 it exceeds <length>.
2401
Willy Tarreau4460d032012-11-21 23:37:37 +01002402 The complete value of the last occurrence of the header is captured. The
Willy Tarreau0ba27502007-12-24 16:55:16 +01002403 result will be added to the logs between braces ('{}') after the captured
2404 request headers. If multiple headers are captured, they will be delimited by
2405 a vertical bar ('|') and will appear in the same order they were declared in
Willy Tarreaucc6c8912009-02-22 10:53:55 +01002406 the configuration. Non-existent headers will be logged just as an empty
2407 string. Common uses for response header captures include the "Content-length"
2408 header which indicates how many bytes are expected to be returned, the
2409 "Location" header to track redirections.
Willy Tarreau0ba27502007-12-24 16:55:16 +01002410
Willy Tarreau0900abb2012-11-22 00:21:46 +01002411 There is no limit to the number of captured response headers nor to their
2412 length, though it is wise to keep them low to limit memory usage per session.
2413 In order to keep log format consistent for a same frontend, header captures
2414 can only be declared in a frontend. It is not possible to specify a capture
2415 in a "defaults" section.
Willy Tarreau0ba27502007-12-24 16:55:16 +01002416
2417 Example:
2418 capture response header Content-length len 9
2419 capture response header Location len 15
2420
Willy Tarreauc57f0e22009-05-10 13:12:33 +02002421 See also : "capture cookie", "capture request header" as well as section 8
Willy Tarreau0ba27502007-12-24 16:55:16 +01002422 about logging.
2423
2424
Cyril Bontéf0c60612010-02-06 14:44:47 +01002425clitimeout <timeout> (deprecated)
Willy Tarreau0ba27502007-12-24 16:55:16 +01002426 Set the maximum inactivity time on the client side.
2427 May be used in sections : defaults | frontend | listen | backend
2428 yes | yes | yes | no
2429 Arguments :
2430 <timeout> is the timeout value is specified in milliseconds by default, but
2431 can be in any other unit if the number is suffixed by the unit,
2432 as explained at the top of this document.
2433
2434 The inactivity timeout applies when the client is expected to acknowledge or
2435 send data. In HTTP mode, this timeout is particularly important to consider
2436 during the first phase, when the client sends the request, and during the
2437 response while it is reading data sent by the server. The value is specified
2438 in milliseconds by default, but can be in any other unit if the number is
2439 suffixed by the unit, as specified at the top of this document. In TCP mode
2440 (and to a lesser extent, in HTTP mode), it is highly recommended that the
2441 client timeout remains equal to the server timeout in order to avoid complex
Willy Tarreaud2a4aa22008-01-31 15:28:22 +01002442 situations to debug. It is a good practice to cover one or several TCP packet
Willy Tarreau0ba27502007-12-24 16:55:16 +01002443 losses by specifying timeouts that are slightly above multiples of 3 seconds
2444 (eg: 4 or 5 seconds).
2445
2446 This parameter is specific to frontends, but can be specified once for all in
2447 "defaults" sections. This is in fact one of the easiest solutions not to
2448 forget about it. An unspecified timeout results in an infinite timeout, which
2449 is not recommended. Such a usage is accepted and works but reports a warning
2450 during startup because it may results in accumulation of expired sessions in
2451 the system if the system's timeouts are not configured either.
2452
2453 This parameter is provided for compatibility but is currently deprecated.
2454 Please use "timeout client" instead.
2455
Willy Tarreau036fae02008-01-06 13:24:40 +01002456 See also : "timeout client", "timeout http-request", "timeout server", and
2457 "srvtimeout".
Willy Tarreau0ba27502007-12-24 16:55:16 +01002458
Cyril Bonté316a8cf2012-11-11 13:38:27 +01002459compression algo <algorithm> ...
2460compression type <mime type> ...
Willy Tarreau70737d12012-10-27 00:34:28 +02002461compression offload
William Lallemand82fe75c2012-10-23 10:25:10 +02002462 Enable HTTP compression.
2463 May be used in sections : defaults | frontend | listen | backend
2464 yes | yes | yes | yes
2465 Arguments :
Cyril Bonté316a8cf2012-11-11 13:38:27 +01002466 algo is followed by the list of supported compression algorithms.
2467 type is followed by the list of MIME types that will be compressed.
2468 offload makes haproxy work as a compression offloader only (see notes).
2469
2470 The currently supported algorithms are :
Willy Tarreauc91840a2015-03-28 17:00:39 +01002471 identity this is mostly for debugging, and it was useful for developing
2472 the compression feature. Identity does not apply any change on
2473 data.
Cyril Bonté316a8cf2012-11-11 13:38:27 +01002474
Willy Tarreauc91840a2015-03-28 17:00:39 +01002475 gzip applies gzip compression. This setting is only available when
2476 support for zlib was built in.
2477
2478 deflate same as "gzip", but with deflate algorithm and zlib format.
2479 Note that this algorithm has ambiguous support on many
2480 browsers and no support at all from recent ones. It is
2481 strongly recommended not to use it for anything else than
2482 experimentation. This setting is only available when support
2483 for zlib was built in.
Cyril Bonté316a8cf2012-11-11 13:38:27 +01002484
Willy Tarreauc91840a2015-03-28 17:00:39 +01002485 raw-deflate same as "deflate" without the zlib wrapper, and used as an
2486 alternative when the browser wants "deflate". All major
2487 browsers understand it and despite violating the standards,
2488 it is known to work better than "deflate", at least on MSIE
2489 and some versions of Safari. Do not use it in conjunction
2490 with "deflate", use either one or the other since both react
2491 to the same Accept-Encoding token. This setting is only
2492 available when support for zlib was built in.
Cyril Bonté316a8cf2012-11-11 13:38:27 +01002493
Dmitry Sivachenko87c208b2012-11-22 20:03:26 +04002494 Compression will be activated depending on the Accept-Encoding request
Cyril Bonté316a8cf2012-11-11 13:38:27 +01002495 header. With identity, it does not take care of that header.
Dmitry Sivachenkoc9f3b452012-11-28 17:47:11 +04002496 If backend servers support HTTP compression, these directives
2497 will be no-op: haproxy will see the compressed response and will not
2498 compress again. If backend servers do not support HTTP compression and
2499 there is Accept-Encoding header in request, haproxy will compress the
2500 matching response.
Willy Tarreau70737d12012-10-27 00:34:28 +02002501
2502 The "offload" setting makes haproxy remove the Accept-Encoding header to
2503 prevent backend servers from compressing responses. It is strongly
2504 recommended not to do this because this means that all the compression work
2505 will be done on the single point where haproxy is located. However in some
2506 deployment scenarios, haproxy may be installed in front of a buggy gateway
Dmitry Sivachenkoc9f3b452012-11-28 17:47:11 +04002507 with broken HTTP compression implementation which can't be turned off.
2508 In that case haproxy can be used to prevent that gateway from emitting
2509 invalid payloads. In this case, simply removing the header in the
2510 configuration does not work because it applies before the header is parsed,
2511 so that prevents haproxy from compressing. The "offload" setting should
Willy Tarreauffea9fd2014-07-12 16:37:02 +02002512 then be used for such scenarios. Note: for now, the "offload" setting is
2513 ignored when set in a defaults section.
William Lallemand82fe75c2012-10-23 10:25:10 +02002514
William Lallemand05097442012-11-20 12:14:28 +01002515 Compression is disabled when:
Baptiste Assmann650d53d2013-01-05 15:44:44 +01002516 * the request does not advertise a supported compression algorithm in the
2517 "Accept-Encoding" header
2518 * the response message is not HTTP/1.1
William Lallemandd3002612012-11-26 14:34:47 +01002519 * HTTP status code is not 200
William Lallemand8bb4e342013-12-10 17:28:48 +01002520 * response header "Transfer-Encoding" contains "chunked" (Temporary
2521 Workaround)
Baptiste Assmann650d53d2013-01-05 15:44:44 +01002522 * response contain neither a "Content-Length" header nor a
2523 "Transfer-Encoding" whose last value is "chunked"
2524 * response contains a "Content-Type" header whose first value starts with
2525 "multipart"
2526 * the response contains the "no-transform" value in the "Cache-control"
2527 header
2528 * User-Agent matches "Mozilla/4" unless it is MSIE 6 with XP SP2, or MSIE 7
2529 and later
2530 * The response contains a "Content-Encoding" header, indicating that the
2531 response is already compressed (see compression offload)
William Lallemand05097442012-11-20 12:14:28 +01002532
Baptiste Assmann650d53d2013-01-05 15:44:44 +01002533 Note: The compression does not rewrite Etag headers, and does not emit the
2534 Warning header.
William Lallemand05097442012-11-20 12:14:28 +01002535
William Lallemand82fe75c2012-10-23 10:25:10 +02002536 Examples :
2537 compression algo gzip
2538 compression type text/html text/plain
Willy Tarreau0ba27502007-12-24 16:55:16 +01002539
Cyril Bontéf0c60612010-02-06 14:44:47 +01002540contimeout <timeout> (deprecated)
Willy Tarreau0ba27502007-12-24 16:55:16 +01002541 Set the maximum time to wait for a connection attempt to a server to succeed.
2542 May be used in sections : defaults | frontend | listen | backend
2543 yes | no | yes | yes
2544 Arguments :
2545 <timeout> is the timeout value is specified in milliseconds by default, but
2546 can be in any other unit if the number is suffixed by the unit,
2547 as explained at the top of this document.
2548
2549 If the server is located on the same LAN as haproxy, the connection should be
Willy Tarreaud2a4aa22008-01-31 15:28:22 +01002550 immediate (less than a few milliseconds). Anyway, it is a good practice to
Willy Tarreaud72758d2010-01-12 10:42:19 +01002551 cover one or several TCP packet losses by specifying timeouts that are
Willy Tarreau0ba27502007-12-24 16:55:16 +01002552 slightly above multiples of 3 seconds (eg: 4 or 5 seconds). By default, the
2553 connect timeout also presets the queue timeout to the same value if this one
2554 has not been specified. Historically, the contimeout was also used to set the
2555 tarpit timeout in a listen section, which is not possible in a pure frontend.
2556
2557 This parameter is specific to backends, but can be specified once for all in
2558 "defaults" sections. This is in fact one of the easiest solutions not to
2559 forget about it. An unspecified timeout results in an infinite timeout, which
2560 is not recommended. Such a usage is accepted and works but reports a warning
2561 during startup because it may results in accumulation of failed sessions in
2562 the system if the system's timeouts are not configured either.
2563
2564 This parameter is provided for backwards compatibility but is currently
2565 deprecated. Please use "timeout connect", "timeout queue" or "timeout tarpit"
2566 instead.
2567
2568 See also : "timeout connect", "timeout queue", "timeout tarpit",
2569 "timeout server", "contimeout".
2570
2571
Willy Tarreau55165fe2009-05-10 12:02:55 +02002572cookie <name> [ rewrite | insert | prefix ] [ indirect ] [ nocache ]
Willy Tarreau4992dd22012-05-31 21:02:17 +02002573 [ postonly ] [ preserve ] [ httponly ] [ secure ]
2574 [ domain <domain> ]* [ maxidle <idle> ] [ maxlife <life> ]
Willy Tarreau0ba27502007-12-24 16:55:16 +01002575 Enable cookie-based persistence in a backend.
2576 May be used in sections : defaults | frontend | listen | backend
2577 yes | no | yes | yes
2578 Arguments :
2579 <name> is the name of the cookie which will be monitored, modified or
2580 inserted in order to bring persistence. This cookie is sent to
2581 the client via a "Set-Cookie" header in the response, and is
2582 brought back by the client in a "Cookie" header in all requests.
2583 Special care should be taken to choose a name which does not
2584 conflict with any likely application cookie. Also, if the same
2585 backends are subject to be used by the same clients (eg:
2586 HTTP/HTTPS), care should be taken to use different cookie names
2587 between all backends if persistence between them is not desired.
2588
2589 rewrite This keyword indicates that the cookie will be provided by the
2590 server and that haproxy will have to modify its value to set the
2591 server's identifier in it. This mode is handy when the management
2592 of complex combinations of "Set-cookie" and "Cache-control"
2593 headers is left to the application. The application can then
2594 decide whether or not it is appropriate to emit a persistence
2595 cookie. Since all responses should be monitored, this mode only
2596 works in HTTP close mode. Unless the application behaviour is
2597 very complex and/or broken, it is advised not to start with this
2598 mode for new deployments. This keyword is incompatible with
2599 "insert" and "prefix".
2600
2601 insert This keyword indicates that the persistence cookie will have to
Willy Tarreaua79094d2010-08-31 22:54:15 +02002602 be inserted by haproxy in server responses if the client did not
Willy Tarreauba4c5be2010-10-23 12:46:42 +02002603
Willy Tarreaua79094d2010-08-31 22:54:15 +02002604 already have a cookie that would have permitted it to access this
Willy Tarreauba4c5be2010-10-23 12:46:42 +02002605 server. When used without the "preserve" option, if the server
2606 emits a cookie with the same name, it will be remove before
2607 processing. For this reason, this mode can be used to upgrade
2608 existing configurations running in the "rewrite" mode. The cookie
2609 will only be a session cookie and will not be stored on the
2610 client's disk. By default, unless the "indirect" option is added,
2611 the server will see the cookies emitted by the client. Due to
2612 caching effects, it is generally wise to add the "nocache" or
2613 "postonly" keywords (see below). The "insert" keyword is not
2614 compatible with "rewrite" and "prefix".
Willy Tarreau0ba27502007-12-24 16:55:16 +01002615
2616 prefix This keyword indicates that instead of relying on a dedicated
2617 cookie for the persistence, an existing one will be completed.
2618 This may be needed in some specific environments where the client
2619 does not support more than one single cookie and the application
2620 already needs it. In this case, whenever the server sets a cookie
2621 named <name>, it will be prefixed with the server's identifier
2622 and a delimiter. The prefix will be removed from all client
2623 requests so that the server still finds the cookie it emitted.
2624 Since all requests and responses are subject to being modified,
2625 this mode requires the HTTP close mode. The "prefix" keyword is
Willy Tarreau37229df2011-10-17 12:24:55 +02002626 not compatible with "rewrite" and "insert". Note: it is highly
2627 recommended not to use "indirect" with "prefix", otherwise server
2628 cookie updates would not be sent to clients.
Willy Tarreau0ba27502007-12-24 16:55:16 +01002629
Willy Tarreaua79094d2010-08-31 22:54:15 +02002630 indirect When this option is specified, no cookie will be emitted to a
2631 client which already has a valid one for the server which has
2632 processed the request. If the server sets such a cookie itself,
Willy Tarreauba4c5be2010-10-23 12:46:42 +02002633 it will be removed, unless the "preserve" option is also set. In
2634 "insert" mode, this will additionally remove cookies from the
2635 requests transmitted to the server, making the persistence
2636 mechanism totally transparent from an application point of view.
Willy Tarreau37229df2011-10-17 12:24:55 +02002637 Note: it is highly recommended not to use "indirect" with
2638 "prefix", otherwise server cookie updates would not be sent to
2639 clients.
Willy Tarreau0ba27502007-12-24 16:55:16 +01002640
2641 nocache This option is recommended in conjunction with the insert mode
2642 when there is a cache between the client and HAProxy, as it
2643 ensures that a cacheable response will be tagged non-cacheable if
2644 a cookie needs to be inserted. This is important because if all
2645 persistence cookies are added on a cacheable home page for
2646 instance, then all customers will then fetch the page from an
2647 outer cache and will all share the same persistence cookie,
2648 leading to one server receiving much more traffic than others.
2649 See also the "insert" and "postonly" options.
2650
2651 postonly This option ensures that cookie insertion will only be performed
2652 on responses to POST requests. It is an alternative to the
2653 "nocache" option, because POST responses are not cacheable, so
2654 this ensures that the persistence cookie will never get cached.
2655 Since most sites do not need any sort of persistence before the
2656 first POST which generally is a login request, this is a very
2657 efficient method to optimize caching without risking to find a
2658 persistence cookie in the cache.
2659 See also the "insert" and "nocache" options.
2660
Willy Tarreauba4c5be2010-10-23 12:46:42 +02002661 preserve This option may only be used with "insert" and/or "indirect". It
2662 allows the server to emit the persistence cookie itself. In this
2663 case, if a cookie is found in the response, haproxy will leave it
2664 untouched. This is useful in order to end persistence after a
2665 logout request for instance. For this, the server just has to
2666 emit a cookie with an invalid value (eg: empty) or with a date in
2667 the past. By combining this mechanism with the "disable-on-404"
2668 check option, it is possible to perform a completely graceful
2669 shutdown because users will definitely leave the server after
2670 they logout.
2671
Willy Tarreau4992dd22012-05-31 21:02:17 +02002672 httponly This option tells haproxy to add an "HttpOnly" cookie attribute
2673 when a cookie is inserted. This attribute is used so that a
2674 user agent doesn't share the cookie with non-HTTP components.
2675 Please check RFC6265 for more information on this attribute.
2676
2677 secure This option tells haproxy to add a "Secure" cookie attribute when
2678 a cookie is inserted. This attribute is used so that a user agent
2679 never emits this cookie over non-secure channels, which means
2680 that a cookie learned with this flag will be presented only over
2681 SSL/TLS connections. Please check RFC6265 for more information on
2682 this attribute.
2683
Krzysztof Piotr Oledzkiefe3b6f2008-05-23 23:49:32 +02002684 domain This option allows to specify the domain at which a cookie is
Krzysztof Piotr Oledzkif8645332009-12-13 21:55:50 +01002685 inserted. It requires exactly one parameter: a valid domain
Willy Tarreau68a897b2009-12-03 23:28:34 +01002686 name. If the domain begins with a dot, the browser is allowed to
2687 use it for any host ending with that name. It is also possible to
2688 specify several domain names by invoking this option multiple
2689 times. Some browsers might have small limits on the number of
2690 domains, so be careful when doing that. For the record, sending
2691 10 domains to MSIE 6 or Firefox 2 works as expected.
Krzysztof Piotr Oledzkiefe3b6f2008-05-23 23:49:32 +02002692
Willy Tarreau996a92c2010-10-13 19:30:47 +02002693 maxidle This option allows inserted cookies to be ignored after some idle
2694 time. It only works with insert-mode cookies. When a cookie is
2695 sent to the client, the date this cookie was emitted is sent too.
2696 Upon further presentations of this cookie, if the date is older
2697 than the delay indicated by the parameter (in seconds), it will
2698 be ignored. Otherwise, it will be refreshed if needed when the
2699 response is sent to the client. This is particularly useful to
2700 prevent users who never close their browsers from remaining for
2701 too long on the same server (eg: after a farm size change). When
2702 this option is set and a cookie has no date, it is always
2703 accepted, but gets refreshed in the response. This maintains the
2704 ability for admins to access their sites. Cookies that have a
2705 date in the future further than 24 hours are ignored. Doing so
2706 lets admins fix timezone issues without risking kicking users off
2707 the site.
2708
2709 maxlife This option allows inserted cookies to be ignored after some life
2710 time, whether they're in use or not. It only works with insert
2711 mode cookies. When a cookie is first sent to the client, the date
2712 this cookie was emitted is sent too. Upon further presentations
2713 of this cookie, if the date is older than the delay indicated by
2714 the parameter (in seconds), it will be ignored. If the cookie in
2715 the request has no date, it is accepted and a date will be set.
2716 Cookies that have a date in the future further than 24 hours are
2717 ignored. Doing so lets admins fix timezone issues without risking
2718 kicking users off the site. Contrary to maxidle, this value is
2719 not refreshed, only the first visit date counts. Both maxidle and
2720 maxlife may be used at the time. This is particularly useful to
2721 prevent users who never close their browsers from remaining for
2722 too long on the same server (eg: after a farm size change). This
2723 is stronger than the maxidle method in that it forces a
2724 redispatch after some absolute delay.
2725
Willy Tarreau0ba27502007-12-24 16:55:16 +01002726 There can be only one persistence cookie per HTTP backend, and it can be
2727 declared in a defaults section. The value of the cookie will be the value
2728 indicated after the "cookie" keyword in a "server" statement. If no cookie
2729 is declared for a given server, the cookie is not set.
Willy Tarreau6a06a402007-07-15 20:15:28 +02002730
Willy Tarreau0ba27502007-12-24 16:55:16 +01002731 Examples :
2732 cookie JSESSIONID prefix
2733 cookie SRV insert indirect nocache
2734 cookie SRV insert postonly indirect
Willy Tarreau996a92c2010-10-13 19:30:47 +02002735 cookie SRV insert indirect nocache maxidle 30m maxlife 8h
Willy Tarreau0ba27502007-12-24 16:55:16 +01002736
Willy Tarreau294d0f02015-08-10 19:40:12 +02002737 See also : "balance source", "capture cookie", "server" and "ignore-persist".
Willy Tarreau0ba27502007-12-24 16:55:16 +01002738
Willy Tarreau983e01e2010-01-11 18:42:06 +01002739
Thierry FOURNIERa0a1b752015-05-26 17:44:32 +02002740declare capture [ request | response ] len <length>
2741 Declares a capture slot.
2742 May be used in sections : defaults | frontend | listen | backend
2743 no | yes | yes | no
2744 Arguments:
2745 <length> is the length allowed for the capture.
2746
2747 This declaration is only available in the frontend or listen section, but the
2748 reserved slot can be used in the backends. The "request" keyword allocates a
2749 capture slot for use in the request, and "response" allocates a capture slot
2750 for use in the response.
2751
2752 See also: "capture-req", "capture-res" (sample converters),
2753 "http-request capture" and "http-response capture".
2754
2755
Krzysztof Piotr Oledzkic6df0662010-01-05 16:38:49 +01002756default-server [param*]
2757 Change default options for a server in a backend
2758 May be used in sections : defaults | frontend | listen | backend
2759 yes | no | yes | yes
2760 Arguments:
Willy Tarreau983e01e2010-01-11 18:42:06 +01002761 <param*> is a list of parameters for this server. The "default-server"
2762 keyword accepts an important number of options and has a complete
2763 section dedicated to it. Please refer to section 5 for more
2764 details.
Krzysztof Piotr Oledzkic6df0662010-01-05 16:38:49 +01002765
Willy Tarreau983e01e2010-01-11 18:42:06 +01002766 Example :
Krzysztof Piotr Oledzkic6df0662010-01-05 16:38:49 +01002767 default-server inter 1000 weight 13
2768
2769 See also: "server" and section 5 about server options
Willy Tarreau0ba27502007-12-24 16:55:16 +01002770
Willy Tarreau983e01e2010-01-11 18:42:06 +01002771
Willy Tarreau0ba27502007-12-24 16:55:16 +01002772default_backend <backend>
2773 Specify the backend to use when no "use_backend" rule has been matched.
2774 May be used in sections : defaults | frontend | listen | backend
2775 yes | yes | yes | no
2776 Arguments :
2777 <backend> is the name of the backend to use.
2778
2779 When doing content-switching between frontend and backends using the
2780 "use_backend" keyword, it is often useful to indicate which backend will be
2781 used when no rule has matched. It generally is the dynamic backend which
2782 will catch all undetermined requests.
2783
Willy Tarreau0ba27502007-12-24 16:55:16 +01002784 Example :
2785
2786 use_backend dynamic if url_dyn
2787 use_backend static if url_css url_img extension_img
2788 default_backend dynamic
2789
Willy Tarreau98d04852015-05-26 12:18:29 +02002790 See also : "use_backend"
Willy Tarreau2769aa02007-12-27 18:26:09 +01002791
Willy Tarreau0ba27502007-12-24 16:55:16 +01002792
Baptiste Assmann27f51342013-10-09 06:51:49 +02002793description <string>
2794 Describe a listen, frontend or backend.
2795 May be used in sections : defaults | frontend | listen | backend
2796 no | yes | yes | yes
2797 Arguments : string
2798
2799 Allows to add a sentence to describe the related object in the HAProxy HTML
2800 stats page. The description will be printed on the right of the object name
2801 it describes.
2802 No need to backslash spaces in the <string> arguments.
2803
2804
Willy Tarreau0ba27502007-12-24 16:55:16 +01002805disabled
2806 Disable a proxy, frontend or backend.
2807 May be used in sections : defaults | frontend | listen | backend
2808 yes | yes | yes | yes
2809 Arguments : none
2810
2811 The "disabled" keyword is used to disable an instance, mainly in order to
2812 liberate a listening port or to temporarily disable a service. The instance
2813 will still be created and its configuration will be checked, but it will be
2814 created in the "stopped" state and will appear as such in the statistics. It
2815 will not receive any traffic nor will it send any health-checks or logs. It
2816 is possible to disable many instances at once by adding the "disabled"
2817 keyword in a "defaults" section.
2818
2819 See also : "enabled"
2820
2821
Willy Tarreau5ce94572010-06-07 14:35:41 +02002822dispatch <address>:<port>
2823 Set a default server address
2824 May be used in sections : defaults | frontend | listen | backend
2825 no | no | yes | yes
Cyril Bonté108cf6e2012-04-21 23:30:29 +02002826 Arguments :
Willy Tarreau5ce94572010-06-07 14:35:41 +02002827
2828 <address> is the IPv4 address of the default server. Alternatively, a
2829 resolvable hostname is supported, but this name will be resolved
2830 during start-up.
2831
2832 <ports> is a mandatory port specification. All connections will be sent
2833 to this port, and it is not permitted to use port offsets as is
2834 possible with normal servers.
2835
Willy Tarreau787aed52011-04-15 06:45:37 +02002836 The "dispatch" keyword designates a default server for use when no other
Willy Tarreau5ce94572010-06-07 14:35:41 +02002837 server can take the connection. In the past it was used to forward non
2838 persistent connections to an auxiliary load balancer. Due to its simple
2839 syntax, it has also been used for simple TCP relays. It is recommended not to
2840 use it for more clarity, and to use the "server" directive instead.
2841
2842 See also : "server"
2843
2844
Willy Tarreau0ba27502007-12-24 16:55:16 +01002845enabled
2846 Enable a proxy, frontend or backend.
2847 May be used in sections : defaults | frontend | listen | backend
2848 yes | yes | yes | yes
2849 Arguments : none
2850
2851 The "enabled" keyword is used to explicitly enable an instance, when the
2852 defaults has been set to "disabled". This is very rarely used.
2853
2854 See also : "disabled"
2855
2856
2857errorfile <code> <file>
2858 Return a file contents instead of errors generated by HAProxy
2859 May be used in sections : defaults | frontend | listen | backend
2860 yes | yes | yes | yes
2861 Arguments :
2862 <code> is the HTTP status code. Currently, HAProxy is capable of
CJ Ess108b1dd2015-04-07 12:03:37 -04002863 generating codes 200, 400, 403, 405, 408, 429, 500, 502, 503, and
2864 504.
Willy Tarreau0ba27502007-12-24 16:55:16 +01002865
2866 <file> designates a file containing the full HTTP response. It is
Willy Tarreaud2a4aa22008-01-31 15:28:22 +01002867 recommended to follow the common practice of appending ".http" to
Willy Tarreau0ba27502007-12-24 16:55:16 +01002868 the filename so that people do not confuse the response with HTML
Willy Tarreau59140a22009-02-22 12:02:30 +01002869 error pages, and to use absolute paths, since files are read
2870 before any chroot is performed.
Willy Tarreau0ba27502007-12-24 16:55:16 +01002871
2872 It is important to understand that this keyword is not meant to rewrite
2873 errors returned by the server, but errors detected and returned by HAProxy.
2874 This is why the list of supported errors is limited to a small set.
2875
Willy Tarreauae94d4d2011-05-11 16:28:49 +02002876 Code 200 is emitted in response to requests matching a "monitor-uri" rule.
2877
Willy Tarreau0ba27502007-12-24 16:55:16 +01002878 The files are returned verbatim on the TCP socket. This allows any trick such
2879 as redirections to another URL or site, as well as tricks to clean cookies,
2880 force enable or disable caching, etc... The package provides default error
2881 files returning the same contents as default errors.
2882
Willy Tarreau59140a22009-02-22 12:02:30 +01002883 The files should not exceed the configured buffer size (BUFSIZE), which
2884 generally is 8 or 16 kB, otherwise they will be truncated. It is also wise
2885 not to put any reference to local contents (eg: images) in order to avoid
2886 loops between the client and HAProxy when all servers are down, causing an
2887 error to be returned instead of an image. For better HTTP compliance, it is
2888 recommended that all header lines end with CR-LF and not LF alone.
2889
Willy Tarreau0ba27502007-12-24 16:55:16 +01002890 The files are read at the same time as the configuration and kept in memory.
2891 For this reason, the errors continue to be returned even when the process is
2892 chrooted, and no file change is considered while the process is running. A
Willy Tarreauc27debf2008-01-06 08:57:02 +01002893 simple method for developing those files consists in associating them to the
Willy Tarreau0ba27502007-12-24 16:55:16 +01002894 403 status code and interrogating a blocked URL.
2895
2896 See also : "errorloc", "errorloc302", "errorloc303"
2897
Willy Tarreau59140a22009-02-22 12:02:30 +01002898 Example :
2899 errorfile 400 /etc/haproxy/errorfiles/400badreq.http
Willy Tarreau2705a612014-05-23 17:38:34 +02002900 errorfile 408 /dev/null # workaround Chrome pre-connect bug
Willy Tarreau59140a22009-02-22 12:02:30 +01002901 errorfile 403 /etc/haproxy/errorfiles/403forbid.http
2902 errorfile 503 /etc/haproxy/errorfiles/503sorry.http
2903
Willy Tarreau2769aa02007-12-27 18:26:09 +01002904
2905errorloc <code> <url>
2906errorloc302 <code> <url>
2907 Return an HTTP redirection to a URL instead of errors generated by HAProxy
2908 May be used in sections : defaults | frontend | listen | backend
2909 yes | yes | yes | yes
2910 Arguments :
2911 <code> is the HTTP status code. Currently, HAProxy is capable of
Willy Tarreauae94d4d2011-05-11 16:28:49 +02002912 generating codes 200, 400, 403, 408, 500, 502, 503, and 504.
Willy Tarreau2769aa02007-12-27 18:26:09 +01002913
2914 <url> it is the exact contents of the "Location" header. It may contain
2915 either a relative URI to an error page hosted on the same site,
2916 or an absolute URI designating an error page on another site.
2917 Special care should be given to relative URIs to avoid redirect
2918 loops if the URI itself may generate the same error (eg: 500).
2919
2920 It is important to understand that this keyword is not meant to rewrite
2921 errors returned by the server, but errors detected and returned by HAProxy.
2922 This is why the list of supported errors is limited to a small set.
2923
Willy Tarreauae94d4d2011-05-11 16:28:49 +02002924 Code 200 is emitted in response to requests matching a "monitor-uri" rule.
2925
Willy Tarreau2769aa02007-12-27 18:26:09 +01002926 Note that both keyword return the HTTP 302 status code, which tells the
2927 client to fetch the designated URL using the same HTTP method. This can be
2928 quite problematic in case of non-GET methods such as POST, because the URL
2929 sent to the client might not be allowed for something other than GET. To
2930 workaround this problem, please use "errorloc303" which send the HTTP 303
2931 status code, indicating to the client that the URL must be fetched with a GET
2932 request.
2933
2934 See also : "errorfile", "errorloc303"
2935
2936
2937errorloc303 <code> <url>
2938 Return an HTTP redirection to a URL instead of errors generated by HAProxy
2939 May be used in sections : defaults | frontend | listen | backend
2940 yes | yes | yes | yes
2941 Arguments :
2942 <code> is the HTTP status code. Currently, HAProxy is capable of
2943 generating codes 400, 403, 408, 500, 502, 503, and 504.
2944
2945 <url> it is the exact contents of the "Location" header. It may contain
2946 either a relative URI to an error page hosted on the same site,
2947 or an absolute URI designating an error page on another site.
2948 Special care should be given to relative URIs to avoid redirect
2949 loops if the URI itself may generate the same error (eg: 500).
2950
2951 It is important to understand that this keyword is not meant to rewrite
2952 errors returned by the server, but errors detected and returned by HAProxy.
2953 This is why the list of supported errors is limited to a small set.
2954
Willy Tarreauae94d4d2011-05-11 16:28:49 +02002955 Code 200 is emitted in response to requests matching a "monitor-uri" rule.
2956
Willy Tarreau2769aa02007-12-27 18:26:09 +01002957 Note that both keyword return the HTTP 303 status code, which tells the
2958 client to fetch the designated URL using the same HTTP GET method. This
2959 solves the usual problems associated with "errorloc" and the 302 code. It is
2960 possible that some very old browsers designed before HTTP/1.1 do not support
Willy Tarreaud2a4aa22008-01-31 15:28:22 +01002961 it, but no such problem has been reported till now.
Willy Tarreau2769aa02007-12-27 18:26:09 +01002962
2963 See also : "errorfile", "errorloc", "errorloc302"
2964
2965
Simon Horman51a1cf62015-02-03 13:00:44 +09002966email-alert from <emailaddr>
2967 Declare the from email address to be used in both the envelope and header
2968 of email alerts. This is the address that email alerts are sent from.
2969 May be used in sections: defaults | frontend | listen | backend
2970 yes | yes | yes | yes
2971
2972 Arguments :
2973
2974 <emailaddr> is the from email address to use when sending email alerts
2975
2976 Also requires "email-alert mailers" and "email-alert to" to be set
2977 and if so sending email alerts is enabled for the proxy.
2978
Simon Horman64e34162015-02-06 11:11:57 +09002979 See also : "email-alert level", "email-alert mailers",
2980 "email-alert myhostname", "email-alert to", section 3.6 about mailers.
2981
2982
2983email-alert level <level>
2984 Declare the maximum log level of messages for which email alerts will be
2985 sent. This acts as a filter on the sending of email alerts.
2986 May be used in sections: defaults | frontend | listen | backend
2987 yes | yes | yes | yes
2988
2989 Arguments :
2990
2991 <level> One of the 8 syslog levels:
2992 emerg alert crit err warning notice info debug
2993 The above syslog levels are ordered from lowest to highest.
2994
2995 By default level is alert
2996
2997 Also requires "email-alert from", "email-alert mailers" and
2998 "email-alert to" to be set and if so sending email alerts is enabled
2999 for the proxy.
3000
Simon Horman1421e212015-04-30 13:10:35 +09003001 Alerts are sent when :
3002
3003 * An un-paused server is marked as down and <level> is alert or lower
3004 * A paused server is marked as down and <level> is notice or lower
3005 * A server is marked as up or enters the drain state and <level>
3006 is notice or lower
3007 * "option log-health-checks" is enabled, <level> is info or lower,
3008 and a health check status update occurs
3009
Simon Horman64e34162015-02-06 11:11:57 +09003010 See also : "email-alert from", "email-alert mailers",
3011 "email-alert myhostname", "email-alert to",
Simon Horman51a1cf62015-02-03 13:00:44 +09003012 section 3.6 about mailers.
3013
3014
3015email-alert mailers <mailersect>
3016 Declare the mailers to be used when sending email alerts
3017 May be used in sections: defaults | frontend | listen | backend
3018 yes | yes | yes | yes
3019
3020 Arguments :
3021
3022 <mailersect> is the name of the mailers section to send email alerts.
3023
3024 Also requires "email-alert from" and "email-alert to" to be set
3025 and if so sending email alerts is enabled for the proxy.
3026
Simon Horman64e34162015-02-06 11:11:57 +09003027 See also : "email-alert from", "email-alert level", "email-alert myhostname",
3028 "email-alert to", section 3.6 about mailers.
Simon Horman51a1cf62015-02-03 13:00:44 +09003029
3030
3031email-alert myhostname <hostname>
3032 Declare the to hostname address to be used when communicating with
3033 mailers.
3034 May be used in sections: defaults | frontend | listen | backend
3035 yes | yes | yes | yes
3036
3037 Arguments :
3038
3039 <emailaddr> is the to email address to use when sending email alerts
3040
3041 By default the systems hostname is used.
3042
3043 Also requires "email-alert from", "email-alert mailers" and
3044 "email-alert to" to be set and if so sending email alerts is enabled
3045 for the proxy.
3046
Simon Horman64e34162015-02-06 11:11:57 +09003047 See also : "email-alert from", "email-alert level", "email-alert mailers",
3048 "email-alert to", section 3.6 about mailers.
Simon Horman51a1cf62015-02-03 13:00:44 +09003049
3050
3051email-alert to <emailaddr>
3052 Declare both the recipent address in the envelope and to address in the
3053 header of email alerts. This is the address that email alerts are sent to.
3054 May be used in sections: defaults | frontend | listen | backend
3055 yes | yes | yes | yes
3056
3057 Arguments :
3058
3059 <emailaddr> is the to email address to use when sending email alerts
3060
3061 Also requires "email-alert mailers" and "email-alert to" to be set
3062 and if so sending email alerts is enabled for the proxy.
3063
Simon Horman64e34162015-02-06 11:11:57 +09003064 See also : "email-alert from", "email-alert level", "email-alert mailers",
Simon Horman51a1cf62015-02-03 13:00:44 +09003065 "email-alert myhostname", section 3.6 about mailers.
3066
3067
Willy Tarreau4de91492010-01-22 19:10:05 +01003068force-persist { if | unless } <condition>
3069 Declare a condition to force persistence on down servers
3070 May be used in sections: defaults | frontend | listen | backend
3071 no | yes | yes | yes
3072
3073 By default, requests are not dispatched to down servers. It is possible to
3074 force this using "option persist", but it is unconditional and redispatches
3075 to a valid server if "option redispatch" is set. That leaves with very little
3076 possibilities to force some requests to reach a server which is artificially
3077 marked down for maintenance operations.
3078
3079 The "force-persist" statement allows one to declare various ACL-based
3080 conditions which, when met, will cause a request to ignore the down status of
3081 a server and still try to connect to it. That makes it possible to start a
3082 server, still replying an error to the health checks, and run a specially
3083 configured browser to test the service. Among the handy methods, one could
3084 use a specific source IP address, or a specific cookie. The cookie also has
3085 the advantage that it can easily be added/removed on the browser from a test
3086 page. Once the service is validated, it is then possible to open the service
3087 to the world by returning a valid response to health checks.
3088
3089 The forced persistence is enabled when an "if" condition is met, or unless an
3090 "unless" condition is met. The final redispatch is always disabled when this
3091 is used.
3092
Cyril Bonté0d4bf012010-04-25 23:21:46 +02003093 See also : "option redispatch", "ignore-persist", "persist",
Cyril Bontéa8e7bbc2010-04-25 22:29:29 +02003094 and section 7 about ACL usage.
Willy Tarreau4de91492010-01-22 19:10:05 +01003095
3096
Willy Tarreau2769aa02007-12-27 18:26:09 +01003097fullconn <conns>
3098 Specify at what backend load the servers will reach their maxconn
3099 May be used in sections : defaults | frontend | listen | backend
3100 yes | no | yes | yes
3101 Arguments :
3102 <conns> is the number of connections on the backend which will make the
3103 servers use the maximal number of connections.
3104
Willy Tarreau198a7442008-01-17 12:05:32 +01003105 When a server has a "maxconn" parameter specified, it means that its number
Willy Tarreau2769aa02007-12-27 18:26:09 +01003106 of concurrent connections will never go higher. Additionally, if it has a
Willy Tarreau198a7442008-01-17 12:05:32 +01003107 "minconn" parameter, it indicates a dynamic limit following the backend's
Willy Tarreau2769aa02007-12-27 18:26:09 +01003108 load. The server will then always accept at least <minconn> connections,
3109 never more than <maxconn>, and the limit will be on the ramp between both
3110 values when the backend has less than <conns> concurrent connections. This
3111 makes it possible to limit the load on the servers during normal loads, but
3112 push it further for important loads without overloading the servers during
Krzysztof Piotr Oledzkif8645332009-12-13 21:55:50 +01003113 exceptional loads.
Willy Tarreau2769aa02007-12-27 18:26:09 +01003114
Willy Tarreaufbb78422011-06-05 15:38:35 +02003115 Since it's hard to get this value right, haproxy automatically sets it to
3116 10% of the sum of the maxconns of all frontends that may branch to this
Bertrand Jacquin702d44f2013-11-19 11:43:06 +01003117 backend (based on "use_backend" and "default_backend" rules). That way it's
3118 safe to leave it unset. However, "use_backend" involving dynamic names are
3119 not counted since there is no way to know if they could match or not.
Willy Tarreaufbb78422011-06-05 15:38:35 +02003120
Willy Tarreau2769aa02007-12-27 18:26:09 +01003121 Example :
3122 # The servers will accept between 100 and 1000 concurrent connections each
3123 # and the maximum of 1000 will be reached when the backend reaches 10000
3124 # connections.
3125 backend dynamic
3126 fullconn 10000
3127 server srv1 dyn1:80 minconn 100 maxconn 1000
3128 server srv2 dyn2:80 minconn 100 maxconn 1000
3129
3130 See also : "maxconn", "server"
3131
3132
3133grace <time>
3134 Maintain a proxy operational for some time after a soft stop
3135 May be used in sections : defaults | frontend | listen | backend
Cyril Bonté99ed3272010-01-24 23:29:44 +01003136 yes | yes | yes | yes
Willy Tarreau2769aa02007-12-27 18:26:09 +01003137 Arguments :
3138 <time> is the time (by default in milliseconds) for which the instance
3139 will remain operational with the frontend sockets still listening
3140 when a soft-stop is received via the SIGUSR1 signal.
3141
3142 This may be used to ensure that the services disappear in a certain order.
3143 This was designed so that frontends which are dedicated to monitoring by an
Krzysztof Piotr Oledzkif8645332009-12-13 21:55:50 +01003144 external equipment fail immediately while other ones remain up for the time
Willy Tarreau2769aa02007-12-27 18:26:09 +01003145 needed by the equipment to detect the failure.
3146
3147 Note that currently, there is very little benefit in using this parameter,
3148 and it may in fact complicate the soft-reconfiguration process more than
3149 simplify it.
3150
Willy Tarreau0ba27502007-12-24 16:55:16 +01003151
Bhaskar Maddalab6c0ac92013-11-05 11:54:02 -05003152hash-type <method> <function> <modifier>
Willy Tarreau6b2e11b2009-10-01 07:52:15 +02003153 Specify a method to use for mapping hashes to servers
3154 May be used in sections : defaults | frontend | listen | backend
3155 yes | no | yes | yes
3156 Arguments :
Bhaskar98634f02013-10-29 23:30:51 -04003157 <method> is the method used to select a server from the hash computed by
3158 the <function> :
Willy Tarreau6b2e11b2009-10-01 07:52:15 +02003159
Bhaskar98634f02013-10-29 23:30:51 -04003160 map-based the hash table is a static array containing all alive servers.
3161 The hashes will be very smooth, will consider weights, but
3162 will be static in that weight changes while a server is up
3163 will be ignored. This means that there will be no slow start.
3164 Also, since a server is selected by its position in the array,
3165 most mappings are changed when the server count changes. This
3166 means that when a server goes up or down, or when a server is
3167 added to a farm, most connections will be redistributed to
3168 different servers. This can be inconvenient with caches for
3169 instance.
Willy Tarreau798a39c2010-11-24 15:04:29 +01003170
Bhaskar98634f02013-10-29 23:30:51 -04003171 consistent the hash table is a tree filled with many occurrences of each
3172 server. The hash key is looked up in the tree and the closest
3173 server is chosen. This hash is dynamic, it supports changing
3174 weights while the servers are up, so it is compatible with the
3175 slow start feature. It has the advantage that when a server
3176 goes up or down, only its associations are moved. When a
3177 server is added to the farm, only a few part of the mappings
3178 are redistributed, making it an ideal method for caches.
3179 However, due to its principle, the distribution will never be
3180 very smooth and it may sometimes be necessary to adjust a
3181 server's weight or its ID to get a more balanced distribution.
3182 In order to get the same distribution on multiple load
3183 balancers, it is important that all servers have the exact
Bhaskar Maddalab6c0ac92013-11-05 11:54:02 -05003184 same IDs. Note: consistent hash uses sdbm and avalanche if no
3185 hash function is specified.
Bhaskar98634f02013-10-29 23:30:51 -04003186
3187 <function> is the hash function to be used :
3188
Jarno Huuskonen0e82b922014-04-12 18:22:19 +03003189 sdbm this function was created initially for sdbm (a public-domain
Bhaskar98634f02013-10-29 23:30:51 -04003190 reimplementation of ndbm) database library. It was found to do
3191 well in scrambling bits, causing better distribution of the keys
3192 and fewer splits. It also happens to be a good general hashing
Bhaskar Maddalab6c0ac92013-11-05 11:54:02 -05003193 function with good distribution, unless the total server weight
3194 is a multiple of 64, in which case applying the avalanche
3195 modifier may help.
Bhaskar98634f02013-10-29 23:30:51 -04003196
3197 djb2 this function was first proposed by Dan Bernstein many years ago
3198 on comp.lang.c. Studies have shown that for certain workload this
Bhaskar Maddalab6c0ac92013-11-05 11:54:02 -05003199 function provides a better distribution than sdbm. It generally
3200 works well with text-based inputs though it can perform extremely
3201 poorly with numeric-only input or when the total server weight is
3202 a multiple of 33, unless the avalanche modifier is also used.
3203
Willy Tarreaua0f42712013-11-14 14:30:35 +01003204 wt6 this function was designed for haproxy while testing other
3205 functions in the past. It is not as smooth as the other ones, but
3206 is much less sensible to the input data set or to the number of
3207 servers. It can make sense as an alternative to sdbm+avalanche or
3208 djb2+avalanche for consistent hashing or when hashing on numeric
3209 data such as a source IP address or a visitor identifier in a URL
3210 parameter.
3211
Willy Tarreau324f07f2015-01-20 19:44:50 +01003212 crc32 this is the most common CRC32 implementation as used in Ethernet,
3213 gzip, PNG, etc. It is slower than the other ones but may provide
3214 a better distribution or less predictable results especially when
3215 used on strings.
3216
Bhaskar Maddalab6c0ac92013-11-05 11:54:02 -05003217 <modifier> indicates an optional method applied after hashing the key :
3218
3219 avalanche This directive indicates that the result from the hash
3220 function above should not be used in its raw form but that
3221 a 4-byte full avalanche hash must be applied first. The
3222 purpose of this step is to mix the resulting bits from the
3223 previous hash in order to avoid any undesired effect when
3224 the input contains some limited values or when the number of
3225 servers is a multiple of one of the hash's components (64
3226 for SDBM, 33 for DJB2). Enabling avalanche tends to make the
3227 result less predictable, but it's also not as smooth as when
3228 using the original function. Some testing might be needed
3229 with some workloads. This hash is one of the many proposed
3230 by Bob Jenkins.
Willy Tarreau6b2e11b2009-10-01 07:52:15 +02003231
Bhaskar98634f02013-10-29 23:30:51 -04003232 The default hash type is "map-based" and is recommended for most usages. The
3233 default function is "sdbm", the selection of a function should be based on
3234 the range of the values being hashed.
Willy Tarreau6b2e11b2009-10-01 07:52:15 +02003235
3236 See also : "balance", "server"
3237
3238
Willy Tarreau0ba27502007-12-24 16:55:16 +01003239http-check disable-on-404
3240 Enable a maintenance mode upon HTTP/404 response to health-checks
3241 May be used in sections : defaults | frontend | listen | backend
Willy Tarreau2769aa02007-12-27 18:26:09 +01003242 yes | no | yes | yes
Willy Tarreau0ba27502007-12-24 16:55:16 +01003243 Arguments : none
3244
3245 When this option is set, a server which returns an HTTP code 404 will be
3246 excluded from further load-balancing, but will still receive persistent
3247 connections. This provides a very convenient method for Web administrators
3248 to perform a graceful shutdown of their servers. It is also important to note
3249 that a server which is detected as failed while it was in this mode will not
3250 generate an alert, just a notice. If the server responds 2xx or 3xx again, it
3251 will immediately be reinserted into the farm. The status on the stats page
3252 reports "NOLB" for a server in this mode. It is important to note that this
Willy Tarreaubd741542010-03-16 18:46:54 +01003253 option only works in conjunction with the "httpchk" option. If this option
3254 is used with "http-check expect", then it has precedence over it so that 404
3255 responses will still be considered as soft-stop.
3256
3257 See also : "option httpchk", "http-check expect"
3258
3259
3260http-check expect [!] <match> <pattern>
Jamie Gloudonaaa21002012-08-25 00:18:33 -04003261 Make HTTP health checks consider response contents or specific status codes
Willy Tarreaubd741542010-03-16 18:46:54 +01003262 May be used in sections : defaults | frontend | listen | backend
Willy Tarreau1ee51a62011-08-19 20:04:17 +02003263 yes | no | yes | yes
Willy Tarreaubd741542010-03-16 18:46:54 +01003264 Arguments :
3265 <match> is a keyword indicating how to look for a specific pattern in the
3266 response. The keyword may be one of "status", "rstatus",
Jamie Gloudonaaa21002012-08-25 00:18:33 -04003267 "string", or "rstring". The keyword may be preceded by an
Willy Tarreaubd741542010-03-16 18:46:54 +01003268 exclamation mark ("!") to negate the match. Spaces are allowed
3269 between the exclamation mark and the keyword. See below for more
3270 details on the supported keywords.
3271
3272 <pattern> is the pattern to look for. It may be a string or a regular
3273 expression. If the pattern contains spaces, they must be escaped
3274 with the usual backslash ('\').
3275
3276 By default, "option httpchk" considers that response statuses 2xx and 3xx
3277 are valid, and that others are invalid. When "http-check expect" is used,
3278 it defines what is considered valid or invalid. Only one "http-check"
3279 statement is supported in a backend. If a server fails to respond or times
3280 out, the check obviously fails. The available matches are :
3281
3282 status <string> : test the exact string match for the HTTP status code.
Jamie Gloudonaaa21002012-08-25 00:18:33 -04003283 A health check response will be considered valid if the
Willy Tarreaubd741542010-03-16 18:46:54 +01003284 response's status code is exactly this string. If the
3285 "status" keyword is prefixed with "!", then the response
3286 will be considered invalid if the status code matches.
3287
3288 rstatus <regex> : test a regular expression for the HTTP status code.
Jamie Gloudonaaa21002012-08-25 00:18:33 -04003289 A health check response will be considered valid if the
Willy Tarreaubd741542010-03-16 18:46:54 +01003290 response's status code matches the expression. If the
3291 "rstatus" keyword is prefixed with "!", then the response
3292 will be considered invalid if the status code matches.
3293 This is mostly used to check for multiple codes.
3294
3295 string <string> : test the exact string match in the HTTP response body.
Jamie Gloudonaaa21002012-08-25 00:18:33 -04003296 A health check response will be considered valid if the
Willy Tarreaubd741542010-03-16 18:46:54 +01003297 response's body contains this exact string. If the
3298 "string" keyword is prefixed with "!", then the response
3299 will be considered invalid if the body contains this
3300 string. This can be used to look for a mandatory word at
3301 the end of a dynamic page, or to detect a failure when a
3302 specific error appears on the check page (eg: a stack
3303 trace).
3304
3305 rstring <regex> : test a regular expression on the HTTP response body.
Jamie Gloudonaaa21002012-08-25 00:18:33 -04003306 A health check response will be considered valid if the
Willy Tarreaubd741542010-03-16 18:46:54 +01003307 response's body matches this expression. If the "rstring"
3308 keyword is prefixed with "!", then the response will be
3309 considered invalid if the body matches the expression.
3310 This can be used to look for a mandatory word at the end
3311 of a dynamic page, or to detect a failure when a specific
3312 error appears on the check page (eg: a stack trace).
3313
3314 It is important to note that the responses will be limited to a certain size
3315 defined by the global "tune.chksize" option, which defaults to 16384 bytes.
3316 Thus, too large responses may not contain the mandatory pattern when using
3317 "string" or "rstring". If a large response is absolutely required, it is
3318 possible to change the default max size by setting the global variable.
3319 However, it is worth keeping in mind that parsing very large responses can
3320 waste some CPU cycles, especially when regular expressions are used, and that
3321 it is always better to focus the checks on smaller resources.
3322
Cyril Bonté32602d22015-01-30 00:07:07 +01003323 Also "http-check expect" doesn't support HTTP keep-alive. Keep in mind that it
3324 will automatically append a "Connection: close" header, meaning that this
3325 header should not be present in the request provided by "option httpchk".
3326
Willy Tarreaubd741542010-03-16 18:46:54 +01003327 Last, if "http-check expect" is combined with "http-check disable-on-404",
3328 then this last one has precedence when the server responds with 404.
3329
3330 Examples :
3331 # only accept status 200 as valid
Willy Tarreau8f2a1e72011-01-06 16:36:10 +01003332 http-check expect status 200
Willy Tarreaubd741542010-03-16 18:46:54 +01003333
3334 # consider SQL errors as errors
Willy Tarreau8f2a1e72011-01-06 16:36:10 +01003335 http-check expect ! string SQL\ Error
Willy Tarreaubd741542010-03-16 18:46:54 +01003336
3337 # consider status 5xx only as errors
Willy Tarreau8f2a1e72011-01-06 16:36:10 +01003338 http-check expect ! rstatus ^5
Willy Tarreaubd741542010-03-16 18:46:54 +01003339
3340 # check that we have a correct hexadecimal tag before /html
Willy Tarreau8f2a1e72011-01-06 16:36:10 +01003341 http-check expect rstring <!--tag:[0-9a-f]*</html>
Willy Tarreau0ba27502007-12-24 16:55:16 +01003342
Willy Tarreaubd741542010-03-16 18:46:54 +01003343 See also : "option httpchk", "http-check disable-on-404"
Willy Tarreau2769aa02007-12-27 18:26:09 +01003344
3345
Willy Tarreauef781042010-01-27 11:53:01 +01003346http-check send-state
3347 Enable emission of a state header with HTTP health checks
3348 May be used in sections : defaults | frontend | listen | backend
3349 yes | no | yes | yes
3350 Arguments : none
3351
3352 When this option is set, haproxy will systematically send a special header
3353 "X-Haproxy-Server-State" with a list of parameters indicating to each server
3354 how they are seen by haproxy. This can be used for instance when a server is
3355 manipulated without access to haproxy and the operator needs to know whether
3356 haproxy still sees it up or not, or if the server is the last one in a farm.
3357
3358 The header is composed of fields delimited by semi-colons, the first of which
3359 is a word ("UP", "DOWN", "NOLB"), possibly followed by a number of valid
3360 checks on the total number before transition, just as appears in the stats
3361 interface. Next headers are in the form "<variable>=<value>", indicating in
3362 no specific order some values available in the stats interface :
Joseph Lynch514061c2015-01-15 17:52:59 -08003363 - a variable "address", containing the address of the backend server.
3364 This corresponds to the <address> field in the server declaration. For
3365 unix domain sockets, it will read "unix".
3366
3367 - a variable "port", containing the port of the backend server. This
3368 corresponds to the <port> field in the server declaration. For unix
3369 domain sockets, it will read "unix".
3370
Willy Tarreauef781042010-01-27 11:53:01 +01003371 - a variable "name", containing the name of the backend followed by a slash
3372 ("/") then the name of the server. This can be used when a server is
3373 checked in multiple backends.
3374
3375 - a variable "node" containing the name of the haproxy node, as set in the
3376 global "node" variable, otherwise the system's hostname if unspecified.
3377
3378 - a variable "weight" indicating the weight of the server, a slash ("/")
3379 and the total weight of the farm (just counting usable servers). This
3380 helps to know if other servers are available to handle the load when this
3381 one fails.
3382
3383 - a variable "scur" indicating the current number of concurrent connections
3384 on the server, followed by a slash ("/") then the total number of
3385 connections on all servers of the same backend.
3386
3387 - a variable "qcur" indicating the current number of requests in the
3388 server's queue.
3389
3390 Example of a header received by the application server :
3391 >>> X-Haproxy-Server-State: UP 2/3; name=bck/srv2; node=lb1; weight=1/2; \
3392 scur=13/22; qcur=0
3393
3394 See also : "option httpchk", "http-check disable-on-404"
3395
Willy Tarreauccbcc372012-12-27 12:37:57 +01003396http-request { allow | deny | tarpit | auth [realm <realm>] | redirect <rule> |
Willy Tarreauf4c43c12013-06-11 17:01:13 +02003397 add-header <name> <fmt> | set-header <name> <fmt> |
Thierry FOURNIER82bf70d2015-05-26 17:58:29 +02003398 capture <sample> [ len <length> | id <id> ] |
Thierry FOURNIERdad3d1d2014-04-22 18:07:25 +02003399 del-header <name> | set-nice <nice> | set-log-level <level> |
Sasha Pachev218f0642014-06-16 12:05:59 -06003400 replace-header <name> <match-regex> <replace-fmt> |
3401 replace-value <name> <match-regex> <replace-fmt> |
Willy Tarreaua0dc23f2015-01-22 20:46:11 +01003402 set-method <fmt> | set-path <fmt> | set-query <fmt> |
3403 set-uri <fmt> | set-tos <tos> | set-mark <mark> |
Baptiste Assmannfabcbe02014-04-24 22:16:59 +02003404 add-acl(<file name>) <key fmt> |
3405 del-acl(<file name>) <key fmt> |
3406 del-map(<file name>) <key fmt> |
Baptiste Assmannbb7e86a2014-09-03 18:29:47 +02003407 set-map(<file name>) <key fmt> <value fmt> |
Thierry FOURNIER4834bc72015-06-06 19:29:07 +02003408 set-var(<var name>) <expr> |
Thierry FOURNIER90da1912015-03-05 11:17:06 +01003409 { track-sc0 | track-sc1 | track-sc2 } <key> [table <table>] |
Thierry FOURNIERe0627bd2015-08-04 08:20:33 +02003410 sc-inc-gpc0(<sc-id>) |
Thierry FOURNIER236657b2015-08-19 08:25:14 +02003411 sc-set-gpt0(<sc-id>) <int> |
Willy Tarreau2d392c22015-08-24 01:43:45 +02003412 silent-drop |
Thierry FOURNIER90da1912015-03-05 11:17:06 +01003413 lua <function name>
Baptiste Assmannfabcbe02014-04-24 22:16:59 +02003414 }
Cyril Bontéf0c60612010-02-06 14:44:47 +01003415 [ { if | unless } <condition> ]
Krzysztof Piotr Oledzki6b35ce12010-02-01 23:35:44 +01003416 Access control for Layer 7 requests
3417
3418 May be used in sections: defaults | frontend | listen | backend
3419 no | yes | yes | yes
3420
Willy Tarreau20b0de52012-12-24 15:45:22 +01003421 The http-request statement defines a set of rules which apply to layer 7
3422 processing. The rules are evaluated in their declaration order when they are
3423 met in a frontend, listen or backend section. Any rule may optionally be
3424 followed by an ACL-based condition, in which case it will only be evaluated
3425 if the condition is true.
Krzysztof Piotr Oledzki6b35ce12010-02-01 23:35:44 +01003426
Willy Tarreau20b0de52012-12-24 15:45:22 +01003427 The first keyword is the rule's action. Currently supported actions include :
3428 - "allow" : this stops the evaluation of the rules and lets the request
3429 pass the check. No further "http-request" rules are evaluated.
3430
3431 - "deny" : this stops the evaluation of the rules and immediately rejects
3432 the request and emits an HTTP 403 error. No further "http-request" rules
3433 are evaluated.
3434
Willy Tarreauccbcc372012-12-27 12:37:57 +01003435 - "tarpit" : this stops the evaluation of the rules and immediately blocks
3436 the request without responding for a delay specified by "timeout tarpit"
3437 or "timeout connect" if the former is not set. After that delay, if the
3438 client is still connected, an HTTP error 500 is returned so that the
3439 client does not suspect it has been tarpitted. Logs will report the flags
3440 "PT". The goal of the tarpit rule is to slow down robots during an attack
3441 when they're limited on the number of concurrent requests. It can be very
3442 efficient against very dumb robots, and will significantly reduce the
3443 load on firewalls compared to a "deny" rule. But when facing "correctly"
Jarno Huuskonen0e82b922014-04-12 18:22:19 +03003444 developed robots, it can make things worse by forcing haproxy and the
Willy Tarreau2d392c22015-08-24 01:43:45 +02003445 front firewall to support insane number of concurrent connections. See
3446 also the "silent-drop" action below.
Willy Tarreauccbcc372012-12-27 12:37:57 +01003447
Willy Tarreau20b0de52012-12-24 15:45:22 +01003448 - "auth" : this stops the evaluation of the rules and immediately responds
3449 with an HTTP 401 or 407 error code to invite the user to present a valid
3450 user name and password. No further "http-request" rules are evaluated. An
3451 optional "realm" parameter is supported, it sets the authentication realm
3452 that is returned with the response (typically the application's name).
3453
Willy Tarreau81499eb2012-12-27 12:19:02 +01003454 - "redirect" : this performs an HTTP redirection based on a redirect rule.
3455 This is exactly the same as the "redirect" statement except that it
3456 inserts a redirect rule which can be processed in the middle of other
Thierry FOURNIERd18cd0f2013-11-29 12:15:45 +01003457 "http-request" rules and that these rules use the "log-format" strings.
3458 See the "redirect" keyword for the rule's syntax.
Willy Tarreau81499eb2012-12-27 12:19:02 +01003459
Willy Tarreau20b0de52012-12-24 15:45:22 +01003460 - "add-header" appends an HTTP header field whose name is specified in
3461 <name> and whose value is defined by <fmt> which follows the log-format
3462 rules (see Custom Log Format in section 8.2.4). This is particularly
3463 useful to pass connection-specific information to the server (eg: the
3464 client's SSL certificate), or to combine several headers into one. This
3465 rule is not final, so it is possible to add other similar rules. Note
3466 that header addition is performed immediately, so one rule might reuse
3467 the resulting header from a previous rule.
3468
3469 - "set-header" does the same as "add-header" except that the header name
3470 is first removed if it existed. This is useful when passing security
3471 information to the server, where the header must not be manipulated by
Willy Tarreau85603282015-01-21 20:39:27 +01003472 external users. Note that the new value is computed before the removal so
3473 it is possible to concatenate a value to an existing header.
Willy Tarreau20b0de52012-12-24 15:45:22 +01003474
Thierry FOURNIERdad3d1d2014-04-22 18:07:25 +02003475 - "del-header" removes all HTTP header fields whose name is specified in
3476 <name>.
3477
Sasha Pachev218f0642014-06-16 12:05:59 -06003478 - "replace-header" matches the regular expression in all occurrences of
3479 header field <name> according to <match-regex>, and replaces them with
3480 the <replace-fmt> argument. Format characters are allowed in replace-fmt
3481 and work like in <fmt> arguments in "add-header". The match is only
3482 case-sensitive. It is important to understand that this action only
3483 considers whole header lines, regardless of the number of values they
3484 may contain. This usage is suited to headers naturally containing commas
3485 in their value, such as If-Modified-Since and so on.
3486
3487 Example:
3488
3489 http-request replace-header Cookie foo=([^;]*);(.*) foo=\1;ip=%bi;\2
3490
3491 applied to:
3492
3493 Cookie: foo=foobar; expires=Tue, 14-Jun-2016 01:40:45 GMT;
3494
3495 outputs:
3496
3497 Cookie: foo=foobar;ip=192.168.1.20; expires=Tue, 14-Jun-2016 01:40:45 GMT;
3498
3499 assuming the backend IP is 192.168.1.20
3500
3501 - "replace-value" works like "replace-header" except that it matches the
3502 regex against every comma-delimited value of the header field <name>
3503 instead of the entire header. This is suited for all headers which are
3504 allowed to carry more than one value. An example could be the Accept
3505 header.
3506
3507 Example:
3508
3509 http-request replace-value X-Forwarded-For ^192\.168\.(.*)$ 172.16.\1
3510
3511 applied to:
3512
3513 X-Forwarded-For: 192.168.10.1, 192.168.13.24, 10.0.0.37
3514
3515 outputs:
3516
3517 X-Forwarded-For: 172.16.10.1, 172.16.13.24, 10.0.0.37
3518
Willy Tarreaua0dc23f2015-01-22 20:46:11 +01003519 - "set-method" rewrites the request method with the result of the
3520 evaluation of format string <fmt>. There should be very few valid reasons
3521 for having to do so as this is more likely to break something than to fix
3522 it.
3523
3524 - "set-path" rewrites the request path with the result of the evaluation of
3525 format string <fmt>. The query string, if any, is left intact. If a
3526 scheme and authority is found before the path, they are left intact as
3527 well. If the request doesn't have a path ("*"), this one is replaced with
3528 the format. This can be used to prepend a directory component in front of
3529 a path for example. See also "set-query" and "set-uri".
3530
3531 Example :
3532 # prepend the host name before the path
3533 http-request set-path /%[hdr(host)]%[path]
3534
3535 - "set-query" rewrites the request's query string which appears after the
3536 first question mark ("?") with the result of the evaluation of format
3537 string <fmt>. The part prior to the question mark is left intact. If the
3538 request doesn't contain a question mark and the new value is not empty,
3539 then one is added at the end of the URI, followed by the new value. If
3540 a question mark was present, it will never be removed even if the value
3541 is empty. This can be used to add or remove parameters from the query
3542 string. See also "set-query" and "set-uri".
3543
3544 Example :
3545 # replace "%3D" with "=" in the query string
3546 http-request set-query %[query,regsub(%3D,=,g)]
3547
3548 - "set-uri" rewrites the request URI with the result of the evaluation of
3549 format string <fmt>. The scheme, authority, path and query string are all
3550 replaced at once. This can be used to rewrite hosts in front of proxies,
3551 or to perform complex modifications to the URI such as moving parts
3552 between the path and the query string. See also "set-path" and
3553 "set-query".
3554
Willy Tarreauf4c43c12013-06-11 17:01:13 +02003555 - "set-nice" sets the "nice" factor of the current request being processed.
3556 It only has effect against the other requests being processed at the same
3557 time. The default value is 0, unless altered by the "nice" setting on the
3558 "bind" line. The accepted range is -1024..1024. The higher the value, the
3559 nicest the request will be. Lower values will make the request more
3560 important than other ones. This can be useful to improve the speed of
3561 some requests, or lower the priority of non-important requests. Using
3562 this setting without prior experimentation can cause some major slowdown.
3563
Willy Tarreau9a355ec2013-06-11 17:45:46 +02003564 - "set-log-level" is used to change the log level of the current request
3565 when a certain condition is met. Valid levels are the 8 syslog levels
3566 (see the "log" keyword) plus the special level "silent" which disables
3567 logging for this request. This rule is not final so the last matching
3568 rule wins. This rule can be useful to disable health checks coming from
3569 another equipment.
3570
Willy Tarreau42cf39e2013-06-11 18:51:32 +02003571 - "set-tos" is used to set the TOS or DSCP field value of packets sent to
3572 the client to the value passed in <tos> on platforms which support this.
3573 This value represents the whole 8 bits of the IP TOS field, and can be
3574 expressed both in decimal or hexadecimal format (prefixed by "0x"). Note
3575 that only the 6 higher bits are used in DSCP or TOS, and the two lower
3576 bits are always 0. This can be used to adjust some routing behaviour on
3577 border routers based on some information from the request. See RFC 2474,
3578 2597, 3260 and 4594 for more information.
3579
Willy Tarreau51347ed2013-06-11 19:34:13 +02003580 - "set-mark" is used to set the Netfilter MARK on all packets sent to the
3581 client to the value passed in <mark> on platforms which support it. This
3582 value is an unsigned 32 bit value which can be matched by netfilter and
3583 by the routing table. It can be expressed both in decimal or hexadecimal
3584 format (prefixed by "0x"). This can be useful to force certain packets to
3585 take a different route (for example a cheaper network path for bulk
3586 downloads). This works on Linux kernels 2.6.32 and above and requires
3587 admin privileges.
3588
Baptiste Assmannfabcbe02014-04-24 22:16:59 +02003589 - "add-acl" is used to add a new entry into an ACL. The ACL must be loaded
3590 from a file (even a dummy empty file). The file name of the ACL to be
3591 updated is passed between parentheses. It takes one argument: <key fmt>,
3592 which follows log-format rules, to collect content of the new entry. It
3593 performs a lookup in the ACL before insertion, to avoid duplicated (or
3594 more) values. This lookup is done by a linear search and can be expensive
3595 with large lists! It is the equivalent of the "add acl" command from the
3596 stats socket, but can be triggered by an HTTP request.
3597
3598 - "del-acl" is used to delete an entry from an ACL. The ACL must be loaded
3599 from a file (even a dummy empty file). The file name of the ACL to be
3600 updated is passed between parentheses. It takes one argument: <key fmt>,
3601 which follows log-format rules, to collect content of the entry to delete.
3602 It is the equivalent of the "del acl" command from the stats socket, but
3603 can be triggered by an HTTP request.
3604
3605 - "del-map" is used to delete an entry from a MAP. The MAP must be loaded
3606 from a file (even a dummy empty file). The file name of the MAP to be
3607 updated is passed between parentheses. It takes one argument: <key fmt>,
3608 which follows log-format rules, to collect content of the entry to delete.
3609 It takes one argument: "file name" It is the equivalent of the "del map"
3610 command from the stats socket, but can be triggered by an HTTP request.
3611
3612 - "set-map" is used to add a new entry into a MAP. The MAP must be loaded
3613 from a file (even a dummy empty file). The file name of the MAP to be
3614 updated is passed between parentheses. It takes 2 arguments: <key fmt>,
3615 which follows log-format rules, used to collect MAP key, and <value fmt>,
3616 which follows log-format rules, used to collect content for the new entry.
3617 It performs a lookup in the MAP before insertion, to avoid duplicated (or
3618 more) values. This lookup is done by a linear search and can be expensive
3619 with large lists! It is the equivalent of the "set map" command from the
3620 stats socket, but can be triggered by an HTTP request.
3621
Thierry FOURNIER82bf70d2015-05-26 17:58:29 +02003622 - capture <sample> [ len <length> | id <id> ] :
Willy Tarreaua9083d02015-05-08 15:27:59 +02003623 captures sample expression <sample> from the request buffer, and converts
3624 it to a string of at most <len> characters. The resulting string is
3625 stored into the next request "capture" slot, so it will possibly appear
3626 next to some captured HTTP headers. It will then automatically appear in
3627 the logs, and it will be possible to extract it using sample fetch rules
3628 to feed it into headers or anything. The length should be limited given
3629 that this size will be allocated for each capture during the whole
3630 session life. Please check section 7.3 (Fetching samples) and "capture
3631 request header" for more information.
3632
Thierry FOURNIER82bf70d2015-05-26 17:58:29 +02003633 If the keyword "id" is used instead of "len", the action tries to store
3634 the captured string in a previously declared capture slot. This is useful
3635 to run captures in backends. The slot id can be declared by a previous
3636 directive "http-request capture" or with the "declare capture" keyword.
3637
Willy Tarreau09448f72014-06-25 18:12:15 +02003638 - { track-sc0 | track-sc1 | track-sc2 } <key> [table <table>] :
3639 enables tracking of sticky counters from current request. These rules
3640 do not stop evaluation and do not change default action. Three sets of
3641 counters may be simultaneously tracked by the same connection. The first
3642 "track-sc0" rule executed enables tracking of the counters of the
3643 specified table as the first set. The first "track-sc1" rule executed
3644 enables tracking of the counters of the specified table as the second
3645 set. The first "track-sc2" rule executed enables tracking of the
3646 counters of the specified table as the third set. It is a recommended
3647 practice to use the first set of counters for the per-frontend counters
3648 and the second set for the per-backend ones. But this is just a
3649 guideline, all may be used everywhere.
3650
3651 These actions take one or two arguments :
3652 <key> is mandatory, and is a sample expression rule as described
3653 in section 7.3. It describes what elements of the incoming
3654 request or connection will be analysed, extracted, combined,
3655 and used to select which table entry to update the counters.
3656
3657 <table> is an optional table to be used instead of the default one,
3658 which is the stick-table declared in the current proxy. All
3659 the counters for the matches and updates for the key will
3660 then be performed in that table until the session ends.
3661
3662 Once a "track-sc*" rule is executed, the key is looked up in the table
3663 and if it is not found, an entry is allocated for it. Then a pointer to
3664 that entry is kept during all the session's life, and this entry's
3665 counters are updated as often as possible, every time the session's
3666 counters are updated, and also systematically when the session ends.
3667 Counters are only updated for events that happen after the tracking has
3668 been started. As an exception, connection counters and request counters
3669 are systematically updated so that they reflect useful information.
3670
3671 If the entry tracks concurrent connection counters, one connection is
3672 counted for as long as the entry is tracked, and the entry will not
3673 expire during that time. Tracking counters also provides a performance
3674 advantage over just checking the keys, because only one table lookup is
3675 performed for all ACL checks that make use of it.
3676
Thierry FOURNIER236657b2015-08-19 08:25:14 +02003677 - sc-set-gpt0(<sc-id>) <int> :
3678 This action sets the GPT0 tag according to the sticky counter designated
3679 by <sc-id> and the value of <int>. The expected result is a boolean. If
3680 an error occurs, this action silently fails and the actions evaluation
3681 continues.
3682
Thierry FOURNIERe0627bd2015-08-04 08:20:33 +02003683 - sc-inc-gpc0(<sc-id>):
3684 This action increments the GPC0 counter according with the sticky counter
3685 designated by <sc-id>. If an error occurs, this action silently fails and
3686 the actions evaluation continues.
3687
Thierry FOURNIER90da1912015-03-05 11:17:06 +01003688 - "lua" is used to run a Lua function if the action is executed. The single
3689 parameter is the name of the function to run. The prototype of the
3690 function is documented in the API documentation.
3691
Thierry FOURNIER4834bc72015-06-06 19:29:07 +02003692 - set-var(<var-name>) <expr> :
3693 Is used to set the contents of a variable. The variable is declared
3694 inline.
3695
3696 <var-name> The name of the variable starts by an indication about its
3697 scope. The allowed scopes are:
3698 "sess" : the variable is shared with all the session,
3699 "txn" : the variable is shared with all the transaction
3700 (request and response)
3701 "req" : the variable is shared only during the request
3702 processing
3703 "res" : the variable is shared only during the response
3704 processing.
3705 This prefix is followed by a name. The separator is a '.'.
3706 The name may only contain characters 'a-z', 'A-Z', '0-9',
3707 and '_'.
3708
3709 <expr> Is a standard HAProxy expression formed by a sample-fetch
3710 followed by some converters.
3711
3712 Example:
3713
3714 http-request set-var(req.my_var) req.fhdr(user-agent),lower
3715
Adis Nezirovic2fbcafc2015-07-06 15:44:30 +02003716 - set-src <expr> :
3717 Is used to set the source IP address to the value of specified
3718 expression. Useful when a proxy in front of HAProxy rewrites source IP,
3719 but provides the correct IP in a HTTP header; or you want to mask
3720 source IP for privacy.
3721
3722 <expr> Is a standard HAProxy expression formed by a sample-fetch
3723 followed by some converters.
3724
3725 Example:
3726
3727 http-request set-src hdr(x-forwarded-for)
3728 http-request set-src src,ipmask(24)
3729
3730 When set-src is successful, the source port is set to 0.
3731
Willy Tarreau2d392c22015-08-24 01:43:45 +02003732 - "silent-drop" : this stops the evaluation of the rules and makes the
3733 client-facing connection suddenly disappear using a system-dependant way
3734 that tries to prevent the client from being notified. The effect it then
3735 that the client still sees an established connection while there's none
3736 on HAProxy. The purpose is to achieve a comparable effect to "tarpit"
3737 except that it doesn't use any local resource at all on the machine
3738 running HAProxy. It can resist much higher loads than "tarpit", and slow
3739 down stronger attackers. It is important to undestand the impact of using
3740 this mechanism. All stateful equipments placed between the client and
3741 HAProxy (firewalls, proxies, load balancers) will also keep the
3742 established connection for a long time and may suffer from this action.
3743 On modern Linux systems running with enough privileges, the TCP_REPAIR
3744 socket option is used to block the emission of a TCP reset. On other
3745 systems, the socket's TTL is reduced to 1 so that the TCP reset doesn't
3746 pass the first router, though it's still delivered to local networks. Do
3747 not use it unless you fully understand how it works.
3748
Willy Tarreau20b0de52012-12-24 15:45:22 +01003749 There is no limit to the number of http-request statements per instance.
3750
3751 It is important to know that http-request rules are processed very early in
3752 the HTTP processing, just after "block" rules and before "reqdel" or "reqrep"
3753 rules. That way, headers added by "add-header"/"set-header" are visible by
3754 almost all further ACL rules.
Krzysztof Piotr Oledzki6b35ce12010-02-01 23:35:44 +01003755
3756 Example:
Cyril Bonté78caf842010-03-10 22:41:43 +01003757 acl nagios src 192.168.129.3
3758 acl local_net src 192.168.0.0/16
3759 acl auth_ok http_auth(L1)
Krzysztof Piotr Oledzki6b35ce12010-02-01 23:35:44 +01003760
Cyril Bonté78caf842010-03-10 22:41:43 +01003761 http-request allow if nagios
3762 http-request allow if local_net auth_ok
3763 http-request auth realm Gimme if local_net auth_ok
3764 http-request deny
Krzysztof Piotr Oledzki6b35ce12010-02-01 23:35:44 +01003765
Cyril Bonté78caf842010-03-10 22:41:43 +01003766 Example:
3767 acl auth_ok http_auth_group(L1) G1
Cyril Bonté78caf842010-03-10 22:41:43 +01003768 http-request auth unless auth_ok
Krzysztof Piotr Oledzki6b35ce12010-02-01 23:35:44 +01003769
Willy Tarreau20b0de52012-12-24 15:45:22 +01003770 Example:
3771 http-request set-header X-Haproxy-Current-Date %T
3772 http-request set-header X-SSL %[ssl_fc]
Willy Tarreaufca42612015-08-27 17:15:05 +02003773 http-request set-header X-SSL-Session_ID %[ssl_fc_session_id,hex]
Willy Tarreau20b0de52012-12-24 15:45:22 +01003774 http-request set-header X-SSL-Client-Verify %[ssl_c_verify]
3775 http-request set-header X-SSL-Client-DN %{+Q}[ssl_c_s_dn]
3776 http-request set-header X-SSL-Client-CN %{+Q}[ssl_c_s_dn(cn)]
3777 http-request set-header X-SSL-Issuer %{+Q}[ssl_c_i_dn]
3778 http-request set-header X-SSL-Client-NotBefore %{+Q}[ssl_c_notbefore]
3779 http-request set-header X-SSL-Client-NotAfter %{+Q}[ssl_c_notafter]
3780
Baptiste Assmannfabcbe02014-04-24 22:16:59 +02003781 Example:
3782 acl key req.hdr(X-Add-Acl-Key) -m found
3783 acl add path /addacl
3784 acl del path /delacl
3785
3786 acl myhost hdr(Host) -f myhost.lst
3787
3788 http-request add-acl(myhost.lst) %[req.hdr(X-Add-Acl-Key)] if key add
3789 http-request del-acl(myhost.lst) %[req.hdr(X-Add-Acl-Key)] if key del
3790
3791 Example:
3792 acl value req.hdr(X-Value) -m found
3793 acl setmap path /setmap
3794 acl delmap path /delmap
3795
3796 use_backend bk_appli if { hdr(Host),map_str(map.lst) -m found }
3797
3798 http-request set-map(map.lst) %[src] %[req.hdr(X-Value)] if setmap value
3799 http-request del-map(map.lst) %[src] if delmap
3800
Cyril Bonté2be1b3f2010-09-30 23:46:30 +02003801 See also : "stats http-request", section 3.4 about userlists and section 7
3802 about ACL usage.
Willy Tarreauef781042010-01-27 11:53:01 +01003803
Willy Tarreauf4c43c12013-06-11 17:01:13 +02003804http-response { allow | deny | add-header <name> <fmt> | set-nice <nice> |
Willy Tarreau51d861a2015-05-22 17:30:48 +02003805 capture <sample> id <id> | redirect <rule> |
Thierry FOURNIERdad3d1d2014-04-22 18:07:25 +02003806 set-header <name> <fmt> | del-header <name> |
Sasha Pachev218f0642014-06-16 12:05:59 -06003807 replace-header <name> <regex-match> <replace-fmt> |
3808 replace-value <name> <regex-match> <replace-fmt> |
Thierry FOURNIER35d70ef2015-08-26 16:21:56 +02003809 set-status <status> |
Baptiste Assmannfabcbe02014-04-24 22:16:59 +02003810 set-log-level <level> | set-mark <mark> | set-tos <tos> |
3811 add-acl(<file name>) <key fmt> |
3812 del-acl(<file name>) <key fmt> |
3813 del-map(<file name>) <key fmt> |
Thierry FOURNIER90da1912015-03-05 11:17:06 +01003814 set-map(<file name>) <key fmt> <value fmt> |
Thierry FOURNIER4834bc72015-06-06 19:29:07 +02003815 set-var(<var-name>) <expr> |
Thierry FOURNIERe0627bd2015-08-04 08:20:33 +02003816 sc-inc-gpc0(<sc-id>) |
Thierry FOURNIER236657b2015-08-19 08:25:14 +02003817 sc-set-gpt0(<sc-id>) <int> |
Willy Tarreau2d392c22015-08-24 01:43:45 +02003818 silent-drop |
Thierry FOURNIER90da1912015-03-05 11:17:06 +01003819 lua <function name>
Baptiste Assmannfabcbe02014-04-24 22:16:59 +02003820 }
Lukas Tribus2dd1d1a2013-06-19 23:34:41 +02003821 [ { if | unless } <condition> ]
Willy Tarreaue365c0b2013-06-11 16:06:12 +02003822 Access control for Layer 7 responses
3823
3824 May be used in sections: defaults | frontend | listen | backend
3825 no | yes | yes | yes
3826
3827 The http-response statement defines a set of rules which apply to layer 7
3828 processing. The rules are evaluated in their declaration order when they are
3829 met in a frontend, listen or backend section. Any rule may optionally be
3830 followed by an ACL-based condition, in which case it will only be evaluated
3831 if the condition is true. Since these rules apply on responses, the backend
3832 rules are applied first, followed by the frontend's rules.
3833
3834 The first keyword is the rule's action. Currently supported actions include :
3835 - "allow" : this stops the evaluation of the rules and lets the response
3836 pass the check. No further "http-response" rules are evaluated for the
3837 current section.
3838
3839 - "deny" : this stops the evaluation of the rules and immediately rejects
3840 the response and emits an HTTP 502 error. No further "http-response"
3841 rules are evaluated.
3842
3843 - "add-header" appends an HTTP header field whose name is specified in
3844 <name> and whose value is defined by <fmt> which follows the log-format
3845 rules (see Custom Log Format in section 8.2.4). This may be used to send
3846 a cookie to a client for example, or to pass some internal information.
3847 This rule is not final, so it is possible to add other similar rules.
3848 Note that header addition is performed immediately, so one rule might
3849 reuse the resulting header from a previous rule.
3850
3851 - "set-header" does the same as "add-header" except that the header name
3852 is first removed if it existed. This is useful when passing security
3853 information to the server, where the header must not be manipulated by
3854 external users.
3855
Thierry FOURNIERdad3d1d2014-04-22 18:07:25 +02003856 - "del-header" removes all HTTP header fields whose name is specified in
3857 <name>.
3858
Sasha Pachev218f0642014-06-16 12:05:59 -06003859 - "replace-header" matches the regular expression in all occurrences of
3860 header field <name> according to <match-regex>, and replaces them with
3861 the <replace-fmt> argument. Format characters are allowed in replace-fmt
3862 and work like in <fmt> arguments in "add-header". The match is only
3863 case-sensitive. It is important to understand that this action only
3864 considers whole header lines, regardless of the number of values they
3865 may contain. This usage is suited to headers naturally containing commas
3866 in their value, such as Set-Cookie, Expires and so on.
3867
3868 Example:
3869
3870 http-response replace-header Set-Cookie (C=[^;]*);(.*) \1;ip=%bi;\2
3871
3872 applied to:
3873
3874 Set-Cookie: C=1; expires=Tue, 14-Jun-2016 01:40:45 GMT
3875
3876 outputs:
3877
3878 Set-Cookie: C=1;ip=192.168.1.20; expires=Tue, 14-Jun-2016 01:40:45 GMT
3879
3880 assuming the backend IP is 192.168.1.20.
3881
3882 - "replace-value" works like "replace-header" except that it matches the
3883 regex against every comma-delimited value of the header field <name>
3884 instead of the entire header. This is suited for all headers which are
3885 allowed to carry more than one value. An example could be the Accept
3886 header.
3887
3888 Example:
3889
3890 http-response replace-value Cache-control ^public$ private
3891
3892 applied to:
3893
3894 Cache-Control: max-age=3600, public
3895
3896 outputs:
3897
3898 Cache-Control: max-age=3600, private
3899
Thierry FOURNIER35d70ef2015-08-26 16:21:56 +02003900 - "set-status" replaces the response status code with <status> which must
3901 be an integer between 100 and 999. Note that the reason is automatically
3902 adapted to the new code.
3903
3904 Example:
3905
3906 # return "431 Request Header Fields Too Large"
3907 http-response set-status 431
3908
Willy Tarreauf4c43c12013-06-11 17:01:13 +02003909 - "set-nice" sets the "nice" factor of the current request being processed.
3910 It only has effect against the other requests being processed at the same
3911 time. The default value is 0, unless altered by the "nice" setting on the
3912 "bind" line. The accepted range is -1024..1024. The higher the value, the
3913 nicest the request will be. Lower values will make the request more
3914 important than other ones. This can be useful to improve the speed of
3915 some requests, or lower the priority of non-important requests. Using
3916 this setting without prior experimentation can cause some major slowdown.
3917
Willy Tarreau9a355ec2013-06-11 17:45:46 +02003918 - "set-log-level" is used to change the log level of the current request
3919 when a certain condition is met. Valid levels are the 8 syslog levels
3920 (see the "log" keyword) plus the special level "silent" which disables
3921 logging for this request. This rule is not final so the last matching
3922 rule wins. This rule can be useful to disable health checks coming from
3923 another equipment.
3924
Willy Tarreau42cf39e2013-06-11 18:51:32 +02003925 - "set-tos" is used to set the TOS or DSCP field value of packets sent to
3926 the client to the value passed in <tos> on platforms which support this.
3927 This value represents the whole 8 bits of the IP TOS field, and can be
3928 expressed both in decimal or hexadecimal format (prefixed by "0x"). Note
3929 that only the 6 higher bits are used in DSCP or TOS, and the two lower
3930 bits are always 0. This can be used to adjust some routing behaviour on
3931 border routers based on some information from the request. See RFC 2474,
3932 2597, 3260 and 4594 for more information.
3933
Willy Tarreau51347ed2013-06-11 19:34:13 +02003934 - "set-mark" is used to set the Netfilter MARK on all packets sent to the
3935 client to the value passed in <mark> on platforms which support it. This
3936 value is an unsigned 32 bit value which can be matched by netfilter and
3937 by the routing table. It can be expressed both in decimal or hexadecimal
3938 format (prefixed by "0x"). This can be useful to force certain packets to
3939 take a different route (for example a cheaper network path for bulk
3940 downloads). This works on Linux kernels 2.6.32 and above and requires
3941 admin privileges.
3942
Baptiste Assmannfabcbe02014-04-24 22:16:59 +02003943 - "add-acl" is used to add a new entry into an ACL. The ACL must be loaded
3944 from a file (even a dummy empty file). The file name of the ACL to be
3945 updated is passed between parentheses. It takes one argument: <key fmt>,
3946 which follows log-format rules, to collect content of the new entry. It
3947 performs a lookup in the ACL before insertion, to avoid duplicated (or
3948 more) values. This lookup is done by a linear search and can be expensive
3949 with large lists! It is the equivalent of the "add acl" command from the
3950 stats socket, but can be triggered by an HTTP response.
3951
3952 - "del-acl" is used to delete an entry from an ACL. The ACL must be loaded
3953 from a file (even a dummy empty file). The file name of the ACL to be
3954 updated is passed between parentheses. It takes one argument: <key fmt>,
3955 which follows log-format rules, to collect content of the entry to delete.
3956 It is the equivalent of the "del acl" command from the stats socket, but
3957 can be triggered by an HTTP response.
3958
3959 - "del-map" is used to delete an entry from a MAP. The MAP must be loaded
3960 from a file (even a dummy empty file). The file name of the MAP to be
3961 updated is passed between parentheses. It takes one argument: <key fmt>,
3962 which follows log-format rules, to collect content of the entry to delete.
3963 It takes one argument: "file name" It is the equivalent of the "del map"
3964 command from the stats socket, but can be triggered by an HTTP response.
3965
3966 - "set-map" is used to add a new entry into a MAP. The MAP must be loaded
3967 from a file (even a dummy empty file). The file name of the MAP to be
3968 updated is passed between parentheses. It takes 2 arguments: <key fmt>,
3969 which follows log-format rules, used to collect MAP key, and <value fmt>,
3970 which follows log-format rules, used to collect content for the new entry.
3971 It performs a lookup in the MAP before insertion, to avoid duplicated (or
3972 more) values. This lookup is done by a linear search and can be expensive
3973 with large lists! It is the equivalent of the "set map" command from the
3974 stats socket, but can be triggered by an HTTP response.
3975
Thierry FOURNIER90da1912015-03-05 11:17:06 +01003976 - "lua" is used to run a Lua function if the action is executed. The single
3977 parameter is the name of the function to run. The prototype of the
3978 function is documented in the API documentation.
3979
Thierry FOURNIERe80fada2015-05-26 18:06:31 +02003980 - capture <sample> id <id> :
3981 captures sample expression <sample> from the response buffer, and converts
3982 it to a string. The resulting string is stored into the next request
3983 "capture" slot, so it will possibly appear next to some captured HTTP
3984 headers. It will then automatically appear in the logs, and it will be
3985 possible to extract it using sample fetch rules to feed it into headers or
3986 anything. Please check section 7.3 (Fetching samples) and "capture
3987 response header" for more information.
3988
3989 The keyword "id" is the id of the capture slot which is used for storing
3990 the string. The capture slot must be defined in an associated frontend.
3991 This is useful to run captures in backends. The slot id can be declared by
3992 a previous directive "http-response capture" or with the "declare capture"
3993 keyword.
3994
Willy Tarreau51d861a2015-05-22 17:30:48 +02003995 - "redirect" : this performs an HTTP redirection based on a redirect rule.
3996 This supports a format string similarly to "http-request redirect" rules,
3997 with the exception that only the "location" type of redirect is possible
3998 on the response. See the "redirect" keyword for the rule's syntax. When
3999 a redirect rule is applied during a response, connections to the server
4000 are closed so that no data can be forwarded from the server to the client.
4001
Thierry FOURNIER4834bc72015-06-06 19:29:07 +02004002 - set-var(<var-name>) expr:
4003 Is used to set the contents of a variable. The variable is declared
4004 inline.
4005
4006 <var-name> The name of the variable starts by an indication about its
4007 scope. The allowed scopes are:
4008 "sess" : the variable is shared with all the session,
4009 "txn" : the variable is shared with all the transaction
4010 (request and response)
4011 "req" : the variable is shared only during the request
4012 processing
4013 "res" : the variable is shared only during the response
4014 processing.
4015 This prefix is followed by a name. The separator is a '.'.
4016 The name may only contain characters 'a-z', 'A-Z', '0-9',
4017 and '_'.
4018
4019 <expr> Is a standard HAProxy expression formed by a sample-fetch
4020 followed by some converters.
4021
4022 Example:
4023
4024 http-response set-var(sess.last_redir) res.hdr(location)
4025
Thierry FOURNIER236657b2015-08-19 08:25:14 +02004026 - sc-set-gpt0(<sc-id>) <int> :
4027 This action sets the GPT0 tag according to the sticky counter designated
4028 by <sc-id> and the value of <int>. The expected result is a boolean. If
4029 an error occurs, this action silently fails and the actions evaluation
4030 continues.
4031
Thierry FOURNIERe0627bd2015-08-04 08:20:33 +02004032 - sc-inc-gpc0(<sc-id>):
4033 This action increments the GPC0 counter according with the sticky counter
4034 designated by <sc-id>. If an error occurs, this action silently fails and
4035 the actions evaluation continues.
4036
Willy Tarreau2d392c22015-08-24 01:43:45 +02004037 - "silent-drop" : this stops the evaluation of the rules and makes the
4038 client-facing connection suddenly disappear using a system-dependant way
4039 that tries to prevent the client from being notified. The effect it then
4040 that the client still sees an established connection while there's none
4041 on HAProxy. The purpose is to achieve a comparable effect to "tarpit"
4042 except that it doesn't use any local resource at all on the machine
4043 running HAProxy. It can resist much higher loads than "tarpit", and slow
4044 down stronger attackers. It is important to undestand the impact of using
4045 this mechanism. All stateful equipments placed between the client and
4046 HAProxy (firewalls, proxies, load balancers) will also keep the
4047 established connection for a long time and may suffer from this action.
4048 On modern Linux systems running with enough privileges, the TCP_REPAIR
4049 socket option is used to block the emission of a TCP reset. On other
4050 systems, the socket's TTL is reduced to 1 so that the TCP reset doesn't
4051 pass the first router, though it's still delivered to local networks. Do
4052 not use it unless you fully understand how it works.
4053
Willy Tarreaue365c0b2013-06-11 16:06:12 +02004054 There is no limit to the number of http-response statements per instance.
4055
Godbach09250262013-07-02 01:19:15 +08004056 It is important to know that http-response rules are processed very early in
Willy Tarreaue365c0b2013-06-11 16:06:12 +02004057 the HTTP processing, before "reqdel" or "reqrep" rules. That way, headers
4058 added by "add-header"/"set-header" are visible by almost all further ACL
4059 rules.
4060
Baptiste Assmannfabcbe02014-04-24 22:16:59 +02004061 Example:
4062 acl key_acl res.hdr(X-Acl-Key) -m found
4063
4064 acl myhost hdr(Host) -f myhost.lst
4065
4066 http-response add-acl(myhost.lst) %[res.hdr(X-Acl-Key)] if key_acl
4067 http-response del-acl(myhost.lst) %[res.hdr(X-Acl-Key)] if key_acl
4068
4069 Example:
4070 acl value res.hdr(X-Value) -m found
4071
4072 use_backend bk_appli if { hdr(Host),map_str(map.lst) -m found }
4073
4074 http-response set-map(map.lst) %[src] %[res.hdr(X-Value)] if value
4075 http-response del-map(map.lst) %[src] if ! value
4076
Willy Tarreaue365c0b2013-06-11 16:06:12 +02004077 See also : "http-request", section 3.4 about userlists and section 7 about
4078 ACL usage.
4079
Baptiste Assmann5ecb77f2013-10-06 23:24:13 +02004080
Willy Tarreau30631952015-08-06 15:05:24 +02004081http-reuse { never | safe | aggressive | always }
4082 Declare how idle HTTP connections may be shared between requests
4083
4084 May be used in sections: defaults | frontend | listen | backend
4085 yes | no | yes | yes
4086
4087 By default, a connection established between haproxy and the backend server
4088 belongs to the session that initiated it. The downside is that between the
4089 response and the next request, the connection remains idle and is not used.
4090 In many cases for performance reasons it is desirable to make it possible to
4091 reuse these idle connections to serve other requests from different sessions.
4092 This directive allows to tune this behaviour.
4093
4094 The argument indicates the desired connection reuse strategy :
4095
4096 - "never" : idle connections are never shared between sessions. This is
4097 the default choice. It may be enforced to cancel a different
4098 strategy inherited from a defaults section or for
4099 troubleshooting. For example, if an old bogus application
4100 considers that multiple requests over the same connection come
4101 from the same client and it is not possible to fix the
4102 application, it may be desirable to disable connection sharing
4103 in a single backend. An example of such an application could
4104 be an old haproxy using cookie insertion in tunnel mode and
4105 not checking any request past the first one.
4106
4107 - "safe" : this is the recommended strategy. The first request of a
4108 session is always sent over its own connection, and only
4109 subsequent requests may be dispatched over other existing
4110 connections. This ensures that in case the server closes the
4111 connection when the request is being sent, the browser can
4112 decide to silently retry it. Since it is exactly equivalent to
4113 regular keep-alive, there should be no side effects.
4114
4115 - "aggressive" : this mode may be useful in webservices environments where
4116 all servers are not necessarily known and where it would be
4117 appreciable to deliver most first requests over existing
4118 connections. In this case, first requests are only delivered
4119 over existing connections that have been reused at least once,
4120 proving that the server correctly supports connection reuse.
4121 It should only be used when it's sure that the client can
4122 retry a failed request once in a while and where the benefit
4123 of aggressive connection reuse significantly outweights the
4124 downsides of rare connection failures.
4125
4126 - "always" : this mode is only recommended when the path to the server is
4127 known for never breaking existing connections quickly after
4128 releasing them. It allows the first request of a session to be
4129 sent to an existing connection. This can provide a significant
4130 performance increase over the "safe" strategy when the backend
4131 is a cache farm, since such components tend to show a
4132 consistent behaviour and will benefit from the connection
4133 sharing. It is recommended that the "http-keep-alive" timeout
4134 remains low in this mode so that no dead connections remain
4135 usable. In most cases, this will lead to the same performance
4136 gains as "aggressive" but with more risks. It should only be
4137 used when it improves the situation over "aggressive".
4138
4139 When http connection sharing is enabled, a great care is taken to respect the
4140 connection properties and compatiblities. Specifically :
4141 - connections made with "usesrc" followed by a client-dependant value
4142 ("client", "clientip", "hdr_ip") are marked private and never shared ;
4143
4144 - connections sent to a server with a TLS SNI extension are marked private
4145 and are never shared ;
4146
4147 - connections receiving a status code 401 or 407 expect some authentication
4148 to be sent in return. Due to certain bogus authentication schemes (such
4149 as NTLM) relying on the connection, these connections are marked private
4150 and are never shared ;
4151
4152 No connection pool is involved, once a session dies, the last idle connection
4153 it was attached to is deleted at the same time. This ensures that connections
4154 may not last after all sessions are closed.
4155
4156 Note: connection reuse improves the accuracy of the "server maxconn" setting,
4157 because almost no new connection will be established while idle connections
4158 remain available. This is particularly true with the "always" strategy.
4159
4160 See also : "option http-keep-alive", "server maxconn"
4161
4162
Mark Lamourinec2247f02012-01-04 13:02:01 -05004163http-send-name-header [<header>]
4164 Add the server name to a request. Use the header string given by <header>
4165
4166 May be used in sections: defaults | frontend | listen | backend
4167 yes | no | yes | yes
4168
4169 Arguments :
4170
4171 <header> The header string to use to send the server name
4172
4173 The "http-send-name-header" statement causes the name of the target
4174 server to be added to the headers of an HTTP request. The name
4175 is added with the header string proved.
4176
4177 See also : "server"
4178
Krzysztof Piotr Oledzkif58a9622008-02-23 01:19:10 +01004179id <value>
Willy Tarreau53fb4ae2009-10-04 23:04:08 +02004180 Set a persistent ID to a proxy.
4181 May be used in sections : defaults | frontend | listen | backend
4182 no | yes | yes | yes
4183 Arguments : none
4184
4185 Set a persistent ID for the proxy. This ID must be unique and positive.
4186 An unused ID will automatically be assigned if unset. The first assigned
4187 value will be 1. This ID is currently only returned in statistics.
Krzysztof Piotr Oledzkif58a9622008-02-23 01:19:10 +01004188
4189
Cyril Bonté0d4bf012010-04-25 23:21:46 +02004190ignore-persist { if | unless } <condition>
4191 Declare a condition to ignore persistence
4192 May be used in sections: defaults | frontend | listen | backend
4193 no | yes | yes | yes
4194
4195 By default, when cookie persistence is enabled, every requests containing
4196 the cookie are unconditionally persistent (assuming the target server is up
4197 and running).
4198
4199 The "ignore-persist" statement allows one to declare various ACL-based
4200 conditions which, when met, will cause a request to ignore persistence.
4201 This is sometimes useful to load balance requests for static files, which
Jarno Huuskonen0e82b922014-04-12 18:22:19 +03004202 often don't require persistence. This can also be used to fully disable
Cyril Bonté0d4bf012010-04-25 23:21:46 +02004203 persistence for a specific User-Agent (for example, some web crawler bots).
4204
Cyril Bonté0d4bf012010-04-25 23:21:46 +02004205 The persistence is ignored when an "if" condition is met, or unless an
4206 "unless" condition is met.
4207
4208 See also : "force-persist", "cookie", and section 7 about ACL usage.
4209
Baptiste Assmann01c6cc32015-08-23 11:45:29 +02004210load-server-state-from-file { global | local | none }
4211 Allow seamless reload of HAProxy
4212 May be used in sections: defaults | frontend | listen | backend
4213 yes | no | yes | yes
4214
4215 This directive points HAProxy to a file where server state from previous
4216 running process has been saved. That way, when starting up, before handling
4217 traffic, the new process can apply old states to servers exactly has if no
4218 reload occured. The purpose of the "load-server-state-from-file" directive is
4219 to tell haproxy which file to use. For now, only 2 arguments to either prevent
4220 loading state or load states from a file containing all backends and servers.
4221 The state file can be generated by running the command "show servers state"
4222 over the stats socket and redirect output.
4223
4224 The format of the file is versionned and is very specific. To understand it,
4225 please read the documentation of the "show servers state" command (chapter
4226 9.2).
4227
4228 Arguments:
4229 global load the content of the file pointed by the global directive
4230 named "server-state-file".
4231
4232 local load the content of the file pointed by the directive
4233 "server-state-file-name" if set. If not set, then the backend
4234 name is used as a file name.
4235
4236 none don't load any stat for this backend
4237
4238 Notes:
4239 - server's IP address is not updated unless DNS resolution is enabled on
4240 the server. It means that if a server IP address has been changed using
4241 the stat socket, this information won't be re-applied after reloading.
4242
4243 - server's weight is applied from previous running process unless it has
4244 has changed between previous and new configuration files.
4245
4246 Example 1:
4247
4248 Minimal configuration:
4249
4250 global
4251 stats socket /tmp/socket
4252 server-state-file /tmp/server_state
4253
4254 defaults
4255 load-server-state-from-file global
4256
4257 backend bk
4258 server s1 127.0.0.1:22 check weight 11
4259 server s2 127.0.0.1:22 check weight 12
4260
4261 Then one can run :
4262
4263 socat /tmp/socket - <<< "show servers state" > /tmp/server_state
4264
4265 Content of the file /tmp/server_state would be like this:
4266
4267 1
4268 # <field names skipped for the doc example>
4269 1 bk 1 s1 127.0.0.1 2 0 11 11 4 6 3 4 6 0 0
4270 1 bk 2 s2 127.0.0.1 2 0 12 12 4 6 3 4 6 0 0
4271
4272 Example 2:
4273
4274 Minimal configuration:
4275
4276 global
4277 stats socket /tmp/socket
4278 server-state-base /etc/haproxy/states
4279
4280 defaults
4281 load-server-state-from-file local
4282
4283 backend bk
4284 server s1 127.0.0.1:22 check weight 11
4285 server s2 127.0.0.1:22 check weight 12
4286
4287 Then one can run :
4288
4289 socat /tmp/socket - <<< "show servers state bk" > /etc/haproxy/states/bk
4290
4291 Content of the file /etc/haproxy/states/bk would be like this:
4292
4293 1
4294 # <field names skipped for the doc example>
4295 1 bk 1 s1 127.0.0.1 2 0 11 11 4 6 3 4 6 0 0
4296 1 bk 2 s2 127.0.0.1 2 0 12 12 4 6 3 4 6 0 0
4297
4298 See also: "server-state-file", "server-state-file-name", and
4299 "show servers state"
4300
Cyril Bonté0d4bf012010-04-25 23:21:46 +02004301
Willy Tarreau2769aa02007-12-27 18:26:09 +01004302log global
Willy Tarreau18324f52014-06-27 18:10:07 +02004303log <address> [len <length>] <facility> [<level> [<minlevel>]]
William Lallemand0f99e342011-10-12 17:50:54 +02004304no log
Willy Tarreau2769aa02007-12-27 18:26:09 +01004305 Enable per-instance logging of events and traffic.
4306 May be used in sections : defaults | frontend | listen | backend
4307 yes | yes | yes | yes
William Lallemand0f99e342011-10-12 17:50:54 +02004308
4309 Prefix :
4310 no should be used when the logger list must be flushed. For example,
4311 if you don't want to inherit from the default logger list. This
4312 prefix does not allow arguments.
4313
Willy Tarreau2769aa02007-12-27 18:26:09 +01004314 Arguments :
4315 global should be used when the instance's logging parameters are the
4316 same as the global ones. This is the most common usage. "global"
4317 replaces <address>, <facility> and <level> with those of the log
4318 entries found in the "global" section. Only one "log global"
4319 statement may be used per instance, and this form takes no other
4320 parameter.
4321
4322 <address> indicates where to send the logs. It takes the same format as
4323 for the "global" section's logs, and can be one of :
4324
4325 - An IPv4 address optionally followed by a colon (':') and a UDP
4326 port. If no port is specified, 514 is used by default (the
4327 standard syslog port).
4328
David du Colombier24bb5f52011-03-17 10:40:23 +01004329 - An IPv6 address followed by a colon (':') and optionally a UDP
4330 port. If no port is specified, 514 is used by default (the
4331 standard syslog port).
4332
Willy Tarreau2769aa02007-12-27 18:26:09 +01004333 - A filesystem path to a UNIX domain socket, keeping in mind
4334 considerations for chroot (be sure the path is accessible
4335 inside the chroot) and uid/gid (be sure the path is
4336 appropriately writeable).
4337
William Lallemandb2f07452015-05-12 14:27:13 +02004338 You may want to reference some environment variables in the
4339 address parameter, see section 2.3 about environment variables.
Willy Tarreaudad36a32013-03-11 01:20:04 +01004340
Willy Tarreau18324f52014-06-27 18:10:07 +02004341 <length> is an optional maximum line length. Log lines larger than this
4342 value will be truncated before being sent. The reason is that
4343 syslog servers act differently on log line length. All servers
4344 support the default value of 1024, but some servers simply drop
4345 larger lines while others do log them. If a server supports long
4346 lines, it may make sense to set this value here in order to avoid
4347 truncating long lines. Similarly, if a server drops long lines,
4348 it is preferable to truncate them before sending them. Accepted
4349 values are 80 to 65535 inclusive. The default value of 1024 is
4350 generally fine for all standard usages. Some specific cases of
4351 long captures or JSON-formated logs may require larger values.
4352
Willy Tarreau2769aa02007-12-27 18:26:09 +01004353 <facility> must be one of the 24 standard syslog facilities :
4354
4355 kern user mail daemon auth syslog lpr news
4356 uucp cron auth2 ftp ntp audit alert cron2
4357 local0 local1 local2 local3 local4 local5 local6 local7
4358
4359 <level> is optional and can be specified to filter outgoing messages. By
4360 default, all messages are sent. If a level is specified, only
4361 messages with a severity at least as important as this level
Willy Tarreauf7edefa2009-05-10 17:20:05 +02004362 will be sent. An optional minimum level can be specified. If it
4363 is set, logs emitted with a more severe level than this one will
4364 be capped to this level. This is used to avoid sending "emerg"
4365 messages on all terminals on some default syslog configurations.
4366 Eight levels are known :
Willy Tarreau2769aa02007-12-27 18:26:09 +01004367
4368 emerg alert crit err warning notice info debug
4369
William Lallemand0f99e342011-10-12 17:50:54 +02004370 It is important to keep in mind that it is the frontend which decides what to
4371 log from a connection, and that in case of content switching, the log entries
4372 from the backend will be ignored. Connections are logged at level "info".
Willy Tarreaucc6c8912009-02-22 10:53:55 +01004373
4374 However, backend log declaration define how and where servers status changes
4375 will be logged. Level "notice" will be used to indicate a server going up,
4376 "warning" will be used for termination signals and definitive service
4377 termination, and "alert" will be used for when a server goes down.
4378
4379 Note : According to RFC3164, messages are truncated to 1024 bytes before
4380 being emitted.
Willy Tarreau2769aa02007-12-27 18:26:09 +01004381
4382 Example :
4383 log global
Willy Tarreauf7edefa2009-05-10 17:20:05 +02004384 log 127.0.0.1:514 local0 notice # only send important events
4385 log 127.0.0.1:514 local0 notice notice # same but limit output level
William Lallemandb2f07452015-05-12 14:27:13 +02004386 log "${LOCAL_SYSLOG}:514" local0 notice # send to local server
Willy Tarreaudad36a32013-03-11 01:20:04 +01004387
Willy Tarreau2769aa02007-12-27 18:26:09 +01004388
William Lallemand48940402012-01-30 16:47:22 +01004389log-format <string>
Willy Tarreaufb4e7ea2015-01-07 14:55:17 +01004390 Specifies the log format string to use for traffic logs
4391 May be used in sections: defaults | frontend | listen | backend
4392 yes | yes | yes | no
William Lallemand48940402012-01-30 16:47:22 +01004393
Willy Tarreaufb4e7ea2015-01-07 14:55:17 +01004394 This directive specifies the log format string that will be used for all logs
4395 resulting from traffic passing through the frontend using this line. If the
4396 directive is used in a defaults section, all subsequent frontends will use
4397 the same log format. Please see section 8.2.4 which covers the log format
4398 string in depth.
William Lallemand48940402012-01-30 16:47:22 +01004399
Dragan Dosen7ad31542015-09-28 17:16:47 +02004400log-format-sd <string>
4401 Specifies the RFC5424 structured-data log format string
4402 May be used in sections: defaults | frontend | listen | backend
4403 yes | yes | yes | no
4404
4405 This directive specifies the RFC5424 structured-data log format string that
4406 will be used for all logs resulting from traffic passing through the frontend
4407 using this line. If the directive is used in a defaults section, all
4408 subsequent frontends will use the same log format. Please see section 8.2.4
4409 which covers the log format string in depth.
4410
4411 See https://tools.ietf.org/html/rfc5424#section-6.3 for more information
4412 about the RFC5424 structured-data part.
4413
4414 Note : This log format string will be used only for loggers that have set
4415 log format to "rfc5424".
4416
4417 Example :
4418 log-format-sd [exampleSDID@1234\ bytes=\"%B\"\ status=\"%ST\"]
4419
4420
Willy Tarreau094af4e2015-01-07 15:03:42 +01004421log-tag <string>
4422 Specifies the log tag to use for all outgoing logs
4423 May be used in sections: defaults | frontend | listen | backend
4424 yes | yes | yes | yes
4425
4426 Sets the tag field in the syslog header to this string. It defaults to the
4427 log-tag set in the global section, otherwise the program name as launched
4428 from the command line, which usually is "haproxy". Sometimes it can be useful
4429 to differentiate between multiple processes running on the same host, or to
4430 differentiate customer instances running in the same process. In the backend,
4431 logs about servers up/down will use this tag. As a hint, it can be convenient
4432 to set a log-tag related to a hosted customer in a defaults section then put
4433 all the frontends and backends for that customer, then start another customer
4434 in a new defaults section. See also the global "log-tag" directive.
Willy Tarreau2769aa02007-12-27 18:26:09 +01004435
Willy Tarreauc35362a2014-04-25 13:58:37 +02004436max-keep-alive-queue <value>
4437 Set the maximum server queue size for maintaining keep-alive connections
4438 May be used in sections: defaults | frontend | listen | backend
4439 yes | no | yes | yes
4440
4441 HTTP keep-alive tries to reuse the same server connection whenever possible,
4442 but sometimes it can be counter-productive, for example if a server has a lot
4443 of connections while other ones are idle. This is especially true for static
4444 servers.
4445
4446 The purpose of this setting is to set a threshold on the number of queued
4447 connections at which haproxy stops trying to reuse the same server and prefers
4448 to find another one. The default value, -1, means there is no limit. A value
4449 of zero means that keep-alive requests will never be queued. For very close
4450 servers which can be reached with a low latency and which are not sensible to
4451 breaking keep-alive, a low value is recommended (eg: local static server can
4452 use a value of 10 or less). For remote servers suffering from a high latency,
4453 higher values might be needed to cover for the latency and/or the cost of
4454 picking a different server.
4455
4456 Note that this has no impact on responses which are maintained to the same
4457 server consecutively to a 401 response. They will still go to the same server
4458 even if they have to be queued.
4459
4460 See also : "option http-server-close", "option prefer-last-server", server
4461 "maxconn" and cookie persistence.
4462
4463
Willy Tarreau2769aa02007-12-27 18:26:09 +01004464maxconn <conns>
4465 Fix the maximum number of concurrent connections on a frontend
4466 May be used in sections : defaults | frontend | listen | backend
4467 yes | yes | yes | no
4468 Arguments :
4469 <conns> is the maximum number of concurrent connections the frontend will
4470 accept to serve. Excess connections will be queued by the system
4471 in the socket's listen queue and will be served once a connection
4472 closes.
4473
4474 If the system supports it, it can be useful on big sites to raise this limit
4475 very high so that haproxy manages connection queues, instead of leaving the
4476 clients with unanswered connection attempts. This value should not exceed the
4477 global maxconn. Also, keep in mind that a connection contains two buffers
4478 of 8kB each, as well as some other data resulting in about 17 kB of RAM being
4479 consumed per established connection. That means that a medium system equipped
4480 with 1GB of RAM can withstand around 40000-50000 concurrent connections if
4481 properly tuned.
4482
4483 Also, when <conns> is set to large values, it is possible that the servers
4484 are not sized to accept such loads, and for this reason it is generally wise
4485 to assign them some reasonable connection limits.
4486
Vincent Bernat6341be52012-06-27 17:18:30 +02004487 By default, this value is set to 2000.
4488
Willy Tarreau2769aa02007-12-27 18:26:09 +01004489 See also : "server", global section's "maxconn", "fullconn"
4490
4491
4492mode { tcp|http|health }
4493 Set the running mode or protocol of the instance
4494 May be used in sections : defaults | frontend | listen | backend
4495 yes | yes | yes | yes
4496 Arguments :
4497 tcp The instance will work in pure TCP mode. A full-duplex connection
4498 will be established between clients and servers, and no layer 7
4499 examination will be performed. This is the default mode. It
4500 should be used for SSL, SSH, SMTP, ...
4501
4502 http The instance will work in HTTP mode. The client request will be
4503 analyzed in depth before connecting to any server. Any request
4504 which is not RFC-compliant will be rejected. Layer 7 filtering,
4505 processing and switching will be possible. This is the mode which
4506 brings HAProxy most of its value.
4507
4508 health The instance will work in "health" mode. It will just reply "OK"
Willy Tarreau82569f92012-09-27 23:48:56 +02004509 to incoming connections and close the connection. Alternatively,
4510 If the "httpchk" option is set, "HTTP/1.0 200 OK" will be sent
4511 instead. Nothing will be logged in either case. This mode is used
4512 to reply to external components health checks. This mode is
4513 deprecated and should not be used anymore as it is possible to do
4514 the same and even better by combining TCP or HTTP modes with the
4515 "monitor" keyword.
Willy Tarreau2769aa02007-12-27 18:26:09 +01004516
Cyril Bonté108cf6e2012-04-21 23:30:29 +02004517 When doing content switching, it is mandatory that the frontend and the
4518 backend are in the same mode (generally HTTP), otherwise the configuration
4519 will be refused.
Willy Tarreau2769aa02007-12-27 18:26:09 +01004520
Cyril Bonté108cf6e2012-04-21 23:30:29 +02004521 Example :
Willy Tarreau2769aa02007-12-27 18:26:09 +01004522 defaults http_instances
4523 mode http
4524
Cyril Bonté108cf6e2012-04-21 23:30:29 +02004525 See also : "monitor", "monitor-net"
Willy Tarreau2769aa02007-12-27 18:26:09 +01004526
Willy Tarreau0ba27502007-12-24 16:55:16 +01004527
Cyril Bontéf0c60612010-02-06 14:44:47 +01004528monitor fail { if | unless } <condition>
Willy Tarreau2769aa02007-12-27 18:26:09 +01004529 Add a condition to report a failure to a monitor HTTP request.
Willy Tarreau0ba27502007-12-24 16:55:16 +01004530 May be used in sections : defaults | frontend | listen | backend
4531 no | yes | yes | no
Willy Tarreau0ba27502007-12-24 16:55:16 +01004532 Arguments :
4533 if <cond> the monitor request will fail if the condition is satisfied,
4534 and will succeed otherwise. The condition should describe a
Krzysztof Piotr Oledzkif8645332009-12-13 21:55:50 +01004535 combined test which must induce a failure if all conditions
Willy Tarreau0ba27502007-12-24 16:55:16 +01004536 are met, for instance a low number of servers both in a
4537 backend and its backup.
4538
4539 unless <cond> the monitor request will succeed only if the condition is
4540 satisfied, and will fail otherwise. Such a condition may be
4541 based on a test on the presence of a minimum number of active
4542 servers in a list of backends.
4543
4544 This statement adds a condition which can force the response to a monitor
4545 request to report a failure. By default, when an external component queries
4546 the URI dedicated to monitoring, a 200 response is returned. When one of the
4547 conditions above is met, haproxy will return 503 instead of 200. This is
4548 very useful to report a site failure to an external component which may base
4549 routing advertisements between multiple sites on the availability reported by
4550 haproxy. In this case, one would rely on an ACL involving the "nbsrv"
Willy Tarreauae94d4d2011-05-11 16:28:49 +02004551 criterion. Note that "monitor fail" only works in HTTP mode. Both status
4552 messages may be tweaked using "errorfile" or "errorloc" if needed.
Willy Tarreau0ba27502007-12-24 16:55:16 +01004553
4554 Example:
4555 frontend www
Willy Tarreau2769aa02007-12-27 18:26:09 +01004556 mode http
Willy Tarreau0ba27502007-12-24 16:55:16 +01004557 acl site_dead nbsrv(dynamic) lt 2
4558 acl site_dead nbsrv(static) lt 2
4559 monitor-uri /site_alive
4560 monitor fail if site_dead
4561
Willy Tarreauae94d4d2011-05-11 16:28:49 +02004562 See also : "monitor-net", "monitor-uri", "errorfile", "errorloc"
Willy Tarreau2769aa02007-12-27 18:26:09 +01004563
4564
4565monitor-net <source>
4566 Declare a source network which is limited to monitor requests
4567 May be used in sections : defaults | frontend | listen | backend
4568 yes | yes | yes | no
4569 Arguments :
4570 <source> is the source IPv4 address or network which will only be able to
4571 get monitor responses to any request. It can be either an IPv4
4572 address, a host name, or an address followed by a slash ('/')
4573 followed by a mask.
4574
4575 In TCP mode, any connection coming from a source matching <source> will cause
4576 the connection to be immediately closed without any log. This allows another
Krzysztof Piotr Oledzkif8645332009-12-13 21:55:50 +01004577 equipment to probe the port and verify that it is still listening, without
Willy Tarreau2769aa02007-12-27 18:26:09 +01004578 forwarding the connection to a remote server.
4579
4580 In HTTP mode, a connection coming from a source matching <source> will be
4581 accepted, the following response will be sent without waiting for a request,
4582 then the connection will be closed : "HTTP/1.0 200 OK". This is normally
4583 enough for any front-end HTTP probe to detect that the service is UP and
Willy Tarreau82569f92012-09-27 23:48:56 +02004584 running without forwarding the request to a backend server. Note that this
4585 response is sent in raw format, without any transformation. This is important
4586 as it means that it will not be SSL-encrypted on SSL listeners.
Willy Tarreau2769aa02007-12-27 18:26:09 +01004587
Willy Tarreau82569f92012-09-27 23:48:56 +02004588 Monitor requests are processed very early, just after tcp-request connection
4589 ACLs which are the only ones able to block them. These connections are short
4590 lived and never wait for any data from the client. They cannot be logged, and
4591 it is the intended purpose. They are only used to report HAProxy's health to
4592 an upper component, nothing more. Please note that "monitor fail" rules do
4593 not apply to connections intercepted by "monitor-net".
Willy Tarreau2769aa02007-12-27 18:26:09 +01004594
Willy Tarreau95cd2832010-03-04 23:36:33 +01004595 Last, please note that only one "monitor-net" statement can be specified in
4596 a frontend. If more than one is found, only the last one will be considered.
Cyril Bonté108cf6e2012-04-21 23:30:29 +02004597
Willy Tarreau2769aa02007-12-27 18:26:09 +01004598 Example :
4599 # addresses .252 and .253 are just probing us.
4600 frontend www
4601 monitor-net 192.168.0.252/31
4602
4603 See also : "monitor fail", "monitor-uri"
4604
4605
4606monitor-uri <uri>
4607 Intercept a URI used by external components' monitor requests
4608 May be used in sections : defaults | frontend | listen | backend
4609 yes | yes | yes | no
4610 Arguments :
4611 <uri> is the exact URI which we want to intercept to return HAProxy's
4612 health status instead of forwarding the request.
4613
4614 When an HTTP request referencing <uri> will be received on a frontend,
4615 HAProxy will not forward it nor log it, but instead will return either
4616 "HTTP/1.0 200 OK" or "HTTP/1.0 503 Service unavailable", depending on failure
4617 conditions defined with "monitor fail". This is normally enough for any
4618 front-end HTTP probe to detect that the service is UP and running without
4619 forwarding the request to a backend server. Note that the HTTP method, the
4620 version and all headers are ignored, but the request must at least be valid
4621 at the HTTP level. This keyword may only be used with an HTTP-mode frontend.
4622
4623 Monitor requests are processed very early. It is not possible to block nor
4624 divert them using ACLs. They cannot be logged either, and it is the intended
4625 purpose. They are only used to report HAProxy's health to an upper component,
4626 nothing more. However, it is possible to add any number of conditions using
4627 "monitor fail" and ACLs so that the result can be adjusted to whatever check
4628 can be imagined (most often the number of available servers in a backend).
4629
4630 Example :
4631 # Use /haproxy_test to report haproxy's status
4632 frontend www
4633 mode http
4634 monitor-uri /haproxy_test
4635
4636 See also : "monitor fail", "monitor-net"
4637
Willy Tarreau0ba27502007-12-24 16:55:16 +01004638
Willy Tarreaubf1f8162007-12-28 17:42:56 +01004639option abortonclose
4640no option abortonclose
4641 Enable or disable early dropping of aborted requests pending in queues.
4642 May be used in sections : defaults | frontend | listen | backend
4643 yes | no | yes | yes
4644 Arguments : none
4645
4646 In presence of very high loads, the servers will take some time to respond.
4647 The per-instance connection queue will inflate, and the response time will
4648 increase respective to the size of the queue times the average per-session
4649 response time. When clients will wait for more than a few seconds, they will
Willy Tarreau198a7442008-01-17 12:05:32 +01004650 often hit the "STOP" button on their browser, leaving a useless request in
Willy Tarreaubf1f8162007-12-28 17:42:56 +01004651 the queue, and slowing down other users, and the servers as well, because the
4652 request will eventually be served, then aborted at the first error
4653 encountered while delivering the response.
4654
4655 As there is no way to distinguish between a full STOP and a simple output
4656 close on the client side, HTTP agents should be conservative and consider
4657 that the client might only have closed its output channel while waiting for
4658 the response. However, this introduces risks of congestion when lots of users
4659 do the same, and is completely useless nowadays because probably no client at
4660 all will close the session while waiting for the response. Some HTTP agents
Willy Tarreaud72758d2010-01-12 10:42:19 +01004661 support this behaviour (Squid, Apache, HAProxy), and others do not (TUX, most
Willy Tarreaubf1f8162007-12-28 17:42:56 +01004662 hardware-based load balancers). So the probability for a closed input channel
Willy Tarreau198a7442008-01-17 12:05:32 +01004663 to represent a user hitting the "STOP" button is close to 100%, and the risk
Willy Tarreaubf1f8162007-12-28 17:42:56 +01004664 of being the single component to break rare but valid traffic is extremely
4665 low, which adds to the temptation to be able to abort a session early while
4666 still not served and not pollute the servers.
4667
4668 In HAProxy, the user can choose the desired behaviour using the option
4669 "abortonclose". By default (without the option) the behaviour is HTTP
4670 compliant and aborted requests will be served. But when the option is
4671 specified, a session with an incoming channel closed will be aborted while
4672 it is still possible, either pending in the queue for a connection slot, or
4673 during the connection establishment if the server has not yet acknowledged
4674 the connection request. This considerably reduces the queue size and the load
4675 on saturated servers when users are tempted to click on STOP, which in turn
Willy Tarreaud72758d2010-01-12 10:42:19 +01004676 reduces the response time for other users.
Willy Tarreaubf1f8162007-12-28 17:42:56 +01004677
4678 If this option has been enabled in a "defaults" section, it can be disabled
4679 in a specific instance by prepending the "no" keyword before it.
4680
4681 See also : "timeout queue" and server's "maxconn" and "maxqueue" parameters
4682
4683
Willy Tarreau4076a152009-04-02 15:18:36 +02004684option accept-invalid-http-request
4685no option accept-invalid-http-request
4686 Enable or disable relaxing of HTTP request parsing
4687 May be used in sections : defaults | frontend | listen | backend
4688 yes | yes | yes | no
4689 Arguments : none
4690
Willy Tarreau91852eb2015-05-01 13:26:00 +02004691 By default, HAProxy complies with RFC7230 in terms of message parsing. This
Willy Tarreau4076a152009-04-02 15:18:36 +02004692 means that invalid characters in header names are not permitted and cause an
4693 error to be returned to the client. This is the desired behaviour as such
4694 forbidden characters are essentially used to build attacks exploiting server
4695 weaknesses, and bypass security filtering. Sometimes, a buggy browser or
4696 server will emit invalid header names for whatever reason (configuration,
4697 implementation) and the issue will not be immediately fixed. In such a case,
4698 it is possible to relax HAProxy's header name parser to accept any character
Willy Tarreau422246e2012-01-07 23:54:13 +01004699 even if that does not make sense, by specifying this option. Similarly, the
4700 list of characters allowed to appear in a URI is well defined by RFC3986, and
4701 chars 0-31, 32 (space), 34 ('"'), 60 ('<'), 62 ('>'), 92 ('\'), 94 ('^'), 96
4702 ('`'), 123 ('{'), 124 ('|'), 125 ('}'), 127 (delete) and anything above are
4703 not allowed at all. Haproxy always blocks a number of them (0..32, 127). The
Willy Tarreau91852eb2015-05-01 13:26:00 +02004704 remaining ones are blocked by default unless this option is enabled. This
Willy Tarreau13317662015-05-01 13:47:08 +02004705 option also relaxes the test on the HTTP version, it allows HTTP/0.9 requests
4706 to pass through (no version specified) and multiple digits for both the major
4707 and the minor version.
Willy Tarreau4076a152009-04-02 15:18:36 +02004708
4709 This option should never be enabled by default as it hides application bugs
4710 and open security breaches. It should only be deployed after a problem has
4711 been confirmed.
4712
4713 When this option is enabled, erroneous header names will still be accepted in
4714 requests, but the complete request will be captured in order to permit later
Willy Tarreau422246e2012-01-07 23:54:13 +01004715 analysis using the "show errors" request on the UNIX stats socket. Similarly,
4716 requests containing invalid chars in the URI part will be logged. Doing this
Willy Tarreau4076a152009-04-02 15:18:36 +02004717 also helps confirming that the issue has been solved.
4718
4719 If this option has been enabled in a "defaults" section, it can be disabled
4720 in a specific instance by prepending the "no" keyword before it.
4721
4722 See also : "option accept-invalid-http-response" and "show errors" on the
4723 stats socket.
4724
4725
4726option accept-invalid-http-response
4727no option accept-invalid-http-response
4728 Enable or disable relaxing of HTTP response parsing
4729 May be used in sections : defaults | frontend | listen | backend
4730 yes | no | yes | yes
4731 Arguments : none
4732
Willy Tarreau91852eb2015-05-01 13:26:00 +02004733 By default, HAProxy complies with RFC7230 in terms of message parsing. This
Willy Tarreau4076a152009-04-02 15:18:36 +02004734 means that invalid characters in header names are not permitted and cause an
4735 error to be returned to the client. This is the desired behaviour as such
4736 forbidden characters are essentially used to build attacks exploiting server
4737 weaknesses, and bypass security filtering. Sometimes, a buggy browser or
4738 server will emit invalid header names for whatever reason (configuration,
4739 implementation) and the issue will not be immediately fixed. In such a case,
4740 it is possible to relax HAProxy's header name parser to accept any character
Willy Tarreau91852eb2015-05-01 13:26:00 +02004741 even if that does not make sense, by specifying this option. This option also
4742 relaxes the test on the HTTP version format, it allows multiple digits for
4743 both the major and the minor version.
Willy Tarreau4076a152009-04-02 15:18:36 +02004744
4745 This option should never be enabled by default as it hides application bugs
4746 and open security breaches. It should only be deployed after a problem has
4747 been confirmed.
4748
4749 When this option is enabled, erroneous header names will still be accepted in
4750 responses, but the complete response will be captured in order to permit
4751 later analysis using the "show errors" request on the UNIX stats socket.
4752 Doing this also helps confirming that the issue has been solved.
4753
4754 If this option has been enabled in a "defaults" section, it can be disabled
4755 in a specific instance by prepending the "no" keyword before it.
4756
4757 See also : "option accept-invalid-http-request" and "show errors" on the
4758 stats socket.
4759
4760
Willy Tarreaubf1f8162007-12-28 17:42:56 +01004761option allbackups
4762no option allbackups
4763 Use either all backup servers at a time or only the first one
4764 May be used in sections : defaults | frontend | listen | backend
4765 yes | no | yes | yes
4766 Arguments : none
4767
4768 By default, the first operational backup server gets all traffic when normal
4769 servers are all down. Sometimes, it may be preferred to use multiple backups
4770 at once, because one will not be enough. When "option allbackups" is enabled,
4771 the load balancing will be performed among all backup servers when all normal
4772 ones are unavailable. The same load balancing algorithm will be used and the
4773 servers' weights will be respected. Thus, there will not be any priority
4774 order between the backup servers anymore.
4775
4776 This option is mostly used with static server farms dedicated to return a
4777 "sorry" page when an application is completely offline.
4778
4779 If this option has been enabled in a "defaults" section, it can be disabled
4780 in a specific instance by prepending the "no" keyword before it.
4781
4782
4783option checkcache
4784no option checkcache
Godbach7056a352013-12-11 20:01:07 +08004785 Analyze all server responses and block responses with cacheable cookies
Willy Tarreaubf1f8162007-12-28 17:42:56 +01004786 May be used in sections : defaults | frontend | listen | backend
4787 yes | no | yes | yes
4788 Arguments : none
4789
4790 Some high-level frameworks set application cookies everywhere and do not
4791 always let enough control to the developer to manage how the responses should
Krzysztof Piotr Oledzkif8645332009-12-13 21:55:50 +01004792 be cached. When a session cookie is returned on a cacheable object, there is a
Willy Tarreaubf1f8162007-12-28 17:42:56 +01004793 high risk of session crossing or stealing between users traversing the same
4794 caches. In some situations, it is better to block the response than to let
Willy Tarreau3c92c5f2011-08-28 09:45:47 +02004795 some sensitive session information go in the wild.
Willy Tarreaubf1f8162007-12-28 17:42:56 +01004796
4797 The option "checkcache" enables deep inspection of all server responses for
Krzysztof Piotr Oledzkif8645332009-12-13 21:55:50 +01004798 strict compliance with HTTP specification in terms of cacheability. It
Willy Tarreau198a7442008-01-17 12:05:32 +01004799 carefully checks "Cache-control", "Pragma" and "Set-cookie" headers in server
Willy Tarreaubf1f8162007-12-28 17:42:56 +01004800 response to check if there's a risk of caching a cookie on a client-side
4801 proxy. When this option is enabled, the only responses which can be delivered
Willy Tarreau198a7442008-01-17 12:05:32 +01004802 to the client are :
4803 - all those without "Set-Cookie" header ;
Willy Tarreaubf1f8162007-12-28 17:42:56 +01004804 - all those with a return code other than 200, 203, 206, 300, 301, 410,
Willy Tarreau198a7442008-01-17 12:05:32 +01004805 provided that the server has not set a "Cache-control: public" header ;
Willy Tarreaubf1f8162007-12-28 17:42:56 +01004806 - all those that come from a POST request, provided that the server has not
4807 set a 'Cache-Control: public' header ;
4808 - those with a 'Pragma: no-cache' header
4809 - those with a 'Cache-control: private' header
4810 - those with a 'Cache-control: no-store' header
4811 - those with a 'Cache-control: max-age=0' header
4812 - those with a 'Cache-control: s-maxage=0' header
4813 - those with a 'Cache-control: no-cache' header
4814 - those with a 'Cache-control: no-cache="set-cookie"' header
4815 - those with a 'Cache-control: no-cache="set-cookie,' header
4816 (allowing other fields after set-cookie)
4817
4818 If a response doesn't respect these requirements, then it will be blocked
Willy Tarreau198a7442008-01-17 12:05:32 +01004819 just as if it was from an "rspdeny" filter, with an "HTTP 502 bad gateway".
Willy Tarreaubf1f8162007-12-28 17:42:56 +01004820 The session state shows "PH--" meaning that the proxy blocked the response
Krzysztof Piotr Oledzkif8645332009-12-13 21:55:50 +01004821 during headers processing. Additionally, an alert will be sent in the logs so
Willy Tarreaubf1f8162007-12-28 17:42:56 +01004822 that admins are informed that there's something to be fixed.
4823
4824 Due to the high impact on the application, the application should be tested
4825 in depth with the option enabled before going to production. It is also a
Willy Tarreaud2a4aa22008-01-31 15:28:22 +01004826 good practice to always activate it during tests, even if it is not used in
Willy Tarreaubf1f8162007-12-28 17:42:56 +01004827 production, as it will report potentially dangerous application behaviours.
4828
4829 If this option has been enabled in a "defaults" section, it can be disabled
4830 in a specific instance by prepending the "no" keyword before it.
4831
4832
4833option clitcpka
4834no option clitcpka
4835 Enable or disable the sending of TCP keepalive packets on the client side
4836 May be used in sections : defaults | frontend | listen | backend
4837 yes | yes | yes | no
4838 Arguments : none
4839
4840 When there is a firewall or any session-aware component between a client and
4841 a server, and when the protocol involves very long sessions with long idle
4842 periods (eg: remote desktops), there is a risk that one of the intermediate
4843 components decides to expire a session which has remained idle for too long.
4844
4845 Enabling socket-level TCP keep-alives makes the system regularly send packets
4846 to the other end of the connection, leaving it active. The delay between
4847 keep-alive probes is controlled by the system only and depends both on the
4848 operating system and its tuning parameters.
4849
4850 It is important to understand that keep-alive packets are neither emitted nor
4851 received at the application level. It is only the network stacks which sees
4852 them. For this reason, even if one side of the proxy already uses keep-alives
4853 to maintain its connection alive, those keep-alive packets will not be
4854 forwarded to the other side of the proxy.
4855
4856 Please note that this has nothing to do with HTTP keep-alive.
4857
4858 Using option "clitcpka" enables the emission of TCP keep-alive probes on the
4859 client side of a connection, which should help when session expirations are
4860 noticed between HAProxy and a client.
4861
4862 If this option has been enabled in a "defaults" section, it can be disabled
4863 in a specific instance by prepending the "no" keyword before it.
4864
4865 See also : "option srvtcpka", "option tcpka"
4866
4867
Willy Tarreau0ba27502007-12-24 16:55:16 +01004868option contstats
4869 Enable continuous traffic statistics updates
4870 May be used in sections : defaults | frontend | listen | backend
4871 yes | yes | yes | no
4872 Arguments : none
4873
4874 By default, counters used for statistics calculation are incremented
4875 only when a session finishes. It works quite well when serving small
4876 objects, but with big ones (for example large images or archives) or
4877 with A/V streaming, a graph generated from haproxy counters looks like
4878 a hedgehog. With this option enabled counters get incremented continuously,
4879 during a whole session. Recounting touches a hotpath directly so
4880 it is not enabled by default, as it has small performance impact (~0.5%).
4881
4882
Willy Tarreauc9bd0cc2009-05-10 11:57:02 +02004883option dontlog-normal
4884no option dontlog-normal
4885 Enable or disable logging of normal, successful connections
4886 May be used in sections : defaults | frontend | listen | backend
4887 yes | yes | yes | no
4888 Arguments : none
4889
4890 There are large sites dealing with several thousand connections per second
4891 and for which logging is a major pain. Some of them are even forced to turn
4892 logs off and cannot debug production issues. Setting this option ensures that
4893 normal connections, those which experience no error, no timeout, no retry nor
4894 redispatch, will not be logged. This leaves disk space for anomalies. In HTTP
4895 mode, the response status code is checked and return codes 5xx will still be
4896 logged.
4897
4898 It is strongly discouraged to use this option as most of the time, the key to
4899 complex issues is in the normal logs which will not be logged here. If you
4900 need to separate logs, see the "log-separate-errors" option instead.
4901
Willy Tarreauc57f0e22009-05-10 13:12:33 +02004902 See also : "log", "dontlognull", "log-separate-errors" and section 8 about
Willy Tarreauc9bd0cc2009-05-10 11:57:02 +02004903 logging.
4904
4905
Willy Tarreaubf1f8162007-12-28 17:42:56 +01004906option dontlognull
4907no option dontlognull
4908 Enable or disable logging of null connections
4909 May be used in sections : defaults | frontend | listen | backend
4910 yes | yes | yes | no
4911 Arguments : none
4912
4913 In certain environments, there are components which will regularly connect to
4914 various systems to ensure that they are still alive. It can be the case from
4915 another load balancer as well as from monitoring systems. By default, even a
4916 simple port probe or scan will produce a log. If those connections pollute
4917 the logs too much, it is possible to enable option "dontlognull" to indicate
4918 that a connection on which no data has been transferred will not be logged,
Willy Tarreau0f228a02015-05-01 15:37:53 +02004919 which typically corresponds to those probes. Note that errors will still be
4920 returned to the client and accounted for in the stats. If this is not what is
4921 desired, option http-ignore-probes can be used instead.
Willy Tarreaubf1f8162007-12-28 17:42:56 +01004922
4923 It is generally recommended not to use this option in uncontrolled
4924 environments (eg: internet), otherwise scans and other malicious activities
4925 would not be logged.
4926
4927 If this option has been enabled in a "defaults" section, it can be disabled
4928 in a specific instance by prepending the "no" keyword before it.
4929
Willy Tarreau0f228a02015-05-01 15:37:53 +02004930 See also : "log", "http-ignore-probes", "monitor-net", "monitor-uri", and
4931 section 8 about logging.
Willy Tarreaubf1f8162007-12-28 17:42:56 +01004932
4933
4934option forceclose
4935no option forceclose
4936 Enable or disable active connection closing after response is transferred.
4937 May be used in sections : defaults | frontend | listen | backend
Willy Tarreaua31e5df2009-12-30 01:10:35 +01004938 yes | yes | yes | yes
Willy Tarreaubf1f8162007-12-28 17:42:56 +01004939 Arguments : none
4940
4941 Some HTTP servers do not necessarily close the connections when they receive
4942 the "Connection: close" set by "option httpclose", and if the client does not
4943 close either, then the connection remains open till the timeout expires. This
4944 causes high number of simultaneous connections on the servers and shows high
4945 global session times in the logs.
4946
4947 When this happens, it is possible to use "option forceclose". It will
Willy Tarreau82eeaf22009-12-29 12:09:05 +01004948 actively close the outgoing server channel as soon as the server has finished
Cyril Bonté653dcd62014-02-20 00:13:15 +01004949 to respond and release some resources earlier than with "option httpclose".
Willy Tarreaubf1f8162007-12-28 17:42:56 +01004950
Willy Tarreau8a8e1d92010-04-05 16:15:16 +02004951 This option may also be combined with "option http-pretend-keepalive", which
4952 will disable sending of the "Connection: close" header, but will still cause
4953 the connection to be closed once the whole response is received.
4954
Cyril Bonté653dcd62014-02-20 00:13:15 +01004955 This option disables and replaces any previous "option httpclose", "option
4956 http-server-close", "option http-keep-alive", or "option http-tunnel".
Willy Tarreau02bce8b2014-01-30 00:15:28 +01004957
Willy Tarreaubf1f8162007-12-28 17:42:56 +01004958 If this option has been enabled in a "defaults" section, it can be disabled
4959 in a specific instance by prepending the "no" keyword before it.
4960
Willy Tarreau8a8e1d92010-04-05 16:15:16 +02004961 See also : "option httpclose" and "option http-pretend-keepalive"
Willy Tarreaubf1f8162007-12-28 17:42:56 +01004962
4963
Willy Tarreau87cf5142011-08-19 22:57:24 +02004964option forwardfor [ except <network> ] [ header <name> ] [ if-none ]
Willy Tarreauc27debf2008-01-06 08:57:02 +01004965 Enable insertion of the X-Forwarded-For header to requests sent to servers
4966 May be used in sections : defaults | frontend | listen | backend
4967 yes | yes | yes | yes
4968 Arguments :
4969 <network> is an optional argument used to disable this option for sources
4970 matching <network>
Ross Westaf72a1d2008-08-03 10:51:45 +02004971 <name> an optional argument to specify a different "X-Forwarded-For"
Willy Tarreaud72758d2010-01-12 10:42:19 +01004972 header name.
Willy Tarreauc27debf2008-01-06 08:57:02 +01004973
4974 Since HAProxy works in reverse-proxy mode, the servers see its IP address as
4975 their client address. This is sometimes annoying when the client's IP address
4976 is expected in server logs. To solve this problem, the well-known HTTP header
4977 "X-Forwarded-For" may be added by HAProxy to all requests sent to the server.
4978 This header contains a value representing the client's IP address. Since this
4979 header is always appended at the end of the existing header list, the server
4980 must be configured to always use the last occurrence of this header only. See
Ross Westaf72a1d2008-08-03 10:51:45 +02004981 the server's manual to find how to enable use of this standard header. Note
4982 that only the last occurrence of the header must be used, since it is really
4983 possible that the client has already brought one.
4984
Willy Tarreaud72758d2010-01-12 10:42:19 +01004985 The keyword "header" may be used to supply a different header name to replace
Ross Westaf72a1d2008-08-03 10:51:45 +02004986 the default "X-Forwarded-For". This can be useful where you might already
Willy Tarreaud72758d2010-01-12 10:42:19 +01004987 have a "X-Forwarded-For" header from a different application (eg: stunnel),
4988 and you need preserve it. Also if your backend server doesn't use the
Ross Westaf72a1d2008-08-03 10:51:45 +02004989 "X-Forwarded-For" header and requires different one (eg: Zeus Web Servers
4990 require "X-Cluster-Client-IP").
Willy Tarreauc27debf2008-01-06 08:57:02 +01004991
4992 Sometimes, a same HAProxy instance may be shared between a direct client
4993 access and a reverse-proxy access (for instance when an SSL reverse-proxy is
4994 used to decrypt HTTPS traffic). It is possible to disable the addition of the
4995 header for a known source address or network by adding the "except" keyword
4996 followed by the network address. In this case, any source IP matching the
4997 network will not cause an addition of this header. Most common uses are with
4998 private networks or 127.0.0.1.
4999
Willy Tarreau87cf5142011-08-19 22:57:24 +02005000 Alternatively, the keyword "if-none" states that the header will only be
5001 added if it is not present. This should only be used in perfectly trusted
5002 environment, as this might cause a security issue if headers reaching haproxy
5003 are under the control of the end-user.
5004
Willy Tarreauc27debf2008-01-06 08:57:02 +01005005 This option may be specified either in the frontend or in the backend. If at
Ross Westaf72a1d2008-08-03 10:51:45 +02005006 least one of them uses it, the header will be added. Note that the backend's
5007 setting of the header subargument takes precedence over the frontend's if
Willy Tarreau87cf5142011-08-19 22:57:24 +02005008 both are defined. In the case of the "if-none" argument, if at least one of
5009 the frontend or the backend does not specify it, it wants the addition to be
5010 mandatory, so it wins.
Willy Tarreauc27debf2008-01-06 08:57:02 +01005011
Ross Westaf72a1d2008-08-03 10:51:45 +02005012 Examples :
Willy Tarreauc27debf2008-01-06 08:57:02 +01005013 # Public HTTP address also used by stunnel on the same machine
5014 frontend www
5015 mode http
5016 option forwardfor except 127.0.0.1 # stunnel already adds the header
5017
Ross Westaf72a1d2008-08-03 10:51:45 +02005018 # Those servers want the IP Address in X-Client
5019 backend www
5020 mode http
5021 option forwardfor header X-Client
5022
Willy Tarreau87cf5142011-08-19 22:57:24 +02005023 See also : "option httpclose", "option http-server-close",
Willy Tarreau70dffda2014-01-30 03:07:23 +01005024 "option forceclose", "option http-keep-alive"
Willy Tarreauc27debf2008-01-06 08:57:02 +01005025
Willy Tarreau8a8e1d92010-04-05 16:15:16 +02005026
Willy Tarreau9fbe18e2015-05-01 22:42:08 +02005027option http-buffer-request
5028no option http-buffer-request
5029 Enable or disable waiting for whole HTTP request body before proceeding
5030 May be used in sections : defaults | frontend | listen | backend
5031 yes | yes | yes | yes
5032 Arguments : none
5033
5034 It is sometimes desirable to wait for the body of an HTTP request before
5035 taking a decision. This is what is being done by "balance url_param" for
5036 example. The first use case is to buffer requests from slow clients before
5037 connecting to the server. Another use case consists in taking the routing
5038 decision based on the request body's contents. This option placed in a
5039 frontend or backend forces the HTTP processing to wait until either the whole
5040 body is received, or the request buffer is full, or the first chunk is
5041 complete in case of chunked encoding. It can have undesired side effects with
5042 some applications abusing HTTP by expecting unbufferred transmissions between
5043 the frontend and the backend, so this should definitely not be used by
5044 default.
5045
5046 See also : "option http-no-delay"
5047
5048
Willy Tarreau0f228a02015-05-01 15:37:53 +02005049option http-ignore-probes
5050no option http-ignore-probes
5051 Enable or disable logging of null connections and request timeouts
5052 May be used in sections : defaults | frontend | listen | backend
5053 yes | yes | yes | no
5054 Arguments : none
5055
5056 Recently some browsers started to implement a "pre-connect" feature
5057 consisting in speculatively connecting to some recently visited web sites
5058 just in case the user would like to visit them. This results in many
5059 connections being established to web sites, which end up in 408 Request
5060 Timeout if the timeout strikes first, or 400 Bad Request when the browser
5061 decides to close them first. These ones pollute the log and feed the error
5062 counters. There was already "option dontlognull" but it's insufficient in
5063 this case. Instead, this option does the following things :
5064 - prevent any 400/408 message from being sent to the client if nothing
5065 was received over a connection before it was closed ;
5066 - prevent any log from being emitted in this situation ;
5067 - prevent any error counter from being incremented
5068
5069 That way the empty connection is silently ignored. Note that it is better
5070 not to use this unless it is clear that it is needed, because it will hide
5071 real problems. The most common reason for not receiving a request and seeing
5072 a 408 is due to an MTU inconsistency between the client and an intermediary
5073 element such as a VPN, which blocks too large packets. These issues are
5074 generally seen with POST requests as well as GET with large cookies. The logs
5075 are often the only way to detect them.
5076
5077 If this option has been enabled in a "defaults" section, it can be disabled
5078 in a specific instance by prepending the "no" keyword before it.
5079
5080 See also : "log", "dontlognull", "errorfile", and section 8 about logging.
5081
5082
Willy Tarreau16bfb022010-01-16 19:48:41 +01005083option http-keep-alive
5084no option http-keep-alive
5085 Enable or disable HTTP keep-alive from client to server
5086 May be used in sections : defaults | frontend | listen | backend
5087 yes | yes | yes | yes
5088 Arguments : none
5089
Willy Tarreau70dffda2014-01-30 03:07:23 +01005090 By default HAProxy operates in keep-alive mode with regards to persistent
5091 connections: for each connection it processes each request and response, and
5092 leaves the connection idle on both sides between the end of a response and the
5093 start of a new request. This mode may be changed by several options such as
5094 "option http-server-close", "option forceclose", "option httpclose" or
5095 "option http-tunnel". This option allows to set back the keep-alive mode,
5096 which can be useful when another mode was used in a defaults section.
5097
5098 Setting "option http-keep-alive" enables HTTP keep-alive mode on the client-
5099 and server- sides. This provides the lowest latency on the client side (slow
Willy Tarreau16bfb022010-01-16 19:48:41 +01005100 network) and the fastest session reuse on the server side at the expense
5101 of maintaining idle connections to the servers. In general, it is possible
5102 with this option to achieve approximately twice the request rate that the
5103 "http-server-close" option achieves on small objects. There are mainly two
5104 situations where this option may be useful :
5105
5106 - when the server is non-HTTP compliant and authenticates the connection
5107 instead of requests (eg: NTLM authentication)
5108
5109 - when the cost of establishing the connection to the server is significant
5110 compared to the cost of retrieving the associated object from the server.
5111
5112 This last case can happen when the server is a fast static server of cache.
5113 In this case, the server will need to be properly tuned to support high enough
5114 connection counts because connections will last until the client sends another
5115 request.
5116
5117 If the client request has to go to another backend or another server due to
5118 content switching or the load balancing algorithm, the idle connection will
Willy Tarreau9420b122013-12-15 18:58:25 +01005119 immediately be closed and a new one re-opened. Option "prefer-last-server" is
5120 available to try optimize server selection so that if the server currently
5121 attached to an idle connection is usable, it will be used.
Willy Tarreau16bfb022010-01-16 19:48:41 +01005122
5123 In general it is preferred to use "option http-server-close" with application
5124 servers, and some static servers might benefit from "option http-keep-alive".
5125
5126 At the moment, logs will not indicate whether requests came from the same
5127 session or not. The accept date reported in the logs corresponds to the end
5128 of the previous request, and the request time corresponds to the time spent
5129 waiting for a new request. The keep-alive request time is still bound to the
5130 timeout defined by "timeout http-keep-alive" or "timeout http-request" if
5131 not set.
5132
Cyril Bonté653dcd62014-02-20 00:13:15 +01005133 This option disables and replaces any previous "option httpclose", "option
5134 http-server-close", "option forceclose" or "option http-tunnel". When backend
Willy Tarreau70dffda2014-01-30 03:07:23 +01005135 and frontend options differ, all of these 4 options have precedence over
Cyril Bonté653dcd62014-02-20 00:13:15 +01005136 "option http-keep-alive".
Willy Tarreau16bfb022010-01-16 19:48:41 +01005137
5138 See also : "option forceclose", "option http-server-close",
Willy Tarreau9420b122013-12-15 18:58:25 +01005139 "option prefer-last-server", "option http-pretend-keepalive",
5140 "option httpclose", and "1.1. The HTTP transaction model".
Willy Tarreau16bfb022010-01-16 19:48:41 +01005141
5142
Willy Tarreau96e31212011-05-30 18:10:30 +02005143option http-no-delay
5144no option http-no-delay
5145 Instruct the system to favor low interactive delays over performance in HTTP
5146 May be used in sections : defaults | frontend | listen | backend
5147 yes | yes | yes | yes
5148 Arguments : none
5149
5150 In HTTP, each payload is unidirectional and has no notion of interactivity.
5151 Any agent is expected to queue data somewhat for a reasonably low delay.
5152 There are some very rare server-to-server applications that abuse the HTTP
5153 protocol and expect the payload phase to be highly interactive, with many
5154 interleaved data chunks in both directions within a single request. This is
5155 absolutely not supported by the HTTP specification and will not work across
5156 most proxies or servers. When such applications attempt to do this through
5157 haproxy, it works but they will experience high delays due to the network
5158 optimizations which favor performance by instructing the system to wait for
5159 enough data to be available in order to only send full packets. Typical
5160 delays are around 200 ms per round trip. Note that this only happens with
5161 abnormal uses. Normal uses such as CONNECT requests nor WebSockets are not
5162 affected.
5163
5164 When "option http-no-delay" is present in either the frontend or the backend
5165 used by a connection, all such optimizations will be disabled in order to
5166 make the exchanges as fast as possible. Of course this offers no guarantee on
5167 the functionality, as it may break at any other place. But if it works via
5168 HAProxy, it will work as fast as possible. This option should never be used
5169 by default, and should never be used at all unless such a buggy application
5170 is discovered. The impact of using this option is an increase of bandwidth
5171 usage and CPU usage, which may significantly lower performance in high
5172 latency environments.
5173
Willy Tarreau9fbe18e2015-05-01 22:42:08 +02005174 See also : "option http-buffer-request"
5175
Willy Tarreau96e31212011-05-30 18:10:30 +02005176
Willy Tarreau8a8e1d92010-04-05 16:15:16 +02005177option http-pretend-keepalive
5178no option http-pretend-keepalive
5179 Define whether haproxy will announce keepalive to the server or not
5180 May be used in sections : defaults | frontend | listen | backend
5181 yes | yes | yes | yes
5182 Arguments : none
5183
5184 When running with "option http-server-close" or "option forceclose", haproxy
5185 adds a "Connection: close" header to the request forwarded to the server.
5186 Unfortunately, when some servers see this header, they automatically refrain
5187 from using the chunked encoding for responses of unknown length, while this
5188 is totally unrelated. The immediate effect is that this prevents haproxy from
5189 maintaining the client connection alive. A second effect is that a client or
5190 a cache could receive an incomplete response without being aware of it, and
5191 consider the response complete.
5192
5193 By setting "option http-pretend-keepalive", haproxy will make the server
5194 believe it will keep the connection alive. The server will then not fall back
5195 to the abnormal undesired above. When haproxy gets the whole response, it
5196 will close the connection with the server just as it would do with the
5197 "forceclose" option. That way the client gets a normal response and the
5198 connection is correctly closed on the server side.
5199
5200 It is recommended not to enable this option by default, because most servers
5201 will more efficiently close the connection themselves after the last packet,
5202 and release its buffers slightly earlier. Also, the added packet on the
5203 network could slightly reduce the overall peak performance. However it is
5204 worth noting that when this option is enabled, haproxy will have slightly
5205 less work to do. So if haproxy is the bottleneck on the whole architecture,
5206 enabling this option might save a few CPU cycles.
5207
5208 This option may be set both in a frontend and in a backend. It is enabled if
5209 at least one of the frontend or backend holding a connection has it enabled.
Jamie Gloudonaaa21002012-08-25 00:18:33 -04005210 This option may be combined with "option httpclose", which will cause
Willy Tarreau22a95342010-09-29 14:31:41 +02005211 keepalive to be announced to the server and close to be announced to the
5212 client. This practice is discouraged though.
Willy Tarreau8a8e1d92010-04-05 16:15:16 +02005213
5214 If this option has been enabled in a "defaults" section, it can be disabled
5215 in a specific instance by prepending the "no" keyword before it.
5216
Willy Tarreau16bfb022010-01-16 19:48:41 +01005217 See also : "option forceclose", "option http-server-close", and
5218 "option http-keep-alive"
Willy Tarreau8a8e1d92010-04-05 16:15:16 +02005219
Willy Tarreauc27debf2008-01-06 08:57:02 +01005220
Willy Tarreaub608feb2010-01-02 22:47:18 +01005221option http-server-close
5222no option http-server-close
5223 Enable or disable HTTP connection closing on the server side
5224 May be used in sections : defaults | frontend | listen | backend
5225 yes | yes | yes | yes
5226 Arguments : none
5227
Willy Tarreau70dffda2014-01-30 03:07:23 +01005228 By default HAProxy operates in keep-alive mode with regards to persistent
5229 connections: for each connection it processes each request and response, and
5230 leaves the connection idle on both sides between the end of a response and
5231 the start of a new request. This mode may be changed by several options such
5232 as "option http-server-close", "option forceclose", "option httpclose" or
5233 "option http-tunnel". Setting "option http-server-close" enables HTTP
5234 connection-close mode on the server side while keeping the ability to support
5235 HTTP keep-alive and pipelining on the client side. This provides the lowest
5236 latency on the client side (slow network) and the fastest session reuse on
5237 the server side to save server resources, similarly to "option forceclose".
5238 It also permits non-keepalive capable servers to be served in keep-alive mode
5239 to the clients if they conform to the requirements of RFC2616. Please note
5240 that some servers do not always conform to those requirements when they see
5241 "Connection: close" in the request. The effect will be that keep-alive will
5242 never be used. A workaround consists in enabling "option
5243 http-pretend-keepalive".
Willy Tarreaub608feb2010-01-02 22:47:18 +01005244
5245 At the moment, logs will not indicate whether requests came from the same
5246 session or not. The accept date reported in the logs corresponds to the end
5247 of the previous request, and the request time corresponds to the time spent
5248 waiting for a new request. The keep-alive request time is still bound to the
Willy Tarreaub16a5742010-01-10 14:46:16 +01005249 timeout defined by "timeout http-keep-alive" or "timeout http-request" if
5250 not set.
Willy Tarreaub608feb2010-01-02 22:47:18 +01005251
5252 This option may be set both in a frontend and in a backend. It is enabled if
5253 at least one of the frontend or backend holding a connection has it enabled.
Cyril Bonté653dcd62014-02-20 00:13:15 +01005254 It disables and replaces any previous "option httpclose", "option forceclose",
5255 "option http-tunnel" or "option http-keep-alive". Please check section 4
Willy Tarreau70dffda2014-01-30 03:07:23 +01005256 ("Proxies") to see how this option combines with others when frontend and
5257 backend options differ.
Willy Tarreaub608feb2010-01-02 22:47:18 +01005258
5259 If this option has been enabled in a "defaults" section, it can be disabled
5260 in a specific instance by prepending the "no" keyword before it.
5261
Patrick Mezard9ec2ec42010-06-12 17:02:45 +02005262 See also : "option forceclose", "option http-pretend-keepalive",
Willy Tarreau16bfb022010-01-16 19:48:41 +01005263 "option httpclose", "option http-keep-alive", and
5264 "1.1. The HTTP transaction model".
Willy Tarreaub608feb2010-01-02 22:47:18 +01005265
5266
Willy Tarreau02bce8b2014-01-30 00:15:28 +01005267option http-tunnel
5268no option http-tunnel
5269 Disable or enable HTTP connection processing after first transaction
5270 May be used in sections : defaults | frontend | listen | backend
5271 yes | yes | yes | yes
5272 Arguments : none
5273
Willy Tarreau70dffda2014-01-30 03:07:23 +01005274 By default HAProxy operates in keep-alive mode with regards to persistent
5275 connections: for each connection it processes each request and response, and
5276 leaves the connection idle on both sides between the end of a response and
5277 the start of a new request. This mode may be changed by several options such
5278 as "option http-server-close", "option forceclose", "option httpclose" or
5279 "option http-tunnel".
5280
5281 Option "http-tunnel" disables any HTTP processing past the first request and
Jarno Huuskonen0e82b922014-04-12 18:22:19 +03005282 the first response. This is the mode which was used by default in versions
Willy Tarreau70dffda2014-01-30 03:07:23 +01005283 1.0 to 1.5-dev21. It is the mode with the lowest processing overhead, which
5284 is normally not needed anymore unless in very specific cases such as when
5285 using an in-house protocol that looks like HTTP but is not compatible, or
5286 just to log one request per client in order to reduce log size. Note that
5287 everything which works at the HTTP level, including header parsing/addition,
5288 cookie processing or content switching will only work for the first request
5289 and will be ignored after the first response.
Willy Tarreau02bce8b2014-01-30 00:15:28 +01005290
5291 If this option has been enabled in a "defaults" section, it can be disabled
5292 in a specific instance by prepending the "no" keyword before it.
5293
5294 See also : "option forceclose", "option http-server-close",
5295 "option httpclose", "option http-keep-alive", and
5296 "1.1. The HTTP transaction model".
5297
5298
Willy Tarreau88d349d2010-01-25 12:15:43 +01005299option http-use-proxy-header
Cyril Bontéf0c60612010-02-06 14:44:47 +01005300no option http-use-proxy-header
Willy Tarreau88d349d2010-01-25 12:15:43 +01005301 Make use of non-standard Proxy-Connection header instead of Connection
5302 May be used in sections : defaults | frontend | listen | backend
5303 yes | yes | yes | no
5304 Arguments : none
5305
5306 While RFC2616 explicitly states that HTTP/1.1 agents must use the
5307 Connection header to indicate their wish of persistent or non-persistent
5308 connections, both browsers and proxies ignore this header for proxied
5309 connections and make use of the undocumented, non-standard Proxy-Connection
5310 header instead. The issue begins when trying to put a load balancer between
5311 browsers and such proxies, because there will be a difference between what
5312 haproxy understands and what the client and the proxy agree on.
5313
5314 By setting this option in a frontend, haproxy can automatically switch to use
5315 that non-standard header if it sees proxied requests. A proxied request is
5316 defined here as one where the URI begins with neither a '/' nor a '*'. The
5317 choice of header only affects requests passing through proxies making use of
5318 one of the "httpclose", "forceclose" and "http-server-close" options. Note
5319 that this option can only be specified in a frontend and will affect the
5320 request along its whole life.
5321
Willy Tarreau844a7e72010-01-31 21:46:18 +01005322 Also, when this option is set, a request which requires authentication will
5323 automatically switch to use proxy authentication headers if it is itself a
5324 proxied request. That makes it possible to check or enforce authentication in
5325 front of an existing proxy.
5326
Willy Tarreau88d349d2010-01-25 12:15:43 +01005327 This option should normally never be used, except in front of a proxy.
5328
5329 See also : "option httpclose", "option forceclose" and "option
5330 http-server-close".
5331
5332
Willy Tarreaud63335a2010-02-26 12:56:52 +01005333option httpchk
5334option httpchk <uri>
5335option httpchk <method> <uri>
5336option httpchk <method> <uri> <version>
5337 Enable HTTP protocol to check on the servers health
5338 May be used in sections : defaults | frontend | listen | backend
5339 yes | no | yes | yes
5340 Arguments :
5341 <method> is the optional HTTP method used with the requests. When not set,
5342 the "OPTIONS" method is used, as it generally requires low server
5343 processing and is easy to filter out from the logs. Any method
5344 may be used, though it is not recommended to invent non-standard
5345 ones.
5346
5347 <uri> is the URI referenced in the HTTP requests. It defaults to " / "
5348 which is accessible by default on almost any server, but may be
5349 changed to any other URI. Query strings are permitted.
5350
5351 <version> is the optional HTTP version string. It defaults to "HTTP/1.0"
5352 but some servers might behave incorrectly in HTTP 1.0, so turning
5353 it to HTTP/1.1 may sometimes help. Note that the Host field is
5354 mandatory in HTTP/1.1, and as a trick, it is possible to pass it
5355 after "\r\n" following the version string.
5356
5357 By default, server health checks only consist in trying to establish a TCP
5358 connection. When "option httpchk" is specified, a complete HTTP request is
5359 sent once the TCP connection is established, and responses 2xx and 3xx are
5360 considered valid, while all other ones indicate a server failure, including
5361 the lack of any response.
5362
5363 The port and interval are specified in the server configuration.
5364
5365 This option does not necessarily require an HTTP backend, it also works with
5366 plain TCP backends. This is particularly useful to check simple scripts bound
5367 to some dedicated ports using the inetd daemon.
5368
5369 Examples :
5370 # Relay HTTPS traffic to Apache instance and check service availability
5371 # using HTTP request "OPTIONS * HTTP/1.1" on port 80.
5372 backend https_relay
5373 mode tcp
5374 option httpchk OPTIONS * HTTP/1.1\r\nHost:\ www
5375 server apache1 192.168.1.1:443 check port 80
5376
Simon Hormanafc47ee2013-11-25 10:46:35 +09005377 See also : "option ssl-hello-chk", "option smtpchk", "option mysql-check",
5378 "option pgsql-check", "http-check" and the "check", "port" and
5379 "inter" server options.
Willy Tarreaud63335a2010-02-26 12:56:52 +01005380
5381
Willy Tarreauc27debf2008-01-06 08:57:02 +01005382option httpclose
5383no option httpclose
5384 Enable or disable passive HTTP connection closing
5385 May be used in sections : defaults | frontend | listen | backend
5386 yes | yes | yes | yes
5387 Arguments : none
5388
Willy Tarreau70dffda2014-01-30 03:07:23 +01005389 By default HAProxy operates in keep-alive mode with regards to persistent
5390 connections: for each connection it processes each request and response, and
5391 leaves the connection idle on both sides between the end of a response and
5392 the start of a new request. This mode may be changed by several options such
Cyril Bonté653dcd62014-02-20 00:13:15 +01005393 as "option http-server-close", "option forceclose", "option httpclose" or
Willy Tarreau70dffda2014-01-30 03:07:23 +01005394 "option http-tunnel".
5395
5396 If "option httpclose" is set, HAProxy will work in HTTP tunnel mode and check
5397 if a "Connection: close" header is already set in each direction, and will
5398 add one if missing. Each end should react to this by actively closing the TCP
5399 connection after each transfer, thus resulting in a switch to the HTTP close
5400 mode. Any "Connection" header different from "close" will also be removed.
5401 Note that this option is deprecated since what it does is very cheap but not
5402 reliable. Using "option http-server-close" or "option forceclose" is strongly
5403 recommended instead.
Willy Tarreauc27debf2008-01-06 08:57:02 +01005404
5405 It seldom happens that some servers incorrectly ignore this header and do not
Jamie Gloudonaaa21002012-08-25 00:18:33 -04005406 close the connection even though they reply "Connection: close". For this
Willy Tarreau0dfdf192010-01-05 11:33:11 +01005407 reason, they are not compatible with older HTTP 1.0 browsers. If this happens
5408 it is possible to use the "option forceclose" which actively closes the
5409 request connection once the server responds. Option "forceclose" also
5410 releases the server connection earlier because it does not have to wait for
5411 the client to acknowledge it.
Willy Tarreauc27debf2008-01-06 08:57:02 +01005412
5413 This option may be set both in a frontend and in a backend. It is enabled if
5414 at least one of the frontend or backend holding a connection has it enabled.
Cyril Bonté653dcd62014-02-20 00:13:15 +01005415 It disables and replaces any previous "option http-server-close",
5416 "option forceclose", "option http-keep-alive" or "option http-tunnel". Please
Willy Tarreau70dffda2014-01-30 03:07:23 +01005417 check section 4 ("Proxies") to see how this option combines with others when
5418 frontend and backend options differ.
Willy Tarreauc27debf2008-01-06 08:57:02 +01005419
5420 If this option has been enabled in a "defaults" section, it can be disabled
5421 in a specific instance by prepending the "no" keyword before it.
5422
Patrick Mezard9ec2ec42010-06-12 17:02:45 +02005423 See also : "option forceclose", "option http-server-close" and
5424 "1.1. The HTTP transaction model".
Willy Tarreauc27debf2008-01-06 08:57:02 +01005425
5426
Emeric Brun3a058f32009-06-30 18:26:00 +02005427option httplog [ clf ]
Willy Tarreauc27debf2008-01-06 08:57:02 +01005428 Enable logging of HTTP request, session state and timers
5429 May be used in sections : defaults | frontend | listen | backend
5430 yes | yes | yes | yes
Emeric Brun3a058f32009-06-30 18:26:00 +02005431 Arguments :
5432 clf if the "clf" argument is added, then the output format will be
5433 the CLF format instead of HAProxy's default HTTP format. You can
5434 use this when you need to feed HAProxy's logs through a specific
5435 log analyser which only support the CLF format and which is not
5436 extensible.
Willy Tarreauc27debf2008-01-06 08:57:02 +01005437
5438 By default, the log output format is very poor, as it only contains the
5439 source and destination addresses, and the instance name. By specifying
5440 "option httplog", each log line turns into a much richer format including,
5441 but not limited to, the HTTP request, the connection timers, the session
5442 status, the connections numbers, the captured headers and cookies, the
5443 frontend, backend and server name, and of course the source address and
5444 ports.
5445
5446 This option may be set either in the frontend or the backend.
5447
PiBa-NLbd556bf2014-12-11 21:31:54 +01005448 Specifying only "option httplog" will automatically clear the 'clf' mode
5449 if it was set by default.
Emeric Brun3a058f32009-06-30 18:26:00 +02005450
Willy Tarreauc57f0e22009-05-10 13:12:33 +02005451 See also : section 8 about logging.
Willy Tarreauc27debf2008-01-06 08:57:02 +01005452
Willy Tarreau55165fe2009-05-10 12:02:55 +02005453
5454option http_proxy
5455no option http_proxy
5456 Enable or disable plain HTTP proxy mode
5457 May be used in sections : defaults | frontend | listen | backend
5458 yes | yes | yes | yes
5459 Arguments : none
5460
5461 It sometimes happens that people need a pure HTTP proxy which understands
5462 basic proxy requests without caching nor any fancy feature. In this case,
5463 it may be worth setting up an HAProxy instance with the "option http_proxy"
5464 set. In this mode, no server is declared, and the connection is forwarded to
5465 the IP address and port found in the URL after the "http://" scheme.
5466
5467 No host address resolution is performed, so this only works when pure IP
5468 addresses are passed. Since this option's usage perimeter is rather limited,
5469 it will probably be used only by experts who know they need exactly it. Last,
5470 if the clients are susceptible of sending keep-alive requests, it will be
Cyril Bonté2409e682010-12-14 22:47:51 +01005471 needed to add "option httpclose" to ensure that all requests will correctly
Willy Tarreau55165fe2009-05-10 12:02:55 +02005472 be analyzed.
5473
5474 If this option has been enabled in a "defaults" section, it can be disabled
5475 in a specific instance by prepending the "no" keyword before it.
5476
5477 Example :
5478 # this backend understands HTTP proxy requests and forwards them directly.
5479 backend direct_forward
5480 option httpclose
5481 option http_proxy
5482
5483 See also : "option httpclose"
5484
Willy Tarreau211ad242009-10-03 21:45:07 +02005485
Jamie Gloudon801a0a32012-08-25 00:18:33 -04005486option independent-streams
5487no option independent-streams
5488 Enable or disable independent timeout processing for both directions
Willy Tarreauf27b5ea2009-10-03 22:01:18 +02005489 May be used in sections : defaults | frontend | listen | backend
5490 yes | yes | yes | yes
5491 Arguments : none
5492
5493 By default, when data is sent over a socket, both the write timeout and the
5494 read timeout for that socket are refreshed, because we consider that there is
5495 activity on that socket, and we have no other means of guessing if we should
5496 receive data or not.
5497
5498 While this default behaviour is desirable for almost all applications, there
5499 exists a situation where it is desirable to disable it, and only refresh the
5500 read timeout if there are incoming data. This happens on sessions with large
5501 timeouts and low amounts of exchanged data such as telnet session. If the
5502 server suddenly disappears, the output data accumulates in the system's
5503 socket buffers, both timeouts are correctly refreshed, and there is no way
5504 to know the server does not receive them, so we don't timeout. However, when
5505 the underlying protocol always echoes sent data, it would be enough by itself
5506 to detect the issue using the read timeout. Note that this problem does not
5507 happen with more verbose protocols because data won't accumulate long in the
5508 socket buffers.
5509
5510 When this option is set on the frontend, it will disable read timeout updates
5511 on data sent to the client. There probably is little use of this case. When
5512 the option is set on the backend, it will disable read timeout updates on
5513 data sent to the server. Doing so will typically break large HTTP posts from
5514 slow lines, so use it with caution.
5515
Jarno Huuskonen0e82b922014-04-12 18:22:19 +03005516 Note: older versions used to call this setting "option independent-streams"
Jamie Gloudon801a0a32012-08-25 00:18:33 -04005517 with a spelling mistake. This spelling is still supported but
5518 deprecated.
5519
Willy Tarreauce887fd2012-05-12 12:50:00 +02005520 See also : "timeout client", "timeout server" and "timeout tunnel"
Willy Tarreauf27b5ea2009-10-03 22:01:18 +02005521
5522
Gabor Lekenyb4c81e42010-09-29 18:17:05 +02005523option ldap-check
5524 Use LDAPv3 health checks for server testing
5525 May be used in sections : defaults | frontend | listen | backend
5526 yes | no | yes | yes
5527 Arguments : none
5528
5529 It is possible to test that the server correctly talks LDAPv3 instead of just
5530 testing that it accepts the TCP connection. When this option is set, an
5531 LDAPv3 anonymous simple bind message is sent to the server, and the response
5532 is analyzed to find an LDAPv3 bind response message.
5533
5534 The server is considered valid only when the LDAP response contains success
5535 resultCode (http://tools.ietf.org/html/rfc4511#section-4.1.9).
5536
5537 Logging of bind requests is server dependent see your documentation how to
5538 configure it.
5539
5540 Example :
5541 option ldap-check
5542
5543 See also : "option httpchk"
5544
5545
Simon Horman98637e52014-06-20 12:30:16 +09005546option external-check
5547 Use external processes for server health checks
5548 May be used in sections : defaults | frontend | listen | backend
5549 yes | no | yes | yes
5550
5551 It is possible to test the health of a server using an external command.
5552 This is achieved by running the executable set using "external-check
5553 command".
5554
5555 Requires the "external-check" global to be set.
5556
5557 See also : "external-check", "external-check command", "external-check path"
5558
5559
Willy Tarreau211ad242009-10-03 21:45:07 +02005560option log-health-checks
5561no option log-health-checks
Willy Tarreaubef1b322014-05-13 21:01:39 +02005562 Enable or disable logging of health checks status updates
Willy Tarreau211ad242009-10-03 21:45:07 +02005563 May be used in sections : defaults | frontend | listen | backend
5564 yes | no | yes | yes
5565 Arguments : none
5566
Willy Tarreaubef1b322014-05-13 21:01:39 +02005567 By default, failed health check are logged if server is UP and successful
5568 health checks are logged if server is DOWN, so the amount of additional
5569 information is limited.
Willy Tarreau211ad242009-10-03 21:45:07 +02005570
Willy Tarreaubef1b322014-05-13 21:01:39 +02005571 When this option is enabled, any change of the health check status or to
5572 the server's health will be logged, so that it becomes possible to know
5573 that a server was failing occasional checks before crashing, or exactly when
5574 it failed to respond a valid HTTP status, then when the port started to
5575 reject connections, then when the server stopped responding at all.
5576
5577 Note that status changes not caused by health checks (eg: enable/disable on
5578 the CLI) are intentionally not logged by this option.
Willy Tarreau211ad242009-10-03 21:45:07 +02005579
Willy Tarreaubef1b322014-05-13 21:01:39 +02005580 See also: "option httpchk", "option ldap-check", "option mysql-check",
5581 "option pgsql-check", "option redis-check", "option smtpchk",
5582 "option tcp-check", "log" and section 8 about logging.
Willy Tarreau211ad242009-10-03 21:45:07 +02005583
Willy Tarreauc9bd0cc2009-05-10 11:57:02 +02005584
5585option log-separate-errors
5586no option log-separate-errors
5587 Change log level for non-completely successful connections
5588 May be used in sections : defaults | frontend | listen | backend
5589 yes | yes | yes | no
5590 Arguments : none
5591
5592 Sometimes looking for errors in logs is not easy. This option makes haproxy
5593 raise the level of logs containing potentially interesting information such
5594 as errors, timeouts, retries, redispatches, or HTTP status codes 5xx. The
5595 level changes from "info" to "err". This makes it possible to log them
5596 separately to a different file with most syslog daemons. Be careful not to
5597 remove them from the original file, otherwise you would lose ordering which
5598 provides very important information.
5599
5600 Using this option, large sites dealing with several thousand connections per
5601 second may log normal traffic to a rotating buffer and only archive smaller
5602 error logs.
5603
Willy Tarreauc57f0e22009-05-10 13:12:33 +02005604 See also : "log", "dontlognull", "dontlog-normal" and section 8 about
Willy Tarreauc9bd0cc2009-05-10 11:57:02 +02005605 logging.
5606
Willy Tarreauc27debf2008-01-06 08:57:02 +01005607
5608option logasap
5609no option logasap
5610 Enable or disable early logging of HTTP requests
5611 May be used in sections : defaults | frontend | listen | backend
5612 yes | yes | yes | no
5613 Arguments : none
5614
5615 By default, HTTP requests are logged upon termination so that the total
5616 transfer time and the number of bytes appear in the logs. When large objects
5617 are being transferred, it may take a while before the request appears in the
5618 logs. Using "option logasap", the request gets logged as soon as the server
5619 sends the complete headers. The only missing information in the logs will be
5620 the total number of bytes which will indicate everything except the amount
5621 of data transferred, and the total time which will not take the transfer
Willy Tarreaud2a4aa22008-01-31 15:28:22 +01005622 time into account. In such a situation, it's a good practice to capture the
Willy Tarreauc27debf2008-01-06 08:57:02 +01005623 "Content-Length" response header so that the logs at least indicate how many
5624 bytes are expected to be transferred.
5625
Willy Tarreaucc6c8912009-02-22 10:53:55 +01005626 Examples :
5627 listen http_proxy 0.0.0.0:80
5628 mode http
5629 option httplog
5630 option logasap
5631 log 192.168.2.200 local3
5632
5633 >>> Feb 6 12:14:14 localhost \
5634 haproxy[14389]: 10.0.1.2:33317 [06/Feb/2009:12:14:14.655] http-in \
5635 static/srv1 9/10/7/14/+30 200 +243 - - ---- 3/1/1/1/0 1/0 \
5636 "GET /image.iso HTTP/1.0"
5637
Willy Tarreauc57f0e22009-05-10 13:12:33 +02005638 See also : "option httplog", "capture response header", and section 8 about
Willy Tarreauc27debf2008-01-06 08:57:02 +01005639 logging.
5640
5641
Nenad Merdanovic6639a7c2014-05-30 14:26:32 +02005642option mysql-check [ user <username> [ post-41 ] ]
Hervé COMMOWICK8776f1b2010-10-18 15:58:36 +02005643 Use MySQL health checks for server testing
Hervé COMMOWICK698ae002010-01-12 09:25:13 +01005644 May be used in sections : defaults | frontend | listen | backend
5645 yes | no | yes | yes
Hervé COMMOWICK8776f1b2010-10-18 15:58:36 +02005646 Arguments :
Cyril Bonté108cf6e2012-04-21 23:30:29 +02005647 <username> This is the username which will be used when connecting to MySQL
5648 server.
Nenad Merdanovic6639a7c2014-05-30 14:26:32 +02005649 post-41 Send post v4.1 client compatible checks
Hervé COMMOWICK8776f1b2010-10-18 15:58:36 +02005650
5651 If you specify a username, the check consists of sending two MySQL packet,
5652 one Client Authentication packet, and one QUIT packet, to correctly close
5653 MySQL session. We then parse the MySQL Handshake Initialisation packet and/or
5654 Error packet. It is a basic but useful test which does not produce error nor
5655 aborted connect on the server. However, it requires adding an authorization
5656 in the MySQL table, like this :
5657
5658 USE mysql;
5659 INSERT INTO user (Host,User) values ('<ip_of_haproxy>','<username>');
5660 FLUSH PRIVILEGES;
5661
5662 If you don't specify a username (it is deprecated and not recommended), the
5663 check only consists in parsing the Mysql Handshake Initialisation packet or
5664 Error packet, we don't send anything in this mode. It was reported that it
5665 can generate lockout if check is too frequent and/or if there is not enough
5666 traffic. In fact, you need in this case to check MySQL "max_connect_errors"
5667 value as if a connection is established successfully within fewer than MySQL
5668 "max_connect_errors" attempts after a previous connection was interrupted,
5669 the error count for the host is cleared to zero. If HAProxy's server get
5670 blocked, the "FLUSH HOSTS" statement is the only way to unblock it.
5671
5672 Remember that this does not check database presence nor database consistency.
5673 To do this, you can use an external check with xinetd for example.
Hervé COMMOWICK698ae002010-01-12 09:25:13 +01005674
Hervé COMMOWICK212f7782011-06-10 14:05:59 +02005675 The check requires MySQL >=3.22, for older version, please use TCP check.
Hervé COMMOWICK698ae002010-01-12 09:25:13 +01005676
5677 Most often, an incoming MySQL server needs to see the client's IP address for
5678 various purposes, including IP privilege matching and connection logging.
5679 When possible, it is often wise to masquerade the client's IP address when
5680 connecting to the server using the "usesrc" argument of the "source" keyword,
Willy Tarreau29fbe512015-08-20 19:35:14 +02005681 which requires the transparent proxy feature to be compiled in, and the MySQL
5682 server to route the client via the machine hosting haproxy.
Hervé COMMOWICK698ae002010-01-12 09:25:13 +01005683
5684 See also: "option httpchk"
5685
5686
Willy Tarreaua453bdd2008-01-08 19:50:52 +01005687option nolinger
5688no option nolinger
Krzysztof Piotr Oledzkif8645332009-12-13 21:55:50 +01005689 Enable or disable immediate session resource cleaning after close
Willy Tarreaua453bdd2008-01-08 19:50:52 +01005690 May be used in sections: defaults | frontend | listen | backend
5691 yes | yes | yes | yes
Willy Tarreaueabeafa2008-01-16 16:17:06 +01005692 Arguments : none
Willy Tarreaua453bdd2008-01-08 19:50:52 +01005693
5694 When clients or servers abort connections in a dirty way (eg: they are
5695 physically disconnected), the session timeouts triggers and the session is
5696 closed. But it will remain in FIN_WAIT1 state for some time in the system,
5697 using some resources and possibly limiting the ability to establish newer
5698 connections.
5699
5700 When this happens, it is possible to activate "option nolinger" which forces
5701 the system to immediately remove any socket's pending data on close. Thus,
5702 the session is instantly purged from the system's tables. This usually has
5703 side effects such as increased number of TCP resets due to old retransmits
5704 getting immediately rejected. Some firewalls may sometimes complain about
5705 this too.
5706
5707 For this reason, it is not recommended to use this option when not absolutely
5708 needed. You know that you need it when you have thousands of FIN_WAIT1
5709 sessions on your system (TIME_WAIT ones do not count).
5710
5711 This option may be used both on frontends and backends, depending on the side
5712 where it is required. Use it on the frontend for clients, and on the backend
5713 for servers.
5714
5715 If this option has been enabled in a "defaults" section, it can be disabled
5716 in a specific instance by prepending the "no" keyword before it.
5717
5718
Willy Tarreau55165fe2009-05-10 12:02:55 +02005719option originalto [ except <network> ] [ header <name> ]
5720 Enable insertion of the X-Original-To header to requests sent to servers
5721 May be used in sections : defaults | frontend | listen | backend
5722 yes | yes | yes | yes
5723 Arguments :
5724 <network> is an optional argument used to disable this option for sources
5725 matching <network>
5726 <name> an optional argument to specify a different "X-Original-To"
5727 header name.
5728
5729 Since HAProxy can work in transparent mode, every request from a client can
5730 be redirected to the proxy and HAProxy itself can proxy every request to a
5731 complex SQUID environment and the destination host from SO_ORIGINAL_DST will
5732 be lost. This is annoying when you want access rules based on destination ip
5733 addresses. To solve this problem, a new HTTP header "X-Original-To" may be
5734 added by HAProxy to all requests sent to the server. This header contains a
5735 value representing the original destination IP address. Since this must be
5736 configured to always use the last occurrence of this header only. Note that
5737 only the last occurrence of the header must be used, since it is really
5738 possible that the client has already brought one.
5739
5740 The keyword "header" may be used to supply a different header name to replace
5741 the default "X-Original-To". This can be useful where you might already
5742 have a "X-Original-To" header from a different application, and you need
5743 preserve it. Also if your backend server doesn't use the "X-Original-To"
5744 header and requires different one.
5745
5746 Sometimes, a same HAProxy instance may be shared between a direct client
5747 access and a reverse-proxy access (for instance when an SSL reverse-proxy is
5748 used to decrypt HTTPS traffic). It is possible to disable the addition of the
5749 header for a known source address or network by adding the "except" keyword
5750 followed by the network address. In this case, any source IP matching the
5751 network will not cause an addition of this header. Most common uses are with
5752 private networks or 127.0.0.1.
5753
5754 This option may be specified either in the frontend or in the backend. If at
5755 least one of them uses it, the header will be added. Note that the backend's
5756 setting of the header subargument takes precedence over the frontend's if
5757 both are defined.
5758
Willy Tarreau55165fe2009-05-10 12:02:55 +02005759 Examples :
5760 # Original Destination address
5761 frontend www
5762 mode http
5763 option originalto except 127.0.0.1
5764
5765 # Those servers want the IP Address in X-Client-Dst
5766 backend www
5767 mode http
5768 option originalto header X-Client-Dst
5769
Willy Tarreau87cf5142011-08-19 22:57:24 +02005770 See also : "option httpclose", "option http-server-close",
5771 "option forceclose"
Willy Tarreau55165fe2009-05-10 12:02:55 +02005772
5773
Willy Tarreaua453bdd2008-01-08 19:50:52 +01005774option persist
5775no option persist
5776 Enable or disable forced persistence on down servers
5777 May be used in sections: defaults | frontend | listen | backend
5778 yes | no | yes | yes
Willy Tarreaueabeafa2008-01-16 16:17:06 +01005779 Arguments : none
Willy Tarreaua453bdd2008-01-08 19:50:52 +01005780
5781 When an HTTP request reaches a backend with a cookie which references a dead
5782 server, by default it is redispatched to another server. It is possible to
5783 force the request to be sent to the dead server first using "option persist"
5784 if absolutely needed. A common use case is when servers are under extreme
5785 load and spend their time flapping. In this case, the users would still be
5786 directed to the server they opened the session on, in the hope they would be
5787 correctly served. It is recommended to use "option redispatch" in conjunction
5788 with this option so that in the event it would not be possible to connect to
5789 the server at all (server definitely dead), the client would finally be
5790 redirected to another valid server.
5791
5792 If this option has been enabled in a "defaults" section, it can be disabled
5793 in a specific instance by prepending the "no" keyword before it.
5794
Willy Tarreau4de91492010-01-22 19:10:05 +01005795 See also : "option redispatch", "retries", "force-persist"
Willy Tarreaua453bdd2008-01-08 19:50:52 +01005796
5797
Willy Tarreau0c122822013-12-15 18:49:01 +01005798option pgsql-check [ user <username> ]
5799 Use PostgreSQL health checks for server testing
5800 May be used in sections : defaults | frontend | listen | backend
5801 yes | no | yes | yes
5802 Arguments :
5803 <username> This is the username which will be used when connecting to
5804 PostgreSQL server.
5805
5806 The check sends a PostgreSQL StartupMessage and waits for either
5807 Authentication request or ErrorResponse message. It is a basic but useful
5808 test which does not produce error nor aborted connect on the server.
5809 This check is identical with the "mysql-check".
5810
5811 See also: "option httpchk"
5812
5813
Willy Tarreau9420b122013-12-15 18:58:25 +01005814option prefer-last-server
5815no option prefer-last-server
5816 Allow multiple load balanced requests to remain on the same server
5817 May be used in sections: defaults | frontend | listen | backend
5818 yes | no | yes | yes
5819 Arguments : none
5820
5821 When the load balancing algorithm in use is not deterministic, and a previous
5822 request was sent to a server to which haproxy still holds a connection, it is
5823 sometimes desirable that subsequent requests on a same session go to the same
5824 server as much as possible. Note that this is different from persistence, as
5825 we only indicate a preference which haproxy tries to apply without any form
5826 of warranty. The real use is for keep-alive connections sent to servers. When
5827 this option is used, haproxy will try to reuse the same connection that is
5828 attached to the server instead of rebalancing to another server, causing a
5829 close of the connection. This can make sense for static file servers. It does
Willy Tarreau068621e2013-12-23 15:11:25 +01005830 not make much sense to use this in combination with hashing algorithms. Note,
5831 haproxy already automatically tries to stick to a server which sends a 401 or
5832 to a proxy which sends a 407 (authentication required). This is mandatory for
5833 use with the broken NTLM authentication challenge, and significantly helps in
5834 troubleshooting some faulty applications. Option prefer-last-server might be
5835 desirable in these environments as well, to avoid redistributing the traffic
5836 after every other response.
Willy Tarreau9420b122013-12-15 18:58:25 +01005837
5838 If this option has been enabled in a "defaults" section, it can be disabled
5839 in a specific instance by prepending the "no" keyword before it.
5840
5841 See also: "option http-keep-alive"
5842
5843
Krzysztof Piotr Oledzki25b501a2008-01-06 16:36:16 +01005844option redispatch
Joseph Lynch726ab712015-05-11 23:25:34 -07005845option redispatch <interval>
Krzysztof Piotr Oledzki25b501a2008-01-06 16:36:16 +01005846no option redispatch
5847 Enable or disable session redistribution in case of connection failure
5848 May be used in sections: defaults | frontend | listen | backend
5849 yes | no | yes | yes
Joseph Lynch726ab712015-05-11 23:25:34 -07005850 Arguments :
5851 <interval> The optional integer value that controls how often redispatches
5852 occur when retrying connections. Positive value P indicates a
5853 redispatch is desired on every Pth retry, and negative value
5854 N indicate a redispath is desired on the Nth retry prior to the
5855 last retry. For example, the default of -1 preserves the
5856 historical behaviour of redispatching on the last retry, a
5857 positive value of 1 would indicate a redispatch on every retry,
5858 and a positive value of 3 would indicate a redispatch on every
5859 third retry. You can disable redispatches with a value of 0.
5860
Krzysztof Piotr Oledzki25b501a2008-01-06 16:36:16 +01005861
5862 In HTTP mode, if a server designated by a cookie is down, clients may
5863 definitely stick to it because they cannot flush the cookie, so they will not
5864 be able to access the service anymore.
5865
5866 Specifying "option redispatch" will allow the proxy to break their
5867 persistence and redistribute them to a working server.
5868
Joseph Lynch726ab712015-05-11 23:25:34 -07005869 It also allows to retry connections to another server in case of multiple
Krzysztof Piotr Oledzki25b501a2008-01-06 16:36:16 +01005870 connection failures. Of course, it requires having "retries" set to a nonzero
5871 value.
Willy Tarreaud72758d2010-01-12 10:42:19 +01005872
Krzysztof Piotr Oledzki25b501a2008-01-06 16:36:16 +01005873 This form is the preferred form, which replaces both the "redispatch" and
5874 "redisp" keywords.
5875
5876 If this option has been enabled in a "defaults" section, it can be disabled
5877 in a specific instance by prepending the "no" keyword before it.
5878
Willy Tarreau4de91492010-01-22 19:10:05 +01005879 See also : "redispatch", "retries", "force-persist"
Krzysztof Piotr Oledzki25b501a2008-01-06 16:36:16 +01005880
Willy Tarreaua453bdd2008-01-08 19:50:52 +01005881
Hervé COMMOWICKec032d62011-08-05 16:23:48 +02005882option redis-check
5883 Use redis health checks for server testing
5884 May be used in sections : defaults | frontend | listen | backend
5885 yes | no | yes | yes
5886 Arguments : none
5887
5888 It is possible to test that the server correctly talks REDIS protocol instead
5889 of just testing that it accepts the TCP connection. When this option is set,
5890 a PING redis command is sent to the server, and the response is analyzed to
5891 find the "+PONG" response message.
5892
5893 Example :
5894 option redis-check
5895
5896 See also : "option httpchk"
5897
5898
Willy Tarreaua453bdd2008-01-08 19:50:52 +01005899option smtpchk
5900option smtpchk <hello> <domain>
5901 Use SMTP health checks for server testing
5902 May be used in sections : defaults | frontend | listen | backend
5903 yes | no | yes | yes
Willy Tarreaud72758d2010-01-12 10:42:19 +01005904 Arguments :
Willy Tarreaua453bdd2008-01-08 19:50:52 +01005905 <hello> is an optional argument. It is the "hello" command to use. It can
5906 be either "HELO" (for SMTP) or "EHLO" (for ESTMP). All other
5907 values will be turned into the default command ("HELO").
5908
5909 <domain> is the domain name to present to the server. It may only be
5910 specified (and is mandatory) if the hello command has been
5911 specified. By default, "localhost" is used.
5912
5913 When "option smtpchk" is set, the health checks will consist in TCP
5914 connections followed by an SMTP command. By default, this command is
5915 "HELO localhost". The server's return code is analyzed and only return codes
5916 starting with a "2" will be considered as valid. All other responses,
5917 including a lack of response will constitute an error and will indicate a
5918 dead server.
5919
5920 This test is meant to be used with SMTP servers or relays. Depending on the
5921 request, it is possible that some servers do not log each connection attempt,
5922 so you may want to experiment to improve the behaviour. Using telnet on port
5923 25 is often easier than adjusting the configuration.
5924
5925 Most often, an incoming SMTP server needs to see the client's IP address for
5926 various purposes, including spam filtering, anti-spoofing and logging. When
5927 possible, it is often wise to masquerade the client's IP address when
5928 connecting to the server using the "usesrc" argument of the "source" keyword,
Willy Tarreau29fbe512015-08-20 19:35:14 +02005929 which requires the transparent proxy feature to be compiled in.
Willy Tarreaua453bdd2008-01-08 19:50:52 +01005930
5931 Example :
5932 option smtpchk HELO mydomain.org
5933
5934 See also : "option httpchk", "source"
5935
Krzysztof Piotr Oledzki25b501a2008-01-06 16:36:16 +01005936
Krzysztof Piotr Oledzkiaeebf9b2009-10-04 15:43:17 +02005937option socket-stats
5938no option socket-stats
5939
5940 Enable or disable collecting & providing separate statistics for each socket.
5941 May be used in sections : defaults | frontend | listen | backend
5942 yes | yes | yes | no
5943
5944 Arguments : none
5945
5946
Willy Tarreauff4f82d2009-02-06 11:28:13 +01005947option splice-auto
5948no option splice-auto
5949 Enable or disable automatic kernel acceleration on sockets in both directions
5950 May be used in sections : defaults | frontend | listen | backend
5951 yes | yes | yes | yes
5952 Arguments : none
5953
5954 When this option is enabled either on a frontend or on a backend, haproxy
5955 will automatically evaluate the opportunity to use kernel tcp splicing to
5956 forward data between the client and the server, in either direction. Haproxy
5957 uses heuristics to estimate if kernel splicing might improve performance or
Krzysztof Piotr Oledzkif8645332009-12-13 21:55:50 +01005958 not. Both directions are handled independently. Note that the heuristics used
Willy Tarreauff4f82d2009-02-06 11:28:13 +01005959 are not much aggressive in order to limit excessive use of splicing. This
5960 option requires splicing to be enabled at compile time, and may be globally
5961 disabled with the global option "nosplice". Since splice uses pipes, using it
5962 requires that there are enough spare pipes.
5963
5964 Important note: kernel-based TCP splicing is a Linux-specific feature which
5965 first appeared in kernel 2.6.25. It offers kernel-based acceleration to
5966 transfer data between sockets without copying these data to user-space, thus
5967 providing noticeable performance gains and CPU cycles savings. Since many
5968 early implementations are buggy, corrupt data and/or are inefficient, this
5969 feature is not enabled by default, and it should be used with extreme care.
5970 While it is not possible to detect the correctness of an implementation,
5971 2.6.29 is the first version offering a properly working implementation. In
5972 case of doubt, splicing may be globally disabled using the global "nosplice"
5973 keyword.
5974
5975 Example :
5976 option splice-auto
5977
5978 If this option has been enabled in a "defaults" section, it can be disabled
5979 in a specific instance by prepending the "no" keyword before it.
5980
5981 See also : "option splice-request", "option splice-response", and global
5982 options "nosplice" and "maxpipes"
5983
5984
5985option splice-request
5986no option splice-request
5987 Enable or disable automatic kernel acceleration on sockets for requests
5988 May be used in sections : defaults | frontend | listen | backend
5989 yes | yes | yes | yes
5990 Arguments : none
5991
5992 When this option is enabled either on a frontend or on a backend, haproxy
Jamie Gloudonaaa21002012-08-25 00:18:33 -04005993 will use kernel tcp splicing whenever possible to forward data going from
Willy Tarreauff4f82d2009-02-06 11:28:13 +01005994 the client to the server. It might still use the recv/send scheme if there
5995 are no spare pipes left. This option requires splicing to be enabled at
5996 compile time, and may be globally disabled with the global option "nosplice".
5997 Since splice uses pipes, using it requires that there are enough spare pipes.
5998
5999 Important note: see "option splice-auto" for usage limitations.
6000
6001 Example :
6002 option splice-request
6003
6004 If this option has been enabled in a "defaults" section, it can be disabled
6005 in a specific instance by prepending the "no" keyword before it.
6006
6007 See also : "option splice-auto", "option splice-response", and global options
6008 "nosplice" and "maxpipes"
6009
6010
6011option splice-response
6012no option splice-response
6013 Enable or disable automatic kernel acceleration on sockets for responses
6014 May be used in sections : defaults | frontend | listen | backend
6015 yes | yes | yes | yes
6016 Arguments : none
6017
6018 When this option is enabled either on a frontend or on a backend, haproxy
Jamie Gloudonaaa21002012-08-25 00:18:33 -04006019 will use kernel tcp splicing whenever possible to forward data going from
Willy Tarreauff4f82d2009-02-06 11:28:13 +01006020 the server to the client. It might still use the recv/send scheme if there
6021 are no spare pipes left. This option requires splicing to be enabled at
6022 compile time, and may be globally disabled with the global option "nosplice".
6023 Since splice uses pipes, using it requires that there are enough spare pipes.
6024
6025 Important note: see "option splice-auto" for usage limitations.
6026
6027 Example :
6028 option splice-response
6029
6030 If this option has been enabled in a "defaults" section, it can be disabled
6031 in a specific instance by prepending the "no" keyword before it.
6032
6033 See also : "option splice-auto", "option splice-request", and global options
6034 "nosplice" and "maxpipes"
6035
6036
Willy Tarreaubf1f8162007-12-28 17:42:56 +01006037option srvtcpka
6038no option srvtcpka
6039 Enable or disable the sending of TCP keepalive packets on the server side
6040 May be used in sections : defaults | frontend | listen | backend
6041 yes | no | yes | yes
6042 Arguments : none
6043
6044 When there is a firewall or any session-aware component between a client and
6045 a server, and when the protocol involves very long sessions with long idle
6046 periods (eg: remote desktops), there is a risk that one of the intermediate
6047 components decides to expire a session which has remained idle for too long.
6048
6049 Enabling socket-level TCP keep-alives makes the system regularly send packets
6050 to the other end of the connection, leaving it active. The delay between
6051 keep-alive probes is controlled by the system only and depends both on the
6052 operating system and its tuning parameters.
6053
6054 It is important to understand that keep-alive packets are neither emitted nor
6055 received at the application level. It is only the network stacks which sees
6056 them. For this reason, even if one side of the proxy already uses keep-alives
6057 to maintain its connection alive, those keep-alive packets will not be
6058 forwarded to the other side of the proxy.
6059
6060 Please note that this has nothing to do with HTTP keep-alive.
6061
6062 Using option "srvtcpka" enables the emission of TCP keep-alive probes on the
6063 server side of a connection, which should help when session expirations are
6064 noticed between HAProxy and a server.
6065
6066 If this option has been enabled in a "defaults" section, it can be disabled
6067 in a specific instance by prepending the "no" keyword before it.
6068
6069 See also : "option clitcpka", "option tcpka"
6070
6071
Willy Tarreaua453bdd2008-01-08 19:50:52 +01006072option ssl-hello-chk
6073 Use SSLv3 client hello health checks for server testing
6074 May be used in sections : defaults | frontend | listen | backend
6075 yes | no | yes | yes
6076 Arguments : none
6077
6078 When some SSL-based protocols are relayed in TCP mode through HAProxy, it is
6079 possible to test that the server correctly talks SSL instead of just testing
6080 that it accepts the TCP connection. When "option ssl-hello-chk" is set, pure
6081 SSLv3 client hello messages are sent once the connection is established to
6082 the server, and the response is analyzed to find an SSL server hello message.
6083 The server is considered valid only when the response contains this server
6084 hello message.
6085
6086 All servers tested till there correctly reply to SSLv3 client hello messages,
6087 and most servers tested do not even log the requests containing only hello
6088 messages, which is appreciable.
6089
Willy Tarreau763a95b2012-10-04 23:15:39 +02006090 Note that this check works even when SSL support was not built into haproxy
6091 because it forges the SSL message. When SSL support is available, it is best
6092 to use native SSL health checks instead of this one.
Willy Tarreaua453bdd2008-01-08 19:50:52 +01006093
Willy Tarreau763a95b2012-10-04 23:15:39 +02006094 See also: "option httpchk", "check-ssl"
6095
Willy Tarreaua453bdd2008-01-08 19:50:52 +01006096
Willy Tarreaued179852013-12-16 01:07:00 +01006097option tcp-check
6098 Perform health checks using tcp-check send/expect sequences
6099 May be used in sections: defaults | frontend | listen | backend
6100 yes | no | yes | yes
6101
6102 This health check method is intended to be combined with "tcp-check" command
6103 lists in order to support send/expect types of health check sequences.
6104
6105 TCP checks currently support 4 modes of operations :
6106 - no "tcp-check" directive : the health check only consists in a connection
6107 attempt, which remains the default mode.
6108
Jarno Huuskonen0e82b922014-04-12 18:22:19 +03006109 - "tcp-check send" or "tcp-check send-binary" only is mentioned : this is
Willy Tarreaued179852013-12-16 01:07:00 +01006110 used to send a string along with a connection opening. With some
6111 protocols, it helps sending a "QUIT" message for example that prevents
6112 the server from logging a connection error for each health check. The
6113 check result will still be based on the ability to open the connection
6114 only.
6115
Jarno Huuskonen0e82b922014-04-12 18:22:19 +03006116 - "tcp-check expect" only is mentioned : this is used to test a banner.
Willy Tarreaued179852013-12-16 01:07:00 +01006117 The connection is opened and haproxy waits for the server to present some
6118 contents which must validate some rules. The check result will be based
6119 on the matching between the contents and the rules. This is suited for
6120 POP, IMAP, SMTP, FTP, SSH, TELNET.
6121
Jarno Huuskonen0e82b922014-04-12 18:22:19 +03006122 - both "tcp-check send" and "tcp-check expect" are mentioned : this is
Willy Tarreaued179852013-12-16 01:07:00 +01006123 used to test a hello-type protocol. Haproxy sends a message, the server
6124 responds and its response is analysed. the check result will be based on
Jarno Huuskonen0e82b922014-04-12 18:22:19 +03006125 the matching between the response contents and the rules. This is often
Willy Tarreaued179852013-12-16 01:07:00 +01006126 suited for protocols which require a binding or a request/response model.
6127 LDAP, MySQL, Redis and SSL are example of such protocols, though they
6128 already all have their dedicated checks with a deeper understanding of
6129 the respective protocols.
6130 In this mode, many questions may be sent and many answers may be
6131 analysed.
6132
Baptiste Assmannd60a9e52015-04-25 16:27:23 +02006133 A fifth mode can be used to insert comments in different steps of the
6134 script.
6135
6136 For each tcp-check rule you create, you can add a "comment" directive,
6137 followed by a string. This string will be reported in the log and stderr
6138 in debug mode. It is useful to make user-friendly error reporting.
6139 The "comment" is of course optional.
6140
6141
Willy Tarreaued179852013-12-16 01:07:00 +01006142 Examples :
6143 # perform a POP check (analyse only server's banner)
6144 option tcp-check
Baptiste Assmannd60a9e52015-04-25 16:27:23 +02006145 tcp-check expect string +OK\ POP3\ ready comment POP\ protocol
Willy Tarreaued179852013-12-16 01:07:00 +01006146
6147 # perform an IMAP check (analyse only server's banner)
6148 option tcp-check
Baptiste Assmannd60a9e52015-04-25 16:27:23 +02006149 tcp-check expect string *\ OK\ IMAP4\ ready comment IMAP\ protocol
Willy Tarreaued179852013-12-16 01:07:00 +01006150
6151 # look for the redis master server after ensuring it speaks well
6152 # redis protocol, then it exits properly.
Jarno Huuskonen0e82b922014-04-12 18:22:19 +03006153 # (send a command then analyse the response 3 times)
Willy Tarreaued179852013-12-16 01:07:00 +01006154 option tcp-check
Baptiste Assmannd60a9e52015-04-25 16:27:23 +02006155 tcp-check comment PING\ phase
Willy Tarreaued179852013-12-16 01:07:00 +01006156 tcp-check send PING\r\n
Baptiste Assmanna3322992015-08-04 10:12:18 +02006157 tcp-check expect string +PONG
Baptiste Assmannd60a9e52015-04-25 16:27:23 +02006158 tcp-check comment role\ check
Willy Tarreaued179852013-12-16 01:07:00 +01006159 tcp-check send info\ replication\r\n
6160 tcp-check expect string role:master
Baptiste Assmannd60a9e52015-04-25 16:27:23 +02006161 tcp-check comment QUIT\ phase
Willy Tarreaued179852013-12-16 01:07:00 +01006162 tcp-check send QUIT\r\n
6163 tcp-check expect string +OK
6164
6165 forge a HTTP request, then analyse the response
6166 (send many headers before analyzing)
6167 option tcp-check
Baptiste Assmannd60a9e52015-04-25 16:27:23 +02006168 tcp-check comment forge\ and\ send\ HTTP\ request
Willy Tarreaued179852013-12-16 01:07:00 +01006169 tcp-check send HEAD\ /\ HTTP/1.1\r\n
6170 tcp-check send Host:\ www.mydomain.com\r\n
6171 tcp-check send User-Agent:\ HAProxy\ tcpcheck\r\n
6172 tcp-check send \r\n
Baptiste Assmannd60a9e52015-04-25 16:27:23 +02006173 tcp-check expect rstring HTTP/1\..\ (2..|3..) comment check\ HTTP\ response
Willy Tarreaued179852013-12-16 01:07:00 +01006174
6175
6176 See also : "tcp-check expect", "tcp-check send"
6177
6178
Willy Tarreau9ea05a72009-06-14 12:07:01 +02006179option tcp-smart-accept
6180no option tcp-smart-accept
6181 Enable or disable the saving of one ACK packet during the accept sequence
6182 May be used in sections : defaults | frontend | listen | backend
6183 yes | yes | yes | no
6184 Arguments : none
6185
6186 When an HTTP connection request comes in, the system acknowledges it on
6187 behalf of HAProxy, then the client immediately sends its request, and the
6188 system acknowledges it too while it is notifying HAProxy about the new
6189 connection. HAProxy then reads the request and responds. This means that we
6190 have one TCP ACK sent by the system for nothing, because the request could
6191 very well be acknowledged by HAProxy when it sends its response.
6192
6193 For this reason, in HTTP mode, HAProxy automatically asks the system to avoid
6194 sending this useless ACK on platforms which support it (currently at least
6195 Linux). It must not cause any problem, because the system will send it anyway
6196 after 40 ms if the response takes more time than expected to come.
6197
6198 During complex network debugging sessions, it may be desirable to disable
6199 this optimization because delayed ACKs can make troubleshooting more complex
6200 when trying to identify where packets are delayed. It is then possible to
6201 fall back to normal behaviour by specifying "no option tcp-smart-accept".
6202
6203 It is also possible to force it for non-HTTP proxies by simply specifying
6204 "option tcp-smart-accept". For instance, it can make sense with some services
6205 such as SMTP where the server speaks first.
6206
6207 It is recommended to avoid forcing this option in a defaults section. In case
6208 of doubt, consider setting it back to automatic values by prepending the
6209 "default" keyword before it, or disabling it using the "no" keyword.
6210
Willy Tarreaud88edf22009-06-14 15:48:17 +02006211 See also : "option tcp-smart-connect"
6212
6213
6214option tcp-smart-connect
6215no option tcp-smart-connect
6216 Enable or disable the saving of one ACK packet during the connect sequence
6217 May be used in sections : defaults | frontend | listen | backend
6218 yes | no | yes | yes
6219 Arguments : none
6220
6221 On certain systems (at least Linux), HAProxy can ask the kernel not to
6222 immediately send an empty ACK upon a connection request, but to directly
6223 send the buffer request instead. This saves one packet on the network and
6224 thus boosts performance. It can also be useful for some servers, because they
6225 immediately get the request along with the incoming connection.
6226
6227 This feature is enabled when "option tcp-smart-connect" is set in a backend.
6228 It is not enabled by default because it makes network troubleshooting more
6229 complex.
6230
6231 It only makes sense to enable it with protocols where the client speaks first
6232 such as HTTP. In other situations, if there is no data to send in place of
6233 the ACK, a normal ACK is sent.
6234
6235 If this option has been enabled in a "defaults" section, it can be disabled
6236 in a specific instance by prepending the "no" keyword before it.
6237
6238 See also : "option tcp-smart-accept"
6239
Willy Tarreau9ea05a72009-06-14 12:07:01 +02006240
Willy Tarreaubf1f8162007-12-28 17:42:56 +01006241option tcpka
6242 Enable or disable the sending of TCP keepalive packets on both sides
6243 May be used in sections : defaults | frontend | listen | backend
6244 yes | yes | yes | yes
6245 Arguments : none
6246
6247 When there is a firewall or any session-aware component between a client and
6248 a server, and when the protocol involves very long sessions with long idle
6249 periods (eg: remote desktops), there is a risk that one of the intermediate
6250 components decides to expire a session which has remained idle for too long.
6251
6252 Enabling socket-level TCP keep-alives makes the system regularly send packets
6253 to the other end of the connection, leaving it active. The delay between
6254 keep-alive probes is controlled by the system only and depends both on the
6255 operating system and its tuning parameters.
6256
6257 It is important to understand that keep-alive packets are neither emitted nor
6258 received at the application level. It is only the network stacks which sees
6259 them. For this reason, even if one side of the proxy already uses keep-alives
6260 to maintain its connection alive, those keep-alive packets will not be
6261 forwarded to the other side of the proxy.
6262
6263 Please note that this has nothing to do with HTTP keep-alive.
6264
6265 Using option "tcpka" enables the emission of TCP keep-alive probes on both
6266 the client and server sides of a connection. Note that this is meaningful
6267 only in "defaults" or "listen" sections. If this option is used in a
6268 frontend, only the client side will get keep-alives, and if this option is
6269 used in a backend, only the server side will get keep-alives. For this
6270 reason, it is strongly recommended to explicitly use "option clitcpka" and
6271 "option srvtcpka" when the configuration is split between frontends and
6272 backends.
6273
6274 See also : "option clitcpka", "option srvtcpka"
6275
Willy Tarreau844e3c52008-01-11 16:28:18 +01006276
6277option tcplog
6278 Enable advanced logging of TCP connections with session state and timers
6279 May be used in sections : defaults | frontend | listen | backend
6280 yes | yes | yes | yes
6281 Arguments : none
6282
6283 By default, the log output format is very poor, as it only contains the
6284 source and destination addresses, and the instance name. By specifying
6285 "option tcplog", each log line turns into a much richer format including, but
6286 not limited to, the connection timers, the session status, the connections
6287 numbers, the frontend, backend and server name, and of course the source
6288 address and ports. This option is useful for pure TCP proxies in order to
6289 find which of the client or server disconnects or times out. For normal HTTP
6290 proxies, it's better to use "option httplog" which is even more complete.
6291
6292 This option may be set either in the frontend or the backend.
6293
Willy Tarreauc57f0e22009-05-10 13:12:33 +02006294 See also : "option httplog", and section 8 about logging.
Willy Tarreau844e3c52008-01-11 16:28:18 +01006295
6296
Willy Tarreau844e3c52008-01-11 16:28:18 +01006297option transparent
6298no option transparent
6299 Enable client-side transparent proxying
6300 May be used in sections : defaults | frontend | listen | backend
Willy Tarreau4b1f8592008-12-23 23:13:55 +01006301 yes | no | yes | yes
Willy Tarreau844e3c52008-01-11 16:28:18 +01006302 Arguments : none
6303
6304 This option was introduced in order to provide layer 7 persistence to layer 3
6305 load balancers. The idea is to use the OS's ability to redirect an incoming
6306 connection for a remote address to a local process (here HAProxy), and let
6307 this process know what address was initially requested. When this option is
6308 used, sessions without cookies will be forwarded to the original destination
6309 IP address of the incoming request (which should match that of another
6310 equipment), while requests with cookies will still be forwarded to the
6311 appropriate server.
6312
6313 Note that contrary to a common belief, this option does NOT make HAProxy
6314 present the client's IP to the server when establishing the connection.
6315
Willy Tarreaua1146052011-03-01 09:51:54 +01006316 See also: the "usesrc" argument of the "source" keyword, and the
Willy Tarreaueabeafa2008-01-16 16:17:06 +01006317 "transparent" option of the "bind" keyword.
Willy Tarreau844e3c52008-01-11 16:28:18 +01006318
Willy Tarreaubf1f8162007-12-28 17:42:56 +01006319
Simon Horman98637e52014-06-20 12:30:16 +09006320external-check command <command>
6321 Executable to run when performing an external-check
6322 May be used in sections : defaults | frontend | listen | backend
6323 yes | no | yes | yes
6324
6325 Arguments :
6326 <command> is the external command to run
6327
Simon Horman98637e52014-06-20 12:30:16 +09006328 The arguments passed to the to the command are:
6329
Cyril Bonté777be862014-12-02 21:21:35 +01006330 <proxy_address> <proxy_port> <server_address> <server_port>
Simon Horman98637e52014-06-20 12:30:16 +09006331
Cyril Bonté777be862014-12-02 21:21:35 +01006332 The <proxy_address> and <proxy_port> are derived from the first listener
6333 that is either IPv4, IPv6 or a UNIX socket. In the case of a UNIX socket
6334 listener the proxy_address will be the path of the socket and the
6335 <proxy_port> will be the string "NOT_USED". In a backend section, it's not
6336 possible to determine a listener, and both <proxy_address> and <proxy_port>
6337 will have the string value "NOT_USED".
Simon Horman98637e52014-06-20 12:30:16 +09006338
Cyril Bonté72cda2a2014-12-27 22:28:39 +01006339 Some values are also provided through environment variables.
6340
6341 Environment variables :
6342 HAPROXY_PROXY_ADDR The first bind address if available (or empty if not
6343 applicable, for example in a "backend" section).
6344
6345 HAPROXY_PROXY_ID The backend id.
6346
6347 HAPROXY_PROXY_NAME The backend name.
6348
6349 HAPROXY_PROXY_PORT The first bind port if available (or empty if not
6350 applicable, for example in a "backend" section or
6351 for a UNIX socket).
6352
6353 HAPROXY_SERVER_ADDR The server address.
6354
6355 HAPROXY_SERVER_CURCONN The current number of connections on the server.
6356
6357 HAPROXY_SERVER_ID The server id.
6358
6359 HAPROXY_SERVER_MAXCONN The server max connections.
6360
6361 HAPROXY_SERVER_NAME The server name.
6362
6363 HAPROXY_SERVER_PORT The server port if available (or empty for a UNIX
6364 socket).
6365
6366 PATH The PATH environment variable used when executing
6367 the command may be set using "external-check path".
6368
Simon Horman98637e52014-06-20 12:30:16 +09006369 If the command executed and exits with a zero status then the check is
6370 considered to have passed, otherwise the check is considered to have
6371 failed.
6372
6373 Example :
6374 external-check command /bin/true
6375
6376 See also : "external-check", "option external-check", "external-check path"
6377
6378
6379external-check path <path>
6380 The value of the PATH environment variable used when running an external-check
6381 May be used in sections : defaults | frontend | listen | backend
6382 yes | no | yes | yes
6383
6384 Arguments :
6385 <path> is the path used when executing external command to run
6386
6387 The default path is "".
6388
6389 Example :
6390 external-check path "/usr/bin:/bin"
6391
6392 See also : "external-check", "option external-check",
6393 "external-check command"
6394
6395
Emeric Brun647caf12009-06-30 17:57:00 +02006396persist rdp-cookie
Hervé COMMOWICKa3eb39c2011-08-05 18:48:51 +02006397persist rdp-cookie(<name>)
Emeric Brun647caf12009-06-30 17:57:00 +02006398 Enable RDP cookie-based persistence
6399 May be used in sections : defaults | frontend | listen | backend
6400 yes | no | yes | yes
6401 Arguments :
6402 <name> is the optional name of the RDP cookie to check. If omitted, the
Willy Tarreau61e28f22010-05-16 22:31:05 +02006403 default cookie name "msts" will be used. There currently is no
6404 valid reason to change this name.
Emeric Brun647caf12009-06-30 17:57:00 +02006405
6406 This statement enables persistence based on an RDP cookie. The RDP cookie
6407 contains all information required to find the server in the list of known
6408 servers. So when this option is set in the backend, the request is analysed
6409 and if an RDP cookie is found, it is decoded. If it matches a known server
6410 which is still UP (or if "option persist" is set), then the connection is
6411 forwarded to this server.
6412
6413 Note that this only makes sense in a TCP backend, but for this to work, the
6414 frontend must have waited long enough to ensure that an RDP cookie is present
6415 in the request buffer. This is the same requirement as with the "rdp-cookie"
Krzysztof Piotr Oledzkif8645332009-12-13 21:55:50 +01006416 load-balancing method. Thus it is highly recommended to put all statements in
Emeric Brun647caf12009-06-30 17:57:00 +02006417 a single "listen" section.
6418
Willy Tarreau61e28f22010-05-16 22:31:05 +02006419 Also, it is important to understand that the terminal server will emit this
6420 RDP cookie only if it is configured for "token redirection mode", which means
6421 that the "IP address redirection" option is disabled.
6422
Emeric Brun647caf12009-06-30 17:57:00 +02006423 Example :
6424 listen tse-farm
6425 bind :3389
6426 # wait up to 5s for an RDP cookie in the request
6427 tcp-request inspect-delay 5s
6428 tcp-request content accept if RDP_COOKIE
6429 # apply RDP cookie persistence
6430 persist rdp-cookie
6431 # if server is unknown, let's balance on the same cookie.
Cyril Bontédc4d9032012-04-08 21:57:39 +02006432 # alternatively, "balance leastconn" may be useful too.
Emeric Brun647caf12009-06-30 17:57:00 +02006433 balance rdp-cookie
6434 server srv1 1.1.1.1:3389
6435 server srv2 1.1.1.2:3389
6436
Simon Hormanab814e02011-06-24 14:50:20 +09006437 See also : "balance rdp-cookie", "tcp-request", the "req_rdp_cookie" ACL and
6438 the rdp_cookie pattern fetch function.
Emeric Brun647caf12009-06-30 17:57:00 +02006439
6440
Willy Tarreau3a7d2072009-03-05 23:48:25 +01006441rate-limit sessions <rate>
6442 Set a limit on the number of new sessions accepted per second on a frontend
6443 May be used in sections : defaults | frontend | listen | backend
6444 yes | yes | yes | no
6445 Arguments :
6446 <rate> The <rate> parameter is an integer designating the maximum number
6447 of new sessions per second to accept on the frontend.
6448
6449 When the frontend reaches the specified number of new sessions per second, it
6450 stops accepting new connections until the rate drops below the limit again.
6451 During this time, the pending sessions will be kept in the socket's backlog
6452 (in system buffers) and haproxy will not even be aware that sessions are
6453 pending. When applying very low limit on a highly loaded service, it may make
6454 sense to increase the socket's backlog using the "backlog" keyword.
6455
6456 This feature is particularly efficient at blocking connection-based attacks
6457 or service abuse on fragile servers. Since the session rate is measured every
6458 millisecond, it is extremely accurate. Also, the limit applies immediately,
6459 no delay is needed at all to detect the threshold.
6460
6461 Example : limit the connection rate on SMTP to 10 per second max
6462 listen smtp
6463 mode tcp
6464 bind :25
6465 rate-limit sessions 10
6466 server 127.0.0.1:1025
6467
Willy Tarreaua17c2d92011-07-25 08:16:20 +02006468 Note : when the maximum rate is reached, the frontend's status is not changed
6469 but its sockets appear as "WAITING" in the statistics if the
6470 "socket-stats" option is enabled.
Willy Tarreau3a7d2072009-03-05 23:48:25 +01006471
6472 See also : the "backlog" keyword and the "fe_sess_rate" ACL criterion.
6473
6474
Willy Tarreau2e1dca82012-09-12 08:43:15 +02006475redirect location <loc> [code <code>] <option> [{if | unless} <condition>]
6476redirect prefix <pfx> [code <code>] <option> [{if | unless} <condition>]
6477redirect scheme <sch> [code <code>] <option> [{if | unless} <condition>]
Willy Tarreaub463dfb2008-06-07 23:08:56 +02006478 Return an HTTP redirection if/unless a condition is matched
6479 May be used in sections : defaults | frontend | listen | backend
6480 no | yes | yes | yes
6481
6482 If/unless the condition is matched, the HTTP request will lead to a redirect
Willy Tarreauf285f542010-01-03 20:03:03 +01006483 response. If no condition is specified, the redirect applies unconditionally.
Willy Tarreaub463dfb2008-06-07 23:08:56 +02006484
Willy Tarreau0140f252008-11-19 21:07:09 +01006485 Arguments :
Willy Tarreau2e1dca82012-09-12 08:43:15 +02006486 <loc> With "redirect location", the exact value in <loc> is placed into
Thierry FOURNIERd18cd0f2013-11-29 12:15:45 +01006487 the HTTP "Location" header. When used in an "http-request" rule,
6488 <loc> value follows the log-format rules and can include some
6489 dynamic values (see Custom Log Format in section 8.2.4).
Willy Tarreau2e1dca82012-09-12 08:43:15 +02006490
6491 <pfx> With "redirect prefix", the "Location" header is built from the
6492 concatenation of <pfx> and the complete URI path, including the
6493 query string, unless the "drop-query" option is specified (see
6494 below). As a special case, if <pfx> equals exactly "/", then
6495 nothing is inserted before the original URI. It allows one to
Thierry FOURNIERd18cd0f2013-11-29 12:15:45 +01006496 redirect to the same URL (for instance, to insert a cookie). When
6497 used in an "http-request" rule, <pfx> value follows the log-format
6498 rules and can include some dynamic values (see Custom Log Format
6499 in section 8.2.4).
Willy Tarreau2e1dca82012-09-12 08:43:15 +02006500
6501 <sch> With "redirect scheme", then the "Location" header is built by
6502 concatenating <sch> with "://" then the first occurrence of the
6503 "Host" header, and then the URI path, including the query string
6504 unless the "drop-query" option is specified (see below). If no
6505 path is found or if the path is "*", then "/" is used instead. If
6506 no "Host" header is found, then an empty host component will be
Jarno Huuskonen0e82b922014-04-12 18:22:19 +03006507 returned, which most recent browsers interpret as redirecting to
Willy Tarreau2e1dca82012-09-12 08:43:15 +02006508 the same host. This directive is mostly used to redirect HTTP to
Thierry FOURNIERd18cd0f2013-11-29 12:15:45 +01006509 HTTPS. When used in an "http-request" rule, <sch> value follows
6510 the log-format rules and can include some dynamic values (see
6511 Custom Log Format in section 8.2.4).
Willy Tarreau0140f252008-11-19 21:07:09 +01006512
6513 <code> The code is optional. It indicates which type of HTTP redirection
Willy Tarreaub67fdc42013-03-29 19:28:11 +01006514 is desired. Only codes 301, 302, 303, 307 and 308 are supported,
6515 with 302 used by default if no code is specified. 301 means
6516 "Moved permanently", and a browser may cache the Location. 302
Baptiste Assmannea849c02015-08-03 11:42:50 +02006517 means "Moved temporarily" and means that the browser should not
Willy Tarreaub67fdc42013-03-29 19:28:11 +01006518 cache the redirection. 303 is equivalent to 302 except that the
6519 browser will fetch the location with a GET method. 307 is just
6520 like 302 but makes it clear that the same method must be reused.
6521 Likewise, 308 replaces 301 if the same method must be used.
Willy Tarreau0140f252008-11-19 21:07:09 +01006522
6523 <option> There are several options which can be specified to adjust the
6524 expected behaviour of a redirection :
6525
6526 - "drop-query"
6527 When this keyword is used in a prefix-based redirection, then the
6528 location will be set without any possible query-string, which is useful
6529 for directing users to a non-secure page for instance. It has no effect
6530 with a location-type redirect.
6531
Willy Tarreau81e3b4f2010-01-10 00:42:19 +01006532 - "append-slash"
6533 This keyword may be used in conjunction with "drop-query" to redirect
6534 users who use a URL not ending with a '/' to the same one with the '/'.
6535 It can be useful to ensure that search engines will only see one URL.
6536 For this, a return code 301 is preferred.
6537
Willy Tarreau0140f252008-11-19 21:07:09 +01006538 - "set-cookie NAME[=value]"
6539 A "Set-Cookie" header will be added with NAME (and optionally "=value")
6540 to the response. This is sometimes used to indicate that a user has
6541 been seen, for instance to protect against some types of DoS. No other
6542 cookie option is added, so the cookie will be a session cookie. Note
6543 that for a browser, a sole cookie name without an equal sign is
6544 different from a cookie with an equal sign.
6545
6546 - "clear-cookie NAME[=]"
6547 A "Set-Cookie" header will be added with NAME (and optionally "="), but
6548 with the "Max-Age" attribute set to zero. This will tell the browser to
6549 delete this cookie. It is useful for instance on logout pages. It is
6550 important to note that clearing the cookie "NAME" will not remove a
6551 cookie set with "NAME=value". You have to clear the cookie "NAME=" for
6552 that, because the browser makes the difference.
Willy Tarreaub463dfb2008-06-07 23:08:56 +02006553
6554 Example: move the login URL only to HTTPS.
6555 acl clear dst_port 80
6556 acl secure dst_port 8080
6557 acl login_page url_beg /login
Willy Tarreau0140f252008-11-19 21:07:09 +01006558 acl logout url_beg /logout
Willy Tarreau79da4692008-11-19 20:03:04 +01006559 acl uid_given url_reg /login?userid=[^&]+
Willy Tarreau0140f252008-11-19 21:07:09 +01006560 acl cookie_set hdr_sub(cookie) SEEN=1
6561
6562 redirect prefix https://mysite.com set-cookie SEEN=1 if !cookie_set
Willy Tarreau79da4692008-11-19 20:03:04 +01006563 redirect prefix https://mysite.com if login_page !secure
6564 redirect prefix http://mysite.com drop-query if login_page !uid_given
6565 redirect location http://mysite.com/ if !login_page secure
Willy Tarreau0140f252008-11-19 21:07:09 +01006566 redirect location / clear-cookie USERID= if logout
Willy Tarreaub463dfb2008-06-07 23:08:56 +02006567
Willy Tarreau81e3b4f2010-01-10 00:42:19 +01006568 Example: send redirects for request for articles without a '/'.
6569 acl missing_slash path_reg ^/article/[^/]*$
6570 redirect code 301 prefix / drop-query append-slash if missing_slash
6571
Willy Tarreau2e1dca82012-09-12 08:43:15 +02006572 Example: redirect all HTTP traffic to HTTPS when SSL is handled by haproxy.
David BERARDe7153042012-11-03 00:11:31 +01006573 redirect scheme https if !{ ssl_fc }
Willy Tarreau2e1dca82012-09-12 08:43:15 +02006574
Thierry FOURNIERd18cd0f2013-11-29 12:15:45 +01006575 Example: append 'www.' prefix in front of all hosts not having it
6576 http-request redirect code 301 location www.%[hdr(host)]%[req.uri] \
6577 unless { hdr_beg(host) -i www }
6578
Willy Tarreauc57f0e22009-05-10 13:12:33 +02006579 See section 7 about ACL usage.
Willy Tarreaub463dfb2008-06-07 23:08:56 +02006580
6581
Krzysztof Piotr Oledzki25b501a2008-01-06 16:36:16 +01006582redisp (deprecated)
6583redispatch (deprecated)
6584 Enable or disable session redistribution in case of connection failure
6585 May be used in sections: defaults | frontend | listen | backend
6586 yes | no | yes | yes
Willy Tarreaueabeafa2008-01-16 16:17:06 +01006587 Arguments : none
Krzysztof Piotr Oledzki25b501a2008-01-06 16:36:16 +01006588
6589 In HTTP mode, if a server designated by a cookie is down, clients may
6590 definitely stick to it because they cannot flush the cookie, so they will not
6591 be able to access the service anymore.
6592
6593 Specifying "redispatch" will allow the proxy to break their persistence and
6594 redistribute them to a working server.
6595
6596 It also allows to retry last connection to another server in case of multiple
6597 connection failures. Of course, it requires having "retries" set to a nonzero
6598 value.
Willy Tarreaud72758d2010-01-12 10:42:19 +01006599
Krzysztof Piotr Oledzki25b501a2008-01-06 16:36:16 +01006600 This form is deprecated, do not use it in any new configuration, use the new
6601 "option redispatch" instead.
6602
6603 See also : "option redispatch"
6604
Willy Tarreaueabeafa2008-01-16 16:17:06 +01006605
Willy Tarreau8abd4cd2010-01-31 14:30:44 +01006606reqadd <string> [{if | unless} <cond>]
Willy Tarreau303c0352008-01-17 19:01:39 +01006607 Add a header at the end of the HTTP request
6608 May be used in sections : defaults | frontend | listen | backend
6609 no | yes | yes | yes
6610 Arguments :
6611 <string> is the complete line to be added. Any space or known delimiter
6612 must be escaped using a backslash ('\'). Please refer to section
Willy Tarreauc57f0e22009-05-10 13:12:33 +02006613 6 about HTTP header manipulation for more information.
Willy Tarreau303c0352008-01-17 19:01:39 +01006614
Willy Tarreau8abd4cd2010-01-31 14:30:44 +01006615 <cond> is an optional matching condition built from ACLs. It makes it
6616 possible to ignore this rule when other conditions are not met.
6617
Willy Tarreau303c0352008-01-17 19:01:39 +01006618 A new line consisting in <string> followed by a line feed will be added after
6619 the last header of an HTTP request.
6620
6621 Header transformations only apply to traffic which passes through HAProxy,
6622 and not to traffic generated by HAProxy, such as health-checks or error
6623 responses.
6624
Willy Tarreau8abd4cd2010-01-31 14:30:44 +01006625 Example : add "X-Proto: SSL" to requests coming via port 81
6626 acl is-ssl dst_port 81
6627 reqadd X-Proto:\ SSL if is-ssl
6628
6629 See also: "rspadd", section 6 about HTTP header manipulation, and section 7
6630 about ACLs.
Willy Tarreau303c0352008-01-17 19:01:39 +01006631
6632
Willy Tarreau5321c422010-01-28 20:35:13 +01006633reqallow <search> [{if | unless} <cond>]
6634reqiallow <search> [{if | unless} <cond>] (ignore case)
Willy Tarreau303c0352008-01-17 19:01:39 +01006635 Definitely allow an HTTP request if a line matches a regular expression
6636 May be used in sections : defaults | frontend | listen | backend
6637 no | yes | yes | yes
6638 Arguments :
6639 <search> is the regular expression applied to HTTP headers and to the
6640 request line. This is an extended regular expression. Parenthesis
6641 grouping is supported and no preliminary backslash is required.
6642 Any space or known delimiter must be escaped using a backslash
6643 ('\'). The pattern applies to a full line at a time. The
6644 "reqallow" keyword strictly matches case while "reqiallow"
6645 ignores case.
6646
Willy Tarreau5321c422010-01-28 20:35:13 +01006647 <cond> is an optional matching condition built from ACLs. It makes it
6648 possible to ignore this rule when other conditions are not met.
6649
Willy Tarreau303c0352008-01-17 19:01:39 +01006650 A request containing any line which matches extended regular expression
6651 <search> will mark the request as allowed, even if any later test would
6652 result in a deny. The test applies both to the request line and to request
6653 headers. Keep in mind that URLs in request line are case-sensitive while
Willy Tarreaud72758d2010-01-12 10:42:19 +01006654 header names are not.
Willy Tarreau303c0352008-01-17 19:01:39 +01006655
6656 It is easier, faster and more powerful to use ACLs to write access policies.
6657 Reqdeny, reqallow and reqpass should be avoided in new designs.
6658
6659 Example :
6660 # allow www.* but refuse *.local
6661 reqiallow ^Host:\ www\.
6662 reqideny ^Host:\ .*\.local
6663
Willy Tarreau5321c422010-01-28 20:35:13 +01006664 See also: "reqdeny", "block", section 6 about HTTP header manipulation, and
6665 section 7 about ACLs.
Willy Tarreau303c0352008-01-17 19:01:39 +01006666
6667
Willy Tarreau5321c422010-01-28 20:35:13 +01006668reqdel <search> [{if | unless} <cond>]
6669reqidel <search> [{if | unless} <cond>] (ignore case)
Willy Tarreau303c0352008-01-17 19:01:39 +01006670 Delete all headers matching a regular expression in an HTTP request
6671 May be used in sections : defaults | frontend | listen | backend
6672 no | yes | yes | yes
6673 Arguments :
6674 <search> is the regular expression applied to HTTP headers and to the
6675 request line. This is an extended regular expression. Parenthesis
6676 grouping is supported and no preliminary backslash is required.
6677 Any space or known delimiter must be escaped using a backslash
6678 ('\'). The pattern applies to a full line at a time. The "reqdel"
6679 keyword strictly matches case while "reqidel" ignores case.
6680
Willy Tarreau5321c422010-01-28 20:35:13 +01006681 <cond> is an optional matching condition built from ACLs. It makes it
6682 possible to ignore this rule when other conditions are not met.
6683
Willy Tarreau303c0352008-01-17 19:01:39 +01006684 Any header line matching extended regular expression <search> in the request
6685 will be completely deleted. Most common use of this is to remove unwanted
6686 and/or dangerous headers or cookies from a request before passing it to the
6687 next servers.
6688
6689 Header transformations only apply to traffic which passes through HAProxy,
6690 and not to traffic generated by HAProxy, such as health-checks or error
6691 responses. Keep in mind that header names are not case-sensitive.
6692
6693 Example :
6694 # remove X-Forwarded-For header and SERVER cookie
6695 reqidel ^X-Forwarded-For:.*
6696 reqidel ^Cookie:.*SERVER=
6697
Willy Tarreau5321c422010-01-28 20:35:13 +01006698 See also: "reqadd", "reqrep", "rspdel", section 6 about HTTP header
6699 manipulation, and section 7 about ACLs.
Willy Tarreau303c0352008-01-17 19:01:39 +01006700
6701
Willy Tarreau5321c422010-01-28 20:35:13 +01006702reqdeny <search> [{if | unless} <cond>]
6703reqideny <search> [{if | unless} <cond>] (ignore case)
Willy Tarreau303c0352008-01-17 19:01:39 +01006704 Deny an HTTP request if a line matches a regular expression
6705 May be used in sections : defaults | frontend | listen | backend
6706 no | yes | yes | yes
6707 Arguments :
6708 <search> is the regular expression applied to HTTP headers and to the
6709 request line. This is an extended regular expression. Parenthesis
6710 grouping is supported and no preliminary backslash is required.
6711 Any space or known delimiter must be escaped using a backslash
6712 ('\'). The pattern applies to a full line at a time. The
6713 "reqdeny" keyword strictly matches case while "reqideny" ignores
6714 case.
6715
Willy Tarreau5321c422010-01-28 20:35:13 +01006716 <cond> is an optional matching condition built from ACLs. It makes it
6717 possible to ignore this rule when other conditions are not met.
6718
Willy Tarreau303c0352008-01-17 19:01:39 +01006719 A request containing any line which matches extended regular expression
6720 <search> will mark the request as denied, even if any later test would
6721 result in an allow. The test applies both to the request line and to request
6722 headers. Keep in mind that URLs in request line are case-sensitive while
Willy Tarreaud72758d2010-01-12 10:42:19 +01006723 header names are not.
Willy Tarreau303c0352008-01-17 19:01:39 +01006724
Willy Tarreauced27012008-01-17 20:35:34 +01006725 A denied request will generate an "HTTP 403 forbidden" response once the
Willy Tarreaud2a4aa22008-01-31 15:28:22 +01006726 complete request has been parsed. This is consistent with what is practiced
Willy Tarreaud72758d2010-01-12 10:42:19 +01006727 using ACLs.
Willy Tarreauced27012008-01-17 20:35:34 +01006728
Willy Tarreau303c0352008-01-17 19:01:39 +01006729 It is easier, faster and more powerful to use ACLs to write access policies.
6730 Reqdeny, reqallow and reqpass should be avoided in new designs.
6731
6732 Example :
6733 # refuse *.local, then allow www.*
6734 reqideny ^Host:\ .*\.local
6735 reqiallow ^Host:\ www\.
6736
Willy Tarreau5321c422010-01-28 20:35:13 +01006737 See also: "reqallow", "rspdeny", "block", section 6 about HTTP header
6738 manipulation, and section 7 about ACLs.
Willy Tarreau303c0352008-01-17 19:01:39 +01006739
6740
Willy Tarreau5321c422010-01-28 20:35:13 +01006741reqpass <search> [{if | unless} <cond>]
6742reqipass <search> [{if | unless} <cond>] (ignore case)
Willy Tarreau303c0352008-01-17 19:01:39 +01006743 Ignore any HTTP request line matching a regular expression in next rules
6744 May be used in sections : defaults | frontend | listen | backend
6745 no | yes | yes | yes
6746 Arguments :
6747 <search> is the regular expression applied to HTTP headers and to the
6748 request line. This is an extended regular expression. Parenthesis
6749 grouping is supported and no preliminary backslash is required.
6750 Any space or known delimiter must be escaped using a backslash
6751 ('\'). The pattern applies to a full line at a time. The
6752 "reqpass" keyword strictly matches case while "reqipass" ignores
6753 case.
6754
Willy Tarreau5321c422010-01-28 20:35:13 +01006755 <cond> is an optional matching condition built from ACLs. It makes it
6756 possible to ignore this rule when other conditions are not met.
6757
Willy Tarreau303c0352008-01-17 19:01:39 +01006758 A request containing any line which matches extended regular expression
6759 <search> will skip next rules, without assigning any deny or allow verdict.
6760 The test applies both to the request line and to request headers. Keep in
6761 mind that URLs in request line are case-sensitive while header names are not.
6762
6763 It is easier, faster and more powerful to use ACLs to write access policies.
6764 Reqdeny, reqallow and reqpass should be avoided in new designs.
6765
6766 Example :
6767 # refuse *.local, then allow www.*, but ignore "www.private.local"
6768 reqipass ^Host:\ www.private\.local
6769 reqideny ^Host:\ .*\.local
6770 reqiallow ^Host:\ www\.
6771
Willy Tarreau5321c422010-01-28 20:35:13 +01006772 See also: "reqallow", "reqdeny", "block", section 6 about HTTP header
6773 manipulation, and section 7 about ACLs.
Willy Tarreau303c0352008-01-17 19:01:39 +01006774
6775
Willy Tarreau5321c422010-01-28 20:35:13 +01006776reqrep <search> <string> [{if | unless} <cond>]
6777reqirep <search> <string> [{if | unless} <cond>] (ignore case)
Willy Tarreau303c0352008-01-17 19:01:39 +01006778 Replace a regular expression with a string in an HTTP request line
6779 May be used in sections : defaults | frontend | listen | backend
6780 no | yes | yes | yes
6781 Arguments :
6782 <search> is the regular expression applied to HTTP headers and to the
6783 request line. This is an extended regular expression. Parenthesis
6784 grouping is supported and no preliminary backslash is required.
6785 Any space or known delimiter must be escaped using a backslash
6786 ('\'). The pattern applies to a full line at a time. The "reqrep"
6787 keyword strictly matches case while "reqirep" ignores case.
6788
6789 <string> is the complete line to be added. Any space or known delimiter
6790 must be escaped using a backslash ('\'). References to matched
6791 pattern groups are possible using the common \N form, with N
6792 being a single digit between 0 and 9. Please refer to section
Willy Tarreauc57f0e22009-05-10 13:12:33 +02006793 6 about HTTP header manipulation for more information.
Willy Tarreau303c0352008-01-17 19:01:39 +01006794
Willy Tarreau5321c422010-01-28 20:35:13 +01006795 <cond> is an optional matching condition built from ACLs. It makes it
6796 possible to ignore this rule when other conditions are not met.
6797
Willy Tarreau303c0352008-01-17 19:01:39 +01006798 Any line matching extended regular expression <search> in the request (both
6799 the request line and header lines) will be completely replaced with <string>.
6800 Most common use of this is to rewrite URLs or domain names in "Host" headers.
6801
6802 Header transformations only apply to traffic which passes through HAProxy,
6803 and not to traffic generated by HAProxy, such as health-checks or error
6804 responses. Note that for increased readability, it is suggested to add enough
6805 spaces between the request and the response. Keep in mind that URLs in
6806 request line are case-sensitive while header names are not.
6807
6808 Example :
6809 # replace "/static/" with "/" at the beginning of any request path.
Dmitry Sivachenko7823de32012-05-16 14:00:26 +04006810 reqrep ^([^\ :]*)\ /static/(.*) \1\ /\2
Willy Tarreau303c0352008-01-17 19:01:39 +01006811 # replace "www.mydomain.com" with "www" in the host name.
6812 reqirep ^Host:\ www.mydomain.com Host:\ www
6813
Dmitry Sivachenkof6f4f7b2012-10-21 18:10:25 +04006814 See also: "reqadd", "reqdel", "rsprep", "tune.bufsize", section 6 about
6815 HTTP header manipulation, and section 7 about ACLs.
Willy Tarreau303c0352008-01-17 19:01:39 +01006816
6817
Willy Tarreau5321c422010-01-28 20:35:13 +01006818reqtarpit <search> [{if | unless} <cond>]
6819reqitarpit <search> [{if | unless} <cond>] (ignore case)
Willy Tarreau303c0352008-01-17 19:01:39 +01006820 Tarpit an HTTP request containing a line matching a regular expression
6821 May be used in sections : defaults | frontend | listen | backend
6822 no | yes | yes | yes
6823 Arguments :
6824 <search> is the regular expression applied to HTTP headers and to the
6825 request line. This is an extended regular expression. Parenthesis
6826 grouping is supported and no preliminary backslash is required.
6827 Any space or known delimiter must be escaped using a backslash
6828 ('\'). The pattern applies to a full line at a time. The
6829 "reqtarpit" keyword strictly matches case while "reqitarpit"
6830 ignores case.
6831
Willy Tarreau5321c422010-01-28 20:35:13 +01006832 <cond> is an optional matching condition built from ACLs. It makes it
6833 possible to ignore this rule when other conditions are not met.
6834
Willy Tarreau303c0352008-01-17 19:01:39 +01006835 A request containing any line which matches extended regular expression
6836 <search> will be tarpitted, which means that it will connect to nowhere, will
Willy Tarreauced27012008-01-17 20:35:34 +01006837 be kept open for a pre-defined time, then will return an HTTP error 500 so
6838 that the attacker does not suspect it has been tarpitted. The status 500 will
6839 be reported in the logs, but the completion flags will indicate "PT". The
Willy Tarreau303c0352008-01-17 19:01:39 +01006840 delay is defined by "timeout tarpit", or "timeout connect" if the former is
6841 not set.
6842
6843 The goal of the tarpit is to slow down robots attacking servers with
6844 identifiable requests. Many robots limit their outgoing number of connections
6845 and stay connected waiting for a reply which can take several minutes to
6846 come. Depending on the environment and attack, it may be particularly
6847 efficient at reducing the load on the network and firewalls.
6848
Willy Tarreau5321c422010-01-28 20:35:13 +01006849 Examples :
Willy Tarreau303c0352008-01-17 19:01:39 +01006850 # ignore user-agents reporting any flavour of "Mozilla" or "MSIE", but
6851 # block all others.
6852 reqipass ^User-Agent:\.*(Mozilla|MSIE)
6853 reqitarpit ^User-Agent:
6854
Willy Tarreau5321c422010-01-28 20:35:13 +01006855 # block bad guys
6856 acl badguys src 10.1.0.3 172.16.13.20/28
6857 reqitarpit . if badguys
6858
6859 See also: "reqallow", "reqdeny", "reqpass", section 6 about HTTP header
6860 manipulation, and section 7 about ACLs.
Willy Tarreau303c0352008-01-17 19:01:39 +01006861
6862
Willy Tarreaue5c5ce92008-06-20 17:27:19 +02006863retries <value>
6864 Set the number of retries to perform on a server after a connection failure
6865 May be used in sections: defaults | frontend | listen | backend
6866 yes | no | yes | yes
6867 Arguments :
6868 <value> is the number of times a connection attempt should be retried on
6869 a server when a connection either is refused or times out. The
6870 default value is 3.
6871
6872 It is important to understand that this value applies to the number of
6873 connection attempts, not full requests. When a connection has effectively
6874 been established to a server, there will be no more retry.
6875
6876 In order to avoid immediate reconnections to a server which is restarting,
Joseph Lynch726ab712015-05-11 23:25:34 -07006877 a turn-around timer of min("timeout connect", one second) is applied before
6878 a retry occurs.
Willy Tarreaue5c5ce92008-06-20 17:27:19 +02006879
6880 When "option redispatch" is set, the last retry may be performed on another
6881 server even if a cookie references a different server.
6882
6883 See also : "option redispatch"
6884
6885
Willy Tarreaufdb563c2010-01-31 15:43:27 +01006886rspadd <string> [{if | unless} <cond>]
Willy Tarreau303c0352008-01-17 19:01:39 +01006887 Add a header at the end of the HTTP response
6888 May be used in sections : defaults | frontend | listen | backend
6889 no | yes | yes | yes
6890 Arguments :
6891 <string> is the complete line to be added. Any space or known delimiter
6892 must be escaped using a backslash ('\'). Please refer to section
Willy Tarreauc57f0e22009-05-10 13:12:33 +02006893 6 about HTTP header manipulation for more information.
Willy Tarreau303c0352008-01-17 19:01:39 +01006894
Willy Tarreaufdb563c2010-01-31 15:43:27 +01006895 <cond> is an optional matching condition built from ACLs. It makes it
6896 possible to ignore this rule when other conditions are not met.
6897
Willy Tarreau303c0352008-01-17 19:01:39 +01006898 A new line consisting in <string> followed by a line feed will be added after
6899 the last header of an HTTP response.
6900
6901 Header transformations only apply to traffic which passes through HAProxy,
6902 and not to traffic generated by HAProxy, such as health-checks or error
6903 responses.
6904
Willy Tarreaufdb563c2010-01-31 15:43:27 +01006905 See also: "reqadd", section 6 about HTTP header manipulation, and section 7
6906 about ACLs.
Willy Tarreau303c0352008-01-17 19:01:39 +01006907
6908
Willy Tarreaufdb563c2010-01-31 15:43:27 +01006909rspdel <search> [{if | unless} <cond>]
6910rspidel <search> [{if | unless} <cond>] (ignore case)
Willy Tarreau303c0352008-01-17 19:01:39 +01006911 Delete all headers matching a regular expression in an HTTP response
6912 May be used in sections : defaults | frontend | listen | backend
6913 no | yes | yes | yes
6914 Arguments :
6915 <search> is the regular expression applied to HTTP headers and to the
6916 response line. This is an extended regular expression, so
6917 parenthesis grouping is supported and no preliminary backslash
6918 is required. Any space or known delimiter must be escaped using
6919 a backslash ('\'). The pattern applies to a full line at a time.
6920 The "rspdel" keyword strictly matches case while "rspidel"
6921 ignores case.
6922
Willy Tarreaufdb563c2010-01-31 15:43:27 +01006923 <cond> is an optional matching condition built from ACLs. It makes it
6924 possible to ignore this rule when other conditions are not met.
6925
Willy Tarreau303c0352008-01-17 19:01:39 +01006926 Any header line matching extended regular expression <search> in the response
6927 will be completely deleted. Most common use of this is to remove unwanted
Willy Tarreau3c92c5f2011-08-28 09:45:47 +02006928 and/or sensitive headers or cookies from a response before passing it to the
Willy Tarreau303c0352008-01-17 19:01:39 +01006929 client.
6930
6931 Header transformations only apply to traffic which passes through HAProxy,
6932 and not to traffic generated by HAProxy, such as health-checks or error
6933 responses. Keep in mind that header names are not case-sensitive.
6934
6935 Example :
6936 # remove the Server header from responses
Willy Tarreau5e80e022013-05-25 08:31:25 +02006937 rspidel ^Server:.*
Willy Tarreau303c0352008-01-17 19:01:39 +01006938
Willy Tarreaufdb563c2010-01-31 15:43:27 +01006939 See also: "rspadd", "rsprep", "reqdel", section 6 about HTTP header
6940 manipulation, and section 7 about ACLs.
Willy Tarreau303c0352008-01-17 19:01:39 +01006941
6942
Willy Tarreaufdb563c2010-01-31 15:43:27 +01006943rspdeny <search> [{if | unless} <cond>]
6944rspideny <search> [{if | unless} <cond>] (ignore case)
Willy Tarreau303c0352008-01-17 19:01:39 +01006945 Block an HTTP response if a line matches a regular expression
6946 May be used in sections : defaults | frontend | listen | backend
6947 no | yes | yes | yes
6948 Arguments :
6949 <search> is the regular expression applied to HTTP headers and to the
6950 response line. This is an extended regular expression, so
6951 parenthesis grouping is supported and no preliminary backslash
6952 is required. Any space or known delimiter must be escaped using
6953 a backslash ('\'). The pattern applies to a full line at a time.
6954 The "rspdeny" keyword strictly matches case while "rspideny"
6955 ignores case.
6956
Willy Tarreaufdb563c2010-01-31 15:43:27 +01006957 <cond> is an optional matching condition built from ACLs. It makes it
6958 possible to ignore this rule when other conditions are not met.
6959
Willy Tarreau303c0352008-01-17 19:01:39 +01006960 A response containing any line which matches extended regular expression
6961 <search> will mark the request as denied. The test applies both to the
6962 response line and to response headers. Keep in mind that header names are not
6963 case-sensitive.
6964
6965 Main use of this keyword is to prevent sensitive information leak and to
Willy Tarreauced27012008-01-17 20:35:34 +01006966 block the response before it reaches the client. If a response is denied, it
6967 will be replaced with an HTTP 502 error so that the client never retrieves
6968 any sensitive data.
Willy Tarreau303c0352008-01-17 19:01:39 +01006969
6970 It is easier, faster and more powerful to use ACLs to write access policies.
6971 Rspdeny should be avoided in new designs.
6972
6973 Example :
6974 # Ensure that no content type matching ms-word will leak
6975 rspideny ^Content-type:\.*/ms-word
6976
Willy Tarreaufdb563c2010-01-31 15:43:27 +01006977 See also: "reqdeny", "acl", "block", section 6 about HTTP header manipulation
6978 and section 7 about ACLs.
Willy Tarreau303c0352008-01-17 19:01:39 +01006979
6980
Willy Tarreaufdb563c2010-01-31 15:43:27 +01006981rsprep <search> <string> [{if | unless} <cond>]
6982rspirep <search> <string> [{if | unless} <cond>] (ignore case)
Willy Tarreau303c0352008-01-17 19:01:39 +01006983 Replace a regular expression with a string in an HTTP response line
6984 May be used in sections : defaults | frontend | listen | backend
6985 no | yes | yes | yes
6986 Arguments :
6987 <search> is the regular expression applied to HTTP headers and to the
6988 response line. This is an extended regular expression, so
6989 parenthesis grouping is supported and no preliminary backslash
6990 is required. Any space or known delimiter must be escaped using
6991 a backslash ('\'). The pattern applies to a full line at a time.
6992 The "rsprep" keyword strictly matches case while "rspirep"
6993 ignores case.
6994
6995 <string> is the complete line to be added. Any space or known delimiter
6996 must be escaped using a backslash ('\'). References to matched
6997 pattern groups are possible using the common \N form, with N
6998 being a single digit between 0 and 9. Please refer to section
Willy Tarreauc57f0e22009-05-10 13:12:33 +02006999 6 about HTTP header manipulation for more information.
Willy Tarreau303c0352008-01-17 19:01:39 +01007000
Willy Tarreaufdb563c2010-01-31 15:43:27 +01007001 <cond> is an optional matching condition built from ACLs. It makes it
7002 possible to ignore this rule when other conditions are not met.
7003
Willy Tarreau303c0352008-01-17 19:01:39 +01007004 Any line matching extended regular expression <search> in the response (both
7005 the response line and header lines) will be completely replaced with
7006 <string>. Most common use of this is to rewrite Location headers.
7007
7008 Header transformations only apply to traffic which passes through HAProxy,
7009 and not to traffic generated by HAProxy, such as health-checks or error
7010 responses. Note that for increased readability, it is suggested to add enough
7011 spaces between the request and the response. Keep in mind that header names
7012 are not case-sensitive.
7013
7014 Example :
7015 # replace "Location: 127.0.0.1:8080" with "Location: www.mydomain.com"
7016 rspirep ^Location:\ 127.0.0.1:8080 Location:\ www.mydomain.com
7017
Willy Tarreaufdb563c2010-01-31 15:43:27 +01007018 See also: "rspadd", "rspdel", "reqrep", section 6 about HTTP header
7019 manipulation, and section 7 about ACLs.
Willy Tarreau303c0352008-01-17 19:01:39 +01007020
7021
David du Colombier486df472011-03-17 10:40:26 +01007022server <name> <address>[:[port]] [param*]
Willy Tarreaueabeafa2008-01-16 16:17:06 +01007023 Declare a server in a backend
7024 May be used in sections : defaults | frontend | listen | backend
7025 no | no | yes | yes
7026 Arguments :
7027 <name> is the internal name assigned to this server. This name will
Cyril Bonté941a0c62012-10-15 19:44:24 +02007028 appear in logs and alerts. If "http-send-name-header" is
Mark Lamourinec2247f02012-01-04 13:02:01 -05007029 set, it will be added to the request header sent to the server.
Willy Tarreaueabeafa2008-01-16 16:17:06 +01007030
David du Colombier486df472011-03-17 10:40:26 +01007031 <address> is the IPv4 or IPv6 address of the server. Alternatively, a
7032 resolvable hostname is supported, but this name will be resolved
7033 during start-up. Address "0.0.0.0" or "*" has a special meaning.
7034 It indicates that the connection will be forwarded to the same IP
Willy Tarreaud669a4f2010-07-13 14:49:50 +02007035 address as the one from the client connection. This is useful in
7036 transparent proxy architectures where the client's connection is
7037 intercepted and haproxy must forward to the original destination
7038 address. This is more or less what the "transparent" keyword does
7039 except that with a server it's possible to limit concurrency and
Willy Tarreau24709282013-03-10 21:32:12 +01007040 to report statistics. Optionally, an address family prefix may be
7041 used before the address to force the family regardless of the
7042 address format, which can be useful to specify a path to a unix
7043 socket with no slash ('/'). Currently supported prefixes are :
7044 - 'ipv4@' -> address is always IPv4
7045 - 'ipv6@' -> address is always IPv6
7046 - 'unix@' -> address is a path to a local unix socket
Willy Tarreauccfccef2014-05-10 01:49:15 +02007047 - 'abns@' -> address is in abstract namespace (Linux only)
William Lallemandb2f07452015-05-12 14:27:13 +02007048 You may want to reference some environment variables in the
7049 address parameter, see section 2.3 about environment
7050 variables.
Willy Tarreaueabeafa2008-01-16 16:17:06 +01007051
Willy Tarreaub6205fd2012-09-24 12:27:33 +02007052 <port> is an optional port specification. If set, all connections will
Willy Tarreaueabeafa2008-01-16 16:17:06 +01007053 be sent to this port. If unset, the same port the client
7054 connected to will be used. The port may also be prefixed by a "+"
7055 or a "-". In this case, the server's port will be determined by
7056 adding this value to the client's port.
7057
7058 <param*> is a list of parameters for this server. The "server" keywords
7059 accepts an important number of options and has a complete section
Willy Tarreauc57f0e22009-05-10 13:12:33 +02007060 dedicated to it. Please refer to section 5 for more details.
Willy Tarreaueabeafa2008-01-16 16:17:06 +01007061
7062 Examples :
7063 server first 10.1.1.1:1080 cookie first check inter 1000
7064 server second 10.1.1.2:1080 cookie second check inter 1000
Willy Tarreau24709282013-03-10 21:32:12 +01007065 server transp ipv4@
William Lallemandb2f07452015-05-12 14:27:13 +02007066 server backup "${SRV_BACKUP}:1080" backup
7067 server www1_dc1 "${LAN_DC1}.101:80"
7068 server www1_dc2 "${LAN_DC2}.101:80"
Willy Tarreaueabeafa2008-01-16 16:17:06 +01007069
Willy Tarreau55dcaf62015-09-27 15:03:15 +02007070 Note: regarding Linux's abstract namespace sockets, HAProxy uses the whole
7071 sun_path length is used for the address length. Some other programs
7072 such as socat use the string length only by default. Pass the option
7073 ",unix-tightsocklen=0" to any abstract socket definition in socat to
7074 make it compatible with HAProxy's.
7075
Mark Lamourinec2247f02012-01-04 13:02:01 -05007076 See also: "default-server", "http-send-name-header" and section 5 about
7077 server options
Willy Tarreaueabeafa2008-01-16 16:17:06 +01007078
Baptiste Assmann01c6cc32015-08-23 11:45:29 +02007079server-state-file-name [<file>]
7080 Set the server state file to read, load and apply to servers available in
7081 this backend. It only applies when the directive "load-server-state-from-file"
7082 is set to "local". When <file> is not provided or if this directive is not
7083 set, then backend name is used. If <file> starts with a slash '/', then it is
7084 considered as an absolute path. Otherwise, <file> is concatenated to the
7085 global directive "server-state-file-base".
7086
7087 Example: the minimal configuration below would make HAProxy look for the
7088 state server file '/etc/haproxy/states/bk':
7089
7090 global
7091 server-state-file-base /etc/haproxy/states
7092
7093 backend bk
7094 load-server-state-from-file
7095
7096 See also: "server-state-file-base", "load-server-state-from-file", and
7097 "show servers state"
Willy Tarreaueabeafa2008-01-16 16:17:06 +01007098
7099source <addr>[:<port>] [usesrc { <addr2>[:<port2>] | client | clientip } ]
Willy Tarreaubce70882009-09-07 11:51:47 +02007100source <addr>[:<port>] [usesrc { <addr2>[:<port2>] | hdr_ip(<hdr>[,<occ>]) } ]
Willy Tarreaud53f96b2009-02-04 18:46:54 +01007101source <addr>[:<port>] [interface <name>]
Willy Tarreaueabeafa2008-01-16 16:17:06 +01007102 Set the source address for outgoing connections
7103 May be used in sections : defaults | frontend | listen | backend
7104 yes | no | yes | yes
7105 Arguments :
7106 <addr> is the IPv4 address HAProxy will bind to before connecting to a
7107 server. This address is also used as a source for health checks.
Willy Tarreau24709282013-03-10 21:32:12 +01007108
Willy Tarreaueabeafa2008-01-16 16:17:06 +01007109 The default value of 0.0.0.0 means that the system will select
Willy Tarreau24709282013-03-10 21:32:12 +01007110 the most appropriate address to reach its destination. Optionally
7111 an address family prefix may be used before the address to force
7112 the family regardless of the address format, which can be useful
7113 to specify a path to a unix socket with no slash ('/'). Currently
7114 supported prefixes are :
7115 - 'ipv4@' -> address is always IPv4
7116 - 'ipv6@' -> address is always IPv6
7117 - 'unix@' -> address is a path to a local unix socket
Willy Tarreauccfccef2014-05-10 01:49:15 +02007118 - 'abns@' -> address is in abstract namespace (Linux only)
William Lallemandb2f07452015-05-12 14:27:13 +02007119 You may want to reference some environment variables in the address
7120 parameter, see section 2.3 about environment variables.
Willy Tarreaueabeafa2008-01-16 16:17:06 +01007121
7122 <port> is an optional port. It is normally not needed but may be useful
7123 in some very specific contexts. The default value of zero means
Willy Tarreauc6f4ce82009-06-10 11:09:37 +02007124 the system will select a free port. Note that port ranges are not
7125 supported in the backend. If you want to force port ranges, you
7126 have to specify them on each "server" line.
Willy Tarreaueabeafa2008-01-16 16:17:06 +01007127
7128 <addr2> is the IP address to present to the server when connections are
7129 forwarded in full transparent proxy mode. This is currently only
7130 supported on some patched Linux kernels. When this address is
7131 specified, clients connecting to the server will be presented
7132 with this address, while health checks will still use the address
7133 <addr>.
7134
7135 <port2> is the optional port to present to the server when connections
7136 are forwarded in full transparent proxy mode (see <addr2> above).
7137 The default value of zero means the system will select a free
7138 port.
7139
Willy Tarreaubce70882009-09-07 11:51:47 +02007140 <hdr> is the name of a HTTP header in which to fetch the IP to bind to.
7141 This is the name of a comma-separated header list which can
7142 contain multiple IP addresses. By default, the last occurrence is
7143 used. This is designed to work with the X-Forwarded-For header
Baptiste Assmannea3e73b2013-02-02 23:47:49 +01007144 and to automatically bind to the client's IP address as seen
Willy Tarreaubce70882009-09-07 11:51:47 +02007145 by previous proxy, typically Stunnel. In order to use another
7146 occurrence from the last one, please see the <occ> parameter
7147 below. When the header (or occurrence) is not found, no binding
7148 is performed so that the proxy's default IP address is used. Also
7149 keep in mind that the header name is case insensitive, as for any
7150 HTTP header.
7151
7152 <occ> is the occurrence number of a value to be used in a multi-value
7153 header. This is to be used in conjunction with "hdr_ip(<hdr>)",
Jamie Gloudonaaa21002012-08-25 00:18:33 -04007154 in order to specify which occurrence to use for the source IP
Willy Tarreaubce70882009-09-07 11:51:47 +02007155 address. Positive values indicate a position from the first
7156 occurrence, 1 being the first one. Negative values indicate
7157 positions relative to the last one, -1 being the last one. This
7158 is helpful for situations where an X-Forwarded-For header is set
7159 at the entry point of an infrastructure and must be used several
7160 proxy layers away. When this value is not specified, -1 is
7161 assumed. Passing a zero here disables the feature.
7162
Willy Tarreaud53f96b2009-02-04 18:46:54 +01007163 <name> is an optional interface name to which to bind to for outgoing
7164 traffic. On systems supporting this features (currently, only
7165 Linux), this allows one to bind all traffic to the server to
7166 this interface even if it is not the one the system would select
7167 based on routing tables. This should be used with extreme care.
7168 Note that using this option requires root privileges.
7169
Willy Tarreaueabeafa2008-01-16 16:17:06 +01007170 The "source" keyword is useful in complex environments where a specific
7171 address only is allowed to connect to the servers. It may be needed when a
7172 private address must be used through a public gateway for instance, and it is
7173 known that the system cannot determine the adequate source address by itself.
7174
7175 An extension which is available on certain patched Linux kernels may be used
7176 through the "usesrc" optional keyword. It makes it possible to connect to the
7177 servers with an IP address which does not belong to the system itself. This
7178 is called "full transparent proxy mode". For this to work, the destination
7179 servers have to route their traffic back to this address through the machine
7180 running HAProxy, and IP forwarding must generally be enabled on this machine.
7181
7182 In this "full transparent proxy" mode, it is possible to force a specific IP
7183 address to be presented to the servers. This is not much used in fact. A more
7184 common use is to tell HAProxy to present the client's IP address. For this,
7185 there are two methods :
7186
7187 - present the client's IP and port addresses. This is the most transparent
7188 mode, but it can cause problems when IP connection tracking is enabled on
7189 the machine, because a same connection may be seen twice with different
7190 states. However, this solution presents the huge advantage of not
7191 limiting the system to the 64k outgoing address+port couples, because all
7192 of the client ranges may be used.
7193
7194 - present only the client's IP address and select a spare port. This
7195 solution is still quite elegant but slightly less transparent (downstream
7196 firewalls logs will not match upstream's). It also presents the downside
7197 of limiting the number of concurrent connections to the usual 64k ports.
7198 However, since the upstream and downstream ports are different, local IP
7199 connection tracking on the machine will not be upset by the reuse of the
7200 same session.
7201
Willy Tarreaueabeafa2008-01-16 16:17:06 +01007202 This option sets the default source for all servers in the backend. It may
7203 also be specified in a "defaults" section. Finer source address specification
7204 is possible at the server level using the "source" server option. Refer to
Willy Tarreauc57f0e22009-05-10 13:12:33 +02007205 section 5 for more information.
Willy Tarreaueabeafa2008-01-16 16:17:06 +01007206
Baptiste Assmann91bd3372015-07-17 21:59:42 +02007207 In order to work, "usesrc" requires root privileges.
7208
Willy Tarreaueabeafa2008-01-16 16:17:06 +01007209 Examples :
7210 backend private
7211 # Connect to the servers using our 192.168.1.200 source address
7212 source 192.168.1.200
7213
7214 backend transparent_ssl1
7215 # Connect to the SSL farm from the client's source address
7216 source 192.168.1.200 usesrc clientip
7217
7218 backend transparent_ssl2
7219 # Connect to the SSL farm from the client's source address and port
7220 # not recommended if IP conntrack is present on the local machine.
7221 source 192.168.1.200 usesrc client
7222
7223 backend transparent_ssl3
7224 # Connect to the SSL farm from the client's source address. It
7225 # is more conntrack-friendly.
7226 source 192.168.1.200 usesrc clientip
7227
7228 backend transparent_smtp
7229 # Connect to the SMTP farm from the client's source address/port
7230 # with Tproxy version 4.
7231 source 0.0.0.0 usesrc clientip
7232
Willy Tarreaubce70882009-09-07 11:51:47 +02007233 backend transparent_http
7234 # Connect to the servers using the client's IP as seen by previous
7235 # proxy.
7236 source 0.0.0.0 usesrc hdr_ip(x-forwarded-for,-1)
7237
Willy Tarreauc57f0e22009-05-10 13:12:33 +02007238 See also : the "source" server option in section 5, the Tproxy patches for
Willy Tarreaueabeafa2008-01-16 16:17:06 +01007239 the Linux kernel on www.balabit.com, the "bind" keyword.
7240
Krzysztof Piotr Oledzki25b501a2008-01-06 16:36:16 +01007241
Willy Tarreau844e3c52008-01-11 16:28:18 +01007242srvtimeout <timeout> (deprecated)
7243 Set the maximum inactivity time on the server side.
7244 May be used in sections : defaults | frontend | listen | backend
7245 yes | no | yes | yes
7246 Arguments :
7247 <timeout> is the timeout value specified in milliseconds by default, but
7248 can be in any other unit if the number is suffixed by the unit,
7249 as explained at the top of this document.
7250
7251 The inactivity timeout applies when the server is expected to acknowledge or
7252 send data. In HTTP mode, this timeout is particularly important to consider
7253 during the first phase of the server's response, when it has to send the
7254 headers, as it directly represents the server's processing time for the
7255 request. To find out what value to put there, it's often good to start with
7256 what would be considered as unacceptable response times, then check the logs
7257 to observe the response time distribution, and adjust the value accordingly.
7258
7259 The value is specified in milliseconds by default, but can be in any other
7260 unit if the number is suffixed by the unit, as specified at the top of this
7261 document. In TCP mode (and to a lesser extent, in HTTP mode), it is highly
7262 recommended that the client timeout remains equal to the server timeout in
7263 order to avoid complex situations to debug. Whatever the expected server
Willy Tarreaud2a4aa22008-01-31 15:28:22 +01007264 response times, it is a good practice to cover at least one or several TCP
Willy Tarreau844e3c52008-01-11 16:28:18 +01007265 packet losses by specifying timeouts that are slightly above multiples of 3
Willy Tarreaud72758d2010-01-12 10:42:19 +01007266 seconds (eg: 4 or 5 seconds minimum).
Willy Tarreau844e3c52008-01-11 16:28:18 +01007267
7268 This parameter is specific to backends, but can be specified once for all in
7269 "defaults" sections. This is in fact one of the easiest solutions not to
7270 forget about it. An unspecified timeout results in an infinite timeout, which
7271 is not recommended. Such a usage is accepted and works but reports a warning
7272 during startup because it may results in accumulation of expired sessions in
7273 the system if the system's timeouts are not configured either.
7274
7275 This parameter is provided for compatibility but is currently deprecated.
7276 Please use "timeout server" instead.
7277
Willy Tarreauce887fd2012-05-12 12:50:00 +02007278 See also : "timeout server", "timeout tunnel", "timeout client" and
7279 "clitimeout".
Willy Tarreau844e3c52008-01-11 16:28:18 +01007280
7281
Cyril Bonté66c327d2010-10-12 00:14:37 +02007282stats admin { if | unless } <cond>
7283 Enable statistics admin level if/unless a condition is matched
7284 May be used in sections : defaults | frontend | listen | backend
Willy Tarreaued2119c2014-04-24 22:10:39 +02007285 no | yes | yes | yes
Cyril Bonté66c327d2010-10-12 00:14:37 +02007286
7287 This statement enables the statistics admin level if/unless a condition is
7288 matched.
7289
7290 The admin level allows to enable/disable servers from the web interface. By
7291 default, statistics page is read-only for security reasons.
7292
Cyril Bonté02ff8ef2010-12-14 22:48:49 +01007293 Note : Consider not using this feature in multi-process mode (nbproc > 1)
7294 unless you know what you do : memory is not shared between the
7295 processes, which can result in random behaviours.
7296
Cyril Bonté23b39d92011-02-10 22:54:44 +01007297 Currently, the POST request is limited to the buffer size minus the reserved
7298 buffer space, which means that if the list of servers is too long, the
7299 request won't be processed. It is recommended to alter few servers at a
7300 time.
Cyril Bonté66c327d2010-10-12 00:14:37 +02007301
7302 Example :
7303 # statistics admin level only for localhost
7304 backend stats_localhost
7305 stats enable
7306 stats admin if LOCALHOST
7307
7308 Example :
7309 # statistics admin level always enabled because of the authentication
7310 backend stats_auth
7311 stats enable
7312 stats auth admin:AdMiN123
7313 stats admin if TRUE
7314
7315 Example :
7316 # statistics admin level depends on the authenticated user
7317 userlist stats-auth
7318 group admin users admin
7319 user admin insecure-password AdMiN123
7320 group readonly users haproxy
7321 user haproxy insecure-password haproxy
7322
7323 backend stats_auth
7324 stats enable
7325 acl AUTH http_auth(stats-auth)
7326 acl AUTH_ADMIN http_auth_group(stats-auth) admin
7327 stats http-request auth unless AUTH
7328 stats admin if AUTH_ADMIN
7329
Cyril Bonté02ff8ef2010-12-14 22:48:49 +01007330 See also : "stats enable", "stats auth", "stats http-request", "nbproc",
7331 "bind-process", section 3.4 about userlists and section 7 about
7332 ACL usage.
Cyril Bonté66c327d2010-10-12 00:14:37 +02007333
7334
Willy Tarreaueabeafa2008-01-16 16:17:06 +01007335stats auth <user>:<passwd>
7336 Enable statistics with authentication and grant access to an account
7337 May be used in sections : defaults | frontend | listen | backend
Willy Tarreaued2119c2014-04-24 22:10:39 +02007338 yes | yes | yes | yes
Willy Tarreaueabeafa2008-01-16 16:17:06 +01007339 Arguments :
7340 <user> is a user name to grant access to
7341
7342 <passwd> is the cleartext password associated to this user
7343
7344 This statement enables statistics with default settings, and restricts access
7345 to declared users only. It may be repeated as many times as necessary to
7346 allow as many users as desired. When a user tries to access the statistics
7347 without a valid account, a "401 Forbidden" response will be returned so that
7348 the browser asks the user to provide a valid user and password. The real
7349 which will be returned to the browser is configurable using "stats realm".
7350
7351 Since the authentication method is HTTP Basic Authentication, the passwords
7352 circulate in cleartext on the network. Thus, it was decided that the
7353 configuration file would also use cleartext passwords to remind the users
Willy Tarreau3c92c5f2011-08-28 09:45:47 +02007354 that those ones should not be sensitive and not shared with any other account.
Willy Tarreaueabeafa2008-01-16 16:17:06 +01007355
7356 It is also possible to reduce the scope of the proxies which appear in the
7357 report using "stats scope".
7358
7359 Though this statement alone is enough to enable statistics reporting, it is
7360 recommended to set all other settings in order to avoid relying on default
7361 unobvious parameters.
7362
7363 Example :
7364 # public access (limited to this backend only)
7365 backend public_www
7366 server srv1 192.168.0.1:80
7367 stats enable
7368 stats hide-version
7369 stats scope .
7370 stats uri /admin?stats
7371 stats realm Haproxy\ Statistics
7372 stats auth admin1:AdMiN123
7373 stats auth admin2:AdMiN321
7374
7375 # internal monitoring access (unlimited)
7376 backend private_monitoring
7377 stats enable
7378 stats uri /admin?stats
7379 stats refresh 5s
7380
7381 See also : "stats enable", "stats realm", "stats scope", "stats uri"
7382
7383
7384stats enable
7385 Enable statistics reporting with default settings
7386 May be used in sections : defaults | frontend | listen | backend
Willy Tarreaued2119c2014-04-24 22:10:39 +02007387 yes | yes | yes | yes
Willy Tarreaueabeafa2008-01-16 16:17:06 +01007388 Arguments : none
7389
7390 This statement enables statistics reporting with default settings defined
7391 at build time. Unless stated otherwise, these settings are used :
7392 - stats uri : /haproxy?stats
7393 - stats realm : "HAProxy Statistics"
7394 - stats auth : no authentication
7395 - stats scope : no restriction
7396
7397 Though this statement alone is enough to enable statistics reporting, it is
7398 recommended to set all other settings in order to avoid relying on default
7399 unobvious parameters.
7400
7401 Example :
7402 # public access (limited to this backend only)
7403 backend public_www
7404 server srv1 192.168.0.1:80
7405 stats enable
7406 stats hide-version
7407 stats scope .
7408 stats uri /admin?stats
7409 stats realm Haproxy\ Statistics
7410 stats auth admin1:AdMiN123
7411 stats auth admin2:AdMiN321
7412
7413 # internal monitoring access (unlimited)
7414 backend private_monitoring
7415 stats enable
7416 stats uri /admin?stats
7417 stats refresh 5s
7418
7419 See also : "stats auth", "stats realm", "stats uri"
7420
7421
Willy Tarreaud63335a2010-02-26 12:56:52 +01007422stats hide-version
7423 Enable statistics and hide HAProxy version reporting
Willy Tarreau1d45b7c2009-08-16 10:29:18 +02007424 May be used in sections : defaults | frontend | listen | backend
Willy Tarreaued2119c2014-04-24 22:10:39 +02007425 yes | yes | yes | yes
Willy Tarreaud63335a2010-02-26 12:56:52 +01007426 Arguments : none
Willy Tarreau1d45b7c2009-08-16 10:29:18 +02007427
Willy Tarreaud63335a2010-02-26 12:56:52 +01007428 By default, the stats page reports some useful status information along with
7429 the statistics. Among them is HAProxy's version. However, it is generally
7430 considered dangerous to report precise version to anyone, as it can help them
7431 target known weaknesses with specific attacks. The "stats hide-version"
7432 statement removes the version from the statistics report. This is recommended
7433 for public sites or any site with a weak login/password.
Willy Tarreau1d45b7c2009-08-16 10:29:18 +02007434
Krzysztof Piotr Oledzki48cb2ae2009-10-02 22:51:14 +02007435 Though this statement alone is enough to enable statistics reporting, it is
7436 recommended to set all other settings in order to avoid relying on default
7437 unobvious parameters.
7438
Willy Tarreaud63335a2010-02-26 12:56:52 +01007439 Example :
7440 # public access (limited to this backend only)
7441 backend public_www
7442 server srv1 192.168.0.1:80
Krzysztof Piotr Oledzki48cb2ae2009-10-02 22:51:14 +02007443 stats enable
Willy Tarreaud63335a2010-02-26 12:56:52 +01007444 stats hide-version
7445 stats scope .
7446 stats uri /admin?stats
7447 stats realm Haproxy\ Statistics
7448 stats auth admin1:AdMiN123
7449 stats auth admin2:AdMiN321
Willy Tarreau1d45b7c2009-08-16 10:29:18 +02007450
Willy Tarreau1d45b7c2009-08-16 10:29:18 +02007451 # internal monitoring access (unlimited)
7452 backend private_monitoring
7453 stats enable
Willy Tarreaud63335a2010-02-26 12:56:52 +01007454 stats uri /admin?stats
7455 stats refresh 5s
Krzysztof Piotr Oledzki15514c22010-01-04 16:03:09 +01007456
Willy Tarreaud63335a2010-02-26 12:56:52 +01007457 See also : "stats auth", "stats enable", "stats realm", "stats uri"
Willy Tarreau1d45b7c2009-08-16 10:29:18 +02007458
Willy Tarreau983e01e2010-01-11 18:42:06 +01007459
Cyril Bonté2be1b3f2010-09-30 23:46:30 +02007460stats http-request { allow | deny | auth [realm <realm>] }
7461 [ { if | unless } <condition> ]
7462 Access control for statistics
7463
7464 May be used in sections: defaults | frontend | listen | backend
7465 no | no | yes | yes
7466
7467 As "http-request", these set of options allow to fine control access to
7468 statistics. Each option may be followed by if/unless and acl.
7469 First option with matched condition (or option without condition) is final.
7470 For "deny" a 403 error will be returned, for "allow" normal processing is
7471 performed, for "auth" a 401/407 error code is returned so the client
7472 should be asked to enter a username and password.
7473
7474 There is no fixed limit to the number of http-request statements per
7475 instance.
7476
7477 See also : "http-request", section 3.4 about userlists and section 7
7478 about ACL usage.
7479
7480
Willy Tarreaueabeafa2008-01-16 16:17:06 +01007481stats realm <realm>
7482 Enable statistics and set authentication realm
7483 May be used in sections : defaults | frontend | listen | backend
Willy Tarreaued2119c2014-04-24 22:10:39 +02007484 yes | yes | yes | yes
Willy Tarreaueabeafa2008-01-16 16:17:06 +01007485 Arguments :
7486 <realm> is the name of the HTTP Basic Authentication realm reported to
7487 the browser. The browser uses it to display it in the pop-up
7488 inviting the user to enter a valid username and password.
7489
7490 The realm is read as a single word, so any spaces in it should be escaped
7491 using a backslash ('\').
7492
7493 This statement is useful only in conjunction with "stats auth" since it is
7494 only related to authentication.
7495
7496 Though this statement alone is enough to enable statistics reporting, it is
7497 recommended to set all other settings in order to avoid relying on default
7498 unobvious parameters.
7499
7500 Example :
7501 # public access (limited to this backend only)
7502 backend public_www
7503 server srv1 192.168.0.1:80
7504 stats enable
7505 stats hide-version
7506 stats scope .
7507 stats uri /admin?stats
7508 stats realm Haproxy\ Statistics
7509 stats auth admin1:AdMiN123
7510 stats auth admin2:AdMiN321
7511
7512 # internal monitoring access (unlimited)
7513 backend private_monitoring
7514 stats enable
7515 stats uri /admin?stats
7516 stats refresh 5s
7517
7518 See also : "stats auth", "stats enable", "stats uri"
7519
7520
7521stats refresh <delay>
7522 Enable statistics with automatic refresh
7523 May be used in sections : defaults | frontend | listen | backend
Willy Tarreaued2119c2014-04-24 22:10:39 +02007524 yes | yes | yes | yes
Willy Tarreaueabeafa2008-01-16 16:17:06 +01007525 Arguments :
7526 <delay> is the suggested refresh delay, specified in seconds, which will
7527 be returned to the browser consulting the report page. While the
7528 browser is free to apply any delay, it will generally respect it
7529 and refresh the page this every seconds. The refresh interval may
7530 be specified in any other non-default time unit, by suffixing the
7531 unit after the value, as explained at the top of this document.
7532
7533 This statement is useful on monitoring displays with a permanent page
7534 reporting the load balancer's activity. When set, the HTML report page will
7535 include a link "refresh"/"stop refresh" so that the user can select whether
7536 he wants automatic refresh of the page or not.
7537
7538 Though this statement alone is enough to enable statistics reporting, it is
7539 recommended to set all other settings in order to avoid relying on default
7540 unobvious parameters.
7541
7542 Example :
7543 # public access (limited to this backend only)
7544 backend public_www
7545 server srv1 192.168.0.1:80
7546 stats enable
7547 stats hide-version
7548 stats scope .
7549 stats uri /admin?stats
7550 stats realm Haproxy\ Statistics
7551 stats auth admin1:AdMiN123
7552 stats auth admin2:AdMiN321
7553
7554 # internal monitoring access (unlimited)
7555 backend private_monitoring
7556 stats enable
7557 stats uri /admin?stats
7558 stats refresh 5s
7559
7560 See also : "stats auth", "stats enable", "stats realm", "stats uri"
7561
7562
7563stats scope { <name> | "." }
7564 Enable statistics and limit access scope
7565 May be used in sections : defaults | frontend | listen | backend
Willy Tarreaued2119c2014-04-24 22:10:39 +02007566 yes | yes | yes | yes
Willy Tarreaueabeafa2008-01-16 16:17:06 +01007567 Arguments :
7568 <name> is the name of a listen, frontend or backend section to be
7569 reported. The special name "." (a single dot) designates the
7570 section in which the statement appears.
7571
7572 When this statement is specified, only the sections enumerated with this
7573 statement will appear in the report. All other ones will be hidden. This
7574 statement may appear as many times as needed if multiple sections need to be
7575 reported. Please note that the name checking is performed as simple string
7576 comparisons, and that it is never checked that a give section name really
7577 exists.
7578
7579 Though this statement alone is enough to enable statistics reporting, it is
7580 recommended to set all other settings in order to avoid relying on default
7581 unobvious parameters.
7582
7583 Example :
7584 # public access (limited to this backend only)
7585 backend public_www
7586 server srv1 192.168.0.1:80
7587 stats enable
7588 stats hide-version
7589 stats scope .
7590 stats uri /admin?stats
7591 stats realm Haproxy\ Statistics
7592 stats auth admin1:AdMiN123
7593 stats auth admin2:AdMiN321
7594
7595 # internal monitoring access (unlimited)
7596 backend private_monitoring
7597 stats enable
7598 stats uri /admin?stats
7599 stats refresh 5s
7600
7601 See also : "stats auth", "stats enable", "stats realm", "stats uri"
7602
Willy Tarreaud63335a2010-02-26 12:56:52 +01007603
Willy Tarreauc9705a12010-07-27 20:05:50 +02007604stats show-desc [ <desc> ]
Willy Tarreaud63335a2010-02-26 12:56:52 +01007605 Enable reporting of a description on the statistics page.
7606 May be used in sections : defaults | frontend | listen | backend
Willy Tarreaued2119c2014-04-24 22:10:39 +02007607 yes | yes | yes | yes
Willy Tarreaud63335a2010-02-26 12:56:52 +01007608
Willy Tarreauc9705a12010-07-27 20:05:50 +02007609 <desc> is an optional description to be reported. If unspecified, the
Willy Tarreaud63335a2010-02-26 12:56:52 +01007610 description from global section is automatically used instead.
7611
7612 This statement is useful for users that offer shared services to their
7613 customers, where node or description should be different for each customer.
7614
7615 Though this statement alone is enough to enable statistics reporting, it is
7616 recommended to set all other settings in order to avoid relying on default
Dmitry Sivachenko7823de32012-05-16 14:00:26 +04007617 unobvious parameters. By default description is not shown.
Willy Tarreaud63335a2010-02-26 12:56:52 +01007618
7619 Example :
7620 # internal monitoring access (unlimited)
7621 backend private_monitoring
7622 stats enable
7623 stats show-desc Master node for Europe, Asia, Africa
7624 stats uri /admin?stats
7625 stats refresh 5s
7626
7627 See also: "show-node", "stats enable", "stats uri" and "description" in
7628 global section.
7629
7630
7631stats show-legends
Willy Tarreaued2119c2014-04-24 22:10:39 +02007632 Enable reporting additional information on the statistics page
7633 May be used in sections : defaults | frontend | listen | backend
7634 yes | yes | yes | yes
7635 Arguments : none
7636
Jarno Huuskonen0e82b922014-04-12 18:22:19 +03007637 Enable reporting additional information on the statistics page :
Willy Tarreaud63335a2010-02-26 12:56:52 +01007638 - cap: capabilities (proxy)
7639 - mode: one of tcp, http or health (proxy)
7640 - id: SNMP ID (proxy, socket, server)
7641 - IP (socket, server)
7642 - cookie (backend, server)
7643
7644 Though this statement alone is enough to enable statistics reporting, it is
7645 recommended to set all other settings in order to avoid relying on default
Dmitry Sivachenko7823de32012-05-16 14:00:26 +04007646 unobvious parameters. Default behaviour is not to show this information.
Willy Tarreaud63335a2010-02-26 12:56:52 +01007647
7648 See also: "stats enable", "stats uri".
7649
7650
7651stats show-node [ <name> ]
7652 Enable reporting of a host name on the statistics page.
7653 May be used in sections : defaults | frontend | listen | backend
Willy Tarreaued2119c2014-04-24 22:10:39 +02007654 yes | yes | yes | yes
Willy Tarreaud63335a2010-02-26 12:56:52 +01007655 Arguments:
7656 <name> is an optional name to be reported. If unspecified, the
7657 node name from global section is automatically used instead.
7658
7659 This statement is useful for users that offer shared services to their
7660 customers, where node or description might be different on a stats page
Dmitry Sivachenko7823de32012-05-16 14:00:26 +04007661 provided for each customer. Default behaviour is not to show host name.
Willy Tarreaud63335a2010-02-26 12:56:52 +01007662
7663 Though this statement alone is enough to enable statistics reporting, it is
7664 recommended to set all other settings in order to avoid relying on default
7665 unobvious parameters.
7666
7667 Example:
7668 # internal monitoring access (unlimited)
7669 backend private_monitoring
7670 stats enable
7671 stats show-node Europe-1
7672 stats uri /admin?stats
7673 stats refresh 5s
7674
7675 See also: "show-desc", "stats enable", "stats uri", and "node" in global
7676 section.
7677
Willy Tarreaueabeafa2008-01-16 16:17:06 +01007678
7679stats uri <prefix>
7680 Enable statistics and define the URI prefix to access them
7681 May be used in sections : defaults | frontend | listen | backend
Willy Tarreaued2119c2014-04-24 22:10:39 +02007682 yes | yes | yes | yes
Willy Tarreaueabeafa2008-01-16 16:17:06 +01007683 Arguments :
7684 <prefix> is the prefix of any URI which will be redirected to stats. This
7685 prefix may contain a question mark ('?') to indicate part of a
7686 query string.
7687
7688 The statistics URI is intercepted on the relayed traffic, so it appears as a
7689 page within the normal application. It is strongly advised to ensure that the
7690 selected URI will never appear in the application, otherwise it will never be
7691 possible to reach it in the application.
7692
7693 The default URI compiled in haproxy is "/haproxy?stats", but this may be
Krzysztof Piotr Oledzkif8645332009-12-13 21:55:50 +01007694 changed at build time, so it's better to always explicitly specify it here.
Willy Tarreaueabeafa2008-01-16 16:17:06 +01007695 It is generally a good idea to include a question mark in the URI so that
7696 intermediate proxies refrain from caching the results. Also, since any string
7697 beginning with the prefix will be accepted as a stats request, the question
7698 mark helps ensuring that no valid URI will begin with the same words.
7699
7700 It is sometimes very convenient to use "/" as the URI prefix, and put that
7701 statement in a "listen" instance of its own. That makes it easy to dedicate
7702 an address or a port to statistics only.
7703
7704 Though this statement alone is enough to enable statistics reporting, it is
7705 recommended to set all other settings in order to avoid relying on default
7706 unobvious parameters.
7707
7708 Example :
7709 # public access (limited to this backend only)
7710 backend public_www
7711 server srv1 192.168.0.1:80
7712 stats enable
7713 stats hide-version
7714 stats scope .
7715 stats uri /admin?stats
7716 stats realm Haproxy\ Statistics
7717 stats auth admin1:AdMiN123
7718 stats auth admin2:AdMiN321
7719
7720 # internal monitoring access (unlimited)
7721 backend private_monitoring
7722 stats enable
7723 stats uri /admin?stats
7724 stats refresh 5s
7725
7726 See also : "stats auth", "stats enable", "stats realm"
7727
7728
Willy Tarreaud63335a2010-02-26 12:56:52 +01007729stick match <pattern> [table <table>] [{if | unless} <cond>]
7730 Define a request pattern matching condition to stick a user to a server
Willy Tarreaueabeafa2008-01-16 16:17:06 +01007731 May be used in sections : defaults | frontend | listen | backend
Willy Tarreaud63335a2010-02-26 12:56:52 +01007732 no | no | yes | yes
Willy Tarreaub937b7e2010-01-12 15:27:54 +01007733
7734 Arguments :
Willy Tarreaube722a22014-06-13 16:31:59 +02007735 <pattern> is a sample expression rule as described in section 7.3. It
Willy Tarreaub937b7e2010-01-12 15:27:54 +01007736 describes what elements of the incoming request or connection
7737 will be analysed in the hope to find a matching entry in a
7738 stickiness table. This rule is mandatory.
7739
7740 <table> is an optional stickiness table name. If unspecified, the same
7741 backend's table is used. A stickiness table is declared using
7742 the "stick-table" statement.
7743
7744 <cond> is an optional matching condition. It makes it possible to match
7745 on a certain criterion only when other conditions are met (or
7746 not met). For instance, it could be used to match on a source IP
7747 address except when a request passes through a known proxy, in
7748 which case we'd match on a header containing that IP address.
7749
7750 Some protocols or applications require complex stickiness rules and cannot
7751 always simply rely on cookies nor hashing. The "stick match" statement
7752 describes a rule to extract the stickiness criterion from an incoming request
7753 or connection. See section 7 for a complete list of possible patterns and
7754 transformation rules.
7755
7756 The table has to be declared using the "stick-table" statement. It must be of
7757 a type compatible with the pattern. By default it is the one which is present
7758 in the same backend. It is possible to share a table with other backends by
7759 referencing it using the "table" keyword. If another table is referenced,
7760 the server's ID inside the backends are used. By default, all server IDs
7761 start at 1 in each backend, so the server ordering is enough. But in case of
7762 doubt, it is highly recommended to force server IDs using their "id" setting.
7763
7764 It is possible to restrict the conditions where a "stick match" statement
7765 will apply, using "if" or "unless" followed by a condition. See section 7 for
7766 ACL based conditions.
7767
7768 There is no limit on the number of "stick match" statements. The first that
7769 applies and matches will cause the request to be directed to the same server
7770 as was used for the request which created the entry. That way, multiple
7771 matches can be used as fallbacks.
7772
7773 The stick rules are checked after the persistence cookies, so they will not
7774 affect stickiness if a cookie has already been used to select a server. That
7775 way, it becomes very easy to insert cookies and match on IP addresses in
7776 order to maintain stickiness between HTTP and HTTPS.
7777
Cyril Bonté02ff8ef2010-12-14 22:48:49 +01007778 Note : Consider not using this feature in multi-process mode (nbproc > 1)
7779 unless you know what you do : memory is not shared between the
7780 processes, which can result in random behaviours.
7781
Willy Tarreaub937b7e2010-01-12 15:27:54 +01007782 Example :
7783 # forward SMTP users to the same server they just used for POP in the
7784 # last 30 minutes
7785 backend pop
7786 mode tcp
7787 balance roundrobin
7788 stick store-request src
7789 stick-table type ip size 200k expire 30m
7790 server s1 192.168.1.1:110
7791 server s2 192.168.1.1:110
7792
7793 backend smtp
7794 mode tcp
7795 balance roundrobin
7796 stick match src table pop
7797 server s1 192.168.1.1:25
7798 server s2 192.168.1.1:25
7799
Cyril Bonté02ff8ef2010-12-14 22:48:49 +01007800 See also : "stick-table", "stick on", "nbproc", "bind-process" and section 7
Willy Tarreaube722a22014-06-13 16:31:59 +02007801 about ACLs and samples fetching.
Willy Tarreaub937b7e2010-01-12 15:27:54 +01007802
7803
7804stick on <pattern> [table <table>] [{if | unless} <condition>]
7805 Define a request pattern to associate a user to a server
7806 May be used in sections : defaults | frontend | listen | backend
7807 no | no | yes | yes
7808
7809 Note : This form is exactly equivalent to "stick match" followed by
7810 "stick store-request", all with the same arguments. Please refer
7811 to both keywords for details. It is only provided as a convenience
7812 for writing more maintainable configurations.
7813
Cyril Bonté02ff8ef2010-12-14 22:48:49 +01007814 Note : Consider not using this feature in multi-process mode (nbproc > 1)
7815 unless you know what you do : memory is not shared between the
7816 processes, which can result in random behaviours.
7817
Willy Tarreaub937b7e2010-01-12 15:27:54 +01007818 Examples :
7819 # The following form ...
Willy Tarreauec579d82010-02-26 19:15:04 +01007820 stick on src table pop if !localhost
Willy Tarreaub937b7e2010-01-12 15:27:54 +01007821
7822 # ...is strictly equivalent to this one :
7823 stick match src table pop if !localhost
7824 stick store-request src table pop if !localhost
7825
7826
7827 # Use cookie persistence for HTTP, and stick on source address for HTTPS as
7828 # well as HTTP without cookie. Share the same table between both accesses.
7829 backend http
7830 mode http
7831 balance roundrobin
7832 stick on src table https
7833 cookie SRV insert indirect nocache
7834 server s1 192.168.1.1:80 cookie s1
7835 server s2 192.168.1.1:80 cookie s2
7836
7837 backend https
7838 mode tcp
7839 balance roundrobin
7840 stick-table type ip size 200k expire 30m
7841 stick on src
7842 server s1 192.168.1.1:443
7843 server s2 192.168.1.1:443
7844
Cyril Bonté02ff8ef2010-12-14 22:48:49 +01007845 See also : "stick match", "stick store-request", "nbproc" and "bind-process".
Willy Tarreaub937b7e2010-01-12 15:27:54 +01007846
7847
7848stick store-request <pattern> [table <table>] [{if | unless} <condition>]
7849 Define a request pattern used to create an entry in a stickiness table
7850 May be used in sections : defaults | frontend | listen | backend
7851 no | no | yes | yes
7852
7853 Arguments :
Willy Tarreaube722a22014-06-13 16:31:59 +02007854 <pattern> is a sample expression rule as described in section 7.3. It
Willy Tarreaub937b7e2010-01-12 15:27:54 +01007855 describes what elements of the incoming request or connection
7856 will be analysed, extracted and stored in the table once a
7857 server is selected.
7858
7859 <table> is an optional stickiness table name. If unspecified, the same
7860 backend's table is used. A stickiness table is declared using
7861 the "stick-table" statement.
7862
7863 <cond> is an optional storage condition. It makes it possible to store
7864 certain criteria only when some conditions are met (or not met).
7865 For instance, it could be used to store the source IP address
7866 except when the request passes through a known proxy, in which
7867 case we'd store a converted form of a header containing that IP
7868 address.
7869
7870 Some protocols or applications require complex stickiness rules and cannot
7871 always simply rely on cookies nor hashing. The "stick store-request" statement
7872 describes a rule to decide what to extract from the request and when to do
7873 it, in order to store it into a stickiness table for further requests to
7874 match it using the "stick match" statement. Obviously the extracted part must
7875 make sense and have a chance to be matched in a further request. Storing a
7876 client's IP address for instance often makes sense. Storing an ID found in a
7877 URL parameter also makes sense. Storing a source port will almost never make
7878 any sense because it will be randomly matched. See section 7 for a complete
7879 list of possible patterns and transformation rules.
7880
7881 The table has to be declared using the "stick-table" statement. It must be of
7882 a type compatible with the pattern. By default it is the one which is present
7883 in the same backend. It is possible to share a table with other backends by
7884 referencing it using the "table" keyword. If another table is referenced,
7885 the server's ID inside the backends are used. By default, all server IDs
7886 start at 1 in each backend, so the server ordering is enough. But in case of
7887 doubt, it is highly recommended to force server IDs using their "id" setting.
7888
7889 It is possible to restrict the conditions where a "stick store-request"
7890 statement will apply, using "if" or "unless" followed by a condition. This
7891 condition will be evaluated while parsing the request, so any criteria can be
7892 used. See section 7 for ACL based conditions.
7893
7894 There is no limit on the number of "stick store-request" statements, but
7895 there is a limit of 8 simultaneous stores per request or response. This
7896 makes it possible to store up to 8 criteria, all extracted from either the
7897 request or the response, regardless of the number of rules. Only the 8 first
7898 ones which match will be kept. Using this, it is possible to feed multiple
7899 tables at once in the hope to increase the chance to recognize a user on
Willy Tarreau9667a802013-12-09 12:52:13 +01007900 another protocol or access method. Using multiple store-request rules with
7901 the same table is possible and may be used to find the best criterion to rely
7902 on, by arranging the rules by decreasing preference order. Only the first
7903 extracted criterion for a given table will be stored. All subsequent store-
7904 request rules referencing the same table will be skipped and their ACLs will
7905 not be evaluated.
Willy Tarreaub937b7e2010-01-12 15:27:54 +01007906
7907 The "store-request" rules are evaluated once the server connection has been
7908 established, so that the table will contain the real server that processed
7909 the request.
7910
Cyril Bonté02ff8ef2010-12-14 22:48:49 +01007911 Note : Consider not using this feature in multi-process mode (nbproc > 1)
7912 unless you know what you do : memory is not shared between the
7913 processes, which can result in random behaviours.
7914
Willy Tarreaub937b7e2010-01-12 15:27:54 +01007915 Example :
7916 # forward SMTP users to the same server they just used for POP in the
7917 # last 30 minutes
7918 backend pop
7919 mode tcp
7920 balance roundrobin
7921 stick store-request src
7922 stick-table type ip size 200k expire 30m
7923 server s1 192.168.1.1:110
7924 server s2 192.168.1.1:110
7925
7926 backend smtp
7927 mode tcp
7928 balance roundrobin
7929 stick match src table pop
7930 server s1 192.168.1.1:25
7931 server s2 192.168.1.1:25
7932
Cyril Bonté02ff8ef2010-12-14 22:48:49 +01007933 See also : "stick-table", "stick on", "nbproc", "bind-process" and section 7
Willy Tarreaube722a22014-06-13 16:31:59 +02007934 about ACLs and sample fetching.
Willy Tarreaub937b7e2010-01-12 15:27:54 +01007935
7936
Emeric Brun7c6b82e2010-09-24 16:34:28 +02007937stick-table type {ip | integer | string [len <length>] | binary [len <length>]}
Emeric Brunf099e792010-09-27 12:05:28 +02007938 size <size> [expire <expire>] [nopurge] [peers <peersect>]
7939 [store <data_type>]*
Godbach64cef792013-12-04 16:08:22 +08007940 Configure the stickiness table for the current section
Willy Tarreaub937b7e2010-01-12 15:27:54 +01007941 May be used in sections : defaults | frontend | listen | backend
Willy Tarreauc00cdc22010-06-06 16:48:26 +02007942 no | yes | yes | yes
Willy Tarreaub937b7e2010-01-12 15:27:54 +01007943
7944 Arguments :
7945 ip a table declared with "type ip" will only store IPv4 addresses.
7946 This form is very compact (about 50 bytes per entry) and allows
7947 very fast entry lookup and stores with almost no overhead. This
7948 is mainly used to store client source IP addresses.
7949
David du Colombier9a6d3c92011-03-17 10:40:24 +01007950 ipv6 a table declared with "type ipv6" will only store IPv6 addresses.
7951 This form is very compact (about 60 bytes per entry) and allows
7952 very fast entry lookup and stores with almost no overhead. This
7953 is mainly used to store client source IP addresses.
7954
Willy Tarreaub937b7e2010-01-12 15:27:54 +01007955 integer a table declared with "type integer" will store 32bit integers
7956 which can represent a client identifier found in a request for
7957 instance.
7958
7959 string a table declared with "type string" will store substrings of up
7960 to <len> characters. If the string provided by the pattern
7961 extractor is larger than <len>, it will be truncated before
7962 being stored. During matching, at most <len> characters will be
7963 compared between the string in the table and the extracted
7964 pattern. When not specified, the string is automatically limited
Emeric Brun7c6b82e2010-09-24 16:34:28 +02007965 to 32 characters.
7966
7967 binary a table declared with "type binary" will store binary blocks
7968 of <len> bytes. If the block provided by the pattern
7969 extractor is larger than <len>, it will be truncated before
Willy Tarreaube722a22014-06-13 16:31:59 +02007970 being stored. If the block provided by the sample expression
Emeric Brun7c6b82e2010-09-24 16:34:28 +02007971 is shorter than <len>, it will be padded by 0. When not
7972 specified, the block is automatically limited to 32 bytes.
Willy Tarreaub937b7e2010-01-12 15:27:54 +01007973
7974 <length> is the maximum number of characters that will be stored in a
Emeric Brun7c6b82e2010-09-24 16:34:28 +02007975 "string" type table (See type "string" above). Or the number
7976 of bytes of the block in "binary" type table. Be careful when
Willy Tarreaub937b7e2010-01-12 15:27:54 +01007977 changing this parameter as memory usage will proportionally
7978 increase.
7979
7980 <size> is the maximum number of entries that can fit in the table. This
Cyril Bonté78caf842010-03-10 22:41:43 +01007981 value directly impacts memory usage. Count approximately
7982 50 bytes per entry, plus the size of a string if any. The size
7983 supports suffixes "k", "m", "g" for 2^10, 2^20 and 2^30 factors.
Willy Tarreaub937b7e2010-01-12 15:27:54 +01007984
7985 [nopurge] indicates that we refuse to purge older entries when the table
7986 is full. When not specified and the table is full when haproxy
7987 wants to store an entry in it, it will flush a few of the oldest
7988 entries in order to release some space for the new ones. This is
7989 most often the desired behaviour. In some specific cases, it
7990 be desirable to refuse new entries instead of purging the older
7991 ones. That may be the case when the amount of data to store is
7992 far above the hardware limits and we prefer not to offer access
7993 to new clients than to reject the ones already connected. When
7994 using this parameter, be sure to properly set the "expire"
7995 parameter (see below).
7996
Emeric Brunf099e792010-09-27 12:05:28 +02007997 <peersect> is the name of the peers section to use for replication. Entries
7998 which associate keys to server IDs are kept synchronized with
7999 the remote peers declared in this section. All entries are also
8000 automatically learned from the local peer (old process) during a
8001 soft restart.
8002
Willy Tarreau1abc6732015-05-01 19:21:02 +02008003 NOTE : each peers section may be referenced only by tables
8004 belonging to the same unique process.
Cyril Bonté02ff8ef2010-12-14 22:48:49 +01008005
Willy Tarreaub937b7e2010-01-12 15:27:54 +01008006 <expire> defines the maximum duration of an entry in the table since it
8007 was last created, refreshed or matched. The expiration delay is
8008 defined using the standard time format, similarly as the various
8009 timeouts. The maximum duration is slightly above 24 days. See
8010 section 2.2 for more information. If this delay is not specified,
Cyril Bontédc4d9032012-04-08 21:57:39 +02008011 the session won't automatically expire, but older entries will
Willy Tarreaub937b7e2010-01-12 15:27:54 +01008012 be removed once full. Be sure not to use the "nopurge" parameter
8013 if not expiration delay is specified.
8014
Willy Tarreau08d5f982010-06-06 13:34:54 +02008015 <data_type> is used to store additional information in the stick-table. This
8016 may be used by ACLs in order to control various criteria related
8017 to the activity of the client matching the stick-table. For each
8018 item specified here, the size of each entry will be inflated so
Willy Tarreauc9705a12010-07-27 20:05:50 +02008019 that the additional data can fit. Several data types may be
8020 stored with an entry. Multiple data types may be specified after
8021 the "store" keyword, as a comma-separated list. Alternatively,
8022 it is possible to repeat the "store" keyword followed by one or
8023 several data types. Except for the "server_id" type which is
8024 automatically detected and enabled, all data types must be
8025 explicitly declared to be stored. If an ACL references a data
8026 type which is not stored, the ACL will simply not match. Some
8027 data types require an argument which must be passed just after
8028 the type between parenthesis. See below for the supported data
8029 types and their arguments.
8030
8031 The data types that can be stored with an entry are the following :
8032 - server_id : this is an integer which holds the numeric ID of the server a
8033 request was assigned to. It is used by the "stick match", "stick store",
8034 and "stick on" rules. It is automatically enabled when referenced.
8035
8036 - gpc0 : first General Purpose Counter. It is a positive 32-bit integer
8037 integer which may be used for anything. Most of the time it will be used
8038 to put a special tag on some entries, for instance to note that a
8039 specific behaviour was detected and must be known for future matches.
8040
Willy Tarreauba2ffd12013-05-29 15:54:14 +02008041 - gpc0_rate(<period>) : increment rate of the first General Purpose Counter
8042 over a period. It is a positive 32-bit integer integer which may be used
8043 for anything. Just like <gpc0>, it counts events, but instead of keeping
8044 a cumulative count, it maintains the rate at which the counter is
8045 incremented. Most of the time it will be used to measure the frequency of
8046 occurrence of certain events (eg: requests to a specific URL).
8047
Willy Tarreauc9705a12010-07-27 20:05:50 +02008048 - conn_cnt : Connection Count. It is a positive 32-bit integer which counts
8049 the absolute number of connections received from clients which matched
8050 this entry. It does not mean the connections were accepted, just that
8051 they were received.
8052
8053 - conn_cur : Current Connections. It is a positive 32-bit integer which
8054 stores the concurrent connection counts for the entry. It is incremented
8055 once an incoming connection matches the entry, and decremented once the
8056 connection leaves. That way it is possible to know at any time the exact
8057 number of concurrent connections for an entry.
8058
8059 - conn_rate(<period>) : frequency counter (takes 12 bytes). It takes an
8060 integer parameter <period> which indicates in milliseconds the length
8061 of the period over which the average is measured. It reports the average
8062 incoming connection rate over that period, in connections per period. The
8063 result is an integer which can be matched using ACLs.
8064
8065 - sess_cnt : Session Count. It is a positive 32-bit integer which counts
8066 the absolute number of sessions received from clients which matched this
8067 entry. A session is a connection that was accepted by the layer 4 rules.
8068
8069 - sess_rate(<period>) : frequency counter (takes 12 bytes). It takes an
8070 integer parameter <period> which indicates in milliseconds the length
8071 of the period over which the average is measured. It reports the average
8072 incoming session rate over that period, in sessions per period. The
8073 result is an integer which can be matched using ACLs.
8074
8075 - http_req_cnt : HTTP request Count. It is a positive 32-bit integer which
8076 counts the absolute number of HTTP requests received from clients which
8077 matched this entry. It does not matter whether they are valid requests or
8078 not. Note that this is different from sessions when keep-alive is used on
8079 the client side.
8080
8081 - http_req_rate(<period>) : frequency counter (takes 12 bytes). It takes an
8082 integer parameter <period> which indicates in milliseconds the length
8083 of the period over which the average is measured. It reports the average
8084 HTTP request rate over that period, in requests per period. The result is
8085 an integer which can be matched using ACLs. It does not matter whether
8086 they are valid requests or not. Note that this is different from sessions
8087 when keep-alive is used on the client side.
8088
8089 - http_err_cnt : HTTP Error Count. It is a positive 32-bit integer which
8090 counts the absolute number of HTTP requests errors induced by clients
8091 which matched this entry. Errors are counted on invalid and truncated
8092 requests, as well as on denied or tarpitted requests, and on failed
8093 authentications. If the server responds with 4xx, then the request is
8094 also counted as an error since it's an error triggered by the client
8095 (eg: vulnerability scan).
8096
8097 - http_err_rate(<period>) : frequency counter (takes 12 bytes). It takes an
8098 integer parameter <period> which indicates in milliseconds the length
8099 of the period over which the average is measured. It reports the average
8100 HTTP request error rate over that period, in requests per period (see
8101 http_err_cnt above for what is accounted as an error). The result is an
8102 integer which can be matched using ACLs.
8103
8104 - bytes_in_cnt : client to server byte count. It is a positive 64-bit
8105 integer which counts the cumulated amount of bytes received from clients
8106 which matched this entry. Headers are included in the count. This may be
8107 used to limit abuse of upload features on photo or video servers.
8108
8109 - bytes_in_rate(<period>) : frequency counter (takes 12 bytes). It takes an
8110 integer parameter <period> which indicates in milliseconds the length
8111 of the period over which the average is measured. It reports the average
8112 incoming bytes rate over that period, in bytes per period. It may be used
8113 to detect users which upload too much and too fast. Warning: with large
8114 uploads, it is possible that the amount of uploaded data will be counted
8115 once upon termination, thus causing spikes in the average transfer speed
8116 instead of having a smooth one. This may partially be smoothed with
8117 "option contstats" though this is not perfect yet. Use of byte_in_cnt is
8118 recommended for better fairness.
8119
8120 - bytes_out_cnt : server to client byte count. It is a positive 64-bit
8121 integer which counts the cumulated amount of bytes sent to clients which
8122 matched this entry. Headers are included in the count. This may be used
8123 to limit abuse of bots sucking the whole site.
8124
8125 - bytes_out_rate(<period>) : frequency counter (takes 12 bytes). It takes
8126 an integer parameter <period> which indicates in milliseconds the length
8127 of the period over which the average is measured. It reports the average
8128 outgoing bytes rate over that period, in bytes per period. It may be used
8129 to detect users which download too much and too fast. Warning: with large
8130 transfers, it is possible that the amount of transferred data will be
8131 counted once upon termination, thus causing spikes in the average
8132 transfer speed instead of having a smooth one. This may partially be
8133 smoothed with "option contstats" though this is not perfect yet. Use of
8134 byte_out_cnt is recommended for better fairness.
Willy Tarreau08d5f982010-06-06 13:34:54 +02008135
Willy Tarreauc00cdc22010-06-06 16:48:26 +02008136 There is only one stick-table per proxy. At the moment of writing this doc,
8137 it does not seem useful to have multiple tables per proxy. If this happens
Willy Tarreaub937b7e2010-01-12 15:27:54 +01008138 to be required, simply create a dummy backend with a stick-table in it and
8139 reference it.
8140
8141 It is important to understand that stickiness based on learning information
8142 has some limitations, including the fact that all learned associations are
8143 lost upon restart. In general it can be good as a complement but not always
8144 as an exclusive stickiness.
8145
Willy Tarreauc9705a12010-07-27 20:05:50 +02008146 Last, memory requirements may be important when storing many data types.
8147 Indeed, storing all indicators above at once in each entry requires 116 bytes
8148 per entry, or 116 MB for a 1-million entries table. This is definitely not
8149 something that can be ignored.
8150
8151 Example:
8152 # Keep track of counters of up to 1 million IP addresses over 5 minutes
8153 # and store a general purpose counter and the average connection rate
8154 # computed over a sliding window of 30 seconds.
8155 stick-table type ip size 1m expire 5m store gpc0,conn_rate(30s)
8156
8157 See also : "stick match", "stick on", "stick store-request", section 2.2
David du Colombiera13d1b92011-03-17 10:40:22 +01008158 about time format and section 7 about ACLs.
Willy Tarreaub937b7e2010-01-12 15:27:54 +01008159
8160
Emeric Brun6a1cefa2010-09-24 18:15:17 +02008161stick store-response <pattern> [table <table>] [{if | unless} <condition>]
8162 Define a request pattern used to create an entry in a stickiness table
8163 May be used in sections : defaults | frontend | listen | backend
8164 no | no | yes | yes
8165
8166 Arguments :
Willy Tarreaube722a22014-06-13 16:31:59 +02008167 <pattern> is a sample expression rule as described in section 7.3. It
Emeric Brun6a1cefa2010-09-24 18:15:17 +02008168 describes what elements of the response or connection will
8169 be analysed, extracted and stored in the table once a
8170 server is selected.
8171
8172 <table> is an optional stickiness table name. If unspecified, the same
8173 backend's table is used. A stickiness table is declared using
8174 the "stick-table" statement.
8175
8176 <cond> is an optional storage condition. It makes it possible to store
8177 certain criteria only when some conditions are met (or not met).
8178 For instance, it could be used to store the SSL session ID only
8179 when the response is a SSL server hello.
8180
8181 Some protocols or applications require complex stickiness rules and cannot
8182 always simply rely on cookies nor hashing. The "stick store-response"
8183 statement describes a rule to decide what to extract from the response and
8184 when to do it, in order to store it into a stickiness table for further
8185 requests to match it using the "stick match" statement. Obviously the
8186 extracted part must make sense and have a chance to be matched in a further
Cyril Bonté108cf6e2012-04-21 23:30:29 +02008187 request. Storing an ID found in a header of a response makes sense.
Emeric Brun6a1cefa2010-09-24 18:15:17 +02008188 See section 7 for a complete list of possible patterns and transformation
8189 rules.
8190
8191 The table has to be declared using the "stick-table" statement. It must be of
8192 a type compatible with the pattern. By default it is the one which is present
8193 in the same backend. It is possible to share a table with other backends by
8194 referencing it using the "table" keyword. If another table is referenced,
8195 the server's ID inside the backends are used. By default, all server IDs
8196 start at 1 in each backend, so the server ordering is enough. But in case of
8197 doubt, it is highly recommended to force server IDs using their "id" setting.
8198
8199 It is possible to restrict the conditions where a "stick store-response"
8200 statement will apply, using "if" or "unless" followed by a condition. This
8201 condition will be evaluated while parsing the response, so any criteria can
8202 be used. See section 7 for ACL based conditions.
8203
8204 There is no limit on the number of "stick store-response" statements, but
8205 there is a limit of 8 simultaneous stores per request or response. This
8206 makes it possible to store up to 8 criteria, all extracted from either the
8207 request or the response, regardless of the number of rules. Only the 8 first
8208 ones which match will be kept. Using this, it is possible to feed multiple
8209 tables at once in the hope to increase the chance to recognize a user on
Willy Tarreau9667a802013-12-09 12:52:13 +01008210 another protocol or access method. Using multiple store-response rules with
8211 the same table is possible and may be used to find the best criterion to rely
8212 on, by arranging the rules by decreasing preference order. Only the first
8213 extracted criterion for a given table will be stored. All subsequent store-
8214 response rules referencing the same table will be skipped and their ACLs will
8215 not be evaluated. However, even if a store-request rule references a table, a
8216 store-response rule may also use the same table. This means that each table
8217 may learn exactly one element from the request and one element from the
8218 response at once.
Emeric Brun6a1cefa2010-09-24 18:15:17 +02008219
8220 The table will contain the real server that processed the request.
8221
8222 Example :
8223 # Learn SSL session ID from both request and response and create affinity.
8224 backend https
8225 mode tcp
8226 balance roundrobin
Cyril Bontédc4d9032012-04-08 21:57:39 +02008227 # maximum SSL session ID length is 32 bytes.
Emeric Brun6a1cefa2010-09-24 18:15:17 +02008228 stick-table type binary len 32 size 30k expire 30m
Cyril Bonté108cf6e2012-04-21 23:30:29 +02008229
Emeric Brun6a1cefa2010-09-24 18:15:17 +02008230 acl clienthello req_ssl_hello_type 1
8231 acl serverhello rep_ssl_hello_type 2
8232
8233 # use tcp content accepts to detects ssl client and server hello.
8234 tcp-request inspect-delay 5s
8235 tcp-request content accept if clienthello
8236
8237 # no timeout on response inspect delay by default.
8238 tcp-response content accept if serverhello
Cyril Bonté108cf6e2012-04-21 23:30:29 +02008239
Emeric Brun6a1cefa2010-09-24 18:15:17 +02008240 # SSL session ID (SSLID) may be present on a client or server hello.
8241 # Its length is coded on 1 byte at offset 43 and its value starts
8242 # at offset 44.
8243
8244 # Match and learn on request if client hello.
8245 stick on payload_lv(43,1) if clienthello
8246
8247 # Learn on response if server hello.
8248 stick store-response payload_lv(43,1) if serverhello
Cyril Bontédc4d9032012-04-08 21:57:39 +02008249
Emeric Brun6a1cefa2010-09-24 18:15:17 +02008250 server s1 192.168.1.1:443
8251 server s2 192.168.1.1:443
8252
8253 See also : "stick-table", "stick on", and section 7 about ACLs and pattern
8254 extraction.
8255
8256
Willy Tarreau938c7fe2014-04-25 14:21:39 +02008257tcp-check connect [params*]
8258 Opens a new connection
8259 May be used in sections: defaults | frontend | listen | backend
8260 no | no | yes | yes
8261
8262 When an application lies on more than a single TCP port or when HAProxy
8263 load-balance many services in a single backend, it makes sense to probe all
8264 the services individually before considering a server as operational.
8265
8266 When there are no TCP port configured on the server line neither server port
8267 directive, then the 'tcp-check connect port <port>' must be the first step
8268 of the sequence.
8269
8270 In a tcp-check ruleset a 'connect' is required, it is also mandatory to start
8271 the ruleset with a 'connect' rule. Purpose is to ensure admin know what they
8272 do.
8273
8274 Parameters :
8275 They are optional and can be used to describe how HAProxy should open and
8276 use the TCP connection.
8277
8278 port if not set, check port or server port is used.
8279 It tells HAProxy where to open the connection to.
8280 <port> must be a valid TCP port source integer, from 1 to 65535.
8281
8282 send-proxy send a PROXY protocol string
8283
8284 ssl opens a ciphered connection
8285
8286 Examples:
8287 # check HTTP and HTTPs services on a server.
8288 # first open port 80 thanks to server line port directive, then
8289 # tcp-check opens port 443, ciphered and run a request on it:
8290 option tcp-check
8291 tcp-check connect
8292 tcp-check send GET\ /\ HTTP/1.0\r\n
8293 tcp-check send Host:\ haproxy.1wt.eu\r\n
8294 tcp-check send \r\n
8295 tcp-check expect rstring (2..|3..)
8296 tcp-check connect port 443 ssl
8297 tcp-check send GET\ /\ HTTP/1.0\r\n
8298 tcp-check send Host:\ haproxy.1wt.eu\r\n
8299 tcp-check send \r\n
8300 tcp-check expect rstring (2..|3..)
8301 server www 10.0.0.1 check port 80
8302
8303 # check both POP and IMAP from a single server:
8304 option tcp-check
8305 tcp-check connect port 110
8306 tcp-check expect string +OK\ POP3\ ready
8307 tcp-check connect port 143
8308 tcp-check expect string *\ OK\ IMAP4\ ready
8309 server mail 10.0.0.1 check
8310
8311 See also : "option tcp-check", "tcp-check send", "tcp-check expect"
8312
8313
8314tcp-check expect [!] <match> <pattern>
8315 Specify data to be collected and analysed during a generic health check
8316 May be used in sections: defaults | frontend | listen | backend
8317 no | no | yes | yes
8318
8319 Arguments :
8320 <match> is a keyword indicating how to look for a specific pattern in the
8321 response. The keyword may be one of "string", "rstring" or
8322 binary.
8323 The keyword may be preceded by an exclamation mark ("!") to negate
8324 the match. Spaces are allowed between the exclamation mark and the
8325 keyword. See below for more details on the supported keywords.
8326
8327 <pattern> is the pattern to look for. It may be a string or a regular
8328 expression. If the pattern contains spaces, they must be escaped
8329 with the usual backslash ('\').
8330 If the match is set to binary, then the pattern must be passed as
8331 a serie of hexadecimal digits in an even number. Each sequence of
8332 two digits will represent a byte. The hexadecimal digits may be
8333 used upper or lower case.
8334
8335
8336 The available matches are intentionally similar to their http-check cousins :
8337
8338 string <string> : test the exact string matches in the response buffer.
8339 A health check response will be considered valid if the
8340 response's buffer contains this exact string. If the
8341 "string" keyword is prefixed with "!", then the response
8342 will be considered invalid if the body contains this
8343 string. This can be used to look for a mandatory pattern
8344 in a protocol response, or to detect a failure when a
8345 specific error appears in a protocol banner.
8346
8347 rstring <regex> : test a regular expression on the response buffer.
8348 A health check response will be considered valid if the
8349 response's buffer matches this expression. If the
8350 "rstring" keyword is prefixed with "!", then the response
8351 will be considered invalid if the body matches the
8352 expression.
8353
8354 binary <hexstring> : test the exact string in its hexadecimal form matches
8355 in the response buffer. A health check response will
8356 be considered valid if the response's buffer contains
8357 this exact hexadecimal string.
8358 Purpose is to match data on binary protocols.
8359
8360 It is important to note that the responses will be limited to a certain size
8361 defined by the global "tune.chksize" option, which defaults to 16384 bytes.
8362 Thus, too large responses may not contain the mandatory pattern when using
8363 "string", "rstring" or binary. If a large response is absolutely required, it
8364 is possible to change the default max size by setting the global variable.
8365 However, it is worth keeping in mind that parsing very large responses can
8366 waste some CPU cycles, especially when regular expressions are used, and that
8367 it is always better to focus the checks on smaller resources. Also, in its
8368 current state, the check will not find any string nor regex past a null
8369 character in the response. Similarly it is not possible to request matching
8370 the null character.
8371
8372 Examples :
8373 # perform a POP check
8374 option tcp-check
8375 tcp-check expect string +OK\ POP3\ ready
8376
8377 # perform an IMAP check
8378 option tcp-check
8379 tcp-check expect string *\ OK\ IMAP4\ ready
8380
8381 # look for the redis master server
8382 option tcp-check
8383 tcp-check send PING\r\n
Baptiste Assmanna3322992015-08-04 10:12:18 +02008384 tcp-check expect string +PONG
Willy Tarreau938c7fe2014-04-25 14:21:39 +02008385 tcp-check send info\ replication\r\n
8386 tcp-check expect string role:master
8387 tcp-check send QUIT\r\n
8388 tcp-check expect string +OK
8389
8390
8391 See also : "option tcp-check", "tcp-check connect", "tcp-check send",
8392 "tcp-check send-binary", "http-check expect", tune.chksize
8393
8394
8395tcp-check send <data>
8396 Specify a string to be sent as a question during a generic health check
8397 May be used in sections: defaults | frontend | listen | backend
8398 no | no | yes | yes
8399
8400 <data> : the data to be sent as a question during a generic health check
8401 session. For now, <data> must be a string.
8402
8403 Examples :
8404 # look for the redis master server
8405 option tcp-check
8406 tcp-check send info\ replication\r\n
8407 tcp-check expect string role:master
8408
8409 See also : "option tcp-check", "tcp-check connect", "tcp-check expect",
8410 "tcp-check send-binary", tune.chksize
8411
8412
8413tcp-check send-binary <hexastring>
8414 Specify an hexa digits string to be sent as a binary question during a raw
8415 tcp health check
8416 May be used in sections: defaults | frontend | listen | backend
8417 no | no | yes | yes
8418
8419 <data> : the data to be sent as a question during a generic health check
8420 session. For now, <data> must be a string.
8421 <hexastring> : test the exact string in its hexadecimal form matches in the
8422 response buffer. A health check response will be considered
8423 valid if the response's buffer contains this exact
8424 hexadecimal string.
8425 Purpose is to send binary data to ask on binary protocols.
8426
8427 Examples :
8428 # redis check in binary
8429 option tcp-check
8430 tcp-check send-binary 50494e470d0a # PING\r\n
8431 tcp-check expect binary 2b504F4e47 # +PONG
8432
8433
8434 See also : "option tcp-check", "tcp-check connect", "tcp-check expect",
8435 "tcp-check send", tune.chksize
8436
8437
Willy Tarreaue9656522010-08-17 15:40:09 +02008438tcp-request connection <action> [{if | unless} <condition>]
8439 Perform an action on an incoming connection depending on a layer 4 condition
Willy Tarreau1a687942010-05-23 22:40:30 +02008440 May be used in sections : defaults | frontend | listen | backend
8441 no | yes | yes | no
Willy Tarreaue9656522010-08-17 15:40:09 +02008442 Arguments :
Willy Tarreauc870bfd2015-09-28 18:47:38 +02008443 <action> defines the action to perform if the condition applies. See
8444 below.
Willy Tarreau1a687942010-05-23 22:40:30 +02008445
Willy Tarreaue9656522010-08-17 15:40:09 +02008446 <condition> is a standard layer4-only ACL-based condition (see section 7).
Willy Tarreau68c03ab2010-08-06 15:08:45 +02008447
8448 Immediately after acceptance of a new incoming connection, it is possible to
8449 evaluate some conditions to decide whether this connection must be accepted
Willy Tarreaue9656522010-08-17 15:40:09 +02008450 or dropped or have its counters tracked. Those conditions cannot make use of
8451 any data contents because the connection has not been read from yet, and the
8452 buffers are not yet allocated. This is used to selectively and very quickly
8453 accept or drop connections from various sources with a very low overhead. If
8454 some contents need to be inspected in order to take the decision, the
8455 "tcp-request content" statements must be used instead.
Willy Tarreau68c03ab2010-08-06 15:08:45 +02008456
Willy Tarreaue9656522010-08-17 15:40:09 +02008457 The "tcp-request connection" rules are evaluated in their exact declaration
8458 order. If no rule matches or if there is no rule, the default action is to
8459 accept the incoming connection. There is no specific limit to the number of
8460 rules which may be inserted.
Willy Tarreau68c03ab2010-08-06 15:08:45 +02008461
Willy Tarreaua9083d02015-05-08 15:27:59 +02008462 Four types of actions are supported :
Willy Tarreaue9656522010-08-17 15:40:09 +02008463 - accept :
8464 accepts the connection if the condition is true (when used with "if")
8465 or false (when used with "unless"). The first such rule executed ends
8466 the rules evaluation.
Willy Tarreau68c03ab2010-08-06 15:08:45 +02008467
Willy Tarreaue9656522010-08-17 15:40:09 +02008468 - reject :
8469 rejects the connection if the condition is true (when used with "if")
8470 or false (when used with "unless"). The first such rule executed ends
8471 the rules evaluation. Rejected connections do not even become a
8472 session, which is why they are accounted separately for in the stats,
8473 as "denied connections". They are not considered for the session
8474 rate-limit and are not logged either. The reason is that these rules
8475 should only be used to filter extremely high connection rates such as
8476 the ones encountered during a massive DDoS attack. Under these extreme
8477 conditions, the simple action of logging each event would make the
8478 system collapse and would considerably lower the filtering capacity. If
8479 logging is absolutely desired, then "tcp-request content" rules should
8480 be used instead.
Willy Tarreau68c03ab2010-08-06 15:08:45 +02008481
Willy Tarreau4f0d9192013-06-11 20:40:55 +02008482 - expect-proxy layer4 :
8483 configures the client-facing connection to receive a PROXY protocol
8484 header before any byte is read from the socket. This is equivalent to
8485 having the "accept-proxy" keyword on the "bind" line, except that using
8486 the TCP rule allows the PROXY protocol to be accepted only for certain
8487 IP address ranges using an ACL. This is convenient when multiple layers
8488 of load balancers are passed through by traffic coming from public
8489 hosts.
8490
Willy Tarreau18bf01e2014-06-13 16:18:52 +02008491 - capture <sample> len <length> :
8492 This only applies to "tcp-request content" rules. It captures sample
8493 expression <sample> from the request buffer, and converts it to a
8494 string of at most <len> characters. The resulting string is stored into
8495 the next request "capture" slot, so it will possibly appear next to
8496 some captured HTTP headers. It will then automatically appear in the
8497 logs, and it will be possible to extract it using sample fetch rules to
8498 feed it into headers or anything. The length should be limited given
8499 that this size will be allocated for each capture during the whole
Willy Tarreaua9083d02015-05-08 15:27:59 +02008500 session life. Please check section 7.3 (Fetching samples) and "capture
8501 request header" for more information.
Willy Tarreau18bf01e2014-06-13 16:18:52 +02008502
Willy Tarreaube4a3ef2013-06-17 15:04:07 +02008503 - { track-sc0 | track-sc1 | track-sc2 } <key> [table <table>] :
Willy Tarreaue9656522010-08-17 15:40:09 +02008504 enables tracking of sticky counters from current connection. These
Willy Tarreau09448f72014-06-25 18:12:15 +02008505 rules do not stop evaluation and do not change default action. 3 sets
Willy Tarreaue9656522010-08-17 15:40:09 +02008506 of counters may be simultaneously tracked by the same connection. The
Willy Tarreaube4a3ef2013-06-17 15:04:07 +02008507 first "track-sc0" rule executed enables tracking of the counters of the
8508 specified table as the first set. The first "track-sc1" rule executed
Willy Tarreaue9656522010-08-17 15:40:09 +02008509 enables tracking of the counters of the specified table as the second
Willy Tarreaube4a3ef2013-06-17 15:04:07 +02008510 set. The first "track-sc2" rule executed enables tracking of the
8511 counters of the specified table as the third set. It is a recommended
8512 practice to use the first set of counters for the per-frontend counters
8513 and the second set for the per-backend ones. But this is just a
8514 guideline, all may be used everywhere.
Willy Tarreau68c03ab2010-08-06 15:08:45 +02008515
Willy Tarreaue9656522010-08-17 15:40:09 +02008516 These actions take one or two arguments :
Willy Tarreaube722a22014-06-13 16:31:59 +02008517 <key> is mandatory, and is a sample expression rule as described
Willy Tarreau74ca5042013-06-11 23:12:07 +02008518 in section 7.3. It describes what elements of the incoming
Willy Tarreau5d5b5d82012-12-09 12:00:04 +01008519 request or connection will be analysed, extracted, combined,
8520 and used to select which table entry to update the counters.
8521 Note that "tcp-request connection" cannot use content-based
8522 fetches.
Willy Tarreau68c03ab2010-08-06 15:08:45 +02008523
Willy Tarreaue9656522010-08-17 15:40:09 +02008524 <table> is an optional table to be used instead of the default one,
8525 which is the stick-table declared in the current proxy. All
8526 the counters for the matches and updates for the key will
8527 then be performed in that table until the session ends.
Willy Tarreau68c03ab2010-08-06 15:08:45 +02008528
Willy Tarreaue9656522010-08-17 15:40:09 +02008529 Once a "track-sc*" rule is executed, the key is looked up in the table
8530 and if it is not found, an entry is allocated for it. Then a pointer to
8531 that entry is kept during all the session's life, and this entry's
8532 counters are updated as often as possible, every time the session's
8533 counters are updated, and also systematically when the session ends.
Willy Tarreau5d5b5d82012-12-09 12:00:04 +01008534 Counters are only updated for events that happen after the tracking has
8535 been started. For example, connection counters will not be updated when
8536 tracking layer 7 information, since the connection event happens before
8537 layer7 information is extracted.
8538
Willy Tarreaue9656522010-08-17 15:40:09 +02008539 If the entry tracks concurrent connection counters, one connection is
8540 counted for as long as the entry is tracked, and the entry will not
8541 expire during that time. Tracking counters also provides a performance
8542 advantage over just checking the keys, because only one table lookup is
8543 performed for all ACL checks that make use of it.
Willy Tarreau68c03ab2010-08-06 15:08:45 +02008544
Thierry FOURNIERe0627bd2015-08-04 08:20:33 +02008545 - sc-inc-gpc0(<sc-id>):
8546 The "sc-inc-gpc0" increments the GPC0 counter according to the sticky
8547 counter designated by <sc-id>. If an error occurs, this action silently
8548 fails and the actions evaluation continues.
8549
Thierry FOURNIER236657b2015-08-19 08:25:14 +02008550 - sc-set-gpt0(<sc-id>) <int>:
8551 This action sets the GPT0 tag according to the sticky counter designated
8552 by <sc-id> and the value of <int>. The expected result is a boolean. If
8553 an error occurs, this action silently fails and the actions evaluation
8554 continues.
8555
Willy Tarreau2d392c22015-08-24 01:43:45 +02008556 - "silent-drop" :
8557 This stops the evaluation of the rules and makes the client-facing
8558 connection suddenly disappear using a system-dependant way that tries
8559 to prevent the client from being notified. The effect it then that the
8560 client still sees an established connection while there's none on
8561 HAProxy. The purpose is to achieve a comparable effect to "tarpit"
8562 except that it doesn't use any local resource at all on the machine
8563 running HAProxy. It can resist much higher loads than "tarpit", and
8564 slow down stronger attackers. It is important to undestand the impact
8565 of using this mechanism. All stateful equipments placed between the
8566 client and HAProxy (firewalls, proxies, load balancers) will also keep
8567 the established connection for a long time and may suffer from this
8568 action. On modern Linux systems running with enough privileges, the
8569 TCP_REPAIR socket option is used to block the emission of a TCP
8570 reset. On other systems, the socket's TTL is reduced to 1 so that the
8571 TCP reset doesn't pass the first router, though it's still delivered to
8572 local networks. Do not use it unless you fully understand how it works.
8573
Willy Tarreaue9656522010-08-17 15:40:09 +02008574 Note that the "if/unless" condition is optional. If no condition is set on
8575 the action, it is simply performed unconditionally. That can be useful for
8576 "track-sc*" actions as well as for changing the default action to a reject.
Willy Tarreau68c03ab2010-08-06 15:08:45 +02008577
Willy Tarreaue9656522010-08-17 15:40:09 +02008578 Example: accept all connections from white-listed hosts, reject too fast
8579 connection without counting them, and track accepted connections.
8580 This results in connection rate being capped from abusive sources.
Willy Tarreau68c03ab2010-08-06 15:08:45 +02008581
Willy Tarreaue9656522010-08-17 15:40:09 +02008582 tcp-request connection accept if { src -f /etc/haproxy/whitelist.lst }
Willy Tarreau68c03ab2010-08-06 15:08:45 +02008583 tcp-request connection reject if { src_conn_rate gt 10 }
Willy Tarreaube4a3ef2013-06-17 15:04:07 +02008584 tcp-request connection track-sc0 src
Willy Tarreau68c03ab2010-08-06 15:08:45 +02008585
Willy Tarreaue9656522010-08-17 15:40:09 +02008586 Example: accept all connections from white-listed hosts, count all other
8587 connections and reject too fast ones. This results in abusive ones
8588 being blocked as long as they don't slow down.
Willy Tarreau68c03ab2010-08-06 15:08:45 +02008589
Willy Tarreaue9656522010-08-17 15:40:09 +02008590 tcp-request connection accept if { src -f /etc/haproxy/whitelist.lst }
Willy Tarreaube4a3ef2013-06-17 15:04:07 +02008591 tcp-request connection track-sc0 src
8592 tcp-request connection reject if { sc0_conn_rate gt 10 }
Willy Tarreau68c03ab2010-08-06 15:08:45 +02008593
Willy Tarreau4f0d9192013-06-11 20:40:55 +02008594 Example: enable the PROXY protocol for traffic coming from all known proxies.
8595
8596 tcp-request connection expect-proxy layer4 if { src -f proxies.lst }
8597
Willy Tarreau68c03ab2010-08-06 15:08:45 +02008598 See section 7 about ACL usage.
8599
Willy Tarreaue9656522010-08-17 15:40:09 +02008600 See also : "tcp-request content", "stick-table"
Willy Tarreau68c03ab2010-08-06 15:08:45 +02008601
8602
Willy Tarreaue9656522010-08-17 15:40:09 +02008603tcp-request content <action> [{if | unless} <condition>]
8604 Perform an action on a new session depending on a layer 4-7 condition
Willy Tarreau62644772008-07-16 18:36:06 +02008605 May be used in sections : defaults | frontend | listen | backend
Willy Tarreaufb356202010-08-03 14:02:05 +02008606 no | yes | yes | yes
Willy Tarreaue9656522010-08-17 15:40:09 +02008607 Arguments :
Willy Tarreauc870bfd2015-09-28 18:47:38 +02008608 <action> defines the action to perform if the condition applies. See
8609 below.
Willy Tarreau62644772008-07-16 18:36:06 +02008610
Willy Tarreaue9656522010-08-17 15:40:09 +02008611 <condition> is a standard layer 4-7 ACL-based condition (see section 7).
Willy Tarreau62644772008-07-16 18:36:06 +02008612
Willy Tarreaue9656522010-08-17 15:40:09 +02008613 A request's contents can be analysed at an early stage of request processing
8614 called "TCP content inspection". During this stage, ACL-based rules are
8615 evaluated every time the request contents are updated, until either an
8616 "accept" or a "reject" rule matches, or the TCP request inspection delay
8617 expires with no matching rule.
Willy Tarreau62644772008-07-16 18:36:06 +02008618
Willy Tarreaue9656522010-08-17 15:40:09 +02008619 The first difference between these rules and "tcp-request connection" rules
8620 is that "tcp-request content" rules can make use of contents to take a
8621 decision. Most often, these decisions will consider a protocol recognition or
8622 validity. The second difference is that content-based rules can be used in
Willy Tarreauf3338342014-01-28 21:40:28 +01008623 both frontends and backends. In case of HTTP keep-alive with the client, all
8624 tcp-request content rules are evaluated again, so haproxy keeps a record of
8625 what sticky counters were assigned by a "tcp-request connection" versus a
8626 "tcp-request content" rule, and flushes all the content-related ones after
8627 processing an HTTP request, so that they may be evaluated again by the rules
8628 being evaluated again for the next request. This is of particular importance
Jarno Huuskonen0e82b922014-04-12 18:22:19 +03008629 when the rule tracks some L7 information or when it is conditioned by an
Willy Tarreauf3338342014-01-28 21:40:28 +01008630 L7-based ACL, since tracking may change between requests.
Willy Tarreau62644772008-07-16 18:36:06 +02008631
Willy Tarreaue9656522010-08-17 15:40:09 +02008632 Content-based rules are evaluated in their exact declaration order. If no
8633 rule matches or if there is no rule, the default action is to accept the
8634 contents. There is no specific limit to the number of rules which may be
8635 inserted.
Willy Tarreau62644772008-07-16 18:36:06 +02008636
Thierry FOURNIER236657b2015-08-19 08:25:14 +02008637 Several types of actions are supported :
Willy Tarreau18bf01e2014-06-13 16:18:52 +02008638 - accept : the request is accepted
8639 - reject : the request is rejected and the connection is closed
8640 - capture : the specified sample expression is captured
Willy Tarreaube4a3ef2013-06-17 15:04:07 +02008641 - { track-sc0 | track-sc1 | track-sc2 } <key> [table <table>]
Thierry FOURNIERe0627bd2015-08-04 08:20:33 +02008642 - sc-inc-gpc0(<sc-id>)
Thierry FOURNIER236657b2015-08-19 08:25:14 +02008643 - set-gpt0(<sc-id>) <int>
Thierry FOURNIER69717b42015-06-04 12:23:41 +02008644 - lua <function>
Thierry FOURNIER4834bc72015-06-06 19:29:07 +02008645 - set-var(<var-name>) <expr>
Willy Tarreau2d392c22015-08-24 01:43:45 +02008646 - silent-drop
Willy Tarreau62644772008-07-16 18:36:06 +02008647
Willy Tarreaue9656522010-08-17 15:40:09 +02008648 They have the same meaning as their counter-parts in "tcp-request connection"
8649 so please refer to that section for a complete description.
Willy Tarreau62644772008-07-16 18:36:06 +02008650
Willy Tarreauf3338342014-01-28 21:40:28 +01008651 While there is nothing mandatory about it, it is recommended to use the
8652 track-sc0 in "tcp-request connection" rules, track-sc1 for "tcp-request
8653 content" rules in the frontend, and track-sc2 for "tcp-request content"
8654 rules in the backend, because that makes the configuration more readable
8655 and easier to troubleshoot, but this is just a guideline and all counters
8656 may be used everywhere.
Willy Tarreau62644772008-07-16 18:36:06 +02008657
Krzysztof Piotr Oledzkif8645332009-12-13 21:55:50 +01008658 Note that the "if/unless" condition is optional. If no condition is set on
Willy Tarreaue9656522010-08-17 15:40:09 +02008659 the action, it is simply performed unconditionally. That can be useful for
8660 "track-sc*" actions as well as for changing the default action to a reject.
Willy Tarreau62644772008-07-16 18:36:06 +02008661
Willy Tarreaue9656522010-08-17 15:40:09 +02008662 It is perfectly possible to match layer 7 contents with "tcp-request content"
Willy Tarreauc0239e02012-04-16 14:42:55 +02008663 rules, since HTTP-specific ACL matches are able to preliminarily parse the
8664 contents of a buffer before extracting the required data. If the buffered
8665 contents do not parse as a valid HTTP message, then the ACL does not match.
8666 The parser which is involved there is exactly the same as for all other HTTP
Willy Tarreauf3338342014-01-28 21:40:28 +01008667 processing, so there is no risk of parsing something differently. In an HTTP
8668 backend connected to from an HTTP frontend, it is guaranteed that HTTP
8669 contents will always be immediately present when the rule is evaluated first.
Willy Tarreau62644772008-07-16 18:36:06 +02008670
Willy Tarreau5d5b5d82012-12-09 12:00:04 +01008671 Tracking layer7 information is also possible provided that the information
Willy Tarreau4d54c7c2014-09-16 15:48:15 +02008672 are present when the rule is processed. The rule processing engine is able to
8673 wait until the inspect delay expires when the data to be tracked is not yet
8674 available.
Willy Tarreau5d5b5d82012-12-09 12:00:04 +01008675
Thierry FOURNIER90da1912015-03-05 11:17:06 +01008676 The "lua" keyword is followed by a Lua function name. It is used to run a Lua
8677 function if the action is executed. The single parameter is the name of the
8678 function to run. The prototype of the function is documented in the API
8679 documentation.
8680
Thierry FOURNIER4834bc72015-06-06 19:29:07 +02008681 The "set-var" is used to set the content of a variable. The variable is
8682 declared inline.
8683
8684 <var-name> The name of the variable starts by an indication about its scope.
8685 The allowed scopes are:
8686 "sess" : the variable is shared with all the session,
8687 "txn" : the variable is shared with all the transaction
8688 (request and response)
8689 "req" : the variable is shared only during the request
8690 processing
8691 "res" : the variable is shared only during the response
8692 processing.
8693 This prefix is followed by a name. The separator is a '.'.
8694 The name may only contain characters 'a-z', 'A-Z', '0-9' and '_'.
8695
8696 <expr> Is a standard HAProxy expression formed by a sample-fetch
8697 followed by some converters.
8698
8699 Example:
8700
8701 tcp-request content set-var(sess.my_var) src
8702
Willy Tarreau62644772008-07-16 18:36:06 +02008703 Example:
Willy Tarreaue9656522010-08-17 15:40:09 +02008704 # Accept HTTP requests containing a Host header saying "example.com"
8705 # and reject everything else.
8706 acl is_host_com hdr(Host) -i example.com
8707 tcp-request inspect-delay 30s
Willy Tarreauc0239e02012-04-16 14:42:55 +02008708 tcp-request content accept if is_host_com
Willy Tarreaue9656522010-08-17 15:40:09 +02008709 tcp-request content reject
8710
8711 Example:
Willy Tarreau62644772008-07-16 18:36:06 +02008712 # reject SMTP connection if client speaks first
8713 tcp-request inspect-delay 30s
8714 acl content_present req_len gt 0
Willy Tarreau68c03ab2010-08-06 15:08:45 +02008715 tcp-request content reject if content_present
Willy Tarreau62644772008-07-16 18:36:06 +02008716
8717 # Forward HTTPS connection only if client speaks
8718 tcp-request inspect-delay 30s
8719 acl content_present req_len gt 0
Willy Tarreau68c03ab2010-08-06 15:08:45 +02008720 tcp-request content accept if content_present
Willy Tarreaue9656522010-08-17 15:40:09 +02008721 tcp-request content reject
8722
Willy Tarreau5d5b5d82012-12-09 12:00:04 +01008723 Example:
8724 # Track the last IP from X-Forwarded-For
8725 tcp-request inspect-delay 10s
Willy Tarreau4d54c7c2014-09-16 15:48:15 +02008726 tcp-request content track-sc0 hdr(x-forwarded-for,-1)
Willy Tarreau5d5b5d82012-12-09 12:00:04 +01008727
8728 Example:
8729 # track request counts per "base" (concatenation of Host+URL)
8730 tcp-request inspect-delay 10s
Willy Tarreau4d54c7c2014-09-16 15:48:15 +02008731 tcp-request content track-sc0 base table req-rate
Willy Tarreau5d5b5d82012-12-09 12:00:04 +01008732
Willy Tarreaue9656522010-08-17 15:40:09 +02008733 Example: track per-frontend and per-backend counters, block abusers at the
8734 frontend when the backend detects abuse.
8735
8736 frontend http
Willy Tarreaube4a3ef2013-06-17 15:04:07 +02008737 # Use General Purpose Couter 0 in SC0 as a global abuse counter
Willy Tarreaue9656522010-08-17 15:40:09 +02008738 # protecting all our sites
8739 stick-table type ip size 1m expire 5m store gpc0
Willy Tarreaube4a3ef2013-06-17 15:04:07 +02008740 tcp-request connection track-sc0 src
8741 tcp-request connection reject if { sc0_get_gpc0 gt 0 }
Willy Tarreaue9656522010-08-17 15:40:09 +02008742 ...
8743 use_backend http_dynamic if { path_end .php }
8744
8745 backend http_dynamic
8746 # if a source makes too fast requests to this dynamic site (tracked
Willy Tarreaube4a3ef2013-06-17 15:04:07 +02008747 # by SC1), block it globally in the frontend.
Willy Tarreaue9656522010-08-17 15:40:09 +02008748 stick-table type ip size 1m expire 5m store http_req_rate(10s)
Willy Tarreaube4a3ef2013-06-17 15:04:07 +02008749 acl click_too_fast sc1_http_req_rate gt 10
8750 acl mark_as_abuser sc0_inc_gpc0 gt 0
8751 tcp-request content track-sc1 src
Willy Tarreaue9656522010-08-17 15:40:09 +02008752 tcp-request content reject if click_too_fast mark_as_abuser
Willy Tarreau62644772008-07-16 18:36:06 +02008753
Willy Tarreauc57f0e22009-05-10 13:12:33 +02008754 See section 7 about ACL usage.
Willy Tarreau62644772008-07-16 18:36:06 +02008755
Willy Tarreaue9656522010-08-17 15:40:09 +02008756 See also : "tcp-request connection", "tcp-request inspect-delay"
Willy Tarreau62644772008-07-16 18:36:06 +02008757
8758
8759tcp-request inspect-delay <timeout>
8760 Set the maximum allowed time to wait for data during content inspection
8761 May be used in sections : defaults | frontend | listen | backend
Willy Tarreaufb356202010-08-03 14:02:05 +02008762 no | yes | yes | yes
Willy Tarreau62644772008-07-16 18:36:06 +02008763 Arguments :
8764 <timeout> is the timeout value specified in milliseconds by default, but
8765 can be in any other unit if the number is suffixed by the unit,
8766 as explained at the top of this document.
8767
8768 People using haproxy primarily as a TCP relay are often worried about the
8769 risk of passing any type of protocol to a server without any analysis. In
8770 order to be able to analyze the request contents, we must first withhold
8771 the data then analyze them. This statement simply enables withholding of
8772 data for at most the specified amount of time.
8773
Willy Tarreaufb356202010-08-03 14:02:05 +02008774 TCP content inspection applies very early when a connection reaches a
8775 frontend, then very early when the connection is forwarded to a backend. This
8776 means that a connection may experience a first delay in the frontend and a
8777 second delay in the backend if both have tcp-request rules.
8778
Willy Tarreau62644772008-07-16 18:36:06 +02008779 Note that when performing content inspection, haproxy will evaluate the whole
8780 rules for every new chunk which gets in, taking into account the fact that
Krzysztof Piotr Oledzkif8645332009-12-13 21:55:50 +01008781 those data are partial. If no rule matches before the aforementioned delay,
Willy Tarreau62644772008-07-16 18:36:06 +02008782 a last check is performed upon expiration, this time considering that the
Willy Tarreaud869b242009-03-15 14:43:58 +01008783 contents are definitive. If no delay is set, haproxy will not wait at all
8784 and will immediately apply a verdict based on the available information.
8785 Obviously this is unlikely to be very useful and might even be racy, so such
8786 setups are not recommended.
Willy Tarreau62644772008-07-16 18:36:06 +02008787
8788 As soon as a rule matches, the request is released and continues as usual. If
8789 the timeout is reached and no rule matches, the default policy will be to let
8790 it pass through unaffected.
8791
8792 For most protocols, it is enough to set it to a few seconds, as most clients
8793 send the full request immediately upon connection. Add 3 or more seconds to
8794 cover TCP retransmits but that's all. For some protocols, it may make sense
Willy Tarreaud72758d2010-01-12 10:42:19 +01008795 to use large values, for instance to ensure that the client never talks
Willy Tarreau62644772008-07-16 18:36:06 +02008796 before the server (eg: SMTP), or to wait for a client to talk before passing
8797 data to the server (eg: SSL). Note that the client timeout must cover at
Willy Tarreaub824b002010-09-29 16:36:16 +02008798 least the inspection delay, otherwise it will expire first. If the client
8799 closes the connection or if the buffer is full, the delay immediately expires
8800 since the contents will not be able to change anymore.
Willy Tarreau62644772008-07-16 18:36:06 +02008801
Willy Tarreau55165fe2009-05-10 12:02:55 +02008802 See also : "tcp-request content accept", "tcp-request content reject",
Willy Tarreau62644772008-07-16 18:36:06 +02008803 "timeout client".
8804
8805
Emeric Brun0a3b67f2010-09-24 15:34:53 +02008806tcp-response content <action> [{if | unless} <condition>]
8807 Perform an action on a session response depending on a layer 4-7 condition
8808 May be used in sections : defaults | frontend | listen | backend
8809 no | no | yes | yes
8810 Arguments :
Willy Tarreauc870bfd2015-09-28 18:47:38 +02008811 <action> defines the action to perform if the condition applies. See
8812 below.
Emeric Brun0a3b67f2010-09-24 15:34:53 +02008813
8814 <condition> is a standard layer 4-7 ACL-based condition (see section 7).
8815
8816 Response contents can be analysed at an early stage of response processing
8817 called "TCP content inspection". During this stage, ACL-based rules are
8818 evaluated every time the response contents are updated, until either an
Willy Tarreaucc1e04b2013-09-11 23:20:29 +02008819 "accept", "close" or a "reject" rule matches, or a TCP response inspection
8820 delay is set and expires with no matching rule.
Emeric Brun0a3b67f2010-09-24 15:34:53 +02008821
8822 Most often, these decisions will consider a protocol recognition or validity.
8823
8824 Content-based rules are evaluated in their exact declaration order. If no
8825 rule matches or if there is no rule, the default action is to accept the
8826 contents. There is no specific limit to the number of rules which may be
8827 inserted.
8828
Thierry FOURNIER236657b2015-08-19 08:25:14 +02008829 Several types of actions are supported :
Emeric Brun0a3b67f2010-09-24 15:34:53 +02008830 - accept :
8831 accepts the response if the condition is true (when used with "if")
8832 or false (when used with "unless"). The first such rule executed ends
8833 the rules evaluation.
8834
Willy Tarreaucc1e04b2013-09-11 23:20:29 +02008835 - close :
8836 immediately closes the connection with the server if the condition is
8837 true (when used with "if"), or false (when used with "unless"). The
8838 first such rule executed ends the rules evaluation. The main purpose of
8839 this action is to force a connection to be finished between a client
8840 and a server after an exchange when the application protocol expects
8841 some long time outs to elapse first. The goal is to eliminate idle
Jarno Huuskonen0e82b922014-04-12 18:22:19 +03008842 connections which take significant resources on servers with certain
Willy Tarreaucc1e04b2013-09-11 23:20:29 +02008843 protocols.
8844
Emeric Brun0a3b67f2010-09-24 15:34:53 +02008845 - reject :
8846 rejects the response if the condition is true (when used with "if")
8847 or false (when used with "unless"). The first such rule executed ends
Jamie Gloudonaaa21002012-08-25 00:18:33 -04008848 the rules evaluation. Rejected session are immediately closed.
Emeric Brun0a3b67f2010-09-24 15:34:53 +02008849
Thierry FOURNIER69717b42015-06-04 12:23:41 +02008850 - lua <function>
8851 Executes Lua.
8852
Thierry FOURNIER4834bc72015-06-06 19:29:07 +02008853 - set-var(<var-name>) <expr>
8854 Sets a variable.
8855
Thierry FOURNIERe0627bd2015-08-04 08:20:33 +02008856 - sc-inc-gpc0(<sc-id>):
8857 This action increments the GPC0 counter according to the sticky
8858 counter designated by <sc-id>. If an error occurs, this action fails
8859 silently and the actions evaluation continues.
8860
Thierry FOURNIER236657b2015-08-19 08:25:14 +02008861 - sc-set-gpt0(<sc-id>) <int> :
8862 This action sets the GPT0 tag according to the sticky counter designated
8863 by <sc-id> and the value of <int>. The expected result is a boolean. If
8864 an error occurs, this action silently fails and the actions evaluation
8865 continues.
8866
Willy Tarreau2d392c22015-08-24 01:43:45 +02008867 - "silent-drop" :
8868 This stops the evaluation of the rules and makes the client-facing
8869 connection suddenly disappear using a system-dependant way that tries
8870 to prevent the client from being notified. The effect it then that the
8871 client still sees an established connection while there's none on
8872 HAProxy. The purpose is to achieve a comparable effect to "tarpit"
8873 except that it doesn't use any local resource at all on the machine
8874 running HAProxy. It can resist much higher loads than "tarpit", and
8875 slow down stronger attackers. It is important to undestand the impact
8876 of using this mechanism. All stateful equipments placed between the
8877 client and HAProxy (firewalls, proxies, load balancers) will also keep
8878 the established connection for a long time and may suffer from this
8879 action. On modern Linux systems running with enough privileges, the
8880 TCP_REPAIR socket option is used to block the emission of a TCP
8881 reset. On other systems, the socket's TTL is reduced to 1 so that the
8882 TCP reset doesn't pass the first router, though it's still delivered to
8883 local networks. Do not use it unless you fully understand how it works.
8884
Emeric Brun0a3b67f2010-09-24 15:34:53 +02008885 Note that the "if/unless" condition is optional. If no condition is set on
8886 the action, it is simply performed unconditionally. That can be useful for
8887 for changing the default action to a reject.
8888
Jamie Gloudonaaa21002012-08-25 00:18:33 -04008889 It is perfectly possible to match layer 7 contents with "tcp-response
8890 content" rules, but then it is important to ensure that a full response has
8891 been buffered, otherwise no contents will match. In order to achieve this,
8892 the best solution involves detecting the HTTP protocol during the inspection
Emeric Brun0a3b67f2010-09-24 15:34:53 +02008893 period.
8894
Thierry FOURNIER90da1912015-03-05 11:17:06 +01008895 The "lua" keyword is followed by a Lua function name. It is used to run a Lua
8896 function if the action is executed. The single parameter is the name of the
8897 function to run. The prototype of the function is documented in the API
8898 documentation.
8899
Thierry FOURNIER4834bc72015-06-06 19:29:07 +02008900 The "set-var" is used to set the content of a variable. The variable is
8901 declared inline.
8902
8903 <var-name> The name of the variable starts by an indication about its scope.
8904 The allowed scopes are:
8905 "sess" : the variable is shared with all the session,
8906 "txn" : the variable is shared with all the transaction
8907 (request and response)
8908 "req" : the variable is shared only during the request
8909 processing
8910 "res" : the variable is shared only during the response
8911 processing.
8912 This prefix is followed by a name. The separator is a '.'.
8913 The name may only contain characters 'a-z', 'A-Z', '0-9' and '_'.
8914
8915 <expr> Is a standard HAProxy expression formed by a sample-fetch
8916 followed by some converters.
8917
8918 Example:
8919
8920 tcp-request content set-var(sess.my_var) src
8921
Emeric Brun0a3b67f2010-09-24 15:34:53 +02008922 See section 7 about ACL usage.
8923
8924 See also : "tcp-request content", "tcp-response inspect-delay"
8925
8926
8927tcp-response inspect-delay <timeout>
8928 Set the maximum allowed time to wait for a response during content inspection
8929 May be used in sections : defaults | frontend | listen | backend
8930 no | no | yes | yes
8931 Arguments :
8932 <timeout> is the timeout value specified in milliseconds by default, but
8933 can be in any other unit if the number is suffixed by the unit,
8934 as explained at the top of this document.
8935
8936 See also : "tcp-response content", "tcp-request inspect-delay".
8937
8938
Krzysztof Piotr Oledzki5259dfe2008-01-21 01:54:06 +01008939timeout check <timeout>
8940 Set additional check timeout, but only after a connection has been already
8941 established.
8942
8943 May be used in sections: defaults | frontend | listen | backend
8944 yes | no | yes | yes
8945 Arguments:
8946 <timeout> is the timeout value specified in milliseconds by default, but
8947 can be in any other unit if the number is suffixed by the unit,
8948 as explained at the top of this document.
8949
8950 If set, haproxy uses min("timeout connect", "inter") as a connect timeout
8951 for check and "timeout check" as an additional read timeout. The "min" is
8952 used so that people running with *very* long "timeout connect" (eg. those
8953 who needed this due to the queue or tarpit) do not slow down their checks.
Willy Tarreaud7550a22010-02-10 05:10:19 +01008954 (Please also note that there is no valid reason to have such long connect
8955 timeouts, because "timeout queue" and "timeout tarpit" can always be used to
8956 avoid that).
Krzysztof Piotr Oledzki5259dfe2008-01-21 01:54:06 +01008957
8958 If "timeout check" is not set haproxy uses "inter" for complete check
8959 timeout (connect + read) exactly like all <1.3.15 version.
8960
8961 In most cases check request is much simpler and faster to handle than normal
8962 requests and people may want to kick out laggy servers so this timeout should
Willy Tarreau41a340d2008-01-22 12:25:31 +01008963 be smaller than "timeout server".
Krzysztof Piotr Oledzki5259dfe2008-01-21 01:54:06 +01008964
8965 This parameter is specific to backends, but can be specified once for all in
8966 "defaults" sections. This is in fact one of the easiest solutions not to
8967 forget about it.
8968
Willy Tarreau41a340d2008-01-22 12:25:31 +01008969 See also: "timeout connect", "timeout queue", "timeout server",
8970 "timeout tarpit".
Krzysztof Piotr Oledzki5259dfe2008-01-21 01:54:06 +01008971
8972
Willy Tarreau0ba27502007-12-24 16:55:16 +01008973timeout client <timeout>
8974timeout clitimeout <timeout> (deprecated)
8975 Set the maximum inactivity time on the client side.
8976 May be used in sections : defaults | frontend | listen | backend
8977 yes | yes | yes | no
8978 Arguments :
Willy Tarreau844e3c52008-01-11 16:28:18 +01008979 <timeout> is the timeout value specified in milliseconds by default, but
Willy Tarreau0ba27502007-12-24 16:55:16 +01008980 can be in any other unit if the number is suffixed by the unit,
8981 as explained at the top of this document.
8982
8983 The inactivity timeout applies when the client is expected to acknowledge or
8984 send data. In HTTP mode, this timeout is particularly important to consider
8985 during the first phase, when the client sends the request, and during the
8986 response while it is reading data sent by the server. The value is specified
8987 in milliseconds by default, but can be in any other unit if the number is
8988 suffixed by the unit, as specified at the top of this document. In TCP mode
8989 (and to a lesser extent, in HTTP mode), it is highly recommended that the
8990 client timeout remains equal to the server timeout in order to avoid complex
Willy Tarreaud2a4aa22008-01-31 15:28:22 +01008991 situations to debug. It is a good practice to cover one or several TCP packet
Willy Tarreau0ba27502007-12-24 16:55:16 +01008992 losses by specifying timeouts that are slightly above multiples of 3 seconds
Willy Tarreauce887fd2012-05-12 12:50:00 +02008993 (eg: 4 or 5 seconds). If some long-lived sessions are mixed with short-lived
8994 sessions (eg: WebSocket and HTTP), it's worth considering "timeout tunnel",
Willy Tarreau05cdd962014-05-10 14:30:07 +02008995 which overrides "timeout client" and "timeout server" for tunnels, as well as
8996 "timeout client-fin" for half-closed connections.
Willy Tarreau0ba27502007-12-24 16:55:16 +01008997
8998 This parameter is specific to frontends, but can be specified once for all in
8999 "defaults" sections. This is in fact one of the easiest solutions not to
9000 forget about it. An unspecified timeout results in an infinite timeout, which
9001 is not recommended. Such a usage is accepted and works but reports a warning
9002 during startup because it may results in accumulation of expired sessions in
9003 the system if the system's timeouts are not configured either.
9004
9005 This parameter replaces the old, deprecated "clitimeout". It is recommended
9006 to use it to write new configurations. The form "timeout clitimeout" is
9007 provided only by backwards compatibility but its use is strongly discouraged.
9008
Willy Tarreauce887fd2012-05-12 12:50:00 +02009009 See also : "clitimeout", "timeout server", "timeout tunnel".
Willy Tarreau0ba27502007-12-24 16:55:16 +01009010
9011
Willy Tarreau05cdd962014-05-10 14:30:07 +02009012timeout client-fin <timeout>
9013 Set the inactivity timeout on the client side for half-closed connections.
9014 May be used in sections : defaults | frontend | listen | backend
9015 yes | yes | yes | no
9016 Arguments :
9017 <timeout> is the timeout value specified in milliseconds by default, but
9018 can be in any other unit if the number is suffixed by the unit,
9019 as explained at the top of this document.
9020
9021 The inactivity timeout applies when the client is expected to acknowledge or
9022 send data while one direction is already shut down. This timeout is different
9023 from "timeout client" in that it only applies to connections which are closed
9024 in one direction. This is particularly useful to avoid keeping connections in
9025 FIN_WAIT state for too long when clients do not disconnect cleanly. This
9026 problem is particularly common long connections such as RDP or WebSocket.
9027 Note that this timeout can override "timeout tunnel" when a connection shuts
9028 down in one direction.
9029
9030 This parameter is specific to frontends, but can be specified once for all in
9031 "defaults" sections. By default it is not set, so half-closed connections
9032 will use the other timeouts (timeout.client or timeout.tunnel).
9033
9034 See also : "timeout client", "timeout server-fin", and "timeout tunnel".
9035
9036
Willy Tarreau0ba27502007-12-24 16:55:16 +01009037timeout connect <timeout>
9038timeout contimeout <timeout> (deprecated)
9039 Set the maximum time to wait for a connection attempt to a server to succeed.
9040 May be used in sections : defaults | frontend | listen | backend
9041 yes | no | yes | yes
9042 Arguments :
Willy Tarreau844e3c52008-01-11 16:28:18 +01009043 <timeout> is the timeout value specified in milliseconds by default, but
Willy Tarreau0ba27502007-12-24 16:55:16 +01009044 can be in any other unit if the number is suffixed by the unit,
9045 as explained at the top of this document.
9046
9047 If the server is located on the same LAN as haproxy, the connection should be
Willy Tarreaud2a4aa22008-01-31 15:28:22 +01009048 immediate (less than a few milliseconds). Anyway, it is a good practice to
Willy Tarreaud72758d2010-01-12 10:42:19 +01009049 cover one or several TCP packet losses by specifying timeouts that are
Willy Tarreau0ba27502007-12-24 16:55:16 +01009050 slightly above multiples of 3 seconds (eg: 4 or 5 seconds). By default, the
Krzysztof Piotr Oledzki5259dfe2008-01-21 01:54:06 +01009051 connect timeout also presets both queue and tarpit timeouts to the same value
9052 if these have not been specified.
Willy Tarreau0ba27502007-12-24 16:55:16 +01009053
9054 This parameter is specific to backends, but can be specified once for all in
9055 "defaults" sections. This is in fact one of the easiest solutions not to
9056 forget about it. An unspecified timeout results in an infinite timeout, which
9057 is not recommended. Such a usage is accepted and works but reports a warning
9058 during startup because it may results in accumulation of failed sessions in
9059 the system if the system's timeouts are not configured either.
9060
9061 This parameter replaces the old, deprecated "contimeout". It is recommended
9062 to use it to write new configurations. The form "timeout contimeout" is
9063 provided only by backwards compatibility but its use is strongly discouraged.
9064
Willy Tarreau41a340d2008-01-22 12:25:31 +01009065 See also: "timeout check", "timeout queue", "timeout server", "contimeout",
9066 "timeout tarpit".
Willy Tarreau0ba27502007-12-24 16:55:16 +01009067
9068
Willy Tarreaub16a5742010-01-10 14:46:16 +01009069timeout http-keep-alive <timeout>
9070 Set the maximum allowed time to wait for a new HTTP request to appear
9071 May be used in sections : defaults | frontend | listen | backend
9072 yes | yes | yes | yes
9073 Arguments :
9074 <timeout> is the timeout value specified in milliseconds by default, but
9075 can be in any other unit if the number is suffixed by the unit,
9076 as explained at the top of this document.
9077
9078 By default, the time to wait for a new request in case of keep-alive is set
9079 by "timeout http-request". However this is not always convenient because some
9080 people want very short keep-alive timeouts in order to release connections
9081 faster, and others prefer to have larger ones but still have short timeouts
9082 once the request has started to present itself.
9083
9084 The "http-keep-alive" timeout covers these needs. It will define how long to
9085 wait for a new HTTP request to start coming after a response was sent. Once
9086 the first byte of request has been seen, the "http-request" timeout is used
9087 to wait for the complete request to come. Note that empty lines prior to a
9088 new request do not refresh the timeout and are not counted as a new request.
9089
9090 There is also another difference between the two timeouts : when a connection
9091 expires during timeout http-keep-alive, no error is returned, the connection
9092 just closes. If the connection expires in "http-request" while waiting for a
9093 connection to complete, a HTTP 408 error is returned.
9094
9095 In general it is optimal to set this value to a few tens to hundreds of
9096 milliseconds, to allow users to fetch all objects of a page at once but
9097 without waiting for further clicks. Also, if set to a very small value (eg:
9098 1 millisecond) it will probably only accept pipelined requests but not the
9099 non-pipelined ones. It may be a nice trade-off for very large sites running
Patrick Mézard2382ad62010-05-09 10:43:32 +02009100 with tens to hundreds of thousands of clients.
Willy Tarreaub16a5742010-01-10 14:46:16 +01009101
9102 If this parameter is not set, the "http-request" timeout applies, and if both
9103 are not set, "timeout client" still applies at the lower level. It should be
9104 set in the frontend to take effect, unless the frontend is in TCP mode, in
9105 which case the HTTP backend's timeout will be used.
9106
9107 See also : "timeout http-request", "timeout client".
9108
9109
Willy Tarreau036fae02008-01-06 13:24:40 +01009110timeout http-request <timeout>
9111 Set the maximum allowed time to wait for a complete HTTP request
9112 May be used in sections : defaults | frontend | listen | backend
Willy Tarreaucd7afc02009-07-12 10:03:17 +02009113 yes | yes | yes | yes
Willy Tarreau036fae02008-01-06 13:24:40 +01009114 Arguments :
Willy Tarreau844e3c52008-01-11 16:28:18 +01009115 <timeout> is the timeout value specified in milliseconds by default, but
Willy Tarreau036fae02008-01-06 13:24:40 +01009116 can be in any other unit if the number is suffixed by the unit,
9117 as explained at the top of this document.
9118
9119 In order to offer DoS protection, it may be required to lower the maximum
9120 accepted time to receive a complete HTTP request without affecting the client
9121 timeout. This helps protecting against established connections on which
9122 nothing is sent. The client timeout cannot offer a good protection against
9123 this abuse because it is an inactivity timeout, which means that if the
9124 attacker sends one character every now and then, the timeout will not
9125 trigger. With the HTTP request timeout, no matter what speed the client
Willy Tarreau2705a612014-05-23 17:38:34 +02009126 types, the request will be aborted if it does not complete in time. When the
9127 timeout expires, an HTTP 408 response is sent to the client to inform it
9128 about the problem, and the connection is closed. The logs will report
9129 termination codes "cR". Some recent browsers are having problems with this
9130 standard, well-documented behaviour, so it might be needed to hide the 408
Willy Tarreau0f228a02015-05-01 15:37:53 +02009131 code using "option http-ignore-probes" or "errorfile 408 /dev/null". See
9132 more details in the explanations of the "cR" termination code in section 8.5.
Willy Tarreau036fae02008-01-06 13:24:40 +01009133
9134 Note that this timeout only applies to the header part of the request, and
9135 not to any data. As soon as the empty line is received, this timeout is not
Willy Tarreaub16a5742010-01-10 14:46:16 +01009136 used anymore. It is used again on keep-alive connections to wait for a second
9137 request if "timeout http-keep-alive" is not set.
Willy Tarreau036fae02008-01-06 13:24:40 +01009138
9139 Generally it is enough to set it to a few seconds, as most clients send the
9140 full request immediately upon connection. Add 3 or more seconds to cover TCP
9141 retransmits but that's all. Setting it to very low values (eg: 50 ms) will
9142 generally work on local networks as long as there are no packet losses. This
9143 will prevent people from sending bare HTTP requests using telnet.
9144
9145 If this parameter is not set, the client timeout still applies between each
Willy Tarreaucd7afc02009-07-12 10:03:17 +02009146 chunk of the incoming request. It should be set in the frontend to take
9147 effect, unless the frontend is in TCP mode, in which case the HTTP backend's
9148 timeout will be used.
Willy Tarreau036fae02008-01-06 13:24:40 +01009149
Willy Tarreau0f228a02015-05-01 15:37:53 +02009150 See also : "errorfile", "http-ignore-probes", "timeout http-keep-alive", and
9151 "timeout client".
Willy Tarreau036fae02008-01-06 13:24:40 +01009152
Willy Tarreau844e3c52008-01-11 16:28:18 +01009153
9154timeout queue <timeout>
9155 Set the maximum time to wait in the queue for a connection slot to be free
9156 May be used in sections : defaults | frontend | listen | backend
9157 yes | no | yes | yes
9158 Arguments :
9159 <timeout> is the timeout value specified in milliseconds by default, but
9160 can be in any other unit if the number is suffixed by the unit,
9161 as explained at the top of this document.
9162
9163 When a server's maxconn is reached, connections are left pending in a queue
9164 which may be server-specific or global to the backend. In order not to wait
9165 indefinitely, a timeout is applied to requests pending in the queue. If the
9166 timeout is reached, it is considered that the request will almost never be
9167 served, so it is dropped and a 503 error is returned to the client.
9168
9169 The "timeout queue" statement allows to fix the maximum time for a request to
9170 be left pending in a queue. If unspecified, the same value as the backend's
9171 connection timeout ("timeout connect") is used, for backwards compatibility
9172 with older versions with no "timeout queue" parameter.
9173
9174 See also : "timeout connect", "contimeout".
9175
9176
9177timeout server <timeout>
9178timeout srvtimeout <timeout> (deprecated)
9179 Set the maximum inactivity time on the server side.
9180 May be used in sections : defaults | frontend | listen | backend
9181 yes | no | yes | yes
9182 Arguments :
9183 <timeout> is the timeout value specified in milliseconds by default, but
9184 can be in any other unit if the number is suffixed by the unit,
9185 as explained at the top of this document.
9186
9187 The inactivity timeout applies when the server is expected to acknowledge or
9188 send data. In HTTP mode, this timeout is particularly important to consider
9189 during the first phase of the server's response, when it has to send the
9190 headers, as it directly represents the server's processing time for the
9191 request. To find out what value to put there, it's often good to start with
9192 what would be considered as unacceptable response times, then check the logs
9193 to observe the response time distribution, and adjust the value accordingly.
9194
9195 The value is specified in milliseconds by default, but can be in any other
9196 unit if the number is suffixed by the unit, as specified at the top of this
9197 document. In TCP mode (and to a lesser extent, in HTTP mode), it is highly
9198 recommended that the client timeout remains equal to the server timeout in
9199 order to avoid complex situations to debug. Whatever the expected server
Willy Tarreaud2a4aa22008-01-31 15:28:22 +01009200 response times, it is a good practice to cover at least one or several TCP
Willy Tarreau844e3c52008-01-11 16:28:18 +01009201 packet losses by specifying timeouts that are slightly above multiples of 3
Willy Tarreauce887fd2012-05-12 12:50:00 +02009202 seconds (eg: 4 or 5 seconds minimum). If some long-lived sessions are mixed
9203 with short-lived sessions (eg: WebSocket and HTTP), it's worth considering
9204 "timeout tunnel", which overrides "timeout client" and "timeout server" for
9205 tunnels.
Willy Tarreau844e3c52008-01-11 16:28:18 +01009206
9207 This parameter is specific to backends, but can be specified once for all in
9208 "defaults" sections. This is in fact one of the easiest solutions not to
9209 forget about it. An unspecified timeout results in an infinite timeout, which
9210 is not recommended. Such a usage is accepted and works but reports a warning
9211 during startup because it may results in accumulation of expired sessions in
9212 the system if the system's timeouts are not configured either.
9213
9214 This parameter replaces the old, deprecated "srvtimeout". It is recommended
9215 to use it to write new configurations. The form "timeout srvtimeout" is
9216 provided only by backwards compatibility but its use is strongly discouraged.
9217
Willy Tarreauce887fd2012-05-12 12:50:00 +02009218 See also : "srvtimeout", "timeout client" and "timeout tunnel".
Willy Tarreau844e3c52008-01-11 16:28:18 +01009219
Willy Tarreau05cdd962014-05-10 14:30:07 +02009220
9221timeout server-fin <timeout>
9222 Set the inactivity timeout on the server side for half-closed connections.
9223 May be used in sections : defaults | frontend | listen | backend
9224 yes | no | yes | yes
9225 Arguments :
9226 <timeout> is the timeout value specified in milliseconds by default, but
9227 can be in any other unit if the number is suffixed by the unit,
9228 as explained at the top of this document.
9229
9230 The inactivity timeout applies when the server is expected to acknowledge or
9231 send data while one direction is already shut down. This timeout is different
9232 from "timeout server" in that it only applies to connections which are closed
9233 in one direction. This is particularly useful to avoid keeping connections in
9234 FIN_WAIT state for too long when a remote server does not disconnect cleanly.
9235 This problem is particularly common long connections such as RDP or WebSocket.
9236 Note that this timeout can override "timeout tunnel" when a connection shuts
9237 down in one direction. This setting was provided for completeness, but in most
9238 situations, it should not be needed.
9239
9240 This parameter is specific to backends, but can be specified once for all in
9241 "defaults" sections. By default it is not set, so half-closed connections
9242 will use the other timeouts (timeout.server or timeout.tunnel).
9243
9244 See also : "timeout client-fin", "timeout server", and "timeout tunnel".
9245
Willy Tarreau844e3c52008-01-11 16:28:18 +01009246
9247timeout tarpit <timeout>
Cyril Bonté78caf842010-03-10 22:41:43 +01009248 Set the duration for which tarpitted connections will be maintained
Willy Tarreau844e3c52008-01-11 16:28:18 +01009249 May be used in sections : defaults | frontend | listen | backend
9250 yes | yes | yes | yes
9251 Arguments :
9252 <timeout> is the tarpit duration specified in milliseconds by default, but
9253 can be in any other unit if the number is suffixed by the unit,
9254 as explained at the top of this document.
9255
9256 When a connection is tarpitted using "reqtarpit", it is maintained open with
9257 no activity for a certain amount of time, then closed. "timeout tarpit"
9258 defines how long it will be maintained open.
9259
9260 The value is specified in milliseconds by default, but can be in any other
9261 unit if the number is suffixed by the unit, as specified at the top of this
9262 document. If unspecified, the same value as the backend's connection timeout
9263 ("timeout connect") is used, for backwards compatibility with older versions
Cyril Bonté78caf842010-03-10 22:41:43 +01009264 with no "timeout tarpit" parameter.
Willy Tarreau844e3c52008-01-11 16:28:18 +01009265
9266 See also : "timeout connect", "contimeout".
9267
9268
Willy Tarreauce887fd2012-05-12 12:50:00 +02009269timeout tunnel <timeout>
9270 Set the maximum inactivity time on the client and server side for tunnels.
9271 May be used in sections : defaults | frontend | listen | backend
9272 yes | no | yes | yes
9273 Arguments :
9274 <timeout> is the timeout value specified in milliseconds by default, but
9275 can be in any other unit if the number is suffixed by the unit,
9276 as explained at the top of this document.
9277
Jamie Gloudonaaa21002012-08-25 00:18:33 -04009278 The tunnel timeout applies when a bidirectional connection is established
Willy Tarreauce887fd2012-05-12 12:50:00 +02009279 between a client and a server, and the connection remains inactive in both
9280 directions. This timeout supersedes both the client and server timeouts once
9281 the connection becomes a tunnel. In TCP, this timeout is used as soon as no
9282 analyser remains attached to either connection (eg: tcp content rules are
9283 accepted). In HTTP, this timeout is used when a connection is upgraded (eg:
9284 when switching to the WebSocket protocol, or forwarding a CONNECT request
9285 to a proxy), or after the first response when no keepalive/close option is
9286 specified.
9287
Willy Tarreau05cdd962014-05-10 14:30:07 +02009288 Since this timeout is usually used in conjunction with long-lived connections,
9289 it usually is a good idea to also set "timeout client-fin" to handle the
9290 situation where a client suddenly disappears from the net and does not
9291 acknowledge a close, or sends a shutdown and does not acknowledge pending
9292 data anymore. This can happen in lossy networks where firewalls are present,
9293 and is detected by the presence of large amounts of sessions in a FIN_WAIT
9294 state.
9295
Willy Tarreauce887fd2012-05-12 12:50:00 +02009296 The value is specified in milliseconds by default, but can be in any other
9297 unit if the number is suffixed by the unit, as specified at the top of this
9298 document. Whatever the expected normal idle time, it is a good practice to
9299 cover at least one or several TCP packet losses by specifying timeouts that
9300 are slightly above multiples of 3 seconds (eg: 4 or 5 seconds minimum).
9301
9302 This parameter is specific to backends, but can be specified once for all in
9303 "defaults" sections. This is in fact one of the easiest solutions not to
9304 forget about it.
9305
9306 Example :
9307 defaults http
9308 option http-server-close
9309 timeout connect 5s
9310 timeout client 30s
Willy Tarreau05cdd962014-05-10 14:30:07 +02009311 timeout client-fin 30s
Willy Tarreauce887fd2012-05-12 12:50:00 +02009312 timeout server 30s
9313 timeout tunnel 1h # timeout to use with WebSocket and CONNECT
9314
Willy Tarreau05cdd962014-05-10 14:30:07 +02009315 See also : "timeout client", "timeout client-fin", "timeout server".
Willy Tarreauce887fd2012-05-12 12:50:00 +02009316
9317
Willy Tarreau844e3c52008-01-11 16:28:18 +01009318transparent (deprecated)
9319 Enable client-side transparent proxying
9320 May be used in sections : defaults | frontend | listen | backend
Willy Tarreau4b1f8592008-12-23 23:13:55 +01009321 yes | no | yes | yes
Willy Tarreau844e3c52008-01-11 16:28:18 +01009322 Arguments : none
9323
9324 This keyword was introduced in order to provide layer 7 persistence to layer
9325 3 load balancers. The idea is to use the OS's ability to redirect an incoming
9326 connection for a remote address to a local process (here HAProxy), and let
9327 this process know what address was initially requested. When this option is
9328 used, sessions without cookies will be forwarded to the original destination
9329 IP address of the incoming request (which should match that of another
9330 equipment), while requests with cookies will still be forwarded to the
9331 appropriate server.
9332
9333 The "transparent" keyword is deprecated, use "option transparent" instead.
9334
9335 Note that contrary to a common belief, this option does NOT make HAProxy
9336 present the client's IP to the server when establishing the connection.
9337
Willy Tarreau844e3c52008-01-11 16:28:18 +01009338 See also: "option transparent"
9339
William Lallemanda73203e2012-03-12 12:48:57 +01009340unique-id-format <string>
9341 Generate a unique ID for each request.
9342 May be used in sections : defaults | frontend | listen | backend
9343 yes | yes | yes | no
9344 Arguments :
9345 <string> is a log-format string.
9346
Cyril Bonté108cf6e2012-04-21 23:30:29 +02009347 This keyword creates a ID for each request using the custom log format. A
9348 unique ID is useful to trace a request passing through many components of
9349 a complex infrastructure. The newly created ID may also be logged using the
9350 %ID tag the log-format string.
William Lallemanda73203e2012-03-12 12:48:57 +01009351
Cyril Bonté108cf6e2012-04-21 23:30:29 +02009352 The format should be composed from elements that are guaranteed to be
9353 unique when combined together. For instance, if multiple haproxy instances
9354 are involved, it might be important to include the node name. It is often
9355 needed to log the incoming connection's source and destination addresses
9356 and ports. Note that since multiple requests may be performed over the same
9357 connection, including a request counter may help differentiate them.
9358 Similarly, a timestamp may protect against a rollover of the counter.
9359 Logging the process ID will avoid collisions after a service restart.
William Lallemanda73203e2012-03-12 12:48:57 +01009360
Cyril Bonté108cf6e2012-04-21 23:30:29 +02009361 It is recommended to use hexadecimal notation for many fields since it
9362 makes them more compact and saves space in logs.
William Lallemanda73203e2012-03-12 12:48:57 +01009363
Cyril Bonté108cf6e2012-04-21 23:30:29 +02009364 Example:
William Lallemanda73203e2012-03-12 12:48:57 +01009365
Julien Vehentf21be322014-03-07 08:27:34 -05009366 unique-id-format %{+X}o\ %ci:%cp_%fi:%fp_%Ts_%rt:%pid
William Lallemanda73203e2012-03-12 12:48:57 +01009367
9368 will generate:
9369
9370 7F000001:8296_7F00001E:1F90_4F7B0A69_0003:790A
9371
9372 See also: "unique-id-header"
9373
9374unique-id-header <name>
9375 Add a unique ID header in the HTTP request.
9376 May be used in sections : defaults | frontend | listen | backend
9377 yes | yes | yes | no
9378 Arguments :
9379 <name> is the name of the header.
9380
Cyril Bonté108cf6e2012-04-21 23:30:29 +02009381 Add a unique-id header in the HTTP request sent to the server, using the
9382 unique-id-format. It can't work if the unique-id-format doesn't exist.
William Lallemanda73203e2012-03-12 12:48:57 +01009383
Cyril Bonté108cf6e2012-04-21 23:30:29 +02009384 Example:
William Lallemanda73203e2012-03-12 12:48:57 +01009385
Julien Vehentf21be322014-03-07 08:27:34 -05009386 unique-id-format %{+X}o\ %ci:%cp_%fi:%fp_%Ts_%rt:%pid
William Lallemanda73203e2012-03-12 12:48:57 +01009387 unique-id-header X-Unique-ID
9388
9389 will generate:
9390
9391 X-Unique-ID: 7F000001:8296_7F00001E:1F90_4F7B0A69_0003:790A
9392
9393 See also: "unique-id-format"
Willy Tarreau844e3c52008-01-11 16:28:18 +01009394
Willy Tarreauf51658d2014-04-23 01:21:56 +02009395use_backend <backend> [{if | unless} <condition>]
Willy Tarreau1d0dfb12009-07-07 15:10:31 +02009396 Switch to a specific backend if/unless an ACL-based condition is matched.
Willy Tarreau844e3c52008-01-11 16:28:18 +01009397 May be used in sections : defaults | frontend | listen | backend
9398 no | yes | yes | no
9399 Arguments :
Bertrand Jacquin702d44f2013-11-19 11:43:06 +01009400 <backend> is the name of a valid backend or "listen" section, or a
9401 "log-format" string resolving to a backend name.
Willy Tarreau844e3c52008-01-11 16:28:18 +01009402
Willy Tarreauf51658d2014-04-23 01:21:56 +02009403 <condition> is a condition composed of ACLs, as described in section 7. If
9404 it is omitted, the rule is unconditionally applied.
Willy Tarreau844e3c52008-01-11 16:28:18 +01009405
9406 When doing content-switching, connections arrive on a frontend and are then
9407 dispatched to various backends depending on a number of conditions. The
9408 relation between the conditions and the backends is described with the
Willy Tarreau1d0dfb12009-07-07 15:10:31 +02009409 "use_backend" keyword. While it is normally used with HTTP processing, it can
9410 also be used in pure TCP, either without content using stateless ACLs (eg:
9411 source address validation) or combined with a "tcp-request" rule to wait for
9412 some payload.
Willy Tarreau844e3c52008-01-11 16:28:18 +01009413
9414 There may be as many "use_backend" rules as desired. All of these rules are
9415 evaluated in their declaration order, and the first one which matches will
9416 assign the backend.
9417
9418 In the first form, the backend will be used if the condition is met. In the
9419 second form, the backend will be used if the condition is not met. If no
9420 condition is valid, the backend defined with "default_backend" will be used.
9421 If no default backend is defined, either the servers in the same section are
9422 used (in case of a "listen" section) or, in case of a frontend, no server is
9423 used and a 503 service unavailable response is returned.
9424
Willy Tarreau51aecc72009-07-12 09:47:04 +02009425 Note that it is possible to switch from a TCP frontend to an HTTP backend. In
Krzysztof Piotr Oledzkif8645332009-12-13 21:55:50 +01009426 this case, either the frontend has already checked that the protocol is HTTP,
Willy Tarreau51aecc72009-07-12 09:47:04 +02009427 and backend processing will immediately follow, or the backend will wait for
9428 a complete HTTP request to get in. This feature is useful when a frontend
9429 must decode several protocols on a unique port, one of them being HTTP.
9430
Bertrand Jacquin702d44f2013-11-19 11:43:06 +01009431 When <backend> is a simple name, it is resolved at configuration time, and an
9432 error is reported if the specified backend does not exist. If <backend> is
9433 a log-format string instead, no check may be done at configuration time, so
9434 the backend name is resolved dynamically at run time. If the resulting
9435 backend name does not correspond to any valid backend, no other rule is
9436 evaluated, and the default_backend directive is applied instead. Note that
9437 when using dynamic backend names, it is highly recommended to use a prefix
9438 that no other backend uses in order to ensure that an unauthorized backend
9439 cannot be forced from the request.
9440
Jarno Huuskonen0e82b922014-04-12 18:22:19 +03009441 It is worth mentioning that "use_backend" rules with an explicit name are
Bertrand Jacquin702d44f2013-11-19 11:43:06 +01009442 used to detect the association between frontends and backends to compute the
9443 backend's "fullconn" setting. This cannot be done for dynamic names.
9444
9445 See also: "default_backend", "tcp-request", "fullconn", "log-format", and
9446 section 7 about ACLs.
Willy Tarreaud72758d2010-01-12 10:42:19 +01009447
Willy Tarreau036fae02008-01-06 13:24:40 +01009448
Willy Tarreau4a5cade2012-04-05 21:09:48 +02009449use-server <server> if <condition>
9450use-server <server> unless <condition>
9451 Only use a specific server if/unless an ACL-based condition is matched.
9452 May be used in sections : defaults | frontend | listen | backend
9453 no | no | yes | yes
9454 Arguments :
Cyril Bonté108cf6e2012-04-21 23:30:29 +02009455 <server> is the name of a valid server in the same backend section.
Willy Tarreau4a5cade2012-04-05 21:09:48 +02009456
9457 <condition> is a condition composed of ACLs, as described in section 7.
9458
9459 By default, connections which arrive to a backend are load-balanced across
9460 the available servers according to the configured algorithm, unless a
9461 persistence mechanism such as a cookie is used and found in the request.
9462
9463 Sometimes it is desirable to forward a particular request to a specific
9464 server without having to declare a dedicated backend for this server. This
9465 can be achieved using the "use-server" rules. These rules are evaluated after
9466 the "redirect" rules and before evaluating cookies, and they have precedence
9467 on them. There may be as many "use-server" rules as desired. All of these
9468 rules are evaluated in their declaration order, and the first one which
9469 matches will assign the server.
9470
9471 If a rule designates a server which is down, and "option persist" is not used
9472 and no force-persist rule was validated, it is ignored and evaluation goes on
9473 with the next rules until one matches.
9474
9475 In the first form, the server will be used if the condition is met. In the
9476 second form, the server will be used if the condition is not met. If no
9477 condition is valid, the processing continues and the server will be assigned
9478 according to other persistence mechanisms.
9479
9480 Note that even if a rule is matched, cookie processing is still performed but
9481 does not assign the server. This allows prefixed cookies to have their prefix
9482 stripped.
9483
9484 The "use-server" statement works both in HTTP and TCP mode. This makes it
9485 suitable for use with content-based inspection. For instance, a server could
9486 be selected in a farm according to the TLS SNI field. And if these servers
9487 have their weight set to zero, they will not be used for other traffic.
9488
9489 Example :
9490 # intercept incoming TLS requests based on the SNI field
9491 use-server www if { req_ssl_sni -i www.example.com }
9492 server www 192.168.0.1:443 weight 0
9493 use-server mail if { req_ssl_sni -i mail.example.com }
9494 server mail 192.168.0.1:587 weight 0
9495 use-server imap if { req_ssl_sni -i imap.example.com }
9496 server mail 192.168.0.1:993 weight 0
9497 # all the rest is forwarded to this server
9498 server default 192.168.0.2:443 check
9499
Jarno Huuskonen0e82b922014-04-12 18:22:19 +03009500 See also: "use_backend", section 5 about server and section 7 about ACLs.
Willy Tarreau4a5cade2012-04-05 21:09:48 +02009501
Willy Tarreaub6205fd2012-09-24 12:27:33 +02009502
95035. Bind and Server options
9504--------------------------
9505
9506The "bind", "server" and "default-server" keywords support a number of settings
9507depending on some build options and on the system HAProxy was built on. These
9508settings generally each consist in one word sometimes followed by a value,
9509written on the same line as the "bind" or "server" line. All these options are
9510described in this section.
9511
9512
95135.1. Bind options
9514-----------------
9515
9516The "bind" keyword supports a certain number of settings which are all passed
9517as arguments on the same line. The order in which those arguments appear makes
9518no importance, provided that they appear after the bind address. All of these
9519parameters are optional. Some of them consist in a single words (booleans),
9520while other ones expect a value after them. In this case, the value must be
9521provided immediately after the setting name.
9522
9523The currently supported settings are the following ones.
9524
9525accept-proxy
9526 Enforces the use of the PROXY protocol over any connection accepted by any of
Willy Tarreau77992672014-06-14 11:06:17 +02009527 the sockets declared on the same line. Versions 1 and 2 of the PROXY protocol
9528 are supported and correctly detected. The PROXY protocol dictates the layer
Willy Tarreaub6205fd2012-09-24 12:27:33 +02009529 3/4 addresses of the incoming connection to be used everywhere an address is
9530 used, with the only exception of "tcp-request connection" rules which will
9531 only see the real connection address. Logs will reflect the addresses
9532 indicated in the protocol, unless it is violated, in which case the real
9533 address will still be used. This keyword combined with support from external
9534 components can be used as an efficient and reliable alternative to the
9535 X-Forwarded-For mechanism which is not always reliable and not even always
Willy Tarreau4f0d9192013-06-11 20:40:55 +02009536 usable. See also "tcp-request connection expect-proxy" for a finer-grained
9537 setting of which client is allowed to use the protocol.
Willy Tarreaub6205fd2012-09-24 12:27:33 +02009538
Willy Tarreauab861d32013-04-02 02:30:41 +02009539alpn <protocols>
9540 This enables the TLS ALPN extension and advertises the specified protocol
9541 list as supported on top of ALPN. The protocol list consists in a comma-
9542 delimited list of protocol names, for instance: "http/1.1,http/1.0" (without
9543 quotes). This requires that the SSL library is build with support for TLS
9544 extensions enabled (check with haproxy -vv). The ALPN extension replaces the
9545 initial NPN extension.
9546
Willy Tarreaub6205fd2012-09-24 12:27:33 +02009547backlog <backlog>
9548 Sets the socket's backlog to this value. If unspecified, the frontend's
9549 backlog is used instead, which generally defaults to the maxconn value.
9550
Emeric Brun7fb34422012-09-28 15:26:15 +02009551ecdhe <named curve>
9552 This setting is only available when support for OpenSSL was built in. It sets
Emeric Brun6924ef82013-03-06 14:08:53 +01009553 the named curve (RFC 4492) used to generate ECDH ephemeral keys. By default,
9554 used named curve is prime256v1.
Emeric Brun7fb34422012-09-28 15:26:15 +02009555
Emeric Brunfd33a262012-10-11 16:28:27 +02009556ca-file <cafile>
Emeric Brun1a073b42012-09-28 17:07:34 +02009557 This setting is only available when support for OpenSSL was built in. It
9558 designates a PEM file from which to load CA certificates used to verify
9559 client's certificate.
9560
Emeric Brunb6dc9342012-09-28 17:55:37 +02009561ca-ignore-err [all|<errorID>,...]
9562 This setting is only available when support for OpenSSL was built in.
9563 Sets a comma separated list of errorIDs to ignore during verify at depth > 0.
9564 If set to 'all', all errors are ignored. SSL handshake is not aborted if an
9565 error is ignored.
9566
Christopher Faulet31af49d2015-06-09 17:29:50 +02009567ca-sign-file <cafile>
9568 This setting is only available when support for OpenSSL was built in. It
9569 designates a PEM file containing both the CA certificate and the CA private
9570 key used to create and sign server's certificates. This is a mandatory
9571 setting when the dynamic generation of certificates is enabled. See
9572 'generate-certificates' for details.
9573
9574ca-sign-passphrase <passphrase>
9575 This setting is only available when support for OpenSSL was built in. It is
9576 the CA private key passphrase. This setting is optional and used only when
9577 the dynamic generation of certificates is enabled. See
9578 'generate-certificates' for details.
9579
Willy Tarreaub6205fd2012-09-24 12:27:33 +02009580ciphers <ciphers>
9581 This setting is only available when support for OpenSSL was built in. It sets
9582 the string describing the list of cipher algorithms ("cipher suite") that are
Jarno Huuskonen0e82b922014-04-12 18:22:19 +03009583 negotiated during the SSL/TLS handshake. The format of the string is defined
Willy Tarreaub6205fd2012-09-24 12:27:33 +02009584 in "man 1 ciphers" from OpenSSL man pages, and can be for instance a string
9585 such as "AES:ALL:!aNULL:!eNULL:+RC4:@STRENGTH" (without quotes).
9586
Emeric Brunfd33a262012-10-11 16:28:27 +02009587crl-file <crlfile>
Emeric Brun1a073b42012-09-28 17:07:34 +02009588 This setting is only available when support for OpenSSL was built in. It
9589 designates a PEM file from which to load certificate revocation list used
9590 to verify client's certificate.
9591
Willy Tarreaub6205fd2012-09-24 12:27:33 +02009592crt <cert>
Alex Davies0fbf0162013-03-02 16:04:50 +00009593 This setting is only available when support for OpenSSL was built in. It
9594 designates a PEM file containing both the required certificates and any
9595 associated private keys. This file can be built by concatenating multiple
9596 PEM files into one (e.g. cat cert.pem key.pem > combined.pem). If your CA
9597 requires an intermediate certificate, this can also be concatenated into this
9598 file.
9599
9600 If the OpenSSL used supports Diffie-Hellman, parameters present in this file
9601 are loaded.
9602
9603 If a directory name is used instead of a PEM file, then all files found in
Cyril Bonté3180f7b2015-01-25 00:16:08 +01009604 that directory will be loaded in alphabetic order unless their name ends with
Janusz Dziemidowicz2c701b52015-03-07 23:03:59 +01009605 '.issuer', '.ocsp' or '.sctl' (reserved extensions). This directive may be
9606 specified multiple times in order to load certificates from multiple files or
9607 directories. The certificates will be presented to clients who provide a
9608 valid TLS Server Name Indication field matching one of their CN or alt
9609 subjects. Wildcards are supported, where a wildcard character '*' is used
9610 instead of the first hostname component (eg: *.example.org matches
9611 www.example.org but not www.sub.example.org).
Alex Davies0fbf0162013-03-02 16:04:50 +00009612
9613 If no SNI is provided by the client or if the SSL library does not support
9614 TLS extensions, or if the client provides an SNI hostname which does not
9615 match any certificate, then the first loaded certificate will be presented.
9616 This means that when loading certificates from a directory, it is highly
Cyril Bonté3180f7b2015-01-25 00:16:08 +01009617 recommended to load the default one first as a file or to ensure that it will
9618 always be the first one in the directory.
Alex Davies0fbf0162013-03-02 16:04:50 +00009619
Emeric Brune032bfa2012-09-28 13:01:45 +02009620 Note that the same cert may be loaded multiple times without side effects.
Willy Tarreaub6205fd2012-09-24 12:27:33 +02009621
Alex Davies0fbf0162013-03-02 16:04:50 +00009622 Some CAs (such as Godaddy) offer a drop down list of server types that do not
9623 include HAProxy when obtaining a certificate. If this happens be sure to
Godbach8bf60a12014-04-21 21:42:41 +08009624 choose a webserver that the CA believes requires an intermediate CA (for
Alex Davies0fbf0162013-03-02 16:04:50 +00009625 Godaddy, selection Apache Tomcat will get the correct bundle, but many
9626 others, e.g. nginx, result in a wrong bundle that will not work for some
9627 clients).
9628
Emeric Brun4147b2e2014-06-16 18:36:30 +02009629 For each PEM file, haproxy checks for the presence of file at the same path
9630 suffixed by ".ocsp". If such file is found, support for the TLS Certificate
9631 Status Request extension (also known as "OCSP stapling") is automatically
9632 enabled. The content of this file is optional. If not empty, it must contain
9633 a valid OCSP Response in DER format. In order to be valid an OCSP Response
9634 must comply with the following rules: it has to indicate a good status,
9635 it has to be a single response for the certificate of the PEM file, and it
9636 has to be valid at the moment of addition. If these rules are not respected
9637 the OCSP Response is ignored and a warning is emitted. In order to identify
9638 which certificate an OCSP Response applies to, the issuer's certificate is
9639 necessary. If the issuer's certificate is not found in the PEM file, it will
9640 be loaded from a file at the same path as the PEM file suffixed by ".issuer"
9641 if it exists otherwise it will fail with an error.
9642
Janusz Dziemidowicz2c701b52015-03-07 23:03:59 +01009643 For each PEM file, haproxy also checks for the presence of file at the same
9644 path suffixed by ".sctl". If such file is found, support for Certificate
9645 Transparency (RFC6962) TLS extension is enabled. The file must contain a
9646 valid Signed Certificate Timestamp List, as described in RFC. File is parsed
9647 to check basic syntax, but no signatures are verified.
9648
Emeric Brunb6dc9342012-09-28 17:55:37 +02009649crt-ignore-err <errors>
Alex Davies0fbf0162013-03-02 16:04:50 +00009650 This setting is only available when support for OpenSSL was built in. Sets a
9651 comma separated list of errorIDs to ignore during verify at depth == 0. If
Jarno Huuskonen0e82b922014-04-12 18:22:19 +03009652 set to 'all', all errors are ignored. SSL handshake is not aborted if an error
Alex Davies0fbf0162013-03-02 16:04:50 +00009653 is ignored.
Emeric Brunb6dc9342012-09-28 17:55:37 +02009654
Emmanuel Hocdetfe616562013-01-22 15:31:15 +01009655crt-list <file>
9656 This setting is only available when support for OpenSSL was built in. It
Emmanuel Hocdet7c41a1b2013-05-07 20:20:06 +02009657 designates a list of PEM file with an optional list of SNI filter per
9658 certificate, with the following format for each line :
Emmanuel Hocdetfe616562013-01-22 15:31:15 +01009659
Emmanuel Hocdet7c41a1b2013-05-07 20:20:06 +02009660 <crtfile> [[!]<snifilter> ...]
Emmanuel Hocdetfe616562013-01-22 15:31:15 +01009661
Emmanuel Hocdet7c41a1b2013-05-07 20:20:06 +02009662 Wildcards are supported in the SNI filter. Negative filter are also supported,
9663 only useful in combination with a wildcard filter to exclude a particular SNI.
9664 The certificates will be presented to clients who provide a valid TLS Server
9665 Name Indication field matching one of the SNI filters. If no SNI filter is
9666 specified, the CN and alt subjects are used. This directive may be specified
9667 multiple times. See the "crt" option for more information. The default
9668 certificate is still needed to meet OpenSSL expectations. If it is not used,
9669 the 'strict-sni' option may be used.
Emmanuel Hocdetfe616562013-01-22 15:31:15 +01009670
Willy Tarreaub6205fd2012-09-24 12:27:33 +02009671defer-accept
9672 Is an optional keyword which is supported only on certain Linux kernels. It
9673 states that a connection will only be accepted once some data arrive on it,
9674 or at worst after the first retransmit. This should be used only on protocols
9675 for which the client talks first (eg: HTTP). It can slightly improve
9676 performance by ensuring that most of the request is already available when
9677 the connection is accepted. On the other hand, it will not be able to detect
9678 connections which don't talk. It is important to note that this option is
9679 broken in all kernels up to 2.6.31, as the connection is never accepted until
9680 the client talks. This can cause issues with front firewalls which would see
9681 an established connection while the proxy will only see it in SYN_RECV. This
9682 option is only supported on TCPv4/TCPv6 sockets and ignored by other ones.
9683
Emeric Brun2cb7ae52012-10-05 14:14:21 +02009684force-sslv3
Jarno Huuskonen0e82b922014-04-12 18:22:19 +03009685 This option enforces use of SSLv3 only on SSL connections instantiated from
Emeric Brun2cb7ae52012-10-05 14:14:21 +02009686 this listener. SSLv3 is generally less expensive than the TLS counterparts
Emeric Brun2c86cbf2014-10-30 15:56:50 +01009687 for high connection rates. This option is also available on global statement
9688 "ssl-default-bind-options". See also "no-tlsv*" and "no-sslv3".
Emeric Brun2cb7ae52012-10-05 14:14:21 +02009689
9690force-tlsv10
Jarno Huuskonen0e82b922014-04-12 18:22:19 +03009691 This option enforces use of TLSv1.0 only on SSL connections instantiated from
Emeric Brun2c86cbf2014-10-30 15:56:50 +01009692 this listener. This option is also available on global statement
9693 "ssl-default-bind-options". See also "no-tlsv*" and "no-sslv3".
Emeric Brun2cb7ae52012-10-05 14:14:21 +02009694
9695force-tlsv11
Jarno Huuskonen0e82b922014-04-12 18:22:19 +03009696 This option enforces use of TLSv1.1 only on SSL connections instantiated from
Emeric Brun2c86cbf2014-10-30 15:56:50 +01009697 this listener. This option is also available on global statement
9698 "ssl-default-bind-options". See also "no-tlsv*", and "no-sslv3".
Emeric Brun2cb7ae52012-10-05 14:14:21 +02009699
9700force-tlsv12
Jarno Huuskonen0e82b922014-04-12 18:22:19 +03009701 This option enforces use of TLSv1.2 only on SSL connections instantiated from
Emeric Brun2c86cbf2014-10-30 15:56:50 +01009702 this listener. This option is also available on global statement
9703 "ssl-default-bind-options". See also "no-tlsv*", and "no-sslv3".
Emeric Brun2cb7ae52012-10-05 14:14:21 +02009704
Christopher Faulet31af49d2015-06-09 17:29:50 +02009705generate-certificates
9706 This setting is only available when support for OpenSSL was built in. It
9707 enables the dynamic SSL certificates generation. A CA certificate and its
9708 private key are necessary (see 'ca-sign-file'). When HAProxy is configured as
9709 a transparent forward proxy, SSL requests generate errors because of a common
9710 name mismatch on the certificate presented to the client. With this option
9711 enabled, HAProxy will try to forge a certificate using the SNI hostname
9712 indicated by the client. This is done only if no certificate matches the SNI
9713 hostname (see 'crt-list'). If an error occurs, the default certificate is
9714 used, else the 'strict-sni' option is set.
9715 It can also be used when HAProxy is configured as a reverse proxy to ease the
9716 deployment of an architecture with many backends.
9717
9718 Creating a SSL certificate is an expensive operation, so a LRU cache is used
9719 to store forged certificates (see 'tune.ssl.ssl-ctx-cache-size'). It
9720 increases the HAProxy's memroy footprint to reduce latency when the same
9721 certificate is used many times.
9722
Willy Tarreaub6205fd2012-09-24 12:27:33 +02009723gid <gid>
9724 Sets the group of the UNIX sockets to the designated system gid. It can also
9725 be set by default in the global section's "unix-bind" statement. Note that
9726 some platforms simply ignore this. This setting is equivalent to the "group"
9727 setting except that the group ID is used instead of its name. This setting is
9728 ignored by non UNIX sockets.
9729
9730group <group>
9731 Sets the group of the UNIX sockets to the designated system group. It can
9732 also be set by default in the global section's "unix-bind" statement. Note
9733 that some platforms simply ignore this. This setting is equivalent to the
9734 "gid" setting except that the group name is used instead of its gid. This
9735 setting is ignored by non UNIX sockets.
9736
9737id <id>
9738 Fixes the socket ID. By default, socket IDs are automatically assigned, but
9739 sometimes it is more convenient to fix them to ease monitoring. This value
9740 must be strictly positive and unique within the listener/frontend. This
9741 option can only be used when defining only a single socket.
9742
9743interface <interface>
Lukas Tribusfce2e962013-02-12 22:13:19 +01009744 Restricts the socket to a specific interface. When specified, only packets
9745 received from that particular interface are processed by the socket. This is
9746 currently only supported on Linux. The interface must be a primary system
9747 interface, not an aliased interface. It is also possible to bind multiple
9748 frontends to the same address if they are bound to different interfaces. Note
9749 that binding to a network interface requires root privileges. This parameter
9750 is only compatible with TCPv4/TCPv6 sockets.
Willy Tarreaub6205fd2012-09-24 12:27:33 +02009751
Willy Tarreauabb175f2012-09-24 12:43:26 +02009752level <level>
9753 This setting is used with the stats sockets only to restrict the nature of
9754 the commands that can be issued on the socket. It is ignored by other
9755 sockets. <level> can be one of :
9756 - "user" is the least privileged level ; only non-sensitive stats can be
9757 read, and no change is allowed. It would make sense on systems where it
9758 is not easy to restrict access to the socket.
9759 - "operator" is the default level and fits most common uses. All data can
9760 be read, and only non-sensitive changes are permitted (eg: clear max
9761 counters).
9762 - "admin" should be used with care, as everything is permitted (eg: clear
9763 all counters).
9764
Willy Tarreaub6205fd2012-09-24 12:27:33 +02009765maxconn <maxconn>
9766 Limits the sockets to this number of concurrent connections. Extraneous
9767 connections will remain in the system's backlog until a connection is
9768 released. If unspecified, the limit will be the same as the frontend's
9769 maxconn. Note that in case of port ranges or multiple addresses, the same
9770 value will be applied to each socket. This setting enables different
9771 limitations on expensive sockets, for instance SSL entries which may easily
9772 eat all memory.
9773
9774mode <mode>
9775 Sets the octal mode used to define access permissions on the UNIX socket. It
9776 can also be set by default in the global section's "unix-bind" statement.
9777 Note that some platforms simply ignore this. This setting is ignored by non
9778 UNIX sockets.
9779
9780mss <maxseg>
9781 Sets the TCP Maximum Segment Size (MSS) value to be advertised on incoming
9782 connections. This can be used to force a lower MSS for certain specific
9783 ports, for instance for connections passing through a VPN. Note that this
9784 relies on a kernel feature which is theoretically supported under Linux but
9785 was buggy in all versions prior to 2.6.28. It may or may not work on other
9786 operating systems. It may also not change the advertised value but change the
9787 effective size of outgoing segments. The commonly advertised value for TCPv4
9788 over Ethernet networks is 1460 = 1500(MTU) - 40(IP+TCP). If this value is
9789 positive, it will be used as the advertised MSS. If it is negative, it will
9790 indicate by how much to reduce the incoming connection's advertised MSS for
9791 outgoing segments. This parameter is only compatible with TCP v4/v6 sockets.
9792
9793name <name>
9794 Sets an optional name for these sockets, which will be reported on the stats
9795 page.
9796
9797nice <nice>
9798 Sets the 'niceness' of connections initiated from the socket. Value must be
9799 in the range -1024..1024 inclusive, and defaults to zero. Positive values
9800 means that such connections are more friendly to others and easily offer
9801 their place in the scheduler. On the opposite, negative values mean that
9802 connections want to run with a higher priority than others. The difference
9803 only happens under high loads when the system is close to saturation.
9804 Negative values are appropriate for low-latency or administration services,
9805 and high values are generally recommended for CPU intensive tasks such as SSL
9806 processing or bulk transfers which are less sensible to latency. For example,
9807 it may make sense to use a positive value for an SMTP socket and a negative
9808 one for an RDP socket.
9809
Emeric Brun9b3009b2012-10-05 11:55:06 +02009810no-sslv3
Willy Tarreaub6205fd2012-09-24 12:27:33 +02009811 This setting is only available when support for OpenSSL was built in. It
Jarno Huuskonen0e82b922014-04-12 18:22:19 +03009812 disables support for SSLv3 on any sockets instantiated from the listener when
Willy Tarreaub6205fd2012-09-24 12:27:33 +02009813 SSL is supported. Note that SSLv2 is forced disabled in the code and cannot
Emeric Brun2c86cbf2014-10-30 15:56:50 +01009814 be enabled using any configuration option. This option is also available on
9815 global statement "ssl-default-bind-options". See also "force-tls*",
Emeric Brun2cb7ae52012-10-05 14:14:21 +02009816 and "force-sslv3".
Willy Tarreaub6205fd2012-09-24 12:27:33 +02009817
Emeric Brun90ad8722012-10-02 14:00:59 +02009818no-tls-tickets
9819 This setting is only available when support for OpenSSL was built in. It
9820 disables the stateless session resumption (RFC 5077 TLS Ticket
9821 extension) and force to use stateful session resumption. Stateless
Emeric Brun2c86cbf2014-10-30 15:56:50 +01009822 session resumption is more expensive in CPU usage. This option is also
9823 available on global statement "ssl-default-bind-options".
Emeric Brun90ad8722012-10-02 14:00:59 +02009824
Emeric Brun9b3009b2012-10-05 11:55:06 +02009825no-tlsv10
Willy Tarreaub6205fd2012-09-24 12:27:33 +02009826 This setting is only available when support for OpenSSL was built in. It
Jarno Huuskonen0e82b922014-04-12 18:22:19 +03009827 disables support for TLSv1.0 on any sockets instantiated from the listener
Emeric Brun2cb7ae52012-10-05 14:14:21 +02009828 when SSL is supported. Note that SSLv2 is forced disabled in the code and
Emeric Brun2c86cbf2014-10-30 15:56:50 +01009829 cannot be enabled using any configuration option. This option is also
9830 available on global statement "ssl-default-bind-options". See also
9831 "force-tlsv*", and "force-sslv3".
Willy Tarreaub6205fd2012-09-24 12:27:33 +02009832
Emeric Brun9b3009b2012-10-05 11:55:06 +02009833no-tlsv11
Emeric Brunf5da4932012-09-28 19:42:54 +02009834 This setting is only available when support for OpenSSL was built in. It
Jarno Huuskonen0e82b922014-04-12 18:22:19 +03009835 disables support for TLSv1.1 on any sockets instantiated from the listener
Emeric Brun2cb7ae52012-10-05 14:14:21 +02009836 when SSL is supported. Note that SSLv2 is forced disabled in the code and
Emeric Brun2c86cbf2014-10-30 15:56:50 +01009837 cannot be enabled using any configuration option. This option is also
9838 available on global statement "ssl-default-bind-options". See also
9839 "force-tlsv*", and "force-sslv3".
Emeric Brunf5da4932012-09-28 19:42:54 +02009840
Emeric Brun9b3009b2012-10-05 11:55:06 +02009841no-tlsv12
Emeric Brunf5da4932012-09-28 19:42:54 +02009842 This setting is only available when support for OpenSSL was built in. It
Jarno Huuskonen0e82b922014-04-12 18:22:19 +03009843 disables support for TLSv1.2 on any sockets instantiated from the listener
Emeric Brun2cb7ae52012-10-05 14:14:21 +02009844 when SSL is supported. Note that SSLv2 is forced disabled in the code and
Emeric Brun2c86cbf2014-10-30 15:56:50 +01009845 cannot be enabled using any configuration option. This option is also
9846 available on global statement "ssl-default-bind-options". See also
9847 "force-tlsv*", and "force-sslv3".
Emeric Brunf5da4932012-09-28 19:42:54 +02009848
Willy Tarreau6c9a3d52012-10-18 18:57:14 +02009849npn <protocols>
9850 This enables the NPN TLS extension and advertises the specified protocol list
9851 as supported on top of NPN. The protocol list consists in a comma-delimited
9852 list of protocol names, for instance: "http/1.1,http/1.0" (without quotes).
9853 This requires that the SSL library is build with support for TLS extensions
Willy Tarreauab861d32013-04-02 02:30:41 +02009854 enabled (check with haproxy -vv). Note that the NPN extension has been
9855 replaced with the ALPN extension (see the "alpn" keyword).
Willy Tarreau6c9a3d52012-10-18 18:57:14 +02009856
Willy Tarreau6ae1ba62014-05-07 19:01:58 +02009857process [ all | odd | even | <number 1-64>[-<number 1-64>] ]
9858 This restricts the list of processes on which this listener is allowed to
9859 run. It does not enforce any process but eliminates those which do not match.
9860 If the frontend uses a "bind-process" setting, the intersection between the
9861 two is applied. If in the end the listener is not allowed to run on any
9862 remaining process, a warning is emitted, and the listener will either run on
9863 the first process of the listener if a single process was specified, or on
9864 all of its processes if multiple processes were specified. For the unlikely
Willy Tarreauae302532014-05-07 19:22:24 +02009865 case where several ranges are needed, this directive may be repeated. The
9866 main purpose of this directive is to be used with the stats sockets and have
9867 one different socket per process. The second purpose is to have multiple bind
9868 lines sharing the same IP:port but not the same process in a listener, so
9869 that the system can distribute the incoming connections into multiple queues
9870 and allow a smoother inter-process load balancing. Currently Linux 3.9 and
9871 above is known for supporting this. See also "bind-process" and "nbproc".
Willy Tarreau6ae1ba62014-05-07 19:01:58 +02009872
Willy Tarreaub6205fd2012-09-24 12:27:33 +02009873ssl
9874 This setting is only available when support for OpenSSL was built in. It
Jarno Huuskonen0e82b922014-04-12 18:22:19 +03009875 enables SSL deciphering on connections instantiated from this listener. A
Willy Tarreaub6205fd2012-09-24 12:27:33 +02009876 certificate is necessary (see "crt" above). All contents in the buffers will
9877 appear in clear text, so that ACLs and HTTP processing will only have access
9878 to deciphered contents.
9879
Emmanuel Hocdet65623372013-01-24 17:17:15 +01009880strict-sni
9881 This setting is only available when support for OpenSSL was built in. The
9882 SSL/TLS negotiation is allow only if the client provided an SNI which match
9883 a certificate. The default certificate is not used.
9884 See the "crt" option for more information.
9885
Willy Tarreau2af207a2015-02-04 00:45:58 +01009886tcp-ut <delay>
9887 Sets the TCP User Timeout for all incoming connections instanciated from this
9888 listening socket. This option is available on Linux since version 2.6.37. It
9889 allows haproxy to configure a timeout for sockets which contain data not
9890 receiving an acknoledgement for the configured delay. This is especially
9891 useful on long-lived connections experiencing long idle periods such as
9892 remote terminals or database connection pools, where the client and server
9893 timeouts must remain high to allow a long period of idle, but where it is
9894 important to detect that the client has disappeared in order to release all
9895 resources associated with its connection (and the server's session). The
9896 argument is a delay expressed in milliseconds by default. This only works
9897 for regular TCP connections, and is ignored for other protocols.
9898
Willy Tarreau1c862c52012-10-05 16:21:00 +02009899tfo
Lukas Tribus0defb902013-02-13 23:35:39 +01009900 Is an optional keyword which is supported only on Linux kernels >= 3.7. It
Willy Tarreau1c862c52012-10-05 16:21:00 +02009901 enables TCP Fast Open on the listening socket, which means that clients which
9902 support this feature will be able to send a request and receive a response
9903 during the 3-way handshake starting from second connection, thus saving one
9904 round-trip after the first connection. This only makes sense with protocols
9905 that use high connection rates and where each round trip matters. This can
9906 possibly cause issues with many firewalls which do not accept data on SYN
9907 packets, so this option should only be enabled once well tested. This option
Lukas Tribus0999f762013-04-02 16:43:24 +02009908 is only supported on TCPv4/TCPv6 sockets and ignored by other ones. You may
9909 need to build HAProxy with USE_TFO=1 if your libc doesn't define
9910 TCP_FASTOPEN.
Willy Tarreau1c862c52012-10-05 16:21:00 +02009911
Nenad Merdanovic188ad3e2015-02-27 19:56:50 +01009912tls-ticket-keys <keyfile>
9913 Sets the TLS ticket keys file to load the keys from. The keys need to be 48
9914 bytes long, encoded with base64 (ex. openssl rand -base64 48). Number of keys
9915 is specified by the TLS_TICKETS_NO build option (default 3) and at least as
9916 many keys need to be present in the file. Last TLS_TICKETS_NO keys will be
9917 used for decryption and the penultimate one for encryption. This enables easy
9918 key rotation by just appending new key to the file and reloading the process.
9919 Keys must be periodically rotated (ex. every 12h) or Perfect Forward Secrecy
9920 is compromised. It is also a good idea to keep the keys off any permanent
9921 storage such as hard drives (hint: use tmpfs and don't swap those files).
9922 Lifetime hint can be changed using tune.ssl.timeout.
9923
Willy Tarreaub6205fd2012-09-24 12:27:33 +02009924transparent
9925 Is an optional keyword which is supported only on certain Linux kernels. It
9926 indicates that the addresses will be bound even if they do not belong to the
9927 local machine, and that packets targeting any of these addresses will be
9928 intercepted just as if the addresses were locally configured. This normally
9929 requires that IP forwarding is enabled. Caution! do not use this with the
9930 default address '*', as it would redirect any traffic for the specified port.
9931 This keyword is available only when HAProxy is built with USE_LINUX_TPROXY=1.
9932 This parameter is only compatible with TCPv4 and TCPv6 sockets, depending on
9933 kernel version. Some distribution kernels include backports of the feature,
9934 so check for support with your vendor.
9935
Willy Tarreau77e3af92012-11-24 15:07:23 +01009936v4v6
9937 Is an optional keyword which is supported only on most recent systems
9938 including Linux kernels >= 2.4.21. It is used to bind a socket to both IPv4
9939 and IPv6 when it uses the default address. Doing so is sometimes necessary
9940 on systems which bind to IPv6 only by default. It has no effect on non-IPv6
Jarno Huuskonen0e82b922014-04-12 18:22:19 +03009941 sockets, and is overridden by the "v6only" option.
Willy Tarreau77e3af92012-11-24 15:07:23 +01009942
Willy Tarreau9b6700f2012-11-24 11:55:28 +01009943v6only
9944 Is an optional keyword which is supported only on most recent systems
9945 including Linux kernels >= 2.4.21. It is used to bind a socket to IPv6 only
9946 when it uses the default address. Doing so is sometimes preferred to doing it
Willy Tarreau77e3af92012-11-24 15:07:23 +01009947 system-wide as it is per-listener. It has no effect on non-IPv6 sockets and
9948 has precedence over the "v4v6" option.
Willy Tarreau9b6700f2012-11-24 11:55:28 +01009949
Willy Tarreaub6205fd2012-09-24 12:27:33 +02009950uid <uid>
9951 Sets the owner of the UNIX sockets to the designated system uid. It can also
9952 be set by default in the global section's "unix-bind" statement. Note that
9953 some platforms simply ignore this. This setting is equivalent to the "user"
9954 setting except that the user numeric ID is used instead of its name. This
9955 setting is ignored by non UNIX sockets.
9956
9957user <user>
9958 Sets the owner of the UNIX sockets to the designated system user. It can also
9959 be set by default in the global section's "unix-bind" statement. Note that
9960 some platforms simply ignore this. This setting is equivalent to the "uid"
9961 setting except that the user name is used instead of its uid. This setting is
9962 ignored by non UNIX sockets.
9963
Emeric Brun1a073b42012-09-28 17:07:34 +02009964verify [none|optional|required]
9965 This setting is only available when support for OpenSSL was built in. If set
9966 to 'none', client certificate is not requested. This is the default. In other
9967 cases, a client certificate is requested. If the client does not provide a
9968 certificate after the request and if 'verify' is set to 'required', then the
9969 handshake is aborted, while it would have succeeded if set to 'optional'. The
Emeric Brunfd33a262012-10-11 16:28:27 +02009970 certificate provided by the client is always verified using CAs from
9971 'ca-file' and optional CRLs from 'crl-file'. On verify failure the handshake
9972 is aborted, regardless of the 'verify' option, unless the error code exactly
9973 matches one of those listed with 'ca-ignore-err' or 'crt-ignore-err'.
Willy Tarreau4a5cade2012-04-05 21:09:48 +02009974
Willy Tarreaub6205fd2012-09-24 12:27:33 +020099755.2. Server and default-server options
Cyril Bontéf0c60612010-02-06 14:44:47 +01009976------------------------------------
Willy Tarreau6a06a402007-07-15 20:15:28 +02009977
Krzysztof Piotr Oledzkic6df0662010-01-05 16:38:49 +01009978The "server" and "default-server" keywords support a certain number of settings
9979which are all passed as arguments on the server line. The order in which those
9980arguments appear does not count, and they are all optional. Some of those
9981settings are single words (booleans) while others expect one or several values
9982after them. In this case, the values must immediately follow the setting name.
9983Except default-server, all those settings must be specified after the server's
9984address if they are used:
Willy Tarreau6a06a402007-07-15 20:15:28 +02009985
Willy Tarreauc57f0e22009-05-10 13:12:33 +02009986 server <name> <address>[:port] [settings ...]
Krzysztof Piotr Oledzkic6df0662010-01-05 16:38:49 +01009987 default-server [settings ...]
Willy Tarreau6a06a402007-07-15 20:15:28 +02009988
Krzysztof Piotr Oledzkic53601c2010-01-06 10:50:42 +01009989The currently supported settings are the following ones.
Willy Tarreau0ba27502007-12-24 16:55:16 +01009990
Willy Tarreauceb4ac92012-04-28 00:41:46 +02009991addr <ipv4|ipv6>
Willy Tarreauc57f0e22009-05-10 13:12:33 +02009992 Using the "addr" parameter, it becomes possible to use a different IP address
9993 to send health-checks. On some servers, it may be desirable to dedicate an IP
9994 address to specific component able to perform complex tests which are more
9995 suitable to health-checks than the application. This parameter is ignored if
9996 the "check" parameter is not set. See also the "port" parameter.
Willy Tarreau6a06a402007-07-15 20:15:28 +02009997
Krzysztof Piotr Oledzkic53601c2010-01-06 10:50:42 +01009998 Supported in default-server: No
9999
Simon Hormand60d6912013-11-25 10:46:36 +090010000agent-check
10001 Enable an auxiliary agent check which is run independently of a regular
Willy Tarreau81f5d942013-12-09 20:51:51 +010010002 health check. An agent health check is performed by making a TCP connection
10003 to the port set by the "agent-port" parameter and reading an ASCII string.
10004 The string is made of a series of words delimited by spaces, tabs or commas
10005 in any order, optionally terminated by '\r' and/or '\n', each consisting of :
Simon Hormand60d6912013-11-25 10:46:36 +090010006
Willy Tarreau81f5d942013-12-09 20:51:51 +010010007 - An ASCII representation of a positive integer percentage, e.g. "75%".
Simon Hormand60d6912013-11-25 10:46:36 +090010008 Values in this format will set the weight proportional to the initial
Willy Tarreauc5af3a62014-10-07 15:27:33 +020010009 weight of a server as configured when haproxy starts. Note that a zero
10010 weight is reported on the stats page as "DRAIN" since it has the same
10011 effect on the server (it's removed from the LB farm).
Simon Hormand60d6912013-11-25 10:46:36 +090010012
Willy Tarreau81f5d942013-12-09 20:51:51 +010010013 - The word "ready". This will turn the server's administrative state to the
10014 READY mode, thus cancelling any DRAIN or MAINT state
Simon Hormand60d6912013-11-25 10:46:36 +090010015
Willy Tarreau81f5d942013-12-09 20:51:51 +010010016 - The word "drain". This will turn the server's administrative state to the
10017 DRAIN mode, thus it will not accept any new connections other than those
10018 that are accepted via persistence.
Simon Hormand60d6912013-11-25 10:46:36 +090010019
Willy Tarreau81f5d942013-12-09 20:51:51 +010010020 - The word "maint". This will turn the server's administrative state to the
10021 MAINT mode, thus it will not accept any new connections at all, and health
10022 checks will be stopped.
Simon Hormand60d6912013-11-25 10:46:36 +090010023
Willy Tarreau81f5d942013-12-09 20:51:51 +010010024 - The words "down", "failed", or "stopped", optionally followed by a
10025 description string after a sharp ('#'). All of these mark the server's
10026 operating state as DOWN, but since the word itself is reported on the stats
10027 page, the difference allows an administrator to know if the situation was
10028 expected or not : the service may intentionally be stopped, may appear up
10029 but fail some validity tests, or may be seen as down (eg: missing process,
10030 or port not responding).
Simon Hormand60d6912013-11-25 10:46:36 +090010031
Willy Tarreau81f5d942013-12-09 20:51:51 +010010032 - The word "up" sets back the server's operating state as UP if health checks
10033 also report that the service is accessible.
Simon Hormand60d6912013-11-25 10:46:36 +090010034
Willy Tarreau81f5d942013-12-09 20:51:51 +010010035 Parameters which are not advertised by the agent are not changed. For
10036 example, an agent might be designed to monitor CPU usage and only report a
10037 relative weight and never interact with the operating status. Similarly, an
10038 agent could be designed as an end-user interface with 3 radio buttons
10039 allowing an administrator to change only the administrative state. However,
10040 it is important to consider that only the agent may revert its own actions,
10041 so if a server is set to DRAIN mode or to DOWN state using the agent, the
10042 agent must implement the other equivalent actions to bring the service into
10043 operations again.
Simon Hormand60d6912013-11-25 10:46:36 +090010044
Simon Horman2f1f9552013-11-25 10:46:37 +090010045 Failure to connect to the agent is not considered an error as connectivity
10046 is tested by the regular health check which is enabled by the "check"
Willy Tarreau81f5d942013-12-09 20:51:51 +010010047 parameter. Warning though, it is not a good idea to stop an agent after it
10048 reports "down", since only an agent reporting "up" will be able to turn the
10049 server up again. Note that the CLI on the Unix stats socket is also able to
10050 force an agent's result in order to workaround a bogus agent if needed.
Simon Horman2f1f9552013-11-25 10:46:37 +090010051
Willy Tarreau81f5d942013-12-09 20:51:51 +010010052 Requires the "agent-port" parameter to be set. See also the "agent-inter"
10053 parameter.
Simon Hormand60d6912013-11-25 10:46:36 +090010054
10055 Supported in default-server: No
10056
10057agent-inter <delay>
10058 The "agent-inter" parameter sets the interval between two agent checks
10059 to <delay> milliseconds. If left unspecified, the delay defaults to 2000 ms.
10060
10061 Just as with every other time-based parameter, it may be entered in any
10062 other explicit unit among { us, ms, s, m, h, d }. The "agent-inter"
10063 parameter also serves as a timeout for agent checks "timeout check" is
10064 not set. In order to reduce "resonance" effects when multiple servers are
10065 hosted on the same hardware, the agent and health checks of all servers
10066 are started with a small time offset between them. It is also possible to
10067 add some random noise in the agent and health checks interval using the
10068 global "spread-checks" keyword. This makes sense for instance when a lot
10069 of backends use the same servers.
10070
10071 See also the "agent-check" and "agent-port" parameters.
10072
10073 Supported in default-server: Yes
10074
10075agent-port <port>
10076 The "agent-port" parameter sets the TCP port used for agent checks.
10077
10078 See also the "agent-check" and "agent-inter" parameters.
10079
10080 Supported in default-server: Yes
10081
Willy Tarreauc57f0e22009-05-10 13:12:33 +020010082backup
10083 When "backup" is present on a server line, the server is only used in load
10084 balancing when all other non-backup servers are unavailable. Requests coming
10085 with a persistence cookie referencing the server will always be served
10086 though. By default, only the first operational backup server is used, unless
10087 the "allbackups" option is set in the backend. See also the "allbackups"
10088 option.
Willy Tarreau6a06a402007-07-15 20:15:28 +020010089
Krzysztof Piotr Oledzkic53601c2010-01-06 10:50:42 +010010090 Supported in default-server: No
10091
Emeric Brunef42d922012-10-11 16:11:36 +020010092ca-file <cafile>
10093 This setting is only available when support for OpenSSL was built in. It
10094 designates a PEM file from which to load CA certificates used to verify
10095 server's certificate.
10096
10097 Supported in default-server: No
10098
Willy Tarreauc57f0e22009-05-10 13:12:33 +020010099check
10100 This option enables health checks on the server. By default, a server is
Patrick Mézardb7aeec62012-01-22 16:01:22 +010010101 always considered available. If "check" is set, the server is available when
10102 accepting periodic TCP connections, to ensure that it is really able to serve
10103 requests. The default address and port to send the tests to are those of the
10104 server, and the default source is the same as the one defined in the
10105 backend. It is possible to change the address using the "addr" parameter, the
10106 port using the "port" parameter, the source address using the "source"
10107 address, and the interval and timers using the "inter", "rise" and "fall"
Simon Hormanafc47ee2013-11-25 10:46:35 +090010108 parameters. The request method is define in the backend using the "httpchk",
10109 "smtpchk", "mysql-check", "pgsql-check" and "ssl-hello-chk" options. Please
10110 refer to those options and parameters for more information.
Willy Tarreauc57f0e22009-05-10 13:12:33 +020010111
Krzysztof Piotr Oledzkic53601c2010-01-06 10:50:42 +010010112 Supported in default-server: No
10113
Willy Tarreau6c16adc2012-10-05 00:04:16 +020010114check-send-proxy
10115 This option forces emission of a PROXY protocol line with outgoing health
10116 checks, regardless of whether the server uses send-proxy or not for the
10117 normal traffic. By default, the PROXY protocol is enabled for health checks
10118 if it is already enabled for normal traffic and if no "port" nor "addr"
10119 directive is present. However, if such a directive is present, the
10120 "check-send-proxy" option needs to be used to force the use of the
10121 protocol. See also the "send-proxy" option for more information.
10122
10123 Supported in default-server: No
10124
Willy Tarreau763a95b2012-10-04 23:15:39 +020010125check-ssl
10126 This option forces encryption of all health checks over SSL, regardless of
10127 whether the server uses SSL or not for the normal traffic. This is generally
10128 used when an explicit "port" or "addr" directive is specified and SSL health
10129 checks are not inherited. It is important to understand that this option
Jarno Huuskonen0e82b922014-04-12 18:22:19 +030010130 inserts an SSL transport layer below the checks, so that a simple TCP connect
Willy Tarreau763a95b2012-10-04 23:15:39 +020010131 check becomes an SSL connect, which replaces the old ssl-hello-chk. The most
10132 common use is to send HTTPS checks by combining "httpchk" with SSL checks.
10133 All SSL settings are common to health checks and traffic (eg: ciphers).
10134 See the "ssl" option for more information.
10135
10136 Supported in default-server: No
10137
Willy Tarreaua0ee1d02012-09-10 09:01:23 +020010138ciphers <ciphers>
10139 This option sets the string describing the list of cipher algorithms that is
Jarno Huuskonen0e82b922014-04-12 18:22:19 +030010140 is negotiated during the SSL/TLS handshake with the server. The format of the
Willy Tarreaua0ee1d02012-09-10 09:01:23 +020010141 string is defined in "man 1 ciphers". When SSL is used to communicate with
10142 servers on the local network, it is common to see a weaker set of algorithms
10143 than what is used over the internet. Doing so reduces CPU usage on both the
10144 server and haproxy while still keeping it compatible with deployed software.
10145 Some algorithms such as RC4-SHA1 are reasonably cheap. If no security at all
10146 is needed and just connectivity, using DES can be appropriate.
10147
Willy Tarreau763a95b2012-10-04 23:15:39 +020010148 Supported in default-server: No
10149
Willy Tarreauc57f0e22009-05-10 13:12:33 +020010150cookie <value>
10151 The "cookie" parameter sets the cookie value assigned to the server to
10152 <value>. This value will be checked in incoming requests, and the first
10153 operational server possessing the same value will be selected. In return, in
10154 cookie insertion or rewrite modes, this value will be assigned to the cookie
10155 sent to the client. There is nothing wrong in having several servers sharing
10156 the same cookie value, and it is in fact somewhat common between normal and
10157 backup servers. See also the "cookie" keyword in backend section.
10158
Krzysztof Piotr Oledzkic53601c2010-01-06 10:50:42 +010010159 Supported in default-server: No
10160
Emeric Brunef42d922012-10-11 16:11:36 +020010161crl-file <crlfile>
10162 This setting is only available when support for OpenSSL was built in. It
10163 designates a PEM file from which to load certificate revocation list used
10164 to verify server's certificate.
10165
10166 Supported in default-server: No
10167
Emeric Bruna7aa3092012-10-26 12:58:00 +020010168crt <cert>
10169 This setting is only available when support for OpenSSL was built in.
10170 It designates a PEM file from which to load both a certificate and the
10171 associated private key. This file can be built by concatenating both PEM
10172 files into one. This certificate will be sent if the server send a client
10173 certificate request.
10174
10175 Supported in default-server: No
10176
Willy Tarreau96839092010-03-29 10:02:24 +020010177disabled
10178 The "disabled" keyword starts the server in the "disabled" state. That means
10179 that it is marked down in maintenance mode, and no connection other than the
10180 ones allowed by persist mode will reach it. It is very well suited to setup
10181 new servers, because normal traffic will never reach them, while it is still
10182 possible to test the service by making use of the force-persist mechanism.
10183
10184 Supported in default-server: No
10185
Krzysztof Piotr Oledzkic53601c2010-01-06 10:50:42 +010010186error-limit <count>
Willy Tarreau983e01e2010-01-11 18:42:06 +010010187 If health observing is enabled, the "error-limit" parameter specifies the
10188 number of consecutive errors that triggers event selected by the "on-error"
10189 option. By default it is set to 10 consecutive errors.
Krzysztof Piotr Oledzki97f07b82009-12-15 22:31:24 +010010190
Krzysztof Piotr Oledzkic53601c2010-01-06 10:50:42 +010010191 Supported in default-server: Yes
10192
10193 See also the "check", "error-limit" and "on-error".
Krzysztof Piotr Oledzki97f07b82009-12-15 22:31:24 +010010194
Krzysztof Piotr Oledzkic53601c2010-01-06 10:50:42 +010010195fall <count>
Willy Tarreauc57f0e22009-05-10 13:12:33 +020010196 The "fall" parameter states that a server will be considered as dead after
10197 <count> consecutive unsuccessful health checks. This value defaults to 3 if
10198 unspecified. See also the "check", "inter" and "rise" parameters.
10199
Krzysztof Piotr Oledzkic53601c2010-01-06 10:50:42 +010010200 Supported in default-server: Yes
10201
Emeric Brun8694b9a2012-10-05 14:39:07 +020010202force-sslv3
10203 This option enforces use of SSLv3 only when SSL is used to communicate with
10204 the server. SSLv3 is generally less expensive than the TLS counterparts for
Emeric Brun2c86cbf2014-10-30 15:56:50 +010010205 high connection rates. This option is also available on global statement
10206 "ssl-default-server-options". See also "no-tlsv*", "no-sslv3".
Emeric Brun8694b9a2012-10-05 14:39:07 +020010207
10208 Supported in default-server: No
10209
10210force-tlsv10
10211 This option enforces use of TLSv1.0 only when SSL is used to communicate with
Emeric Brun2c86cbf2014-10-30 15:56:50 +010010212 the server. This option is also available on global statement
10213 "ssl-default-server-options". See also "no-tlsv*", "no-sslv3".
Emeric Brun8694b9a2012-10-05 14:39:07 +020010214
10215 Supported in default-server: No
10216
10217force-tlsv11
10218 This option enforces use of TLSv1.1 only when SSL is used to communicate with
Emeric Brun2c86cbf2014-10-30 15:56:50 +010010219 the server. This option is also available on global statement
10220 "ssl-default-server-options". See also "no-tlsv*", "no-sslv3".
Emeric Brun8694b9a2012-10-05 14:39:07 +020010221
10222 Supported in default-server: No
10223
10224force-tlsv12
10225 This option enforces use of TLSv1.2 only when SSL is used to communicate with
Emeric Brun2c86cbf2014-10-30 15:56:50 +010010226 the server. This option is also available on global statement
10227 "ssl-default-server-options". See also "no-tlsv*", "no-sslv3".
Emeric Brun8694b9a2012-10-05 14:39:07 +020010228
10229 Supported in default-server: No
10230
Willy Tarreauc57f0e22009-05-10 13:12:33 +020010231id <value>
Willy Tarreau53fb4ae2009-10-04 23:04:08 +020010232 Set a persistent ID for the server. This ID must be positive and unique for
10233 the proxy. An unused ID will automatically be assigned if unset. The first
10234 assigned value will be 1. This ID is currently only returned in statistics.
Willy Tarreauc57f0e22009-05-10 13:12:33 +020010235
Krzysztof Piotr Oledzkic53601c2010-01-06 10:50:42 +010010236 Supported in default-server: No
10237
10238inter <delay>
10239fastinter <delay>
10240downinter <delay>
Willy Tarreauc57f0e22009-05-10 13:12:33 +020010241 The "inter" parameter sets the interval between two consecutive health checks
10242 to <delay> milliseconds. If left unspecified, the delay defaults to 2000 ms.
10243 It is also possible to use "fastinter" and "downinter" to optimize delays
10244 between checks depending on the server state :
10245
Pieter Baauw44fc9df2015-09-17 21:30:46 +020010246 Server state | Interval used
10247 ----------------------------------------+----------------------------------
10248 UP 100% (non-transitional) | "inter"
10249 ----------------------------------------+----------------------------------
10250 Transitionally UP (going down "fall"), | "fastinter" if set,
10251 Transitionally DOWN (going up "rise"), | "inter" otherwise.
10252 or yet unchecked. |
10253 ----------------------------------------+----------------------------------
10254 DOWN 100% (non-transitional) | "downinter" if set,
10255 | "inter" otherwise.
10256 ----------------------------------------+----------------------------------
Willy Tarreaud72758d2010-01-12 10:42:19 +010010257
Willy Tarreauc57f0e22009-05-10 13:12:33 +020010258 Just as with every other time-based parameter, they can be entered in any
10259 other explicit unit among { us, ms, s, m, h, d }. The "inter" parameter also
10260 serves as a timeout for health checks sent to servers if "timeout check" is
10261 not set. In order to reduce "resonance" effects when multiple servers are
Simon Hormand60d6912013-11-25 10:46:36 +090010262 hosted on the same hardware, the agent and health checks of all servers
10263 are started with a small time offset between them. It is also possible to
10264 add some random noise in the agent and health checks interval using the
10265 global "spread-checks" keyword. This makes sense for instance when a lot
10266 of backends use the same servers.
Willy Tarreauc57f0e22009-05-10 13:12:33 +020010267
Krzysztof Piotr Oledzkic53601c2010-01-06 10:50:42 +010010268 Supported in default-server: Yes
10269
10270maxconn <maxconn>
Willy Tarreauc57f0e22009-05-10 13:12:33 +020010271 The "maxconn" parameter specifies the maximal number of concurrent
10272 connections that will be sent to this server. If the number of incoming
10273 concurrent requests goes higher than this value, they will be queued, waiting
10274 for a connection to be released. This parameter is very important as it can
10275 save fragile servers from going down under extreme loads. If a "minconn"
10276 parameter is specified, the limit becomes dynamic. The default value is "0"
10277 which means unlimited. See also the "minconn" and "maxqueue" parameters, and
10278 the backend's "fullconn" keyword.
10279
Krzysztof Piotr Oledzkic53601c2010-01-06 10:50:42 +010010280 Supported in default-server: Yes
10281
10282maxqueue <maxqueue>
Willy Tarreauc57f0e22009-05-10 13:12:33 +020010283 The "maxqueue" parameter specifies the maximal number of connections which
10284 will wait in the queue for this server. If this limit is reached, next
10285 requests will be redispatched to other servers instead of indefinitely
10286 waiting to be served. This will break persistence but may allow people to
10287 quickly re-log in when the server they try to connect to is dying. The
10288 default value is "0" which means the queue is unlimited. See also the
10289 "maxconn" and "minconn" parameters.
10290
Krzysztof Piotr Oledzkic53601c2010-01-06 10:50:42 +010010291 Supported in default-server: Yes
10292
10293minconn <minconn>
Willy Tarreauc57f0e22009-05-10 13:12:33 +020010294 When the "minconn" parameter is set, the maxconn limit becomes a dynamic
10295 limit following the backend's load. The server will always accept at least
10296 <minconn> connections, never more than <maxconn>, and the limit will be on
10297 the ramp between both values when the backend has less than <fullconn>
10298 concurrent connections. This makes it possible to limit the load on the
10299 server during normal loads, but push it further for important loads without
Krzysztof Piotr Oledzkif8645332009-12-13 21:55:50 +010010300 overloading the server during exceptional loads. See also the "maxconn"
Willy Tarreauc57f0e22009-05-10 13:12:33 +020010301 and "maxqueue" parameters, as well as the "fullconn" backend keyword.
Krzysztof Piotr Oledzki97f07b82009-12-15 22:31:24 +010010302
Krzysztof Piotr Oledzkic53601c2010-01-06 10:50:42 +010010303 Supported in default-server: Yes
10304
Willy Tarreau2a3fb1c2015-02-05 16:47:07 +010010305no-ssl-reuse
10306 This option disables SSL session reuse when SSL is used to communicate with
10307 the server. It will force the server to perform a full handshake for every
10308 new connection. It's probably only useful for benchmarking, troubleshooting,
10309 and for paranoid users.
10310
10311 Supported in default-server: No
10312
Emeric Brun9b3009b2012-10-05 11:55:06 +020010313no-sslv3
Willy Tarreaua0ee1d02012-09-10 09:01:23 +020010314 This option disables support for SSLv3 when SSL is used to communicate with
10315 the server. Note that SSLv2 is disabled in the code and cannot be enabled
Emeric Brun8694b9a2012-10-05 14:39:07 +020010316 using any configuration option. See also "force-sslv3", "force-tlsv*".
Willy Tarreaua0ee1d02012-09-10 09:01:23 +020010317
Willy Tarreau763a95b2012-10-04 23:15:39 +020010318 Supported in default-server: No
10319
Emeric Brunf9c5c472012-10-11 15:28:34 +020010320no-tls-tickets
10321 This setting is only available when support for OpenSSL was built in. It
10322 disables the stateless session resumption (RFC 5077 TLS Ticket
10323 extension) and force to use stateful session resumption. Stateless
Emeric Brun2c86cbf2014-10-30 15:56:50 +010010324 session resumption is more expensive in CPU usage for servers. This option
10325 is also available on global statement "ssl-default-server-options".
Emeric Brunf9c5c472012-10-11 15:28:34 +020010326
10327 Supported in default-server: No
10328
Emeric Brun9b3009b2012-10-05 11:55:06 +020010329no-tlsv10
Emeric Brun8694b9a2012-10-05 14:39:07 +020010330 This option disables support for TLSv1.0 when SSL is used to communicate with
Emeric Brunf5da4932012-09-28 19:42:54 +020010331 the server. Note that SSLv2 is disabled in the code and cannot be enabled
10332 using any configuration option. TLSv1 is more expensive than SSLv3 so it
Emeric Brun2c86cbf2014-10-30 15:56:50 +010010333 often makes sense to disable it when communicating with local servers. This
10334 option is also available on global statement "ssl-default-server-options".
10335 See also "force-sslv3", "force-tlsv*".
Emeric Brunf5da4932012-09-28 19:42:54 +020010336
Willy Tarreau763a95b2012-10-04 23:15:39 +020010337 Supported in default-server: No
10338
Emeric Brun9b3009b2012-10-05 11:55:06 +020010339no-tlsv11
Emeric Brun8694b9a2012-10-05 14:39:07 +020010340 This option disables support for TLSv1.1 when SSL is used to communicate with
Emeric Brunf5da4932012-09-28 19:42:54 +020010341 the server. Note that SSLv2 is disabled in the code and cannot be enabled
10342 using any configuration option. TLSv1 is more expensive than SSLv3 so it
Emeric Brun2c86cbf2014-10-30 15:56:50 +010010343 often makes sense to disable it when communicating with local servers. This
10344 option is also available on global statement "ssl-default-server-options".
10345 See also "force-sslv3", "force-tlsv*".
Emeric Brunf5da4932012-09-28 19:42:54 +020010346
Willy Tarreau763a95b2012-10-04 23:15:39 +020010347 Supported in default-server: No
10348
Emeric Brun9b3009b2012-10-05 11:55:06 +020010349no-tlsv12
Emeric Brun8694b9a2012-10-05 14:39:07 +020010350 This option disables support for TLSv1.2 when SSL is used to communicate with
Willy Tarreaua0ee1d02012-09-10 09:01:23 +020010351 the server. Note that SSLv2 is disabled in the code and cannot be enabled
10352 using any configuration option. TLSv1 is more expensive than SSLv3 so it
Emeric Brun2c86cbf2014-10-30 15:56:50 +010010353 often makes sense to disable it when communicating with local servers. This
10354 option is also available on global statement "ssl-default-server-options".
10355 See also "force-sslv3", "force-tlsv*".
Willy Tarreaua0ee1d02012-09-10 09:01:23 +020010356
Willy Tarreau763a95b2012-10-04 23:15:39 +020010357 Supported in default-server: No
10358
Simon Hormanfa461682011-06-25 09:39:49 +090010359non-stick
10360 Never add connections allocated to this sever to a stick-table.
10361 This may be used in conjunction with backup to ensure that
10362 stick-table persistence is disabled for backup servers.
10363
Willy Tarreau763a95b2012-10-04 23:15:39 +020010364 Supported in default-server: No
10365
Krzysztof Piotr Oledzki97f07b82009-12-15 22:31:24 +010010366observe <mode>
10367 This option enables health adjusting based on observing communication with
10368 the server. By default this functionality is disabled and enabling it also
10369 requires to enable health checks. There are two supported modes: "layer4" and
10370 "layer7". In layer4 mode, only successful/unsuccessful tcp connections are
10371 significant. In layer7, which is only allowed for http proxies, responses
10372 received from server are verified, like valid/wrong http code, unparsable
Willy Tarreau150d1462012-03-10 08:19:02 +010010373 headers, a timeout, etc. Valid status codes include 100 to 499, 501 and 505.
Krzysztof Piotr Oledzki97f07b82009-12-15 22:31:24 +010010374
Krzysztof Piotr Oledzkic53601c2010-01-06 10:50:42 +010010375 Supported in default-server: No
10376
Krzysztof Piotr Oledzki97f07b82009-12-15 22:31:24 +010010377 See also the "check", "on-error" and "error-limit".
10378
Krzysztof Piotr Oledzkic53601c2010-01-06 10:50:42 +010010379on-error <mode>
Krzysztof Piotr Oledzki97f07b82009-12-15 22:31:24 +010010380 Select what should happen when enough consecutive errors are detected.
10381 Currently, four modes are available:
10382 - fastinter: force fastinter
10383 - fail-check: simulate a failed check, also forces fastinter (default)
10384 - sudden-death: simulate a pre-fatal failed health check, one more failed
10385 check will mark a server down, forces fastinter
10386 - mark-down: mark the server immediately down and force fastinter
10387
Krzysztof Piotr Oledzkic53601c2010-01-06 10:50:42 +010010388 Supported in default-server: Yes
10389
Krzysztof Piotr Oledzki97f07b82009-12-15 22:31:24 +010010390 See also the "check", "observe" and "error-limit".
10391
Simon Hormane0d1bfb2011-06-21 14:34:58 +090010392on-marked-down <action>
10393 Modify what occurs when a server is marked down.
10394 Currently one action is available:
Justin Karnegeseb2c24a2012-05-24 15:28:52 -070010395 - shutdown-sessions: Shutdown peer sessions. When this setting is enabled,
10396 all connections to the server are immediately terminated when the server
10397 goes down. It might be used if the health check detects more complex cases
10398 than a simple connection status, and long timeouts would cause the service
10399 to remain unresponsive for too long a time. For instance, a health check
10400 might detect that a database is stuck and that there's no chance to reuse
10401 existing connections anymore. Connections killed this way are logged with
10402 a 'D' termination code (for "Down").
Simon Hormane0d1bfb2011-06-21 14:34:58 +090010403
10404 Actions are disabled by default
10405
10406 Supported in default-server: Yes
10407
Justin Karnegeseb2c24a2012-05-24 15:28:52 -070010408on-marked-up <action>
10409 Modify what occurs when a server is marked up.
10410 Currently one action is available:
10411 - shutdown-backup-sessions: Shutdown sessions on all backup servers. This is
10412 done only if the server is not in backup state and if it is not disabled
10413 (it must have an effective weight > 0). This can be used sometimes to force
10414 an active server to take all the traffic back after recovery when dealing
10415 with long sessions (eg: LDAP, SQL, ...). Doing this can cause more trouble
10416 than it tries to solve (eg: incomplete transactions), so use this feature
10417 with extreme care. Sessions killed because a server comes up are logged
10418 with an 'U' termination code (for "Up").
10419
10420 Actions are disabled by default
10421
10422 Supported in default-server: Yes
10423
Krzysztof Piotr Oledzkic53601c2010-01-06 10:50:42 +010010424port <port>
Willy Tarreauc57f0e22009-05-10 13:12:33 +020010425 Using the "port" parameter, it becomes possible to use a different port to
10426 send health-checks. On some servers, it may be desirable to dedicate a port
10427 to a specific component able to perform complex tests which are more suitable
10428 to health-checks than the application. It is common to run a simple script in
10429 inetd for instance. This parameter is ignored if the "check" parameter is not
10430 set. See also the "addr" parameter.
10431
Krzysztof Piotr Oledzkic53601c2010-01-06 10:50:42 +010010432 Supported in default-server: Yes
10433
Willy Tarreauc57f0e22009-05-10 13:12:33 +020010434redir <prefix>
10435 The "redir" parameter enables the redirection mode for all GET and HEAD
10436 requests addressing this server. This means that instead of having HAProxy
10437 forward the request to the server, it will send an "HTTP 302" response with
10438 the "Location" header composed of this prefix immediately followed by the
10439 requested URI beginning at the leading '/' of the path component. That means
10440 that no trailing slash should be used after <prefix>. All invalid requests
10441 will be rejected, and all non-GET or HEAD requests will be normally served by
10442 the server. Note that since the response is completely forged, no header
Krzysztof Piotr Oledzkif8645332009-12-13 21:55:50 +010010443 mangling nor cookie insertion is possible in the response. However, cookies in
Willy Tarreauc57f0e22009-05-10 13:12:33 +020010444 requests are still analysed, making this solution completely usable to direct
10445 users to a remote location in case of local disaster. Main use consists in
10446 increasing bandwidth for static servers by having the clients directly
10447 connect to them. Note: never use a relative location here, it would cause a
10448 loop between the client and HAProxy!
10449
10450 Example : server srv1 192.168.1.1:80 redir http://image1.mydomain.com check
10451
Krzysztof Piotr Oledzkic53601c2010-01-06 10:50:42 +010010452 Supported in default-server: No
10453
10454rise <count>
Willy Tarreauc57f0e22009-05-10 13:12:33 +020010455 The "rise" parameter states that a server will be considered as operational
10456 after <count> consecutive successful health checks. This value defaults to 2
10457 if unspecified. See also the "check", "inter" and "fall" parameters.
10458
Krzysztof Piotr Oledzkic53601c2010-01-06 10:50:42 +010010459 Supported in default-server: Yes
10460
Baptiste Assmann1fa66662015-04-14 00:28:47 +020010461resolve-prefer <family>
10462 When DNS resolution is enabled for a server and multiple IP addresses from
10463 different families are returned, HAProxy will prefer using an IP address
10464 from the family mentioned in the "resolve-prefer" parameter.
10465 Available families: "ipv4" and "ipv6"
10466
Baptiste Assmannc4aabae2015-08-04 22:43:06 +020010467 Default value: ipv6
10468
10469 Supported in default-server: Yes
Baptiste Assmann1fa66662015-04-14 00:28:47 +020010470
10471 Example: server s1 app1.domain.com:80 resolvers mydns resolve-prefer ipv6
10472
10473resolvers <id>
10474 Points to an existing "resolvers" section to resolve current server's
10475 hostname.
Baptiste Assmann62b75b42015-09-09 01:11:36 +020010476 In order to be operational, DNS resolution requires that health check is
10477 enabled on the server. Actually, health checks triggers the DNS resolution.
10478 You must precise one 'resolvers' parameter on each server line where DNS
10479 resolution is required.
Baptiste Assmann1fa66662015-04-14 00:28:47 +020010480
Baptiste Assmann62b75b42015-09-09 01:11:36 +020010481 Supported in default-server: No
10482
10483 Example: server s1 app1.domain.com:80 check resolvers mydns
Baptiste Assmann1fa66662015-04-14 00:28:47 +020010484
10485 See also chapter 5.3
10486
Willy Tarreau5ab04ec2011-03-20 10:32:26 +010010487send-proxy
10488 The "send-proxy" parameter enforces use of the PROXY protocol over any
10489 connection established to this server. The PROXY protocol informs the other
10490 end about the layer 3/4 addresses of the incoming connection, so that it can
10491 know the client's address or the public address it accessed to, whatever the
10492 upper layer protocol. For connections accepted by an "accept-proxy" listener,
10493 the advertised address will be used. Only TCPv4 and TCPv6 address families
10494 are supported. Other families such as Unix sockets, will report an UNKNOWN
10495 family. Servers using this option can fully be chained to another instance of
10496 haproxy listening with an "accept-proxy" setting. This setting must not be
Willy Tarreau6c16adc2012-10-05 00:04:16 +020010497 used if the server isn't aware of the protocol. When health checks are sent
10498 to the server, the PROXY protocol is automatically used when this option is
10499 set, unless there is an explicit "port" or "addr" directive, in which case an
10500 explicit "check-send-proxy" directive would also be needed to use the PROXY
10501 protocol. See also the "accept-proxy" option of the "bind" keyword.
Willy Tarreau5ab04ec2011-03-20 10:32:26 +010010502
10503 Supported in default-server: No
10504
David Safb76832014-05-08 23:42:08 -040010505send-proxy-v2
10506 The "send-proxy-v2" parameter enforces use of the PROXY protocol version 2
10507 over any connection established to this server. The PROXY protocol informs
10508 the other end about the layer 3/4 addresses of the incoming connection, so
10509 that it can know the client's address or the public address it accessed to,
10510 whatever the upper layer protocol. This setting must not be used if the
10511 server isn't aware of this version of the protocol. See also the "send-proxy"
10512 option of the "bind" keyword.
10513
10514 Supported in default-server: No
10515
10516send-proxy-v2-ssl
10517 The "send-proxy-v2-ssl" parameter enforces use of the PROXY protocol version
10518 2 over any connection established to this server. The PROXY protocol informs
10519 the other end about the layer 3/4 addresses of the incoming connection, so
10520 that it can know the client's address or the public address it accessed to,
10521 whatever the upper layer protocol. In addition, the SSL information extension
10522 of the PROXY protocol is added to the PROXY protocol header. This setting
10523 must not be used if the server isn't aware of this version of the protocol.
10524 See also the "send-proxy-v2" option of the "bind" keyword.
10525
10526 Supported in default-server: No
10527
10528send-proxy-v2-ssl-cn
10529 The "send-proxy-v2-ssl" parameter enforces use of the PROXY protocol version
10530 2 over any connection established to this server. The PROXY protocol informs
10531 the other end about the layer 3/4 addresses of the incoming connection, so
10532 that it can know the client's address or the public address it accessed to,
10533 whatever the upper layer protocol. In addition, the SSL information extension
10534 of the PROXY protocol, along along with the Common Name from the subject of
10535 the client certificate (if any), is added to the PROXY protocol header. This
10536 setting must not be used if the server isn't aware of this version of the
10537 protocol. See also the "send-proxy-v2" option of the "bind" keyword.
10538
10539 Supported in default-server: No
10540
Krzysztof Piotr Oledzkic53601c2010-01-06 10:50:42 +010010541slowstart <start_time_in_ms>
Willy Tarreauc57f0e22009-05-10 13:12:33 +020010542 The "slowstart" parameter for a server accepts a value in milliseconds which
10543 indicates after how long a server which has just come back up will run at
10544 full speed. Just as with every other time-based parameter, it can be entered
10545 in any other explicit unit among { us, ms, s, m, h, d }. The speed grows
10546 linearly from 0 to 100% during this time. The limitation applies to two
10547 parameters :
10548
10549 - maxconn: the number of connections accepted by the server will grow from 1
10550 to 100% of the usual dynamic limit defined by (minconn,maxconn,fullconn).
10551
10552 - weight: when the backend uses a dynamic weighted algorithm, the weight
10553 grows linearly from 1 to 100%. In this case, the weight is updated at every
10554 health-check. For this reason, it is important that the "inter" parameter
10555 is smaller than the "slowstart", in order to maximize the number of steps.
10556
10557 The slowstart never applies when haproxy starts, otherwise it would cause
10558 trouble to running servers. It only applies when a server has been previously
10559 seen as failed.
10560
Krzysztof Piotr Oledzkic53601c2010-01-06 10:50:42 +010010561 Supported in default-server: Yes
10562
Willy Tarreau732eac42015-07-09 11:40:25 +020010563sni <expression>
10564 The "sni" parameter evaluates the sample fetch expression, converts it to a
10565 string and uses the result as the host name sent in the SNI TLS extension to
10566 the server. A typical use case is to send the SNI received from the client in
10567 a bridged HTTPS scenario, using the "ssl_fc_sni" sample fetch for the
10568 expression, though alternatives such as req.hdr(host) can also make sense.
10569
10570 Supported in default-server: no
10571
Willy Tarreauc6f4ce82009-06-10 11:09:37 +020010572source <addr>[:<pl>[-<ph>]] [usesrc { <addr2>[:<port2>] | client | clientip } ]
Willy Tarreaubce70882009-09-07 11:51:47 +020010573source <addr>[:<port>] [usesrc { <addr2>[:<port2>] | hdr_ip(<hdr>[,<occ>]) } ]
Willy Tarreauc6f4ce82009-06-10 11:09:37 +020010574source <addr>[:<pl>[-<ph>]] [interface <name>] ...
Willy Tarreauc57f0e22009-05-10 13:12:33 +020010575 The "source" parameter sets the source address which will be used when
10576 connecting to the server. It follows the exact same parameters and principle
10577 as the backend "source" keyword, except that it only applies to the server
10578 referencing it. Please consult the "source" keyword for details.
10579
Willy Tarreauc6f4ce82009-06-10 11:09:37 +020010580 Additionally, the "source" statement on a server line allows one to specify a
10581 source port range by indicating the lower and higher bounds delimited by a
10582 dash ('-'). Some operating systems might require a valid IP address when a
10583 source port range is specified. It is permitted to have the same IP/range for
10584 several servers. Doing so makes it possible to bypass the maximum of 64k
10585 total concurrent connections. The limit will then reach 64k connections per
10586 server.
10587
Krzysztof Piotr Oledzkic53601c2010-01-06 10:50:42 +010010588 Supported in default-server: No
10589
Willy Tarreaua0ee1d02012-09-10 09:01:23 +020010590ssl
Willy Tarreau44f65392013-06-25 07:56:20 +020010591 This option enables SSL ciphering on outgoing connections to the server. It
10592 is critical to verify server certificates using "verify" when using SSL to
10593 connect to servers, otherwise the communication is prone to trivial man in
10594 the-middle attacks rendering SSL useless. When this option is used, health
10595 checks are automatically sent in SSL too unless there is a "port" or an
10596 "addr" directive indicating the check should be sent to a different location.
Jarno Huuskonen0e82b922014-04-12 18:22:19 +030010597 See the "check-ssl" option to force SSL health checks.
Willy Tarreau763a95b2012-10-04 23:15:39 +020010598
10599 Supported in default-server: No
Willy Tarreaua0ee1d02012-09-10 09:01:23 +020010600
Willy Tarreauc57f0e22009-05-10 13:12:33 +020010601track [<proxy>/]<server>
Willy Tarreau32091232014-05-16 13:52:00 +020010602 This option enables ability to set the current state of the server by tracking
10603 another one. It is possible to track a server which itself tracks another
10604 server, provided that at the end of the chain, a server has health checks
10605 enabled. If <proxy> is omitted the current one is used. If disable-on-404 is
Willy Tarreauc57f0e22009-05-10 13:12:33 +020010606 used, it has to be enabled on both proxies.
10607
Krzysztof Piotr Oledzkic53601c2010-01-06 10:50:42 +010010608 Supported in default-server: No
10609
Emeric Brunef42d922012-10-11 16:11:36 +020010610verify [none|required]
10611 This setting is only available when support for OpenSSL was built in. If set
Emeric Brun850efd52014-01-29 12:24:34 +010010612 to 'none', server certificate is not verified. In the other case, The
10613 certificate provided by the server is verified using CAs from 'ca-file'
10614 and optional CRLs from 'crl-file'. If 'ssl_server_verify' is not specified
10615 in global section, this is the default. On verify failure the handshake
Willy Tarreau44f65392013-06-25 07:56:20 +020010616 is aborted. It is critically important to verify server certificates when
10617 using SSL to connect to servers, otherwise the communication is prone to
10618 trivial man-in-the-middle attacks rendering SSL totally useless.
Emeric Brunef42d922012-10-11 16:11:36 +020010619
10620 Supported in default-server: No
10621
Evan Broderbe554312013-06-27 00:05:25 -070010622verifyhost <hostname>
10623 This setting is only available when support for OpenSSL was built in, and
10624 only takes effect if 'verify required' is also specified. When set, the
10625 hostnames in the subject and subjectAlternateNames of the certificate
10626 provided by the server are checked. If none of the hostnames in the
10627 certificate match the specified hostname, the handshake is aborted. The
10628 hostnames in the server-provided certificate may include wildcards.
10629
10630 Supported in default-server: No
10631
Krzysztof Piotr Oledzkic53601c2010-01-06 10:50:42 +010010632weight <weight>
Willy Tarreauc57f0e22009-05-10 13:12:33 +020010633 The "weight" parameter is used to adjust the server's weight relative to
10634 other servers. All servers will receive a load proportional to their weight
10635 relative to the sum of all weights, so the higher the weight, the higher the
Willy Tarreau6704d672009-06-15 10:56:05 +020010636 load. The default weight is 1, and the maximal value is 256. A value of 0
10637 means the server will not participate in load-balancing but will still accept
10638 persistent connections. If this parameter is used to distribute the load
10639 according to server's capacity, it is recommended to start with values which
10640 can both grow and shrink, for instance between 10 and 100 to leave enough
10641 room above and below for later adjustments.
Willy Tarreauc57f0e22009-05-10 13:12:33 +020010642
Krzysztof Piotr Oledzkic53601c2010-01-06 10:50:42 +010010643 Supported in default-server: Yes
10644
Willy Tarreauc57f0e22009-05-10 13:12:33 +020010645
Cyril Bonté46175dd2015-07-02 22:45:32 +0200106465.3. Server IP address resolution using DNS
10647-------------------------------------------
Baptiste Assmann1fa66662015-04-14 00:28:47 +020010648
Baptiste Assmann62b75b42015-09-09 01:11:36 +020010649HAProxy allows using a host name on the server line to retrieve its IP address
10650using name servers. By default, HAProxy resolves the name when parsing the
10651configuration file, at startup and cache the result for the process' life.
Baptiste Assmann1fa66662015-04-14 00:28:47 +020010652This is not sufficient in some cases, such as in Amazon where a server's IP
10653can change after a reboot or an ELB Virtual IP can change based on current
10654workload.
10655This chapter describes how HAProxy can be configured to process server's name
10656resolution at run time.
10657Whether run time server name resolution has been enable or not, HAProxy will
10658carry on doing the first resolution when parsing the configuration.
10659
Baptiste Assmann62b75b42015-09-09 01:11:36 +020010660Bear in mind that DNS resolution is triggered by health checks. This makes
10661health checks mandatory to allow DNS resolution.
10662
Baptiste Assmann1fa66662015-04-14 00:28:47 +020010663
Cyril Bonté46175dd2015-07-02 22:45:32 +0200106645.3.1. Global overview
10665----------------------
Baptiste Assmann1fa66662015-04-14 00:28:47 +020010666
10667As we've seen in introduction, name resolution in HAProxy occurs at two
10668different steps of the process life:
10669
10670 1. when starting up, HAProxy parses the server line definition and matches a
10671 host name. It uses libc functions to get the host name resolved. This
10672 resolution relies on /etc/resolv.conf file.
10673
10674 2. at run time, when HAProxy gets prepared to run a health check on a server,
10675 it verifies if the current name resolution is still considered as valid.
10676 If not, it processes a new resolution, in parallel of the health check.
10677
10678A few other events can trigger a name resolution at run time:
10679 - when a server's health check ends up in a connection timeout: this may be
10680 because the server has a new IP address. So we need to trigger a name
10681 resolution to know this new IP.
10682
10683A few things important to notice:
10684 - all the name servers are queried in the mean time. HAProxy will process the
10685 first valid response.
10686
10687 - a resolution is considered as invalid (NX, timeout, refused), when all the
10688 servers return an error.
10689
10690
Cyril Bonté46175dd2015-07-02 22:45:32 +0200106915.3.2. The resolvers section
10692----------------------------
Baptiste Assmann1fa66662015-04-14 00:28:47 +020010693
10694This section is dedicated to host information related to name resolution in
10695HAProxy.
10696There can be as many as resolvers section as needed. Each section can contain
10697many name servers.
10698
Baptiste Assmann62b75b42015-09-09 01:11:36 +020010699When multiple name servers are configured in a resolvers section, then HAProxy
10700uses the first valid response. In case of invalid responses, only the last one
10701is treated. Purpose is to give the chance to a slow server to deliver a valid
10702answer after a fast faulty or outdated server.
10703
10704When each server returns a different error type, then only the last error is
10705used by HAProxy to decide what type of behavior to apply.
10706
10707Two types of behavior can be applied:
10708 1. stop DNS resolution
10709 2. replay the DNS query with a new query type
10710 In such case, the following types are applied in this exact order:
10711 1. ANY query type
10712 2. query type corresponding to family pointed by resolve-prefer
10713 server's parameter
10714 3. remaining family type
10715
10716HAProxy stops DNS resolution when the following errors occur:
10717 - invalid DNS response packet
10718 - wrong name in the query section of the response
10719 - NX domain
10720 - Query refused by server
10721 - CNAME not pointing to an IP address
10722
10723HAProxy tries a new query type when the following errors occur:
10724 - no Answer records in the response
10725 - DNS response truncated
10726 - Error in DNS response
10727 - No expected DNS records found in the response
10728 - name server timeout
10729
10730For example, with 2 name servers configured in a resolvers section:
10731 - first response is valid and is applied directly, second response is ignored
10732 - first response is invalid and second one is valid, then second response is
10733 applied;
10734 - first response is a NX domain and second one a truncated response, then
10735 HAProxy replays the query with a new type;
10736 - first response is truncated and second one is a NX Domain, then HAProxy
10737 stops resolution.
10738
10739
Baptiste Assmann1fa66662015-04-14 00:28:47 +020010740resolvers <resolvers id>
10741 Creates a new name server list labelled <resolvers id>
10742
10743A resolvers section accept the following parameters:
10744
10745nameserver <id> <ip>:<port>
10746 DNS server description:
10747 <id> : label of the server, should be unique
10748 <ip> : IP address of the server
10749 <port> : port where the DNS service actually runs
10750
10751hold <status> <period>
10752 Defines <period> during which the last name resolution should be kept based
10753 on last resolution <status>
10754 <status> : last name resolution status. Only "valid" is accepted for now.
10755 <period> : interval between two successive name resolution when the last
10756 answer was in <status>. It follows the HAProxy time format.
10757 <period> is in milliseconds by default.
10758
10759 Default value is 10s for "valid".
10760
10761 Note: since the name resolution is triggered by the health checks, a new
10762 resolution is triggered after <period> modulo the <inter> parameter of
10763 the healch check.
10764
10765resolve_retries <nb>
10766 Defines the number <nb> of queries to send to resolve a server name before
10767 giving up.
10768 Default value: 3
10769
Baptiste Assmann62b75b42015-09-09 01:11:36 +020010770 A retry occurs on name server timeout or when the full sequence of DNS query
10771 type failover is over and we need to start up from the default ANY query
10772 type.
10773
Baptiste Assmann1fa66662015-04-14 00:28:47 +020010774timeout <event> <time>
10775 Defines timeouts related to name resolution
10776 <event> : the event on which the <time> timeout period applies to.
10777 events available are:
10778 - retry: time between two DNS queries, when no response have
10779 been received.
10780 Default value: 1s
10781 <time> : time related to the event. It follows the HAProxy time format.
10782 <time> is expressed in milliseconds.
10783
10784Example of a resolvers section (with default values):
10785
10786 resolvers mydns
10787 nameserver dns1 10.0.0.1:53
10788 nameserver dns2 10.0.0.2:53
10789 resolve_retries 3
10790 timeout retry 1s
10791 hold valid 10s
10792
10793
Willy Tarreauc57f0e22009-05-10 13:12:33 +0200107946. HTTP header manipulation
10795---------------------------
10796
10797In HTTP mode, it is possible to rewrite, add or delete some of the request and
10798response headers based on regular expressions. It is also possible to block a
10799request or a response if a particular header matches a regular expression,
10800which is enough to stop most elementary protocol attacks, and to protect
Willy Tarreau70dffda2014-01-30 03:07:23 +010010801against information leak from the internal network.
Willy Tarreauc57f0e22009-05-10 13:12:33 +020010802
Willy Tarreau70dffda2014-01-30 03:07:23 +010010803If HAProxy encounters an "Informational Response" (status code 1xx), it is able
10804to process all rsp* rules which can allow, deny, rewrite or delete a header,
10805but it will refuse to add a header to any such messages as this is not
10806HTTP-compliant. The reason for still processing headers in such responses is to
10807stop and/or fix any possible information leak which may happen, for instance
10808because another downstream equipment would unconditionally add a header, or if
10809a server name appears there. When such messages are seen, normal processing
10810still occurs on the next non-informational messages.
Willy Tarreau816b9792009-09-15 21:25:21 +020010811
Willy Tarreauc57f0e22009-05-10 13:12:33 +020010812This section covers common usage of the following keywords, described in detail
10813in section 4.2 :
10814
10815 - reqadd <string>
10816 - reqallow <search>
10817 - reqiallow <search>
10818 - reqdel <search>
10819 - reqidel <search>
10820 - reqdeny <search>
10821 - reqideny <search>
10822 - reqpass <search>
10823 - reqipass <search>
10824 - reqrep <search> <replace>
10825 - reqirep <search> <replace>
10826 - reqtarpit <search>
10827 - reqitarpit <search>
10828 - rspadd <string>
10829 - rspdel <search>
10830 - rspidel <search>
10831 - rspdeny <search>
10832 - rspideny <search>
10833 - rsprep <search> <replace>
10834 - rspirep <search> <replace>
10835
10836With all these keywords, the same conventions are used. The <search> parameter
10837is a POSIX extended regular expression (regex) which supports grouping through
10838parenthesis (without the backslash). Spaces and other delimiters must be
10839prefixed with a backslash ('\') to avoid confusion with a field delimiter.
10840Other characters may be prefixed with a backslash to change their meaning :
10841
10842 \t for a tab
10843 \r for a carriage return (CR)
10844 \n for a new line (LF)
10845 \ to mark a space and differentiate it from a delimiter
10846 \# to mark a sharp and differentiate it from a comment
10847 \\ to use a backslash in a regex
10848 \\\\ to use a backslash in the text (*2 for regex, *2 for haproxy)
10849 \xXX to write the ASCII hex code XX as in the C language
10850
10851The <replace> parameter contains the string to be used to replace the largest
10852portion of text matching the regex. It can make use of the special characters
10853above, and can reference a substring which is delimited by parenthesis in the
10854regex, by writing a backslash ('\') immediately followed by one digit from 0 to
108559 indicating the group position (0 designating the entire line). This practice
10856is very common to users of the "sed" program.
10857
10858The <string> parameter represents the string which will systematically be added
10859after the last header line. It can also use special character sequences above.
10860
10861Notes related to these keywords :
10862---------------------------------
10863 - these keywords are not always convenient to allow/deny based on header
10864 contents. It is strongly recommended to use ACLs with the "block" keyword
10865 instead, resulting in far more flexible and manageable rules.
10866
10867 - lines are always considered as a whole. It is not possible to reference
10868 a header name only or a value only. This is important because of the way
10869 headers are written (notably the number of spaces after the colon).
10870
10871 - the first line is always considered as a header, which makes it possible to
10872 rewrite or filter HTTP requests URIs or response codes, but in turn makes
10873 it harder to distinguish between headers and request line. The regex prefix
10874 ^[^\ \t]*[\ \t] matches any HTTP method followed by a space, and the prefix
10875 ^[^ \t:]*: matches any header name followed by a colon.
10876
10877 - for performances reasons, the number of characters added to a request or to
10878 a response is limited at build time to values between 1 and 4 kB. This
10879 should normally be far more than enough for most usages. If it is too short
10880 on occasional usages, it is possible to gain some space by removing some
10881 useless headers before adding new ones.
10882
Krzysztof Piotr Oledzkif8645332009-12-13 21:55:50 +010010883 - keywords beginning with "reqi" and "rspi" are the same as their counterpart
Willy Tarreauc57f0e22009-05-10 13:12:33 +020010884 without the 'i' letter except that they ignore case when matching patterns.
10885
10886 - when a request passes through a frontend then a backend, all req* rules
10887 from the frontend will be evaluated, then all req* rules from the backend
10888 will be evaluated. The reverse path is applied to responses.
10889
10890 - req* statements are applied after "block" statements, so that "block" is
10891 always the first one, but before "use_backend" in order to permit rewriting
Willy Tarreaud72758d2010-01-12 10:42:19 +010010892 before switching.
Willy Tarreauc57f0e22009-05-10 13:12:33 +020010893
10894
Willy Tarreau74ca5042013-06-11 23:12:07 +0200108957. Using ACLs and fetching samples
10896----------------------------------
10897
10898Haproxy is capable of extracting data from request or response streams, from
10899client or server information, from tables, environmental information etc...
10900The action of extracting such data is called fetching a sample. Once retrieved,
10901these samples may be used for various purposes such as a key to a stick-table,
10902but most common usages consist in matching them against predefined constant
10903data called patterns.
10904
10905
109067.1. ACL basics
10907---------------
Willy Tarreauc57f0e22009-05-10 13:12:33 +020010908
10909The use of Access Control Lists (ACL) provides a flexible solution to perform
10910content switching and generally to take decisions based on content extracted
10911from the request, the response or any environmental status. The principle is
10912simple :
10913
Willy Tarreau74ca5042013-06-11 23:12:07 +020010914 - extract a data sample from a stream, table or the environment
Willy Tarreaue6b11e42013-11-26 19:02:32 +010010915 - optionally apply some format conversion to the extracted sample
Willy Tarreau74ca5042013-06-11 23:12:07 +020010916 - apply one or multiple pattern matching methods on this sample
10917 - perform actions only when a pattern matches the sample
Willy Tarreauc57f0e22009-05-10 13:12:33 +020010918
Willy Tarreau74ca5042013-06-11 23:12:07 +020010919The actions generally consist in blocking a request, selecting a backend, or
10920adding a header.
Willy Tarreauc57f0e22009-05-10 13:12:33 +020010921
10922In order to define a test, the "acl" keyword is used. The syntax is :
10923
Willy Tarreau74ca5042013-06-11 23:12:07 +020010924 acl <aclname> <criterion> [flags] [operator] [<value>] ...
Willy Tarreauc57f0e22009-05-10 13:12:33 +020010925
10926This creates a new ACL <aclname> or completes an existing one with new tests.
10927Those tests apply to the portion of request/response specified in <criterion>
10928and may be adjusted with optional flags [flags]. Some criteria also support
Willy Tarreaue6b11e42013-11-26 19:02:32 +010010929an operator which may be specified before the set of values. Optionally some
10930conversion operators may be applied to the sample, and they will be specified
10931as a comma-delimited list of keywords just after the first keyword. The values
10932are of the type supported by the criterion, and are separated by spaces.
Willy Tarreauc57f0e22009-05-10 13:12:33 +020010933
10934ACL names must be formed from upper and lower case letters, digits, '-' (dash),
10935'_' (underscore) , '.' (dot) and ':' (colon). ACL names are case-sensitive,
10936which means that "my_acl" and "My_Acl" are two different ACLs.
10937
10938There is no enforced limit to the number of ACLs. The unused ones do not affect
10939performance, they just consume a small amount of memory.
10940
Willy Tarreau74ca5042013-06-11 23:12:07 +020010941The criterion generally is the name of a sample fetch method, or one of its ACL
10942specific declinations. The default test method is implied by the output type of
10943this sample fetch method. The ACL declinations can describe alternate matching
Willy Tarreaue6b11e42013-11-26 19:02:32 +010010944methods of a same sample fetch method. The sample fetch methods are the only
10945ones supporting a conversion.
Willy Tarreau74ca5042013-06-11 23:12:07 +020010946
10947Sample fetch methods return data which can be of the following types :
10948 - boolean
10949 - integer (signed or unsigned)
10950 - IPv4 or IPv6 address
10951 - string
10952 - data block
10953
Willy Tarreaue6b11e42013-11-26 19:02:32 +010010954Converters transform any of these data into any of these. For example, some
10955converters might convert a string to a lower-case string while other ones
10956would turn a string to an IPv4 address, or apply a netmask to an IP address.
10957The resulting sample is of the type of the last converter applied to the list,
10958which defaults to the type of the sample fetch method.
10959
Thierry FOURNIER2a06e392014-05-11 15:49:55 +020010960Each sample or converter returns data of a specific type, specified with its
10961keyword in this documentation. When an ACL is declared using a standard sample
10962fetch method, certain types automatically involved a default matching method
10963which are summarized in the table below :
10964
10965 +---------------------+-----------------+
10966 | Sample or converter | Default |
10967 | output type | matching method |
10968 +---------------------+-----------------+
10969 | boolean | bool |
10970 +---------------------+-----------------+
10971 | integer | int |
10972 +---------------------+-----------------+
10973 | ip | ip |
10974 +---------------------+-----------------+
10975 | string | str |
10976 +---------------------+-----------------+
10977 | binary | none, use "-m" |
10978 +---------------------+-----------------+
10979
10980Note that in order to match a binary samples, it is mandatory to specify a
10981matching method, see below.
10982
Willy Tarreau74ca5042013-06-11 23:12:07 +020010983The ACL engine can match these types against patterns of the following types :
10984 - boolean
10985 - integer or integer range
10986 - IP address / network
10987 - string (exact, substring, suffix, prefix, subdir, domain)
10988 - regular expression
10989 - hex block
10990
Willy Tarreauc57f0e22009-05-10 13:12:33 +020010991The following ACL flags are currently supported :
10992
Willy Tarreau2b5285d2010-05-09 23:45:24 +020010993 -i : ignore case during matching of all subsequent patterns.
10994 -f : load patterns from a file.
Willy Tarreau74ca5042013-06-11 23:12:07 +020010995 -m : use a specific pattern matching method
Thierry FOURNIERb7729c92014-02-11 16:24:41 +010010996 -n : forbid the DNS resolutions
Thierry FOURNIER9860c412014-01-29 14:23:29 +010010997 -M : load the file pointed by -f like a map file.
Thierry FOURNIER3534d882014-01-20 17:01:44 +010010998 -u : force the unique id of the ACL
Willy Tarreau6a06a402007-07-15 20:15:28 +020010999 -- : force end of flags. Useful when a string looks like one of the flags.
11000
Willy Tarreau74ca5042013-06-11 23:12:07 +020011001The "-f" flag is followed by the name of a file from which all lines will be
11002read as individual values. It is even possible to pass multiple "-f" arguments
11003if the patterns are to be loaded from multiple files. Empty lines as well as
11004lines beginning with a sharp ('#') will be ignored. All leading spaces and tabs
11005will be stripped. If it is absolutely necessary to insert a valid pattern
11006beginning with a sharp, just prefix it with a space so that it is not taken for
11007a comment. Depending on the data type and match method, haproxy may load the
11008lines into a binary tree, allowing very fast lookups. This is true for IPv4 and
11009exact string matching. In this case, duplicates will automatically be removed.
11010
Thierry FOURNIER9860c412014-01-29 14:23:29 +010011011The "-M" flag allows an ACL to use a map file. If this flag is set, the file is
11012parsed as two column file. The first column contains the patterns used by the
11013ACL, and the second column contain the samples. The sample can be used later by
11014a map. This can be useful in some rare cases where an ACL would just be used to
11015check for the existence of a pattern in a map before a mapping is applied.
11016
Thierry FOURNIER3534d882014-01-20 17:01:44 +010011017The "-u" flag forces the unique id of the ACL. This unique id is used with the
11018socket interface to identify ACL and dynamically change its values. Note that a
11019file is always identified by its name even if an id is set.
11020
Willy Tarreau74ca5042013-06-11 23:12:07 +020011021Also, note that the "-i" flag applies to subsequent entries and not to entries
11022loaded from files preceding it. For instance :
11023
11024 acl valid-ua hdr(user-agent) -f exact-ua.lst -i -f generic-ua.lst test
11025
11026In this example, each line of "exact-ua.lst" will be exactly matched against
11027the "user-agent" header of the request. Then each line of "generic-ua" will be
11028case-insensitively matched. Then the word "test" will be insensitively matched
11029as well.
11030
11031The "-m" flag is used to select a specific pattern matching method on the input
11032sample. All ACL-specific criteria imply a pattern matching method and generally
11033do not need this flag. However, this flag is useful with generic sample fetch
11034methods to describe how they're going to be matched against the patterns. This
11035is required for sample fetches which return data type for which there is no
11036obvious matching method (eg: string or binary). When "-m" is specified and
11037followed by a pattern matching method name, this method is used instead of the
11038default one for the criterion. This makes it possible to match contents in ways
11039that were not initially planned, or with sample fetch methods which return a
11040string. The matching method also affects the way the patterns are parsed.
11041
Thierry FOURNIERb7729c92014-02-11 16:24:41 +010011042The "-n" flag forbids the dns resolutions. It is used with the load of ip files.
11043By default, if the parser cannot parse ip address it considers that the parsed
11044string is maybe a domain name and try dns resolution. The flag "-n" disable this
11045resolution. It is useful for detecting malformed ip lists. Note that if the DNS
11046server is not reachable, the haproxy configuration parsing may last many minutes
11047waiting fir the timeout. During this time no error messages are displayed. The
11048flag "-n" disable this behavior. Note also that during the runtime, this
11049function is disabled for the dynamic acl modifications.
11050
Willy Tarreau74ca5042013-06-11 23:12:07 +020011051There are some restrictions however. Not all methods can be used with all
11052sample fetch methods. Also, if "-m" is used in conjunction with "-f", it must
11053be placed first. The pattern matching method must be one of the following :
Willy Tarreau5adeda12013-03-31 22:13:34 +020011054
11055 - "found" : only check if the requested sample could be found in the stream,
11056 but do not compare it against any pattern. It is recommended not
Willy Tarreau74ca5042013-06-11 23:12:07 +020011057 to pass any pattern to avoid confusion. This matching method is
11058 particularly useful to detect presence of certain contents such
11059 as headers, cookies, etc... even if they are empty and without
11060 comparing them to anything nor counting them.
Willy Tarreau5adeda12013-03-31 22:13:34 +020011061
11062 - "bool" : check the value as a boolean. It can only be applied to fetches
11063 which return a boolean or integer value, and takes no pattern.
Willy Tarreau74ca5042013-06-11 23:12:07 +020011064 Value zero or false does not match, all other values do match.
Willy Tarreau5adeda12013-03-31 22:13:34 +020011065
11066 - "int" : match the value as an integer. It can be used with integer and
Willy Tarreau74ca5042013-06-11 23:12:07 +020011067 boolean samples. Boolean false is integer 0, true is integer 1.
Willy Tarreau5adeda12013-03-31 22:13:34 +020011068
11069 - "ip" : match the value as an IPv4 or IPv6 address. It is compatible
Willy Tarreau74ca5042013-06-11 23:12:07 +020011070 with IP address samples only, so it is implied and never needed.
Willy Tarreau5adeda12013-03-31 22:13:34 +020011071
11072 - "bin" : match the contents against an hexadecimal string representing a
11073 binary sequence. This may be used with binary or string samples.
11074
11075 - "len" : match the sample's length as an integer. This may be used with
11076 binary or string samples.
11077
Willy Tarreau74ca5042013-06-11 23:12:07 +020011078 - "str" : exact match : match the contents against a string. This may be
11079 used with binary or string samples.
Willy Tarreau5adeda12013-03-31 22:13:34 +020011080
Willy Tarreau74ca5042013-06-11 23:12:07 +020011081 - "sub" : substring match : check that the contents contain at least one of
11082 the provided string patterns. This may be used with binary or
11083 string samples.
Willy Tarreau5adeda12013-03-31 22:13:34 +020011084
Willy Tarreau74ca5042013-06-11 23:12:07 +020011085 - "reg" : regex match : match the contents against a list of regular
11086 expressions. This may be used with binary or string samples.
Willy Tarreau5adeda12013-03-31 22:13:34 +020011087
Willy Tarreau74ca5042013-06-11 23:12:07 +020011088 - "beg" : prefix match : check that the contents begin like the provided
11089 string patterns. This may be used with binary or string samples.
Willy Tarreau5adeda12013-03-31 22:13:34 +020011090
Willy Tarreau74ca5042013-06-11 23:12:07 +020011091 - "end" : suffix match : check that the contents end like the provided
11092 string patterns. This may be used with binary or string samples.
Willy Tarreau5adeda12013-03-31 22:13:34 +020011093
Willy Tarreau74ca5042013-06-11 23:12:07 +020011094 - "dir" : subdir match : check that a slash-delimited portion of the
11095 contents exactly matches one of the provided string patterns.
Willy Tarreau5adeda12013-03-31 22:13:34 +020011096 This may be used with binary or string samples.
11097
Willy Tarreau74ca5042013-06-11 23:12:07 +020011098 - "dom" : domain match : check that a dot-delimited portion of the contents
11099 exactly match one of the provided string patterns. This may be
11100 used with binary or string samples.
Willy Tarreau5adeda12013-03-31 22:13:34 +020011101
11102For example, to quickly detect the presence of cookie "JSESSIONID" in an HTTP
11103request, it is possible to do :
11104
11105 acl jsess_present cook(JSESSIONID) -m found
11106
11107In order to apply a regular expression on the 500 first bytes of data in the
11108buffer, one would use the following acl :
11109
11110 acl script_tag payload(0,500) -m reg -i <script>
11111
Willy Tarreaue6b11e42013-11-26 19:02:32 +010011112On systems where the regex library is much slower when using "-i", it is
11113possible to convert the sample to lowercase before matching, like this :
11114
11115 acl script_tag payload(0,500),lower -m reg <script>
11116
Willy Tarreau74ca5042013-06-11 23:12:07 +020011117All ACL-specific criteria imply a default matching method. Most often, these
11118criteria are composed by concatenating the name of the original sample fetch
11119method and the matching method. For example, "hdr_beg" applies the "beg" match
11120to samples retrieved using the "hdr" fetch method. Since all ACL-specific
11121criteria rely on a sample fetch method, it is always possible instead to use
11122the original sample fetch method and the explicit matching method using "-m".
Willy Tarreau2b5285d2010-05-09 23:45:24 +020011123
Willy Tarreau74ca5042013-06-11 23:12:07 +020011124If an alternate match is specified using "-m" on an ACL-specific criterion,
Jarno Huuskonen0e82b922014-04-12 18:22:19 +030011125the matching method is simply applied to the underlying sample fetch method.
11126For example, all ACLs below are exact equivalent :
Willy Tarreau2b5285d2010-05-09 23:45:24 +020011127
Willy Tarreau74ca5042013-06-11 23:12:07 +020011128 acl short_form hdr_beg(host) www.
11129 acl alternate1 hdr_beg(host) -m beg www.
11130 acl alternate2 hdr_dom(host) -m beg www.
11131 acl alternate3 hdr(host) -m beg www.
Willy Tarreau2b5285d2010-05-09 23:45:24 +020011132
Willy Tarreau2b5285d2010-05-09 23:45:24 +020011133
Thierry FOURNIER2a06e392014-05-11 15:49:55 +020011134The table below summarizes the compatibility matrix between sample or converter
11135types and the pattern types to fetch against. It indicates for each compatible
11136combination the name of the matching method to be used, surrounded with angle
11137brackets ">" and "<" when the method is the default one and will work by
11138default without "-m".
Willy Tarreau0ba27502007-12-24 16:55:16 +010011139
Willy Tarreau74ca5042013-06-11 23:12:07 +020011140 +-------------------------------------------------+
11141 | Input sample type |
11142 +----------------------+---------+---------+---------+---------+---------+
Thierry FOURNIER2a06e392014-05-11 15:49:55 +020011143 | pattern type | boolean | integer | ip | string | binary |
Willy Tarreau74ca5042013-06-11 23:12:07 +020011144 +----------------------+---------+---------+---------+---------+---------+
11145 | none (presence only) | found | found | found | found | found |
11146 +----------------------+---------+---------+---------+---------+---------+
Thierry FOURNIER2a06e392014-05-11 15:49:55 +020011147 | none (boolean value) |> bool <| bool | | bool | |
Willy Tarreau74ca5042013-06-11 23:12:07 +020011148 +----------------------+---------+---------+---------+---------+---------+
Thierry FOURNIER2a06e392014-05-11 15:49:55 +020011149 | integer (value) | int |> int <| int | int | |
Willy Tarreau74ca5042013-06-11 23:12:07 +020011150 +----------------------+---------+---------+---------+---------+---------+
Thierry FOURNIERe3ded592013-12-06 15:36:54 +010011151 | integer (length) | len | len | len | len | len |
Willy Tarreau74ca5042013-06-11 23:12:07 +020011152 +----------------------+---------+---------+---------+---------+---------+
Thierry FOURNIER2a06e392014-05-11 15:49:55 +020011153 | IP address | | |> ip <| ip | ip |
Willy Tarreau74ca5042013-06-11 23:12:07 +020011154 +----------------------+---------+---------+---------+---------+---------+
Thierry FOURNIER2a06e392014-05-11 15:49:55 +020011155 | exact string | str | str | str |> str <| str |
Willy Tarreau74ca5042013-06-11 23:12:07 +020011156 +----------------------+---------+---------+---------+---------+---------+
Thierry FOURNIERe3ded592013-12-06 15:36:54 +010011157 | prefix | beg | beg | beg | beg | beg |
Willy Tarreau74ca5042013-06-11 23:12:07 +020011158 +----------------------+---------+---------+---------+---------+---------+
Thierry FOURNIERe3ded592013-12-06 15:36:54 +010011159 | suffix | end | end | end | end | end |
Willy Tarreau74ca5042013-06-11 23:12:07 +020011160 +----------------------+---------+---------+---------+---------+---------+
Thierry FOURNIERe3ded592013-12-06 15:36:54 +010011161 | substring | sub | sub | sub | sub | sub |
Willy Tarreau74ca5042013-06-11 23:12:07 +020011162 +----------------------+---------+---------+---------+---------+---------+
Thierry FOURNIERe3ded592013-12-06 15:36:54 +010011163 | subdir | dir | dir | dir | dir | dir |
Willy Tarreau74ca5042013-06-11 23:12:07 +020011164 +----------------------+---------+---------+---------+---------+---------+
Thierry FOURNIERe3ded592013-12-06 15:36:54 +010011165 | domain | dom | dom | dom | dom | dom |
Willy Tarreau74ca5042013-06-11 23:12:07 +020011166 +----------------------+---------+---------+---------+---------+---------+
Thierry FOURNIERe3ded592013-12-06 15:36:54 +010011167 | regex | reg | reg | reg | reg | reg |
Willy Tarreau74ca5042013-06-11 23:12:07 +020011168 +----------------------+---------+---------+---------+---------+---------+
11169 | hex block | | | | bin | bin |
11170 +----------------------+---------+---------+---------+---------+---------+
Willy Tarreau6a06a402007-07-15 20:15:28 +020011171
11172
Willy Tarreau74ca5042013-06-11 23:12:07 +0200111737.1.1. Matching booleans
11174------------------------
11175
11176In order to match a boolean, no value is needed and all values are ignored.
11177Boolean matching is used by default for all fetch methods of type "boolean".
11178When boolean matching is used, the fetched value is returned as-is, which means
11179that a boolean "true" will always match and a boolean "false" will never match.
11180
11181Boolean matching may also be enforced using "-m bool" on fetch methods which
11182return an integer value. Then, integer value 0 is converted to the boolean
11183"false" and all other values are converted to "true".
11184
Willy Tarreau6a06a402007-07-15 20:15:28 +020011185
Willy Tarreau74ca5042013-06-11 23:12:07 +0200111867.1.2. Matching integers
11187------------------------
11188
11189Integer matching applies by default to integer fetch methods. It can also be
11190enforced on boolean fetches using "-m int". In this case, "false" is converted
11191to the integer 0, and "true" is converted to the integer 1.
11192
11193Integer matching also supports integer ranges and operators. Note that integer
11194matching only applies to positive values. A range is a value expressed with a
11195lower and an upper bound separated with a colon, both of which may be omitted.
Willy Tarreau6a06a402007-07-15 20:15:28 +020011196
11197For instance, "1024:65535" is a valid range to represent a range of
11198unprivileged ports, and "1024:" would also work. "0:1023" is a valid
11199representation of privileged ports, and ":1023" would also work.
11200
Willy Tarreau62644772008-07-16 18:36:06 +020011201As a special case, some ACL functions support decimal numbers which are in fact
11202two integers separated by a dot. This is used with some version checks for
11203instance. All integer properties apply to those decimal numbers, including
11204ranges and operators.
11205
Willy Tarreau6a06a402007-07-15 20:15:28 +020011206For an easier usage, comparison operators are also supported. Note that using
Willy Tarreau0ba27502007-12-24 16:55:16 +010011207operators with ranges does not make much sense and is strongly discouraged.
11208Similarly, it does not make much sense to perform order comparisons with a set
11209of values.
Willy Tarreau6a06a402007-07-15 20:15:28 +020011210
Willy Tarreau0ba27502007-12-24 16:55:16 +010011211Available operators for integer matching are :
Willy Tarreau6a06a402007-07-15 20:15:28 +020011212
11213 eq : true if the tested value equals at least one value
11214 ge : true if the tested value is greater than or equal to at least one value
11215 gt : true if the tested value is greater than at least one value
11216 le : true if the tested value is less than or equal to at least one value
11217 lt : true if the tested value is less than at least one value
11218
Willy Tarreau0ba27502007-12-24 16:55:16 +010011219For instance, the following ACL matches any negative Content-Length header :
Willy Tarreau6a06a402007-07-15 20:15:28 +020011220
11221 acl negative-length hdr_val(content-length) lt 0
11222
Willy Tarreau62644772008-07-16 18:36:06 +020011223This one matches SSL versions between 3.0 and 3.1 (inclusive) :
11224
11225 acl sslv3 req_ssl_ver 3:3.1
11226
Willy Tarreau6a06a402007-07-15 20:15:28 +020011227
Willy Tarreau74ca5042013-06-11 23:12:07 +0200112287.1.3. Matching strings
11229-----------------------
11230
11231String matching applies to string or binary fetch methods, and exists in 6
11232different forms :
11233
11234 - exact match (-m str) : the extracted string must exactly match the
11235 patterns ;
11236
11237 - substring match (-m sub) : the patterns are looked up inside the
11238 extracted string, and the ACL matches if any of them is found inside ;
11239
11240 - prefix match (-m beg) : the patterns are compared with the beginning of
11241 the extracted string, and the ACL matches if any of them matches.
11242
11243 - suffix match (-m end) : the patterns are compared with the end of the
11244 extracted string, and the ACL matches if any of them matches.
11245
11246 - subdir match (-m sub) : the patterns are looked up inside the extracted
11247 string, delimited with slashes ("/"), and the ACL matches if any of them
11248 matches.
11249
11250 - domain match (-m dom) : the patterns are looked up inside the extracted
11251 string, delimited with dots ("."), and the ACL matches if any of them
11252 matches.
Willy Tarreau6a06a402007-07-15 20:15:28 +020011253
11254String matching applies to verbatim strings as they are passed, with the
11255exception of the backslash ("\") which makes it possible to escape some
11256characters such as the space. If the "-i" flag is passed before the first
11257string, then the matching will be performed ignoring the case. In order
11258to match the string "-i", either set it second, or pass the "--" flag
Willy Tarreau0ba27502007-12-24 16:55:16 +010011259before the first string. Same applies of course to match the string "--".
Willy Tarreau6a06a402007-07-15 20:15:28 +020011260
11261
Willy Tarreau74ca5042013-06-11 23:12:07 +0200112627.1.4. Matching regular expressions (regexes)
11263---------------------------------------------
Willy Tarreau6a06a402007-07-15 20:15:28 +020011264
11265Just like with string matching, regex matching applies to verbatim strings as
11266they are passed, with the exception of the backslash ("\") which makes it
11267possible to escape some characters such as the space. If the "-i" flag is
11268passed before the first regex, then the matching will be performed ignoring
11269the case. In order to match the string "-i", either set it second, or pass
Willy Tarreau0ba27502007-12-24 16:55:16 +010011270the "--" flag before the first string. Same principle applies of course to
11271match the string "--".
Willy Tarreau6a06a402007-07-15 20:15:28 +020011272
11273
Willy Tarreau74ca5042013-06-11 23:12:07 +0200112747.1.5. Matching arbitrary data blocks
11275-------------------------------------
11276
11277It is possible to match some extracted samples against a binary block which may
11278not safely be represented as a string. For this, the patterns must be passed as
11279a series of hexadecimal digits in an even number, when the match method is set
11280to binary. Each sequence of two digits will represent a byte. The hexadecimal
11281digits may be used upper or lower case.
11282
11283Example :
11284 # match "Hello\n" in the input stream (\x48 \x65 \x6c \x6c \x6f \x0a)
11285 acl hello payload(0,6) -m bin 48656c6c6f0a
11286
11287
112887.1.6. Matching IPv4 and IPv6 addresses
11289---------------------------------------
Willy Tarreau6a06a402007-07-15 20:15:28 +020011290
11291IPv4 addresses values can be specified either as plain addresses or with a
11292netmask appended, in which case the IPv4 address matches whenever it is
11293within the network. Plain addresses may also be replaced with a resolvable
Willy Tarreaud2a4aa22008-01-31 15:28:22 +010011294host name, but this practice is generally discouraged as it makes it more
Willy Tarreau0ba27502007-12-24 16:55:16 +010011295difficult to read and debug configurations. If hostnames are used, you should
11296at least ensure that they are present in /etc/hosts so that the configuration
11297does not depend on any random DNS match at the moment the configuration is
11298parsed.
Willy Tarreau6a06a402007-07-15 20:15:28 +020011299
Willy Tarreauceb4ac92012-04-28 00:41:46 +020011300IPv6 may be entered in their usual form, with or without a netmask appended.
11301Only bit counts are accepted for IPv6 netmasks. In order to avoid any risk of
11302trouble with randomly resolved IP addresses, host names are never allowed in
11303IPv6 patterns.
11304
11305HAProxy is also able to match IPv4 addresses with IPv6 addresses in the
11306following situations :
11307 - tested address is IPv4, pattern address is IPv4, the match applies
11308 in IPv4 using the supplied mask if any.
11309 - tested address is IPv6, pattern address is IPv6, the match applies
11310 in IPv6 using the supplied mask if any.
11311 - tested address is IPv6, pattern address is IPv4, the match applies in IPv4
11312 using the pattern's mask if the IPv6 address matches with 2002:IPV4::,
11313 ::IPV4 or ::ffff:IPV4, otherwise it fails.
11314 - tested address is IPv4, pattern address is IPv6, the IPv4 address is first
11315 converted to IPv6 by prefixing ::ffff: in front of it, then the match is
11316 applied in IPv6 using the supplied IPv6 mask.
11317
Willy Tarreau74ca5042013-06-11 23:12:07 +020011318
113197.2. Using ACLs to form conditions
11320----------------------------------
11321
11322Some actions are only performed upon a valid condition. A condition is a
11323combination of ACLs with operators. 3 operators are supported :
11324
11325 - AND (implicit)
11326 - OR (explicit with the "or" keyword or the "||" operator)
11327 - Negation with the exclamation mark ("!")
Willy Tarreau6a06a402007-07-15 20:15:28 +020011328
Willy Tarreau74ca5042013-06-11 23:12:07 +020011329A condition is formed as a disjunctive form:
Willy Tarreau6a06a402007-07-15 20:15:28 +020011330
Willy Tarreau74ca5042013-06-11 23:12:07 +020011331 [!]acl1 [!]acl2 ... [!]acln { or [!]acl1 [!]acl2 ... [!]acln } ...
Willy Tarreaubef91e72013-03-31 23:14:46 +020011332
Willy Tarreau74ca5042013-06-11 23:12:07 +020011333Such conditions are generally used after an "if" or "unless" statement,
11334indicating when the condition will trigger the action.
Willy Tarreaubef91e72013-03-31 23:14:46 +020011335
Willy Tarreau74ca5042013-06-11 23:12:07 +020011336For instance, to block HTTP requests to the "*" URL with methods other than
11337"OPTIONS", as well as POST requests without content-length, and GET or HEAD
11338requests with a content-length greater than 0, and finally every request which
11339is not either GET/HEAD/POST/OPTIONS !
11340
11341 acl missing_cl hdr_cnt(Content-length) eq 0
11342 block if HTTP_URL_STAR !METH_OPTIONS || METH_POST missing_cl
11343 block if METH_GET HTTP_CONTENT
11344 block unless METH_GET or METH_POST or METH_OPTIONS
11345
11346To select a different backend for requests to static contents on the "www" site
11347and to every request on the "img", "video", "download" and "ftp" hosts :
11348
11349 acl url_static path_beg /static /images /img /css
11350 acl url_static path_end .gif .png .jpg .css .js
11351 acl host_www hdr_beg(host) -i www
11352 acl host_static hdr_beg(host) -i img. video. download. ftp.
11353
11354 # now use backend "static" for all static-only hosts, and for static urls
11355 # of host "www". Use backend "www" for the rest.
11356 use_backend static if host_static or host_www url_static
11357 use_backend www if host_www
11358
11359It is also possible to form rules using "anonymous ACLs". Those are unnamed ACL
11360expressions that are built on the fly without needing to be declared. They must
11361be enclosed between braces, with a space before and after each brace (because
11362the braces must be seen as independent words). Example :
11363
11364 The following rule :
11365
11366 acl missing_cl hdr_cnt(Content-length) eq 0
11367 block if METH_POST missing_cl
11368
11369 Can also be written that way :
11370
11371 block if METH_POST { hdr_cnt(Content-length) eq 0 }
11372
11373It is generally not recommended to use this construct because it's a lot easier
11374to leave errors in the configuration when written that way. However, for very
11375simple rules matching only one source IP address for instance, it can make more
11376sense to use them than to declare ACLs with random names. Another example of
11377good use is the following :
11378
11379 With named ACLs :
11380
11381 acl site_dead nbsrv(dynamic) lt 2
11382 acl site_dead nbsrv(static) lt 2
11383 monitor fail if site_dead
11384
11385 With anonymous ACLs :
11386
11387 monitor fail if { nbsrv(dynamic) lt 2 } || { nbsrv(static) lt 2 }
11388
11389See section 4.2 for detailed help on the "block" and "use_backend" keywords.
11390
11391
113927.3. Fetching samples
11393---------------------
11394
11395Historically, sample fetch methods were only used to retrieve data to match
11396against patterns using ACLs. With the arrival of stick-tables, a new class of
11397sample fetch methods was created, most often sharing the same syntax as their
11398ACL counterpart. These sample fetch methods are also known as "fetches". As
11399of now, ACLs and fetches have converged. All ACL fetch methods have been made
11400available as fetch methods, and ACLs may use any sample fetch method as well.
11401
11402This section details all available sample fetch methods and their output type.
11403Some sample fetch methods have deprecated aliases that are used to maintain
11404compatibility with existing configurations. They are then explicitly marked as
11405deprecated and should not be used in new setups.
11406
11407The ACL derivatives are also indicated when available, with their respective
11408matching methods. These ones all have a well defined default pattern matching
11409method, so it is never necessary (though allowed) to pass the "-m" option to
11410indicate how the sample will be matched using ACLs.
11411
11412As indicated in the sample type versus matching compatibility matrix above,
11413when using a generic sample fetch method in an ACL, the "-m" option is
11414mandatory unless the sample type is one of boolean, integer, IPv4 or IPv6. When
11415the same keyword exists as an ACL keyword and as a standard fetch method, the
11416ACL engine will automatically pick the ACL-only one by default.
11417
11418Some of these keywords support one or multiple mandatory arguments, and one or
11419multiple optional arguments. These arguments are strongly typed and are checked
11420when the configuration is parsed so that there is no risk of running with an
11421incorrect argument (eg: an unresolved backend name). Fetch function arguments
11422are passed between parenthesis and are delimited by commas. When an argument
11423is optional, it will be indicated below between square brackets ('[ ]'). When
11424all arguments are optional, the parenthesis may be omitted.
11425
11426Thus, the syntax of a standard sample fetch method is one of the following :
11427 - name
11428 - name(arg1)
11429 - name(arg1,arg2)
11430
Thierry FOURNIER060762e2014-04-23 13:29:15 +020011431
114327.3.1. Converters
11433-----------------
11434
Willy Tarreaue6b11e42013-11-26 19:02:32 +010011435Sample fetch methods may be combined with transformations to be applied on top
11436of the fetched sample (also called "converters"). These combinations form what
11437is called "sample expressions" and the result is a "sample". Initially this
11438was only supported by "stick on" and "stick store-request" directives but this
11439has now be extended to all places where samples may be used (acls, log-format,
11440unique-id-format, add-header, ...).
11441
11442These transformations are enumerated as a series of specific keywords after the
11443sample fetch method. These keywords may equally be appended immediately after
11444the fetch keyword's argument, delimited by a comma. These keywords can also
11445support some arguments (eg: a netmask) which must be passed in parenthesis.
Willy Tarreau0ba27502007-12-24 16:55:16 +010011446
Willy Tarreau97707872015-01-27 15:12:13 +010011447A certain category of converters are bitwise and arithmetic operators which
11448support performing basic operations on integers. Some bitwise operations are
11449supported (and, or, xor, cpl) and some arithmetic operations are supported
11450(add, sub, mul, div, mod, neg). Some comparators are provided (odd, even, not,
11451bool) which make it possible to report a match without having to write an ACL.
11452
Willy Tarreau74ca5042013-06-11 23:12:07 +020011453The currently available list of transformation keywords include :
Willy Tarreau0ba27502007-12-24 16:55:16 +010011454
Willy Tarreau97707872015-01-27 15:12:13 +010011455add(<value>)
Thierry FOURNIER07ee64e2015-07-06 23:43:03 +020011456 Adds <value> to the input value of type signed integer, and returns the
Thierry FOURNIER5d86fae2015-07-07 21:10:16 +020011457 result as a signed integer. <value> can be a numeric value or a variable
11458 name. The name of the variable starts by an indication about its scope. The
11459 allowed scopes are:
11460 "sess" : the variable is shared with all the session,
11461 "txn" : the variable is shared with all the transaction (request and
11462 response),
11463 "req" : the variable is shared only during the request processing,
11464 "res" : the variable is shared only during the response processing.
11465 This prefix is followed by a name. The separator is a '.'. The name may only
11466 contain characters 'a-z', 'A-Z', '0-9' and '_'.
Willy Tarreau97707872015-01-27 15:12:13 +010011467
11468and(<value>)
Thierry FOURNIER07ee64e2015-07-06 23:43:03 +020011469 Performs a bitwise "AND" between <value> and the input value of type signed
Thierry FOURNIER5d86fae2015-07-07 21:10:16 +020011470 integer, and returns the result as an signed integer. <value> can be a
11471 numeric value or a variable name. The name of the variable starts by an
11472 indication about its scope. The allowed scopes are:
11473 "sess" : the variable is shared with all the session,
11474 "txn" : the variable is shared with all the transaction (request and
11475 response),
11476 "req" : the variable is shared only during the request processing,
11477 "res" : the variable is shared only during the response processing.
11478 This prefix is followed by a name. The separator is a '.'. The name may only
11479 contain characters 'a-z', 'A-Z', '0-9' and '_'.
Willy Tarreau97707872015-01-27 15:12:13 +010011480
Emeric Brun53d1a982014-04-30 18:21:37 +020011481base64
11482 Converts a binary input sample to a base64 string. It is used to log or
11483 transfer binary content in a way that can be reliably transferred (eg:
11484 an SSL ID can be copied in a header).
11485
Willy Tarreau97707872015-01-27 15:12:13 +010011486bool
Thierry FOURNIER07ee64e2015-07-06 23:43:03 +020011487 Returns a boolean TRUE if the input value of type signed integer is
Willy Tarreau97707872015-01-27 15:12:13 +010011488 non-null, otherwise returns FALSE. Used in conjunction with and(), it can be
11489 used to report true/false for bit testing on input values (eg: verify the
11490 presence of a flag).
11491
Emeric Brun54c4ac82014-11-03 15:32:43 +010011492bytes(<offset>[,<length>])
11493 Extracts some bytes from an input binary sample. The result is a binary
11494 sample starting at an offset (in bytes) of the original sample and
11495 optionnaly truncated at the given length.
11496
Willy Tarreau97707872015-01-27 15:12:13 +010011497cpl
Thierry FOURNIER07ee64e2015-07-06 23:43:03 +020011498 Takes the input value of type signed integer, applies a ones-complement
11499 (flips all bits) and returns the result as an signed integer.
Willy Tarreau97707872015-01-27 15:12:13 +010011500
Willy Tarreau80599772015-01-20 19:35:24 +010011501crc32([<avalanche>])
11502 Hashes a binary input sample into an unsigned 32-bit quantity using the CRC32
11503 hash function. Optionally, it is possible to apply a full avalanche hash
11504 function to the output if the optional <avalanche> argument equals 1. This
11505 converter uses the same functions as used by the various hash-based load
11506 balancing algorithms, so it will provide exactly the same results. It is
11507 provided for compatibility with other software which want a CRC32 to be
11508 computed on some input keys, so it follows the most common implementation as
11509 found in Ethernet, Gzip, PNG, etc... It is slower than the other algorithms
11510 but may provide a better or at least less predictable distribution. It must
11511 not be used for security purposes as a 32-bit hash is trivial to break. See
11512 also "djb2", "sdbm", "wt6" and the "hash-type" directive.
11513
David Carlier29b3ca32015-09-25 14:09:21 +010011514da-csv-conv(<prop>[,<prop>*])
David Carlier4542b102015-06-01 13:54:29 +020011515 Asks the DeviceAtlas converter to identify the User Agent string passed on
11516 input, and to emit a string made of the concatenation of the properties
11517 enumerated in argument, delimited by the separator defined by the global
11518 keyword "deviceatlas-property-separator", or by default the pipe character
11519 ('|'). There's a limit of 5 different properties imposed by the haproxy
11520 configuration language.
11521
11522 Example:
11523 frontend www
11524 bind *:8881
11525 default_backend servers
11526 http-request set-header X-DeviceAtlas-Data %[req.fhdr(User-Agent),da-csv(primaryHardwareType,osName,osVersion,browserName,browserVersion)]
11527
Thierry FOURNIER9687c772015-05-07 15:46:29 +020011528debug
11529 This converter is used as debug tool. It dumps on screen the content and the
11530 type of the input sample. The sample is returned as is on its output. This
11531 converter only exists when haproxy was built with debugging enabled.
11532
Willy Tarreau97707872015-01-27 15:12:13 +010011533div(<value>)
Thierry FOURNIER07ee64e2015-07-06 23:43:03 +020011534 Divides the input value of type signed integer by <value>, and returns the
11535 result as an signed integer. If <value> is null, the largest unsigned
Thierry FOURNIER5d86fae2015-07-07 21:10:16 +020011536 integer is returned (typically 2^63-1). <value> can be a numeric value or a
11537 variable name. The name of the variable starts by an indication about it
11538 scope. The scope allowed are:
11539 "sess" : the variable is shared with all the session,
11540 "txn" : the variable is shared with all the transaction (request and
11541 response),
11542 "req" : the variable is shared only during the request processing,
11543 "res" : the variable is shared only during the response processing.
11544 This prefix is followed by a name. The separator is a '.'. The name may only
11545 contain characters 'a-z', 'A-Z', '0-9' and '_'.
Willy Tarreau97707872015-01-27 15:12:13 +010011546
Willy Tarreau23ec4ca2014-07-15 20:15:37 +020011547djb2([<avalanche>])
11548 Hashes a binary input sample into an unsigned 32-bit quantity using the DJB2
11549 hash function. Optionally, it is possible to apply a full avalanche hash
11550 function to the output if the optional <avalanche> argument equals 1. This
11551 converter uses the same functions as used by the various hash-based load
11552 balancing algorithms, so it will provide exactly the same results. It is
11553 mostly intended for debugging, but can be used as a stick-table entry to
11554 collect rough statistics. It must not be used for security purposes as a
Willy Tarreau80599772015-01-20 19:35:24 +010011555 32-bit hash is trivial to break. See also "crc32", "sdbm", "wt6" and the
11556 "hash-type" directive.
Willy Tarreau23ec4ca2014-07-15 20:15:37 +020011557
Willy Tarreau97707872015-01-27 15:12:13 +010011558even
Thierry FOURNIER07ee64e2015-07-06 23:43:03 +020011559 Returns a boolean TRUE if the input value of type signed integer is even
Willy Tarreau97707872015-01-27 15:12:13 +010011560 otherwise returns FALSE. It is functionally equivalent to "not,and(1),bool".
11561
Emeric Brunf399b0d2014-11-03 17:07:03 +010011562field(<index>,<delimiters>)
11563 Extracts the substring at the given index considering given delimiters from
11564 an input string. Indexes start at 1 and delimiters are a string formatted
11565 list of chars.
11566
Thierry FOURNIER060762e2014-04-23 13:29:15 +020011567hex
11568 Converts a binary input sample to an hex string containing two hex digits per
11569 input byte. It is used to log or transfer hex dumps of some binary input data
11570 in a way that can be reliably transferred (eg: an SSL ID can be copied in a
11571 header).
Thierry FOURNIER2f49d6d2014-03-12 15:01:52 +010011572
Thierry FOURNIER060762e2014-04-23 13:29:15 +020011573http_date([<offset>])
11574 Converts an integer supposed to contain a date since epoch to a string
11575 representing this date in a format suitable for use in HTTP header fields. If
11576 an offset value is specified, then it is a number of seconds that is added to
11577 the date before the conversion is operated. This is particularly useful to
11578 emit Date header fields, Expires values in responses when combined with a
11579 positive offset, or Last-Modified values when the offset is negative.
Willy Tarreau74ca5042013-06-11 23:12:07 +020011580
Willy Tarreaud9f316a2014-07-10 14:03:38 +020011581in_table(<table>)
11582 Uses the string representation of the input sample to perform a look up in
11583 the specified table. If the key is not found in the table, a boolean false
11584 is returned. Otherwise a boolean true is returned. This can be used to verify
11585 the presence of a certain key in a table tracking some elements (eg: whether
11586 or not a source IP address or an Authorization header was already seen).
11587
Willy Tarreauffcb2e42014-07-10 16:29:08 +020011588ipmask(<mask>)
11589 Apply a mask to an IPv4 address, and use the result for lookups and storage.
11590 This can be used to make all hosts within a certain mask to share the same
11591 table entries and as such use the same server. The mask can be passed in
11592 dotted form (eg: 255.255.255.0) or in CIDR form (eg: 24).
11593
Thierry FOURNIER317e1c42014-08-12 10:20:47 +020011594json([<input-code>])
11595 Escapes the input string and produces an ASCII ouput string ready to use as a
11596 JSON string. The converter tries to decode the input string according to the
11597 <input-code> parameter. It can be "ascii", "utf8", "utf8s", "utf8"" or
11598 "utf8ps". The "ascii" decoder never fails. The "utf8" decoder detects 3 types
11599 of errors:
11600 - bad UTF-8 sequence (lone continuation byte, bad number of continuation
11601 bytes, ...)
11602 - invalid range (the decoded value is within a UTF-8 prohibited range),
11603 - code overlong (the value is encoded with more bytes than necessary).
11604
11605 The UTF-8 JSON encoding can produce a "too long value" error when the UTF-8
11606 character is greater than 0xffff because the JSON string escape specification
11607 only authorizes 4 hex digits for the value encoding. The UTF-8 decoder exists
11608 in 4 variants designated by a combination of two suffix letters : "p" for
11609 "permissive" and "s" for "silently ignore". The behaviors of the decoders
11610 are :
11611 - "ascii" : never fails ;
11612 - "utf8" : fails on any detected errors ;
11613 - "utf8s" : never fails, but removes characters corresponding to errors ;
11614 - "utf8p" : accepts and fixes the overlong errors, but fails on any other
11615 error ;
11616 - "utf8ps" : never fails, accepts and fixes the overlong errors, but removes
11617 characters corresponding to the other errors.
11618
11619 This converter is particularly useful for building properly escaped JSON for
11620 logging to servers which consume JSON-formated traffic logs.
11621
11622 Example:
11623 capture request header user-agent len 150
11624 capture request header Host len 15
11625 log-format {"ip":"%[src]","user-agent":"%[capture.req.hdr(1),json]"}
11626
11627 Input request from client 127.0.0.1:
11628 GET / HTTP/1.0
11629 User-Agent: Very "Ugly" UA 1/2
11630
11631 Output log:
11632 {"ip":"127.0.0.1","user-agent":"Very \"Ugly\" UA 1\/2"}
11633
Thierry FOURNIER060762e2014-04-23 13:29:15 +020011634language(<value>[,<default>])
11635 Returns the value with the highest q-factor from a list as extracted from the
11636 "accept-language" header using "req.fhdr". Values with no q-factor have a
11637 q-factor of 1. Values with a q-factor of 0 are dropped. Only values which
11638 belong to the list of semi-colon delimited <values> will be considered. The
11639 argument <value> syntax is "lang[;lang[;lang[;...]]]". If no value matches the
11640 given list and a default value is provided, it is returned. Note that language
11641 names may have a variant after a dash ('-'). If this variant is present in the
11642 list, it will be matched, but if it is not, only the base language is checked.
11643 The match is case-sensitive, and the output string is always one of those
11644 provided in arguments. The ordering of arguments is meaningless, only the
11645 ordering of the values in the request counts, as the first value among
11646 multiple sharing the same q-factor is used.
Thierry FOURNIERad903512014-04-11 17:51:01 +020011647
Thierry FOURNIER060762e2014-04-23 13:29:15 +020011648 Example :
Thierry FOURNIERad903512014-04-11 17:51:01 +020011649
Thierry FOURNIER060762e2014-04-23 13:29:15 +020011650 # this configuration switches to the backend matching a
11651 # given language based on the request :
Thierry FOURNIERad903512014-04-11 17:51:01 +020011652
Thierry FOURNIER060762e2014-04-23 13:29:15 +020011653 acl es req.fhdr(accept-language),language(es;fr;en) -m str es
11654 acl fr req.fhdr(accept-language),language(es;fr;en) -m str fr
11655 acl en req.fhdr(accept-language),language(es;fr;en) -m str en
11656 use_backend spanish if es
11657 use_backend french if fr
11658 use_backend english if en
11659 default_backend choose_your_language
Thierry FOURNIERad903512014-04-11 17:51:01 +020011660
Willy Tarreauffcb2e42014-07-10 16:29:08 +020011661lower
11662 Convert a string sample to lower case. This can only be placed after a string
11663 sample fetch function or after a transformation keyword returning a string
11664 type. The result is of type string.
11665
Willy Tarreau0dbfdba2014-07-10 16:37:47 +020011666ltime(<format>[,<offset>])
11667 Converts an integer supposed to contain a date since epoch to a string
11668 representing this date in local time using a format defined by the <format>
11669 string using strftime(3). The purpose is to allow any date format to be used
11670 in logs. An optional <offset> in seconds may be applied to the input date
11671 (positive or negative). See the strftime() man page for the format supported
11672 by your operating system. See also the utime converter.
11673
11674 Example :
11675
11676 # Emit two colons, one with the local time and another with ip:port
11677 # Eg: 20140710162350 127.0.0.1:57325
11678 log-format %[date,ltime(%Y%m%d%H%M%S)]\ %ci:%cp
11679
Thierry FOURNIER060762e2014-04-23 13:29:15 +020011680map(<map_file>[,<default_value>])
11681map_<match_type>(<map_file>[,<default_value>])
11682map_<match_type>_<output_type>(<map_file>[,<default_value>])
11683 Search the input value from <map_file> using the <match_type> matching method,
11684 and return the associated value converted to the type <output_type>. If the
11685 input value cannot be found in the <map_file>, the converter returns the
11686 <default_value>. If the <default_value> is not set, the converter fails and
11687 acts as if no input value could be fetched. If the <match_type> is not set, it
11688 defaults to "str". Likewise, if the <output_type> is not set, it defaults to
11689 "str". For convenience, the "map" keyword is an alias for "map_str" and maps a
11690 string to another string.
Thierry FOURNIERd5f624d2013-11-26 11:52:33 +010011691
Thierry FOURNIER060762e2014-04-23 13:29:15 +020011692 It is important to avoid overlapping between the keys : IP addresses and
11693 strings are stored in trees, so the first of the finest match will be used.
11694 Other keys are stored in lists, so the first matching occurrence will be used.
Thierry FOURNIERd5f624d2013-11-26 11:52:33 +010011695
Thierry FOURNIER060762e2014-04-23 13:29:15 +020011696 The following array contains the list of all map functions avalaible sorted by
11697 input type, match type and output type.
Thierry FOURNIERd5f624d2013-11-26 11:52:33 +010011698
Thierry FOURNIER060762e2014-04-23 13:29:15 +020011699 input type | match method | output type str | output type int | output type ip
11700 -----------+--------------+-----------------+-----------------+---------------
11701 str | str | map_str | map_str_int | map_str_ip
11702 -----------+--------------+-----------------+-----------------+---------------
Willy Tarreau787a4c02014-05-10 07:55:30 +020011703 str | beg | map_beg | map_beg_int | map_end_ip
11704 -----------+--------------+-----------------+-----------------+---------------
Thierry FOURNIER060762e2014-04-23 13:29:15 +020011705 str | sub | map_sub | map_sub_int | map_sub_ip
11706 -----------+--------------+-----------------+-----------------+---------------
11707 str | dir | map_dir | map_dir_int | map_dir_ip
11708 -----------+--------------+-----------------+-----------------+---------------
11709 str | dom | map_dom | map_dom_int | map_dom_ip
11710 -----------+--------------+-----------------+-----------------+---------------
11711 str | end | map_end | map_end_int | map_end_ip
11712 -----------+--------------+-----------------+-----------------+---------------
11713 str | reg | map_reg | map_reg_int | map_reg_ip
11714 -----------+--------------+-----------------+-----------------+---------------
11715 int | int | map_int | map_int_int | map_int_ip
11716 -----------+--------------+-----------------+-----------------+---------------
11717 ip | ip | map_ip | map_ip_int | map_ip_ip
11718 -----------+--------------+-----------------+-----------------+---------------
Thierry FOURNIERd5f624d2013-11-26 11:52:33 +010011719
Thierry FOURNIER060762e2014-04-23 13:29:15 +020011720 The file contains one key + value per line. Lines which start with '#' are
11721 ignored, just like empty lines. Leading tabs and spaces are stripped. The key
11722 is then the first "word" (series of non-space/tabs characters), and the value
11723 is what follows this series of space/tab till the end of the line excluding
11724 trailing spaces/tabs.
Thierry FOURNIERd5f624d2013-11-26 11:52:33 +010011725
Thierry FOURNIER060762e2014-04-23 13:29:15 +020011726 Example :
11727
11728 # this is a comment and is ignored
11729 2.22.246.0/23 United Kingdom \n
11730 <-><-----------><--><------------><---->
11731 | | | | `- trailing spaces ignored
11732 | | | `---------- value
11733 | | `-------------------- middle spaces ignored
11734 | `---------------------------- key
11735 `------------------------------------ leading spaces ignored
11736
Willy Tarreau97707872015-01-27 15:12:13 +010011737mod(<value>)
Thierry FOURNIER07ee64e2015-07-06 23:43:03 +020011738 Divides the input value of type signed integer by <value>, and returns the
11739 remainder as an signed integer. If <value> is null, then zero is returned.
Thierry FOURNIER5d86fae2015-07-07 21:10:16 +020011740 <value> can be a numeric value or a variable name. The name of the variable
11741 starts by an indication about its scope. The allowed scopes are:
11742 "sess" : the variable is shared with all the session,
11743 "txn" : the variable is shared with all the transaction (request and
11744 response),
11745 "req" : the variable is shared only during the request processing,
11746 "res" : the variable is shared only during the response processing.
11747 This prefix is followed by a name. The separator is a '.'. The name may only
11748 contain characters 'a-z', 'A-Z', '0-9' and '_'.
Willy Tarreau97707872015-01-27 15:12:13 +010011749
11750mul(<value>)
Thierry FOURNIER07ee64e2015-07-06 23:43:03 +020011751 Multiplies the input value of type signed integer by <value>, and returns
Thierry FOURNIER00c005c2015-07-08 01:10:21 +020011752 the product as an signed integer. In case of overflow, the largest possible
11753 value for the sign is returned so that the operation doesn't wrap around.
Thierry FOURNIER5d86fae2015-07-07 21:10:16 +020011754 <value> can be a numeric value or a variable name. The name of the variable
11755 starts by an indication about its scope. The allowed scopes are:
11756 "sess" : the variable is shared with all the session,
11757 "txn" : the variable is shared with all the transaction (request and
11758 response),
11759 "req" : the variable is shared only during the request processing,
11760 "res" : the variable is shared only during the response processing.
11761 This prefix is followed by a name. The separator is a '.'. The name may only
11762 contain characters 'a-z', 'A-Z', '0-9' and '_'.
Willy Tarreau97707872015-01-27 15:12:13 +010011763
11764neg
Thierry FOURNIER07ee64e2015-07-06 23:43:03 +020011765 Takes the input value of type signed integer, computes the opposite value,
11766 and returns the remainder as an signed integer. 0 is identity. This operator
11767 is provided for reversed subtracts : in order to subtract the input from a
11768 constant, simply perform a "neg,add(value)".
Willy Tarreau97707872015-01-27 15:12:13 +010011769
11770not
Thierry FOURNIER07ee64e2015-07-06 23:43:03 +020011771 Returns a boolean FALSE if the input value of type signed integer is
Willy Tarreau97707872015-01-27 15:12:13 +010011772 non-null, otherwise returns TRUE. Used in conjunction with and(), it can be
11773 used to report true/false for bit testing on input values (eg: verify the
11774 absence of a flag).
11775
11776odd
Thierry FOURNIER07ee64e2015-07-06 23:43:03 +020011777 Returns a boolean TRUE if the input value of type signed integer is odd
Willy Tarreau97707872015-01-27 15:12:13 +010011778 otherwise returns FALSE. It is functionally equivalent to "and(1),bool".
11779
11780or(<value>)
Thierry FOURNIER07ee64e2015-07-06 23:43:03 +020011781 Performs a bitwise "OR" between <value> and the input value of type signed
Thierry FOURNIER5d86fae2015-07-07 21:10:16 +020011782 integer, and returns the result as an signed integer. <value> can be a
11783 numeric value or a variable name. The name of the variable starts by an
11784 indication about its scope. The allowed scopes are:
11785 "sess" : the variable is shared with all the session,
11786 "txn" : the variable is shared with all the transaction (request and
11787 response),
11788 "req" : the variable is shared only during the request processing,
11789 "res" : the variable is shared only during the response processing.
11790 This prefix is followed by a name. The separator is a '.'. The name may only
11791 contain characters 'a-z', 'A-Z', '0-9' and '_'.
Willy Tarreau97707872015-01-27 15:12:13 +010011792
Willy Tarreauc4dc3502015-01-23 20:39:28 +010011793regsub(<regex>,<subst>[,<flags>])
Willy Tarreau7eda8492015-01-20 19:47:06 +010011794 Applies a regex-based substitution to the input string. It does the same
11795 operation as the well-known "sed" utility with "s/<regex>/<subst>/". By
11796 default it will replace in the input string the first occurrence of the
11797 largest part matching the regular expression <regex> with the substitution
11798 string <subst>. It is possible to replace all occurrences instead by adding
11799 the flag "g" in the third argument <flags>. It is also possible to make the
11800 regex case insensitive by adding the flag "i" in <flags>. Since <flags> is a
11801 string, it is made up from the concatenation of all desired flags. Thus if
11802 both "i" and "g" are desired, using "gi" or "ig" will have the same effect.
11803 It is important to note that due to the current limitations of the
11804 configuration parser, some characters such as closing parenthesis or comma
11805 are not possible to use in the arguments. The first use of this converter is
11806 to replace certain characters or sequence of characters with other ones.
11807
11808 Example :
11809
11810 # de-duplicate "/" in header "x-path".
11811 # input: x-path: /////a///b/c/xzxyz/
11812 # output: x-path: /a/b/c/xzxyz/
11813 http-request set-header x-path %[hdr(x-path),regsub(/+,/,g)]
11814
Thierry FOURNIER35ab2752015-05-28 13:22:03 +020011815capture-req(<id>)
11816 Capture the string entry in the request slot <id> and returns the entry as
11817 is. If the slot doesn't exist, the capture fails silently.
11818
11819 See also: "declare capture", "http-request capture",
11820 "http-response capture", "req.hdr.capture" and
11821 "res.hdr.capture" (sample fetches).
11822
11823capture-res(<id>)
11824 Capture the string entry in the response slot <id> and returns the entry as
11825 is. If the slot doesn't exist, the capture fails silently.
11826
11827 See also: "declare capture", "http-request capture",
11828 "http-response capture", "req.hdr.capture" and
11829 "res.hdr.capture" (sample fetches).
11830
Willy Tarreau23ec4ca2014-07-15 20:15:37 +020011831sdbm([<avalanche>])
11832 Hashes a binary input sample into an unsigned 32-bit quantity using the SDBM
11833 hash function. Optionally, it is possible to apply a full avalanche hash
11834 function to the output if the optional <avalanche> argument equals 1. This
11835 converter uses the same functions as used by the various hash-based load
11836 balancing algorithms, so it will provide exactly the same results. It is
11837 mostly intended for debugging, but can be used as a stick-table entry to
11838 collect rough statistics. It must not be used for security purposes as a
Willy Tarreau80599772015-01-20 19:35:24 +010011839 32-bit hash is trivial to break. See also "crc32", "djb2", "wt6" and the
11840 "hash-type" directive.
Willy Tarreau23ec4ca2014-07-15 20:15:37 +020011841
Thierry FOURNIER4834bc72015-06-06 19:29:07 +020011842set-var(<var name>)
11843 Sets a variable with the input content and return the content on the output as
11844 is. The variable keep the value and the associated input type. The name of the
11845 variable starts by an indication about it scope. The scope allowed are:
11846 "sess" : the variable is shared with all the session,
11847 "txn" : the variable is shared with all the transaction (request and
11848 response),
11849 "req" : the variable is shared only during the request processing,
11850 "res" : the variable is shared only during the response processing.
11851 This prefix is followed by a name. The separator is a '.'. The name may only
11852 contain characters 'a-z', 'A-Z', '0-9' and '_'.
11853
Willy Tarreau97707872015-01-27 15:12:13 +010011854sub(<value>)
Thierry FOURNIER07ee64e2015-07-06 23:43:03 +020011855 Subtracts <value> from the input value of type signed integer, and returns
11856 the result as an signed integer. Note: in order to subtract the input from
Thierry FOURNIER5d86fae2015-07-07 21:10:16 +020011857 a constant, simply perform a "neg,add(value)". <value> can be a numeric value
11858 or a variable name. The name of the variable starts by an indication about its
11859 scope. The allowed scopes are:
11860 "sess" : the variable is shared with all the session,
11861 "txn" : the variable is shared with all the transaction (request and
11862 response),
11863 "req" : the variable is shared only during the request processing,
11864 "res" : the variable is shared only during the response processing.
11865 This prefix is followed by a name. The separator is a '.'. The name may only
11866 contain characters 'a-z', 'A-Z', '0-9' and '_'.
Willy Tarreau97707872015-01-27 15:12:13 +010011867
Willy Tarreaud9f316a2014-07-10 14:03:38 +020011868table_bytes_in_rate(<table>)
11869 Uses the string representation of the input sample to perform a look up in
11870 the specified table. If the key is not found in the table, integer value zero
11871 is returned. Otherwise the converter returns the average client-to-server
11872 bytes rate associated with the input sample in the designated table, measured
11873 in amount of bytes over the period configured in the table. See also the
11874 sc_bytes_in_rate sample fetch keyword.
11875
11876
11877table_bytes_out_rate(<table>)
11878 Uses the string representation of the input sample to perform a look up in
11879 the specified table. If the key is not found in the table, integer value zero
11880 is returned. Otherwise the converter returns the average server-to-client
11881 bytes rate associated with the input sample in the designated table, measured
11882 in amount of bytes over the period configured in the table. See also the
11883 sc_bytes_out_rate sample fetch keyword.
11884
11885table_conn_cnt(<table>)
11886 Uses the string representation of the input sample to perform a look up in
11887 the specified table. If the key is not found in the table, integer value zero
11888 is returned. Otherwise the converter returns the cumulated amount of incoming
11889 connections associated with the input sample in the designated table. See
11890 also the sc_conn_cnt sample fetch keyword.
11891
11892table_conn_cur(<table>)
11893 Uses the string representation of the input sample to perform a look up in
11894 the specified table. If the key is not found in the table, integer value zero
11895 is returned. Otherwise the converter returns the current amount of concurrent
11896 tracked connections associated with the input sample in the designated table.
11897 See also the sc_conn_cur sample fetch keyword.
11898
11899table_conn_rate(<table>)
11900 Uses the string representation of the input sample to perform a look up in
11901 the specified table. If the key is not found in the table, integer value zero
11902 is returned. Otherwise the converter returns the average incoming connection
11903 rate associated with the input sample in the designated table. See also the
11904 sc_conn_rate sample fetch keyword.
11905
Thierry FOURNIER236657b2015-08-19 08:25:14 +020011906table_gpt0(<table>)
11907 Uses the string representation of the input sample to perform a look up in
11908 the specified table. If the key is not found in the table, boolean value zero
11909 is returned. Otherwise the converter returns the current value of the first
11910 general purpose tag associated with the input sample in the designated table.
11911 See also the sc_get_gpt0 sample fetch keyword.
11912
Willy Tarreaud9f316a2014-07-10 14:03:38 +020011913table_gpc0(<table>)
11914 Uses the string representation of the input sample to perform a look up in
11915 the specified table. If the key is not found in the table, integer value zero
11916 is returned. Otherwise the converter returns the current value of the first
11917 general purpose counter associated with the input sample in the designated
11918 table. See also the sc_get_gpc0 sample fetch keyword.
11919
11920table_gpc0_rate(<table>)
11921 Uses the string representation of the input sample to perform a look up in
11922 the specified table. If the key is not found in the table, integer value zero
11923 is returned. Otherwise the converter returns the frequency which the gpc0
11924 counter was incremented over the configured period in the table, associated
11925 with the input sample in the designated table. See also the sc_get_gpc0_rate
11926 sample fetch keyword.
11927
11928table_http_err_cnt(<table>)
11929 Uses the string representation of the input sample to perform a look up in
11930 the specified table. If the key is not found in the table, integer value zero
11931 is returned. Otherwise the converter returns the cumulated amount of HTTP
11932 errors associated with the input sample in the designated table. See also the
11933 sc_http_err_cnt sample fetch keyword.
11934
11935table_http_err_rate(<table>)
11936 Uses the string representation of the input sample to perform a look up in
11937 the specified table. If the key is not found in the table, integer value zero
11938 is returned. Otherwise the average rate of HTTP errors associated with the
11939 input sample in the designated table, measured in amount of errors over the
11940 period configured in the table. See also the sc_http_err_rate sample fetch
11941 keyword.
11942
11943table_http_req_cnt(<table>)
11944 Uses the string representation of the input sample to perform a look up in
11945 the specified table. If the key is not found in the table, integer value zero
11946 is returned. Otherwise the converter returns the cumulated amount of HTTP
11947 requests associated with the input sample in the designated table. See also
11948 the sc_http_req_cnt sample fetch keyword.
11949
11950table_http_req_rate(<table>)
11951 Uses the string representation of the input sample to perform a look up in
11952 the specified table. If the key is not found in the table, integer value zero
11953 is returned. Otherwise the average rate of HTTP requests associated with the
11954 input sample in the designated table, measured in amount of requests over the
11955 period configured in the table. See also the sc_http_req_rate sample fetch
11956 keyword.
11957
11958table_kbytes_in(<table>)
11959 Uses the string representation of the input sample to perform a look up in
11960 the specified table. If the key is not found in the table, integer value zero
11961 is returned. Otherwise the converter returns the cumulated amount of client-
11962 to-server data associated with the input sample in the designated table,
11963 measured in kilobytes. The test is currently performed on 32-bit integers,
11964 which limits values to 4 terabytes. See also the sc_kbytes_in sample fetch
11965 keyword.
11966
11967table_kbytes_out(<table>)
11968 Uses the string representation of the input sample to perform a look up in
11969 the specified table. If the key is not found in the table, integer value zero
11970 is returned. Otherwise the converter returns the cumulated amount of server-
11971 to-client data associated with the input sample in the designated table,
11972 measured in kilobytes. The test is currently performed on 32-bit integers,
11973 which limits values to 4 terabytes. See also the sc_kbytes_out sample fetch
11974 keyword.
11975
11976table_server_id(<table>)
11977 Uses the string representation of the input sample to perform a look up in
11978 the specified table. If the key is not found in the table, integer value zero
11979 is returned. Otherwise the converter returns the server ID associated with
11980 the input sample in the designated table. A server ID is associated to a
11981 sample by a "stick" rule when a connection to a server succeeds. A server ID
11982 zero means that no server is associated with this key.
11983
11984table_sess_cnt(<table>)
11985 Uses the string representation of the input sample to perform a look up in
11986 the specified table. If the key is not found in the table, integer value zero
11987 is returned. Otherwise the converter returns the cumulated amount of incoming
11988 sessions associated with the input sample in the designated table. Note that
11989 a session here refers to an incoming connection being accepted by the
11990 "tcp-request connection" rulesets. See also the sc_sess_cnt sample fetch
11991 keyword.
11992
11993table_sess_rate(<table>)
11994 Uses the string representation of the input sample to perform a look up in
11995 the specified table. If the key is not found in the table, integer value zero
11996 is returned. Otherwise the converter returns the average incoming session
11997 rate associated with the input sample in the designated table. Note that a
11998 session here refers to an incoming connection being accepted by the
11999 "tcp-request connection" rulesets. See also the sc_sess_rate sample fetch
12000 keyword.
12001
12002table_trackers(<table>)
12003 Uses the string representation of the input sample to perform a look up in
12004 the specified table. If the key is not found in the table, integer value zero
12005 is returned. Otherwise the converter returns the current amount of concurrent
12006 connections tracking the same key as the input sample in the designated
12007 table. It differs from table_conn_cur in that it does not rely on any stored
12008 information but on the table's reference count (the "use" value which is
12009 returned by "show table" on the CLI). This may sometimes be more suited for
12010 layer7 tracking. It can be used to tell a server how many concurrent
12011 connections there are from a given address for example. See also the
12012 sc_trackers sample fetch keyword.
12013
Willy Tarreauffcb2e42014-07-10 16:29:08 +020012014upper
12015 Convert a string sample to upper case. This can only be placed after a string
12016 sample fetch function or after a transformation keyword returning a string
12017 type. The result is of type string.
12018
Thierry FOURNIER82ff3c92015-05-07 15:46:20 +020012019url_dec
12020 Takes an url-encoded string provided as input and returns the decoded
12021 version as output. The input and the output are of type string.
12022
Willy Tarreau0dbfdba2014-07-10 16:37:47 +020012023utime(<format>[,<offset>])
12024 Converts an integer supposed to contain a date since epoch to a string
12025 representing this date in UTC time using a format defined by the <format>
12026 string using strftime(3). The purpose is to allow any date format to be used
12027 in logs. An optional <offset> in seconds may be applied to the input date
12028 (positive or negative). See the strftime() man page for the format supported
12029 by your operating system. See also the ltime converter.
12030
12031 Example :
12032
12033 # Emit two colons, one with the UTC time and another with ip:port
12034 # Eg: 20140710162350 127.0.0.1:57325
12035 log-format %[date,utime(%Y%m%d%H%M%S)]\ %ci:%cp
12036
Emeric Brunc9a0f6d2014-11-25 14:09:01 +010012037word(<index>,<delimiters>)
12038 Extracts the nth word considering given delimiters from an input string.
12039 Indexes start at 1 and delimiters are a string formatted list of chars.
12040
Willy Tarreau23ec4ca2014-07-15 20:15:37 +020012041wt6([<avalanche>])
12042 Hashes a binary input sample into an unsigned 32-bit quantity using the WT6
12043 hash function. Optionally, it is possible to apply a full avalanche hash
12044 function to the output if the optional <avalanche> argument equals 1. This
12045 converter uses the same functions as used by the various hash-based load
12046 balancing algorithms, so it will provide exactly the same results. It is
12047 mostly intended for debugging, but can be used as a stick-table entry to
12048 collect rough statistics. It must not be used for security purposes as a
Willy Tarreau80599772015-01-20 19:35:24 +010012049 32-bit hash is trivial to break. See also "crc32", "djb2", "sdbm", and the
12050 "hash-type" directive.
Willy Tarreau23ec4ca2014-07-15 20:15:37 +020012051
Willy Tarreau97707872015-01-27 15:12:13 +010012052xor(<value>)
12053 Performs a bitwise "XOR" (exclusive OR) between <value> and the input value
Thierry FOURNIER07ee64e2015-07-06 23:43:03 +020012054 of type signed integer, and returns the result as an signed integer.
Thierry FOURNIER5d86fae2015-07-07 21:10:16 +020012055 <value> can be a numeric value or a variable name. The name of the variable
12056 starts by an indication about its scope. The allowed scopes are:
12057 "sess" : the variable is shared with all the session,
12058 "txn" : the variable is shared with all the transaction (request and
12059 response),
12060 "req" : the variable is shared only during the request processing,
12061 "res" : the variable is shared only during the response processing.
12062 This prefix is followed by a name. The separator is a '.'. The name may only
12063 contain characters 'a-z', 'A-Z', '0-9' and '_'.
Willy Tarreau97707872015-01-27 15:12:13 +010012064
Thierry FOURNIERd5f624d2013-11-26 11:52:33 +010012065
Thierry FOURNIER060762e2014-04-23 13:29:15 +0200120667.3.2. Fetching samples from internal states
Willy Tarreau74ca5042013-06-11 23:12:07 +020012067--------------------------------------------
12068
12069A first set of sample fetch methods applies to internal information which does
12070not even relate to any client information. These ones are sometimes used with
12071"monitor-fail" directives to report an internal status to external watchers.
12072The sample fetch methods described in this section are usable anywhere.
12073
12074always_false : boolean
12075 Always returns the boolean "false" value. It may be used with ACLs as a
12076 temporary replacement for another one when adjusting configurations.
12077
12078always_true : boolean
12079 Always returns the boolean "true" value. It may be used with ACLs as a
12080 temporary replacement for another one when adjusting configurations.
12081
12082avg_queue([<backend>]) : integer
Willy Tarreaud63335a2010-02-26 12:56:52 +010012083 Returns the total number of queued connections of the designated backend
Willy Tarreau74ca5042013-06-11 23:12:07 +020012084 divided by the number of active servers. The current backend is used if no
12085 backend is specified. This is very similar to "queue" except that the size of
12086 the farm is considered, in order to give a more accurate measurement of the
12087 time it may take for a new connection to be processed. The main usage is with
12088 ACL to return a sorry page to new users when it becomes certain they will get
12089 a degraded service, or to pass to the backend servers in a header so that
12090 they decide to work in degraded mode or to disable some functions to speed up
12091 the processing a bit. Note that in the event there would not be any active
12092 server anymore, twice the number of queued connections would be considered as
12093 the measured value. This is a fair estimate, as we expect one server to get
12094 back soon anyway, but we still prefer to send new traffic to another backend
12095 if in better shape. See also the "queue", "be_conn", and "be_sess_rate"
12096 sample fetches.
Krzysztof Piotr Oledzki346f76d2010-01-12 21:59:30 +010012097
Willy Tarreau74ca5042013-06-11 23:12:07 +020012098be_conn([<backend>]) : integer
Willy Tarreaua36af912009-10-10 12:02:45 +020012099 Applies to the number of currently established connections on the backend,
12100 possibly including the connection being evaluated. If no backend name is
12101 specified, the current one is used. But it is also possible to check another
12102 backend. It can be used to use a specific farm when the nominal one is full.
12103 See also the "fe_conn", "queue" and "be_sess_rate" criteria.
Willy Tarreau6a06a402007-07-15 20:15:28 +020012104
Willy Tarreau74ca5042013-06-11 23:12:07 +020012105be_sess_rate([<backend>]) : integer
12106 Returns an integer value corresponding to the sessions creation rate on the
12107 backend, in number of new sessions per second. This is used with ACLs to
12108 switch to an alternate backend when an expensive or fragile one reaches too
12109 high a session rate, or to limit abuse of service (eg. prevent sucking of an
12110 online dictionary). It can also be useful to add this element to logs using a
12111 log-format directive.
Willy Tarreaud63335a2010-02-26 12:56:52 +010012112
12113 Example :
12114 # Redirect to an error page if the dictionary is requested too often
12115 backend dynamic
12116 mode http
12117 acl being_scanned be_sess_rate gt 100
12118 redirect location /denied.html if being_scanned
Willy Tarreau0ba27502007-12-24 16:55:16 +010012119
Thierry FOURNIERcc103292015-06-06 19:30:17 +020012120bin(<hexa>) : bin
12121 Returns a binary chain. The input is the hexadecimal representation
12122 of the string.
12123
12124bool(<bool>) : bool
12125 Returns a boolean value. <bool> can be 'true', 'false', '1' or '0'.
12126 'false' and '0' are the same. 'true' and '1' are the same.
12127
Willy Tarreau74ca5042013-06-11 23:12:07 +020012128connslots([<backend>]) : integer
12129 Returns an integer value corresponding to the number of connection slots
Jarno Huuskonen0e82b922014-04-12 18:22:19 +030012130 still available in the backend, by totaling the maximum amount of
Willy Tarreau74ca5042013-06-11 23:12:07 +020012131 connections on all servers and the maximum queue size. This is probably only
12132 used with ACLs.
Tait Clarridge7896d522012-12-05 21:39:31 -050012133
Jeffrey 'jf' Lim5051d7b2008-09-04 01:03:03 +080012134 The basic idea here is to be able to measure the number of connection "slots"
Willy Tarreau55165fe2009-05-10 12:02:55 +020012135 still available (connection + queue), so that anything beyond that (intended
Jeffrey 'jf' Lim5051d7b2008-09-04 01:03:03 +080012136 usage; see "use_backend" keyword) can be redirected to a different backend.
12137
Willy Tarreau55165fe2009-05-10 12:02:55 +020012138 'connslots' = number of available server connection slots, + number of
12139 available server queue slots.
Jeffrey 'jf' Lim5051d7b2008-09-04 01:03:03 +080012140
Willy Tarreaua36af912009-10-10 12:02:45 +020012141 Note that while "fe_conn" may be used, "connslots" comes in especially
Willy Tarreau55165fe2009-05-10 12:02:55 +020012142 useful when you have a case of traffic going to one single ip, splitting into
Willy Tarreau74ca5042013-06-11 23:12:07 +020012143 multiple backends (perhaps using ACLs to do name-based load balancing) and
Willy Tarreau55165fe2009-05-10 12:02:55 +020012144 you want to be able to differentiate between different backends, and their
12145 available "connslots". Also, whereas "nbsrv" only measures servers that are
Willy Tarreau74ca5042013-06-11 23:12:07 +020012146 actually *down*, this fetch is more fine-grained and looks into the number of
Willy Tarreaua36af912009-10-10 12:02:45 +020012147 available connection slots as well. See also "queue" and "avg_queue".
Jeffrey 'jf' Lim5051d7b2008-09-04 01:03:03 +080012148
Willy Tarreau55165fe2009-05-10 12:02:55 +020012149 OTHER CAVEATS AND NOTES: at this point in time, the code does not take care
12150 of dynamic connections. Also, if any of the server maxconn, or maxqueue is 0,
Willy Tarreau74ca5042013-06-11 23:12:07 +020012151 then this fetch clearly does not make sense, in which case the value returned
Willy Tarreau55165fe2009-05-10 12:02:55 +020012152 will be -1.
Jeffrey 'jf' Lim5051d7b2008-09-04 01:03:03 +080012153
Willy Tarreau6236d3a2013-07-25 14:28:25 +020012154date([<offset>]) : integer
12155 Returns the current date as the epoch (number of seconds since 01/01/1970).
12156 If an offset value is specified, then it is a number of seconds that is added
12157 to the current date before returning the value. This is particularly useful
12158 to compute relative dates, as both positive and negative offsets are allowed.
Willy Tarreau276fae92013-07-25 14:36:01 +020012159 It is useful combined with the http_date converter.
12160
12161 Example :
12162
12163 # set an expires header to now+1 hour in every response
12164 http-response set-header Expires %[date(3600),http_date]
Willy Tarreau6236d3a2013-07-25 14:28:25 +020012165
Willy Tarreau595ec542013-06-12 21:34:28 +020012166env(<name>) : string
12167 Returns a string containing the value of environment variable <name>. As a
12168 reminder, environment variables are per-process and are sampled when the
12169 process starts. This can be useful to pass some information to a next hop
12170 server, or with ACLs to take specific action when the process is started a
12171 certain way.
12172
12173 Examples :
12174 # Pass the Via header to next hop with the local hostname in it
12175 http-request add-header Via 1.1\ %[env(HOSTNAME)]
12176
12177 # reject cookie-less requests when the STOP environment variable is set
12178 http-request deny if !{ cook(SESSIONID) -m found } { env(STOP) -m found }
12179
Willy Tarreau74ca5042013-06-11 23:12:07 +020012180fe_conn([<frontend>]) : integer
12181 Returns the number of currently established connections on the frontend,
Willy Tarreaud63335a2010-02-26 12:56:52 +010012182 possibly including the connection being evaluated. If no frontend name is
12183 specified, the current one is used. But it is also possible to check another
Willy Tarreau74ca5042013-06-11 23:12:07 +020012184 frontend. It can be used to return a sorry page before hard-blocking, or to
12185 use a specific backend to drain new requests when the farm is considered
12186 full. This is mostly used with ACLs but can also be used to pass some
12187 statistics to servers in HTTP headers. See also the "dst_conn", "be_conn",
12188 "fe_sess_rate" fetches.
Willy Tarreaua36af912009-10-10 12:02:45 +020012189
Willy Tarreau74ca5042013-06-11 23:12:07 +020012190fe_sess_rate([<frontend>]) : integer
12191 Returns an integer value corresponding to the sessions creation rate on the
12192 frontend, in number of new sessions per second. This is used with ACLs to
12193 limit the incoming session rate to an acceptable range in order to prevent
12194 abuse of service at the earliest moment, for example when combined with other
12195 layer 4 ACLs in order to force the clients to wait a bit for the rate to go
12196 down below the limit. It can also be useful to add this element to logs using
12197 a log-format directive. See also the "rate-limit sessions" directive for use
12198 in frontends.
Willy Tarreau079ff0a2009-03-05 21:34:28 +010012199
12200 Example :
12201 # This frontend limits incoming mails to 10/s with a max of 100
12202 # concurrent connections. We accept any connection below 10/s, and
12203 # force excess clients to wait for 100 ms. Since clients are limited to
12204 # 100 max, there cannot be more than 10 incoming mails per second.
12205 frontend mail
12206 bind :25
12207 mode tcp
12208 maxconn 100
12209 acl too_fast fe_sess_rate ge 10
12210 tcp-request inspect-delay 100ms
12211 tcp-request content accept if ! too_fast
12212 tcp-request content accept if WAIT_END
Willy Tarreaud72758d2010-01-12 10:42:19 +010012213
Thierry FOURNIER07ee64e2015-07-06 23:43:03 +020012214int(<integer>) : signed integer
12215 Returns a signed integer.
12216
Thierry FOURNIERcc103292015-06-06 19:30:17 +020012217ipv4(<ipv4>) : ipv4
12218 Returns an ipv4.
12219
12220ipv6(<ipv6>) : ipv6
12221 Returns an ipv6.
12222
12223meth(<method>) : method
12224 Returns a method.
12225
Willy Tarreau0f30d262014-11-24 16:02:05 +010012226nbproc : integer
12227 Returns an integer value corresponding to the number of processes that were
12228 started (it equals the global "nbproc" setting). This is useful for logging
12229 and debugging purposes.
12230
Willy Tarreau74ca5042013-06-11 23:12:07 +020012231nbsrv([<backend>]) : integer
12232 Returns an integer value corresponding to the number of usable servers of
12233 either the current backend or the named backend. This is mostly used with
12234 ACLs but can also be useful when added to logs. This is normally used to
Willy Tarreaud63335a2010-02-26 12:56:52 +010012235 switch to an alternate backend when the number of servers is too low to
12236 to handle some load. It is useful to report a failure when combined with
12237 "monitor fail".
Willy Tarreau079ff0a2009-03-05 21:34:28 +010012238
Willy Tarreau0f30d262014-11-24 16:02:05 +010012239proc : integer
12240 Returns an integer value corresponding to the position of the process calling
12241 the function, between 1 and global.nbproc. This is useful for logging and
12242 debugging purposes.
12243
Willy Tarreau74ca5042013-06-11 23:12:07 +020012244queue([<backend>]) : integer
Willy Tarreaud63335a2010-02-26 12:56:52 +010012245 Returns the total number of queued connections of the designated backend,
12246 including all the connections in server queues. If no backend name is
12247 specified, the current one is used, but it is also possible to check another
Willy Tarreau74ca5042013-06-11 23:12:07 +020012248 one. This is useful with ACLs or to pass statistics to backend servers. This
12249 can be used to take actions when queuing goes above a known level, generally
12250 indicating a surge of traffic or a massive slowdown on the servers. One
12251 possible action could be to reject new users but still accept old ones. See
12252 also the "avg_queue", "be_conn", and "be_sess_rate" fetches.
12253
Willy Tarreau84310e22014-02-14 11:59:04 +010012254rand([<range>]) : integer
12255 Returns a random integer value within a range of <range> possible values,
12256 starting at zero. If the range is not specified, it defaults to 2^32, which
12257 gives numbers between 0 and 4294967295. It can be useful to pass some values
12258 needed to take some routing decisions for example, or just for debugging
12259 purposes. This random must not be used for security purposes.
12260
Willy Tarreau74ca5042013-06-11 23:12:07 +020012261srv_conn([<backend>/]<server>) : integer
12262 Returns an integer value corresponding to the number of currently established
12263 connections on the designated server, possibly including the connection being
12264 evaluated. If <backend> is omitted, then the server is looked up in the
12265 current backend. It can be used to use a specific farm when one server is
12266 full, or to inform the server about our view of the number of active
12267 connections with it. See also the "fe_conn", "be_conn" and "queue" fetch
12268 methods.
12269
12270srv_is_up([<backend>/]<server>) : boolean
12271 Returns true when the designated server is UP, and false when it is either
12272 DOWN or in maintenance mode. If <backend> is omitted, then the server is
12273 looked up in the current backend. It is mainly used to take action based on
12274 an external status reported via a health check (eg: a geographical site's
12275 availability). Another possible use which is more of a hack consists in
12276 using dummy servers as boolean variables that can be enabled or disabled from
12277 the CLI, so that rules depending on those ACLs can be tweaked in realtime.
12278
12279srv_sess_rate([<backend>/]<server>) : integer
12280 Returns an integer corresponding to the sessions creation rate on the
12281 designated server, in number of new sessions per second. If <backend> is
Jarno Huuskonen0e82b922014-04-12 18:22:19 +030012282 omitted, then the server is looked up in the current backend. This is mostly
Willy Tarreau74ca5042013-06-11 23:12:07 +020012283 used with ACLs but can make sense with logs too. This is used to switch to an
12284 alternate backend when an expensive or fragile one reaches too high a session
12285 rate, or to limit abuse of service (eg. prevent latent requests from
12286 overloading servers).
12287
12288 Example :
12289 # Redirect to a separate back
12290 acl srv1_full srv_sess_rate(be1/srv1) gt 50
12291 acl srv2_full srv_sess_rate(be1/srv2) gt 50
12292 use_backend be2 if srv1_full or srv2_full
12293
Willy Tarreau0f30d262014-11-24 16:02:05 +010012294stopping : boolean
12295 Returns TRUE if the process calling the function is currently stopping. This
12296 can be useful for logging, or for relaxing certain checks or helping close
12297 certain connections upon graceful shutdown.
12298
Thierry FOURNIERcc103292015-06-06 19:30:17 +020012299str(<string>) : string
12300 Returns a string.
12301
Willy Tarreau74ca5042013-06-11 23:12:07 +020012302table_avl([<table>]) : integer
12303 Returns the total number of available entries in the current proxy's
12304 stick-table or in the designated stick-table. See also table_cnt.
12305
12306table_cnt([<table>]) : integer
12307 Returns the total number of entries currently in use in the current proxy's
12308 stick-table or in the designated stick-table. See also src_conn_cnt and
12309 table_avl for other entry counting methods.
12310
Thierry FOURNIER4834bc72015-06-06 19:29:07 +020012311var(<var-name>) : undefined
12312 Returns a variable with the stored type. If the variable is not set, the
12313 sample fetch fails. The name of the variable starts by an indication about its
12314 scope. The scope allowed are:
12315 "sess" : the variable is shared with all the session,
12316 "txn" : the variable is shared with all the transaction (request and
12317 response),
12318 "req" : the variable is shared only during the request processing,
12319 "res" : the variable is shared only during the response processing.
12320 This prefix is followed by a name. The separator is a '.'. The name may only
12321 contain characters 'a-z', 'A-Z', '0-9' and '_'.
12322
Willy Tarreau74ca5042013-06-11 23:12:07 +020012323
Thierry FOURNIER060762e2014-04-23 13:29:15 +0200123247.3.3. Fetching samples at Layer 4
Willy Tarreau74ca5042013-06-11 23:12:07 +020012325----------------------------------
12326
12327The layer 4 usually describes just the transport layer which in haproxy is
12328closest to the connection, where no content is yet made available. The fetch
12329methods described here are usable as low as the "tcp-request connection" rule
12330sets unless they require some future information. Those generally include
12331TCP/IP addresses and ports, as well as elements from stick-tables related to
Willy Tarreau4d4149c2013-07-23 19:33:46 +020012332the incoming connection. For retrieving a value from a sticky counters, the
12333counter number can be explicitly set as 0, 1, or 2 using the pre-defined
12334"sc0_", "sc1_", or "sc2_" prefix, or it can be specified as the first integer
Willy Tarreau0f791d42013-07-23 19:56:43 +020012335argument when using the "sc_" prefix. An optional table may be specified with
12336the "sc*" form, in which case the currently tracked key will be looked up into
12337this alternate table instead of the table currently being tracked.
Willy Tarreau74ca5042013-06-11 23:12:07 +020012338
12339be_id : integer
12340 Returns an integer containing the current backend's id. It can be used in
12341 frontends with responses to check which backend processed the request.
12342
12343dst : ip
12344 This is the destination IPv4 address of the connection on the client side,
12345 which is the address the client connected to. It can be useful when running
12346 in transparent mode. It is of type IP and works on both IPv4 and IPv6 tables.
12347 On IPv6 tables, IPv4 address is mapped to its IPv6 equivalent, according to
12348 RFC 4291.
12349
12350dst_conn : integer
12351 Returns an integer value corresponding to the number of currently established
12352 connections on the same socket including the one being evaluated. It is
12353 normally used with ACLs but can as well be used to pass the information to
12354 servers in an HTTP header or in logs. It can be used to either return a sorry
12355 page before hard-blocking, or to use a specific backend to drain new requests
12356 when the socket is considered saturated. This offers the ability to assign
12357 different limits to different listening ports or addresses. See also the
12358 "fe_conn" and "be_conn" fetches.
Willy Tarreaud63335a2010-02-26 12:56:52 +010012359
Willy Tarreau74ca5042013-06-11 23:12:07 +020012360dst_port : integer
12361 Returns an integer value corresponding to the destination TCP port of the
12362 connection on the client side, which is the port the client connected to.
12363 This might be used when running in transparent mode, when assigning dynamic
12364 ports to some clients for a whole application session, to stick all users to
12365 a same server, or to pass the destination port information to a server using
12366 an HTTP header.
12367
12368fe_id : integer
12369 Returns an integer containing the current frontend's id. It can be used in
12370 backends to check from which backend it was called, or to stick all users
12371 coming via a same frontend to the same server.
12372
Cyril Bonté62ba8702014-04-22 23:52:25 +020012373sc_bytes_in_rate(<ctr>[,<table>]) : integer
Willy Tarreau0f791d42013-07-23 19:56:43 +020012374sc0_bytes_in_rate([<table>]) : integer
12375sc1_bytes_in_rate([<table>]) : integer
12376sc2_bytes_in_rate([<table>]) : integer
Willy Tarreaue9656522010-08-17 15:40:09 +020012377 Returns the average client-to-server bytes rate from the currently tracked
12378 counters, measured in amount of bytes over the period configured in the
12379 table. See also src_bytes_in_rate.
12380
Cyril Bonté62ba8702014-04-22 23:52:25 +020012381sc_bytes_out_rate(<ctr>[,<table>]) : integer
Willy Tarreau0f791d42013-07-23 19:56:43 +020012382sc0_bytes_out_rate([<table>]) : integer
12383sc1_bytes_out_rate([<table>]) : integer
12384sc2_bytes_out_rate([<table>]) : integer
Willy Tarreaue9656522010-08-17 15:40:09 +020012385 Returns the average server-to-client bytes rate from the currently tracked
12386 counters, measured in amount of bytes over the period configured in the
12387 table. See also src_bytes_out_rate.
12388
Cyril Bonté62ba8702014-04-22 23:52:25 +020012389sc_clr_gpc0(<ctr>[,<table>]) : integer
Willy Tarreau0f791d42013-07-23 19:56:43 +020012390sc0_clr_gpc0([<table>]) : integer
12391sc1_clr_gpc0([<table>]) : integer
12392sc2_clr_gpc0([<table>]) : integer
Willy Tarreauf73cd112011-08-13 01:45:16 +020012393 Clears the first General Purpose Counter associated to the currently tracked
12394 counters, and returns its previous value. Before the first invocation, the
Willy Tarreau869948b2013-01-04 14:14:57 +010012395 stored value is zero, so first invocation will always return zero. This is
12396 typically used as a second ACL in an expression in order to mark a connection
12397 when a first ACL was verified :
Willy Tarreauf73cd112011-08-13 01:45:16 +020012398
12399 # block if 5 consecutive requests continue to come faster than 10 sess
12400 # per second, and reset the counter as soon as the traffic slows down.
Willy Tarreaube4a3ef2013-06-17 15:04:07 +020012401 acl abuse sc0_http_req_rate gt 10
12402 acl kill sc0_inc_gpc0 gt 5
12403 acl save sc0_clr_gpc0 ge 0
Willy Tarreauf73cd112011-08-13 01:45:16 +020012404 tcp-request connection accept if !abuse save
12405 tcp-request connection reject if abuse kill
12406
Cyril Bonté62ba8702014-04-22 23:52:25 +020012407sc_conn_cnt(<ctr>[,<table>]) : integer
Willy Tarreau0f791d42013-07-23 19:56:43 +020012408sc0_conn_cnt([<table>]) : integer
12409sc1_conn_cnt([<table>]) : integer
12410sc2_conn_cnt([<table>]) : integer
Willy Tarreaue9656522010-08-17 15:40:09 +020012411 Returns the cumulated number of incoming connections from currently tracked
12412 counters. See also src_conn_cnt.
12413
Cyril Bonté62ba8702014-04-22 23:52:25 +020012414sc_conn_cur(<ctr>[,<table>]) : integer
Willy Tarreau0f791d42013-07-23 19:56:43 +020012415sc0_conn_cur([<table>]) : integer
12416sc1_conn_cur([<table>]) : integer
12417sc2_conn_cur([<table>]) : integer
Willy Tarreaue9656522010-08-17 15:40:09 +020012418 Returns the current amount of concurrent connections tracking the same
12419 tracked counters. This number is automatically incremented when tracking
12420 begins and decremented when tracking stops. See also src_conn_cur.
12421
Cyril Bonté62ba8702014-04-22 23:52:25 +020012422sc_conn_rate(<ctr>[,<table>]) : integer
Willy Tarreau0f791d42013-07-23 19:56:43 +020012423sc0_conn_rate([<table>]) : integer
12424sc1_conn_rate([<table>]) : integer
12425sc2_conn_rate([<table>]) : integer
Willy Tarreaue9656522010-08-17 15:40:09 +020012426 Returns the average connection rate from the currently tracked counters,
12427 measured in amount of connections over the period configured in the table.
12428 See also src_conn_rate.
12429
Cyril Bonté62ba8702014-04-22 23:52:25 +020012430sc_get_gpc0(<ctr>[,<table>]) : integer
Willy Tarreau0f791d42013-07-23 19:56:43 +020012431sc0_get_gpc0([<table>]) : integer
12432sc1_get_gpc0([<table>]) : integer
12433sc2_get_gpc0([<table>]) : integer
Willy Tarreaue9656522010-08-17 15:40:09 +020012434 Returns the value of the first General Purpose Counter associated to the
Willy Tarreau4d4149c2013-07-23 19:33:46 +020012435 currently tracked counters. See also src_get_gpc0 and sc/sc0/sc1/sc2_inc_gpc0.
Willy Tarreauba2ffd12013-05-29 15:54:14 +020012436
Thierry FOURNIER236657b2015-08-19 08:25:14 +020012437sc_get_gpt0(<ctr>[,<table>]) : integer
12438sc0_get_gpt0([<table>]) : integer
12439sc1_get_gpt0([<table>]) : integer
12440sc2_get_gpt0([<table>]) : integer
12441 Returns the value of the first General Purpose Tag associated to the
12442 currently tracked counters. See also src_get_gpt0.
12443
Cyril Bonté62ba8702014-04-22 23:52:25 +020012444sc_gpc0_rate(<ctr>[,<table>]) : integer
Willy Tarreau0f791d42013-07-23 19:56:43 +020012445sc0_gpc0_rate([<table>]) : integer
12446sc1_gpc0_rate([<table>]) : integer
12447sc2_gpc0_rate([<table>]) : integer
Willy Tarreauba2ffd12013-05-29 15:54:14 +020012448 Returns the average increment rate of the first General Purpose Counter
12449 associated to the currently tracked counters. It reports the frequency
12450 which the gpc0 counter was incremented over the configured period. See also
Willy Tarreau4d4149c2013-07-23 19:33:46 +020012451 src_gpc0_rate, sc/sc0/sc1/sc2_get_gpc0, and sc/sc0/sc1/sc2_inc_gpc0. Note
12452 that the "gpc0_rate" counter must be stored in the stick-table for a value to
12453 be returned, as "gpc0" only holds the event count.
Willy Tarreaue9656522010-08-17 15:40:09 +020012454
Cyril Bonté62ba8702014-04-22 23:52:25 +020012455sc_http_err_cnt(<ctr>[,<table>]) : integer
Willy Tarreau0f791d42013-07-23 19:56:43 +020012456sc0_http_err_cnt([<table>]) : integer
12457sc1_http_err_cnt([<table>]) : integer
12458sc2_http_err_cnt([<table>]) : integer
Willy Tarreaue9656522010-08-17 15:40:09 +020012459 Returns the cumulated number of HTTP errors from the currently tracked
12460 counters. This includes the both request errors and 4xx error responses.
12461 See also src_http_err_cnt.
12462
Cyril Bonté62ba8702014-04-22 23:52:25 +020012463sc_http_err_rate(<ctr>[,<table>]) : integer
Willy Tarreau0f791d42013-07-23 19:56:43 +020012464sc0_http_err_rate([<table>]) : integer
12465sc1_http_err_rate([<table>]) : integer
12466sc2_http_err_rate([<table>]) : integer
Willy Tarreaue9656522010-08-17 15:40:09 +020012467 Returns the average rate of HTTP errors from the currently tracked counters,
12468 measured in amount of errors over the period configured in the table. This
12469 includes the both request errors and 4xx error responses. See also
12470 src_http_err_rate.
12471
Cyril Bonté62ba8702014-04-22 23:52:25 +020012472sc_http_req_cnt(<ctr>[,<table>]) : integer
Willy Tarreau0f791d42013-07-23 19:56:43 +020012473sc0_http_req_cnt([<table>]) : integer
12474sc1_http_req_cnt([<table>]) : integer
12475sc2_http_req_cnt([<table>]) : integer
Willy Tarreaue9656522010-08-17 15:40:09 +020012476 Returns the cumulated number of HTTP requests from the currently tracked
12477 counters. This includes every started request, valid or not. See also
12478 src_http_req_cnt.
12479
Cyril Bonté62ba8702014-04-22 23:52:25 +020012480sc_http_req_rate(<ctr>[,<table>]) : integer
Willy Tarreau0f791d42013-07-23 19:56:43 +020012481sc0_http_req_rate([<table>]) : integer
12482sc1_http_req_rate([<table>]) : integer
12483sc2_http_req_rate([<table>]) : integer
Willy Tarreaue9656522010-08-17 15:40:09 +020012484 Returns the average rate of HTTP requests from the currently tracked
12485 counters, measured in amount of requests over the period configured in
12486 the table. This includes every started request, valid or not. See also
12487 src_http_req_rate.
12488
Cyril Bonté62ba8702014-04-22 23:52:25 +020012489sc_inc_gpc0(<ctr>[,<table>]) : integer
Willy Tarreau0f791d42013-07-23 19:56:43 +020012490sc0_inc_gpc0([<table>]) : integer
12491sc1_inc_gpc0([<table>]) : integer
12492sc2_inc_gpc0([<table>]) : integer
Willy Tarreaue9656522010-08-17 15:40:09 +020012493 Increments the first General Purpose Counter associated to the currently
Willy Tarreau869948b2013-01-04 14:14:57 +010012494 tracked counters, and returns its new value. Before the first invocation,
12495 the stored value is zero, so first invocation will increase it to 1 and will
12496 return 1. This is typically used as a second ACL in an expression in order
12497 to mark a connection when a first ACL was verified :
Willy Tarreaue9656522010-08-17 15:40:09 +020012498
Willy Tarreaube4a3ef2013-06-17 15:04:07 +020012499 acl abuse sc0_http_req_rate gt 10
12500 acl kill sc0_inc_gpc0 gt 0
Willy Tarreaue9656522010-08-17 15:40:09 +020012501 tcp-request connection reject if abuse kill
12502
Cyril Bonté62ba8702014-04-22 23:52:25 +020012503sc_kbytes_in(<ctr>[,<table>]) : integer
Willy Tarreau0f791d42013-07-23 19:56:43 +020012504sc0_kbytes_in([<table>]) : integer
12505sc1_kbytes_in([<table>]) : integer
12506sc2_kbytes_in([<table>]) : integer
Willy Tarreaua01b9742014-07-10 15:29:24 +020012507 Returns the total amount of client-to-server data from the currently tracked
12508 counters, measured in kilobytes. The test is currently performed on 32-bit
12509 integers, which limits values to 4 terabytes. See also src_kbytes_in.
Willy Tarreaue9656522010-08-17 15:40:09 +020012510
Cyril Bonté62ba8702014-04-22 23:52:25 +020012511sc_kbytes_out(<ctr>[,<table>]) : integer
Willy Tarreau0f791d42013-07-23 19:56:43 +020012512sc0_kbytes_out([<table>]) : integer
12513sc1_kbytes_out([<table>]) : integer
12514sc2_kbytes_out([<table>]) : integer
Willy Tarreaua01b9742014-07-10 15:29:24 +020012515 Returns the total amount of server-to-client data from the currently tracked
12516 counters, measured in kilobytes. The test is currently performed on 32-bit
12517 integers, which limits values to 4 terabytes. See also src_kbytes_out.
Willy Tarreaue9656522010-08-17 15:40:09 +020012518
Cyril Bonté62ba8702014-04-22 23:52:25 +020012519sc_sess_cnt(<ctr>[,<table>]) : integer
Willy Tarreau0f791d42013-07-23 19:56:43 +020012520sc0_sess_cnt([<table>]) : integer
12521sc1_sess_cnt([<table>]) : integer
12522sc2_sess_cnt([<table>]) : integer
Willy Tarreaue9656522010-08-17 15:40:09 +020012523 Returns the cumulated number of incoming connections that were transformed
12524 into sessions, which means that they were accepted by a "tcp-request
12525 connection" rule, from the currently tracked counters. A backend may count
12526 more sessions than connections because each connection could result in many
Jamie Gloudonaaa21002012-08-25 00:18:33 -040012527 backend sessions if some HTTP keep-alive is performed over the connection
Willy Tarreaue9656522010-08-17 15:40:09 +020012528 with the client. See also src_sess_cnt.
12529
Cyril Bonté62ba8702014-04-22 23:52:25 +020012530sc_sess_rate(<ctr>[,<table>]) : integer
Willy Tarreau0f791d42013-07-23 19:56:43 +020012531sc0_sess_rate([<table>]) : integer
12532sc1_sess_rate([<table>]) : integer
12533sc2_sess_rate([<table>]) : integer
Willy Tarreaue9656522010-08-17 15:40:09 +020012534 Returns the average session rate from the currently tracked counters,
12535 measured in amount of sessions over the period configured in the table. A
12536 session is a connection that got past the early "tcp-request connection"
12537 rules. A backend may count more sessions than connections because each
12538 connection could result in many backend sessions if some HTTP keep-alive is
Jamie Gloudonaaa21002012-08-25 00:18:33 -040012539 performed over the connection with the client. See also src_sess_rate.
Willy Tarreaue9656522010-08-17 15:40:09 +020012540
Cyril Bonté62ba8702014-04-22 23:52:25 +020012541sc_tracked(<ctr>[,<table>]) : boolean
Willy Tarreau0f791d42013-07-23 19:56:43 +020012542sc0_tracked([<table>]) : boolean
12543sc1_tracked([<table>]) : boolean
12544sc2_tracked([<table>]) : boolean
Willy Tarreau6f1615f2013-06-03 15:15:22 +020012545 Returns true if the designated session counter is currently being tracked by
12546 the current session. This can be useful when deciding whether or not we want
12547 to set some values in a header passed to the server.
12548
Cyril Bonté62ba8702014-04-22 23:52:25 +020012549sc_trackers(<ctr>[,<table>]) : integer
Willy Tarreau0f791d42013-07-23 19:56:43 +020012550sc0_trackers([<table>]) : integer
12551sc1_trackers([<table>]) : integer
12552sc2_trackers([<table>]) : integer
Willy Tarreau2406db42012-12-09 12:16:43 +010012553 Returns the current amount of concurrent connections tracking the same
12554 tracked counters. This number is automatically incremented when tracking
Willy Tarreaube4a3ef2013-06-17 15:04:07 +020012555 begins and decremented when tracking stops. It differs from sc0_conn_cur in
Willy Tarreau2406db42012-12-09 12:16:43 +010012556 that it does not rely on any stored information but on the table's reference
12557 count (the "use" value which is returned by "show table" on the CLI). This
Willy Tarreau74ca5042013-06-11 23:12:07 +020012558 may sometimes be more suited for layer7 tracking. It can be used to tell a
12559 server how many concurrent connections there are from a given address for
12560 example.
Willy Tarreau2406db42012-12-09 12:16:43 +010012561
Willy Tarreau74ca5042013-06-11 23:12:07 +020012562so_id : integer
12563 Returns an integer containing the current listening socket's id. It is useful
12564 in frontends involving many "bind" lines, or to stick all users coming via a
12565 same socket to the same server.
Willy Tarreaud63335a2010-02-26 12:56:52 +010012566
Willy Tarreau74ca5042013-06-11 23:12:07 +020012567src : ip
12568 This is the source IPv4 address of the client of the session. It is of type
12569 IP and works on both IPv4 and IPv6 tables. On IPv6 tables, IPv4 addresses are
12570 mapped to their IPv6 equivalent, according to RFC 4291. Note that it is the
12571 TCP-level source address which is used, and not the address of a client
12572 behind a proxy. However if the "accept-proxy" bind directive is used, it can
12573 be the address of a client behind another PROXY-protocol compatible component
12574 for all rule sets except "tcp-request connection" which sees the real address.
Willy Tarreaud63335a2010-02-26 12:56:52 +010012575
Thierry FOURNIERd5f624d2013-11-26 11:52:33 +010012576 Example:
12577 # add an HTTP header in requests with the originating address' country
12578 http-request set-header X-Country %[src,map_ip(geoip.lst)]
12579
Willy Tarreau74ca5042013-06-11 23:12:07 +020012580src_bytes_in_rate([<table>]) : integer
12581 Returns the average bytes rate from the incoming connection's source address
12582 in the current proxy's stick-table or in the designated stick-table, measured
12583 in amount of bytes over the period configured in the table. If the address is
Willy Tarreau4d4149c2013-07-23 19:33:46 +020012584 not found, zero is returned. See also sc/sc0/sc1/sc2_bytes_in_rate.
Willy Tarreauc9705a12010-07-27 20:05:50 +020012585
Willy Tarreau74ca5042013-06-11 23:12:07 +020012586src_bytes_out_rate([<table>]) : integer
12587 Returns the average bytes rate to the incoming connection's source address in
12588 the current proxy's stick-table or in the designated stick-table, measured in
Willy Tarreauc9705a12010-07-27 20:05:50 +020012589 amount of bytes over the period configured in the table. If the address is
Willy Tarreau4d4149c2013-07-23 19:33:46 +020012590 not found, zero is returned. See also sc/sc0/sc1/sc2_bytes_out_rate.
Willy Tarreauc9705a12010-07-27 20:05:50 +020012591
Willy Tarreau74ca5042013-06-11 23:12:07 +020012592src_clr_gpc0([<table>]) : integer
12593 Clears the first General Purpose Counter associated to the incoming
12594 connection's source address in the current proxy's stick-table or in the
12595 designated stick-table, and returns its previous value. If the address is not
12596 found, an entry is created and 0 is returned. This is typically used as a
12597 second ACL in an expression in order to mark a connection when a first ACL
12598 was verified :
Willy Tarreauf73cd112011-08-13 01:45:16 +020012599
12600 # block if 5 consecutive requests continue to come faster than 10 sess
12601 # per second, and reset the counter as soon as the traffic slows down.
12602 acl abuse src_http_req_rate gt 10
12603 acl kill src_inc_gpc0 gt 5
Willy Tarreau869948b2013-01-04 14:14:57 +010012604 acl save src_clr_gpc0 ge 0
Willy Tarreauf73cd112011-08-13 01:45:16 +020012605 tcp-request connection accept if !abuse save
12606 tcp-request connection reject if abuse kill
12607
Willy Tarreau74ca5042013-06-11 23:12:07 +020012608src_conn_cnt([<table>]) : integer
Willy Tarreauc9705a12010-07-27 20:05:50 +020012609 Returns the cumulated number of connections initiated from the current
Willy Tarreau74ca5042013-06-11 23:12:07 +020012610 incoming connection's source address in the current proxy's stick-table or in
Willy Tarreauc9705a12010-07-27 20:05:50 +020012611 the designated stick-table. If the address is not found, zero is returned.
Willy Tarreau4d4149c2013-07-23 19:33:46 +020012612 See also sc/sc0/sc1/sc2_conn_cnt.
Willy Tarreauc9705a12010-07-27 20:05:50 +020012613
Willy Tarreau74ca5042013-06-11 23:12:07 +020012614src_conn_cur([<table>]) : integer
Willy Tarreauc9705a12010-07-27 20:05:50 +020012615 Returns the current amount of concurrent connections initiated from the
Willy Tarreau74ca5042013-06-11 23:12:07 +020012616 current incoming connection's source address in the current proxy's
12617 stick-table or in the designated stick-table. If the address is not found,
Willy Tarreau4d4149c2013-07-23 19:33:46 +020012618 zero is returned. See also sc/sc0/sc1/sc2_conn_cur.
Willy Tarreauc9705a12010-07-27 20:05:50 +020012619
Willy Tarreau74ca5042013-06-11 23:12:07 +020012620src_conn_rate([<table>]) : integer
12621 Returns the average connection rate from the incoming connection's source
12622 address in the current proxy's stick-table or in the designated stick-table,
12623 measured in amount of connections over the period configured in the table. If
Willy Tarreau4d4149c2013-07-23 19:33:46 +020012624 the address is not found, zero is returned. See also sc/sc0/sc1/sc2_conn_rate.
Willy Tarreauc9705a12010-07-27 20:05:50 +020012625
Willy Tarreau74ca5042013-06-11 23:12:07 +020012626src_get_gpc0([<table>]) : integer
Willy Tarreauc9705a12010-07-27 20:05:50 +020012627 Returns the value of the first General Purpose Counter associated to the
Willy Tarreau74ca5042013-06-11 23:12:07 +020012628 incoming connection's source address in the current proxy's stick-table or in
Willy Tarreauc9705a12010-07-27 20:05:50 +020012629 the designated stick-table. If the address is not found, zero is returned.
Willy Tarreau4d4149c2013-07-23 19:33:46 +020012630 See also sc/sc0/sc1/sc2_get_gpc0 and src_inc_gpc0.
Willy Tarreauc9705a12010-07-27 20:05:50 +020012631
Thierry FOURNIER236657b2015-08-19 08:25:14 +020012632src_get_gpt0([<table>]) : integer
12633 Returns the value of the first General Purpose Tag associated to the
12634 incoming connection's source address in the current proxy's stick-table or in
12635 the designated stick-table. If the address is not found, zero is returned.
12636 See also sc/sc0/sc1/sc2_get_gpt0.
12637
Willy Tarreau74ca5042013-06-11 23:12:07 +020012638src_gpc0_rate([<table>]) : integer
Willy Tarreauba2ffd12013-05-29 15:54:14 +020012639 Returns the average increment rate of the first General Purpose Counter
Willy Tarreau74ca5042013-06-11 23:12:07 +020012640 associated to the incoming connection's source address in the current proxy's
Willy Tarreauba2ffd12013-05-29 15:54:14 +020012641 stick-table or in the designated stick-table. It reports the frequency
12642 which the gpc0 counter was incremented over the configured period. See also
Willy Tarreau4d4149c2013-07-23 19:33:46 +020012643 sc/sc0/sc1/sc2_gpc0_rate, src_get_gpc0, and sc/sc0/sc1/sc2_inc_gpc0. Note
12644 that the "gpc0_rate" counter must be stored in the stick-table for a value to
12645 be returned, as "gpc0" only holds the event count.
Willy Tarreauba2ffd12013-05-29 15:54:14 +020012646
Willy Tarreau74ca5042013-06-11 23:12:07 +020012647src_http_err_cnt([<table>]) : integer
12648 Returns the cumulated number of HTTP errors from the incoming connection's
12649 source address in the current proxy's stick-table or in the designated
Willy Tarreauc9705a12010-07-27 20:05:50 +020012650 stick-table. This includes the both request errors and 4xx error responses.
Willy Tarreau4d4149c2013-07-23 19:33:46 +020012651 See also sc/sc0/sc1/sc2_http_err_cnt. If the address is not found, zero is
Willy Tarreau74ca5042013-06-11 23:12:07 +020012652 returned.
Willy Tarreauc9705a12010-07-27 20:05:50 +020012653
Willy Tarreau74ca5042013-06-11 23:12:07 +020012654src_http_err_rate([<table>]) : integer
12655 Returns the average rate of HTTP errors from the incoming connection's source
12656 address in the current proxy's stick-table or in the designated stick-table,
12657 measured in amount of errors over the period configured in the table. This
12658 includes the both request errors and 4xx error responses. If the address is
Willy Tarreau4d4149c2013-07-23 19:33:46 +020012659 not found, zero is returned. See also sc/sc0/sc1/sc2_http_err_rate.
Willy Tarreauc9705a12010-07-27 20:05:50 +020012660
Willy Tarreau74ca5042013-06-11 23:12:07 +020012661src_http_req_cnt([<table>]) : integer
12662 Returns the cumulated number of HTTP requests from the incoming connection's
12663 source address in the current proxy's stick-table or in the designated stick-
12664 table. This includes every started request, valid or not. If the address is
Willy Tarreau4d4149c2013-07-23 19:33:46 +020012665 not found, zero is returned. See also sc/sc0/sc1/sc2_http_req_cnt.
Willy Tarreauc9705a12010-07-27 20:05:50 +020012666
Willy Tarreau74ca5042013-06-11 23:12:07 +020012667src_http_req_rate([<table>]) : integer
12668 Returns the average rate of HTTP requests from the incoming connection's
12669 source address in the current proxy's stick-table or in the designated stick-
12670 table, measured in amount of requests over the period configured in the
Willy Tarreauc9705a12010-07-27 20:05:50 +020012671 table. This includes every started request, valid or not. If the address is
Willy Tarreau4d4149c2013-07-23 19:33:46 +020012672 not found, zero is returned. See also sc/sc0/sc1/sc2_http_req_rate.
Willy Tarreauc9705a12010-07-27 20:05:50 +020012673
Willy Tarreau74ca5042013-06-11 23:12:07 +020012674src_inc_gpc0([<table>]) : integer
12675 Increments the first General Purpose Counter associated to the incoming
12676 connection's source address in the current proxy's stick-table or in the
12677 designated stick-table, and returns its new value. If the address is not
Willy Tarreaube4a3ef2013-06-17 15:04:07 +020012678 found, an entry is created and 1 is returned. See also sc0/sc2/sc2_inc_gpc0.
Willy Tarreau74ca5042013-06-11 23:12:07 +020012679 This is typically used as a second ACL in an expression in order to mark a
12680 connection when a first ACL was verified :
Willy Tarreauc9705a12010-07-27 20:05:50 +020012681
12682 acl abuse src_http_req_rate gt 10
Willy Tarreau869948b2013-01-04 14:14:57 +010012683 acl kill src_inc_gpc0 gt 0
Willy Tarreaue9656522010-08-17 15:40:09 +020012684 tcp-request connection reject if abuse kill
Willy Tarreauc9705a12010-07-27 20:05:50 +020012685
Willy Tarreau74ca5042013-06-11 23:12:07 +020012686src_kbytes_in([<table>]) : integer
Willy Tarreaua01b9742014-07-10 15:29:24 +020012687 Returns the total amount of data received from the incoming connection's
12688 source address in the current proxy's stick-table or in the designated
12689 stick-table, measured in kilobytes. If the address is not found, zero is
12690 returned. The test is currently performed on 32-bit integers, which limits
12691 values to 4 terabytes. See also sc/sc0/sc1/sc2_kbytes_in.
Willy Tarreauc9705a12010-07-27 20:05:50 +020012692
Willy Tarreau74ca5042013-06-11 23:12:07 +020012693src_kbytes_out([<table>]) : integer
Willy Tarreaua01b9742014-07-10 15:29:24 +020012694 Returns the total amount of data sent to the incoming connection's source
12695 address in the current proxy's stick-table or in the designated stick-table,
12696 measured in kilobytes. If the address is not found, zero is returned. The
12697 test is currently performed on 32-bit integers, which limits values to 4
12698 terabytes. See also sc/sc0/sc1/sc2_kbytes_out.
Willy Tarreaua975b8f2010-06-05 19:13:27 +020012699
Willy Tarreau74ca5042013-06-11 23:12:07 +020012700src_port : integer
12701 Returns an integer value corresponding to the TCP source port of the
12702 connection on the client side, which is the port the client connected from.
12703 Usage of this function is very limited as modern protocols do not care much
12704 about source ports nowadays.
Willy Tarreau079ff0a2009-03-05 21:34:28 +010012705
Willy Tarreau74ca5042013-06-11 23:12:07 +020012706src_sess_cnt([<table>]) : integer
12707 Returns the cumulated number of connections initiated from the incoming
Willy Tarreauc9705a12010-07-27 20:05:50 +020012708 connection's source IPv4 address in the current proxy's stick-table or in the
12709 designated stick-table, that were transformed into sessions, which means that
12710 they were accepted by "tcp-request" rules. If the address is not found, zero
Willy Tarreau4d4149c2013-07-23 19:33:46 +020012711 is returned. See also sc/sc0/sc1/sc2_sess_cnt.
Willy Tarreauc9705a12010-07-27 20:05:50 +020012712
Willy Tarreau74ca5042013-06-11 23:12:07 +020012713src_sess_rate([<table>]) : integer
12714 Returns the average session rate from the incoming connection's source
12715 address in the current proxy's stick-table or in the designated stick-table,
12716 measured in amount of sessions over the period configured in the table. A
12717 session is a connection that went past the early "tcp-request" rules. If the
Willy Tarreau4d4149c2013-07-23 19:33:46 +020012718 address is not found, zero is returned. See also sc/sc0/sc1/sc2_sess_rate.
Willy Tarreauc9705a12010-07-27 20:05:50 +020012719
Willy Tarreau74ca5042013-06-11 23:12:07 +020012720src_updt_conn_cnt([<table>]) : integer
12721 Creates or updates the entry associated to the incoming connection's source
12722 address in the current proxy's stick-table or in the designated stick-table.
12723 This table must be configured to store the "conn_cnt" data type, otherwise
12724 the match will be ignored. The current count is incremented by one, and the
12725 expiration timer refreshed. The updated count is returned, so this match
12726 can't return zero. This was used to reject service abusers based on their
12727 source address. Note: it is recommended to use the more complete "track-sc*"
12728 actions in "tcp-request" rules instead.
Willy Tarreaua975b8f2010-06-05 19:13:27 +020012729
12730 Example :
12731 # This frontend limits incoming SSH connections to 3 per 10 second for
12732 # each source address, and rejects excess connections until a 10 second
12733 # silence is observed. At most 20 addresses are tracked.
12734 listen ssh
12735 bind :22
12736 mode tcp
12737 maxconn 100
Willy Tarreauc9705a12010-07-27 20:05:50 +020012738 stick-table type ip size 20 expire 10s store conn_cnt
Willy Tarreau74ca5042013-06-11 23:12:07 +020012739 tcp-request content reject if { src_updt_conn_cnt gt 3 }
Willy Tarreaua975b8f2010-06-05 19:13:27 +020012740 server local 127.0.0.1:22
12741
Willy Tarreau74ca5042013-06-11 23:12:07 +020012742srv_id : integer
12743 Returns an integer containing the server's id when processing the response.
12744 While it's almost only used with ACLs, it may be used for logging or
12745 debugging.
Hervé COMMOWICKdaa824e2011-08-05 12:09:44 +020012746
Hervé COMMOWICK35ed8012010-12-15 14:04:51 +010012747
Thierry FOURNIER060762e2014-04-23 13:29:15 +0200127487.3.4. Fetching samples at Layer 5
Willy Tarreau74ca5042013-06-11 23:12:07 +020012749----------------------------------
Willy Tarreau0b1cd942010-05-16 22:18:27 +020012750
Willy Tarreau74ca5042013-06-11 23:12:07 +020012751The layer 5 usually describes just the session layer which in haproxy is
12752closest to the session once all the connection handshakes are finished, but
12753when no content is yet made available. The fetch methods described here are
12754usable as low as the "tcp-request content" rule sets unless they require some
Jarno Huuskonen0e82b922014-04-12 18:22:19 +030012755future information. Those generally include the results of SSL negotiations.
Willy Tarreauc735a072011-03-29 00:57:02 +020012756
Emeric Brun645ae792014-04-30 14:21:06 +020012757ssl_bc : boolean
12758 Returns true when the back connection was made via an SSL/TLS transport
12759 layer and is locally deciphered. This means the outgoing connection was made
12760 other a server with the "ssl" option.
12761
12762ssl_bc_alg_keysize : integer
12763 Returns the symmetric cipher key size supported in bits when the outgoing
12764 connection was made over an SSL/TLS transport layer.
12765
12766ssl_bc_cipher : string
12767 Returns the name of the used cipher when the outgoing connection was made
12768 over an SSL/TLS transport layer.
12769
12770ssl_bc_protocol : string
12771 Returns the name of the used protocol when the outgoing connection was made
12772 over an SSL/TLS transport layer.
12773
Emeric Brunb73a9b02014-04-30 18:49:19 +020012774ssl_bc_unique_id : binary
Emeric Brun645ae792014-04-30 14:21:06 +020012775 When the outgoing connection was made over an SSL/TLS transport layer,
Emeric Brunb73a9b02014-04-30 18:49:19 +020012776 returns the TLS unique ID as defined in RFC5929 section 3. The unique id
12777 can be encoded to base64 using the converter: "ssl_bc_unique_id,base64".
Emeric Brun645ae792014-04-30 14:21:06 +020012778
12779ssl_bc_session_id : binary
12780 Returns the SSL ID of the back connection when the outgoing connection was
12781 made over an SSL/TLS transport layer. It is useful to log if we want to know
12782 if session was reused or not.
12783
12784ssl_bc_use_keysize : integer
12785 Returns the symmetric cipher key size used in bits when the outgoing
12786 connection was made over an SSL/TLS transport layer.
12787
Willy Tarreau74ca5042013-06-11 23:12:07 +020012788ssl_c_ca_err : integer
12789 When the incoming connection was made over an SSL/TLS transport layer,
12790 returns the ID of the first error detected during verification of the client
12791 certificate at depth > 0, or 0 if no error was encountered during this
12792 verification process. Please refer to your SSL library's documentation to
12793 find the exhaustive list of error codes.
Willy Tarreauc735a072011-03-29 00:57:02 +020012794
Willy Tarreau74ca5042013-06-11 23:12:07 +020012795ssl_c_ca_err_depth : integer
12796 When the incoming connection was made over an SSL/TLS transport layer,
12797 returns the depth in the CA chain of the first error detected during the
12798 verification of the client certificate. If no error is encountered, 0 is
12799 returned.
Willy Tarreau0ba27502007-12-24 16:55:16 +010012800
Emeric Brun43e79582014-10-29 19:03:26 +010012801ssl_c_der : binary
12802 Returns the DER formatted certificate presented by the client when the
12803 incoming connection was made over an SSL/TLS transport layer. When used for
12804 an ACL, the value(s) to match against can be passed in hexadecimal form.
12805
Willy Tarreau74ca5042013-06-11 23:12:07 +020012806ssl_c_err : integer
12807 When the incoming connection was made over an SSL/TLS transport layer,
12808 returns the ID of the first error detected during verification at depth 0, or
12809 0 if no error was encountered during this verification process. Please refer
12810 to your SSL library's documentation to find the exhaustive list of error
12811 codes.
Willy Tarreau62644772008-07-16 18:36:06 +020012812
Willy Tarreau74ca5042013-06-11 23:12:07 +020012813ssl_c_i_dn([<entry>[,<occ>]]) : string
12814 When the incoming connection was made over an SSL/TLS transport layer,
12815 returns the full distinguished name of the issuer of the certificate
12816 presented by the client when no <entry> is specified, or the value of the
12817 first given entry found from the beginning of the DN. If a positive/negative
12818 occurrence number is specified as the optional second argument, it returns
12819 the value of the nth given entry value from the beginning/end of the DN.
12820 For instance, "ssl_c_i_dn(OU,2)" the second organization unit, and
12821 "ssl_c_i_dn(CN)" retrieves the common name.
Willy Tarreau62644772008-07-16 18:36:06 +020012822
Willy Tarreau74ca5042013-06-11 23:12:07 +020012823ssl_c_key_alg : string
12824 Returns the name of the algorithm used to generate the key of the certificate
12825 presented by the client when the incoming connection was made over an SSL/TLS
12826 transport layer.
Willy Tarreau62644772008-07-16 18:36:06 +020012827
Willy Tarreau74ca5042013-06-11 23:12:07 +020012828ssl_c_notafter : string
12829 Returns the end date presented by the client as a formatted string
12830 YYMMDDhhmmss[Z] when the incoming connection was made over an SSL/TLS
12831 transport layer.
Emeric Brunbede3d02009-06-30 17:54:00 +020012832
Willy Tarreau74ca5042013-06-11 23:12:07 +020012833ssl_c_notbefore : string
12834 Returns the start date presented by the client as a formatted string
12835 YYMMDDhhmmss[Z] when the incoming connection was made over an SSL/TLS
12836 transport layer.
Willy Tarreaub6672b52011-12-12 17:23:41 +010012837
Willy Tarreau74ca5042013-06-11 23:12:07 +020012838ssl_c_s_dn([<entry>[,<occ>]]) : string
12839 When the incoming connection was made over an SSL/TLS transport layer,
12840 returns the full distinguished name of the subject of the certificate
12841 presented by the client when no <entry> is specified, or the value of the
12842 first given entry found from the beginning of the DN. If a positive/negative
12843 occurrence number is specified as the optional second argument, it returns
12844 the value of the nth given entry value from the beginning/end of the DN.
12845 For instance, "ssl_c_s_dn(OU,2)" the second organization unit, and
12846 "ssl_c_s_dn(CN)" retrieves the common name.
Willy Tarreaub6672b52011-12-12 17:23:41 +010012847
Willy Tarreau74ca5042013-06-11 23:12:07 +020012848ssl_c_serial : binary
12849 Returns the serial of the certificate presented by the client when the
12850 incoming connection was made over an SSL/TLS transport layer. When used for
12851 an ACL, the value(s) to match against can be passed in hexadecimal form.
Emeric Brun2525b6b2012-10-18 15:59:43 +020012852
Willy Tarreau74ca5042013-06-11 23:12:07 +020012853ssl_c_sha1 : binary
12854 Returns the SHA-1 fingerprint of the certificate presented by the client when
12855 the incoming connection was made over an SSL/TLS transport layer. This can be
12856 used to stick a client to a server, or to pass this information to a server.
Willy Tarreau2d0caa32014-07-02 19:01:22 +020012857 Note that the output is binary, so if you want to pass that signature to the
12858 server, you need to encode it in hex or base64, such as in the example below:
12859
12860 http-request set-header X-SSL-Client-SHA1 %[ssl_c_sha1,hex]
Emeric Brun2525b6b2012-10-18 15:59:43 +020012861
Willy Tarreau74ca5042013-06-11 23:12:07 +020012862ssl_c_sig_alg : string
12863 Returns the name of the algorithm used to sign the certificate presented by
12864 the client when the incoming connection was made over an SSL/TLS transport
12865 layer.
Emeric Brun87855892012-10-17 17:39:35 +020012866
Willy Tarreau74ca5042013-06-11 23:12:07 +020012867ssl_c_used : boolean
12868 Returns true if current SSL session uses a client certificate even if current
12869 connection uses SSL session resumption. See also "ssl_fc_has_crt".
Emeric Brun7f56e742012-10-19 18:15:40 +020012870
Willy Tarreau74ca5042013-06-11 23:12:07 +020012871ssl_c_verify : integer
12872 Returns the verify result error ID when the incoming connection was made over
12873 an SSL/TLS transport layer, otherwise zero if no error is encountered. Please
12874 refer to your SSL library's documentation for an exhaustive list of error
12875 codes.
Emeric Brunce5ad802012-10-22 14:11:22 +020012876
Willy Tarreau74ca5042013-06-11 23:12:07 +020012877ssl_c_version : integer
12878 Returns the version of the certificate presented by the client when the
12879 incoming connection was made over an SSL/TLS transport layer.
Emeric Brunce5ad802012-10-22 14:11:22 +020012880
Emeric Brun43e79582014-10-29 19:03:26 +010012881ssl_f_der : binary
12882 Returns the DER formatted certificate presented by the frontend when the
12883 incoming connection was made over an SSL/TLS transport layer. When used for
12884 an ACL, the value(s) to match against can be passed in hexadecimal form.
12885
Willy Tarreau74ca5042013-06-11 23:12:07 +020012886ssl_f_i_dn([<entry>[,<occ>]]) : string
12887 When the incoming connection was made over an SSL/TLS transport layer,
12888 returns the full distinguished name of the issuer of the certificate
12889 presented by the frontend when no <entry> is specified, or the value of the
12890 first given entry found from the beginning of the DN. If a positive/negative
Emeric Brun87855892012-10-17 17:39:35 +020012891 occurrence number is specified as the optional second argument, it returns
Willy Tarreau74ca5042013-06-11 23:12:07 +020012892 the value of the nth given entry value from the beginning/end of the DN.
12893 For instance, "ssl_f_i_dn(OU,2)" the second organization unit, and
12894 "ssl_f_i_dn(CN)" retrieves the common name.
Emeric Brun87855892012-10-17 17:39:35 +020012895
Willy Tarreau74ca5042013-06-11 23:12:07 +020012896ssl_f_key_alg : string
12897 Returns the name of the algorithm used to generate the key of the certificate
12898 presented by the frontend when the incoming connection was made over an
12899 SSL/TLS transport layer.
Emeric Brun7f56e742012-10-19 18:15:40 +020012900
Willy Tarreau74ca5042013-06-11 23:12:07 +020012901ssl_f_notafter : string
12902 Returns the end date presented by the frontend as a formatted string
12903 YYMMDDhhmmss[Z] when the incoming connection was made over an SSL/TLS
12904 transport layer.
Emeric Brun2525b6b2012-10-18 15:59:43 +020012905
Willy Tarreau74ca5042013-06-11 23:12:07 +020012906ssl_f_notbefore : string
12907 Returns the start date presented by the frontend as a formatted string
12908 YYMMDDhhmmss[Z] when the incoming connection was made over an SSL/TLS
12909 transport layer.
Emeric Brun87855892012-10-17 17:39:35 +020012910
Willy Tarreau74ca5042013-06-11 23:12:07 +020012911ssl_f_s_dn([<entry>[,<occ>]]) : string
12912 When the incoming connection was made over an SSL/TLS transport layer,
12913 returns the full distinguished name of the subject of the certificate
12914 presented by the frontend when no <entry> is specified, or the value of the
12915 first given entry found from the beginning of the DN. If a positive/negative
12916 occurrence number is specified as the optional second argument, it returns
12917 the value of the nth given entry value from the beginning/end of the DN.
12918 For instance, "ssl_f_s_dn(OU,2)" the second organization unit, and
12919 "ssl_f_s_dn(CN)" retrieves the common name.
Emeric Brunce5ad802012-10-22 14:11:22 +020012920
Willy Tarreau74ca5042013-06-11 23:12:07 +020012921ssl_f_serial : binary
12922 Returns the serial of the certificate presented by the frontend when the
12923 incoming connection was made over an SSL/TLS transport layer. When used for
12924 an ACL, the value(s) to match against can be passed in hexadecimal form.
Emeric Brun87855892012-10-17 17:39:35 +020012925
Emeric Brun55f4fa82014-04-30 17:11:25 +020012926ssl_f_sha1 : binary
12927 Returns the SHA-1 fingerprint of the certificate presented by the frontend
12928 when the incoming connection was made over an SSL/TLS transport layer. This
12929 can be used to know which certificate was chosen using SNI.
12930
Willy Tarreau74ca5042013-06-11 23:12:07 +020012931ssl_f_sig_alg : string
12932 Returns the name of the algorithm used to sign the certificate presented by
12933 the frontend when the incoming connection was made over an SSL/TLS transport
12934 layer.
Emeric Brun7f56e742012-10-19 18:15:40 +020012935
Willy Tarreau74ca5042013-06-11 23:12:07 +020012936ssl_f_version : integer
12937 Returns the version of the certificate presented by the frontend when the
12938 incoming connection was made over an SSL/TLS transport layer.
12939
12940ssl_fc : boolean
Emeric Brun2525b6b2012-10-18 15:59:43 +020012941 Returns true when the front connection was made via an SSL/TLS transport
12942 layer and is locally deciphered. This means it has matched a socket declared
12943 with a "bind" line having the "ssl" option.
12944
Willy Tarreau74ca5042013-06-11 23:12:07 +020012945 Example :
12946 # This passes "X-Proto: https" to servers when client connects over SSL
12947 listen http-https
12948 bind :80
12949 bind :443 ssl crt /etc/haproxy.pem
12950 http-request add-header X-Proto https if { ssl_fc }
12951
12952ssl_fc_alg_keysize : integer
12953 Returns the symmetric cipher key size supported in bits when the incoming
12954 connection was made over an SSL/TLS transport layer.
12955
12956ssl_fc_alpn : string
Jarno Huuskonen0e82b922014-04-12 18:22:19 +030012957 This extracts the Application Layer Protocol Negotiation field from an
Willy Tarreau74ca5042013-06-11 23:12:07 +020012958 incoming connection made via a TLS transport layer and locally deciphered by
12959 haproxy. The result is a string containing the protocol name advertised by
12960 the client. The SSL library must have been built with support for TLS
12961 extensions enabled (check haproxy -vv). Note that the TLS ALPN extension is
12962 not advertised unless the "alpn" keyword on the "bind" line specifies a
12963 protocol list. Also, nothing forces the client to pick a protocol from this
12964 list, any other one may be requested. The TLS ALPN extension is meant to
12965 replace the TLS NPN extension. See also "ssl_fc_npn".
12966
Willy Tarreau74ca5042013-06-11 23:12:07 +020012967ssl_fc_cipher : string
12968 Returns the name of the used cipher when the incoming connection was made
12969 over an SSL/TLS transport layer.
Willy Tarreauab861d32013-04-02 02:30:41 +020012970
Willy Tarreau74ca5042013-06-11 23:12:07 +020012971ssl_fc_has_crt : boolean
Emeric Brun2525b6b2012-10-18 15:59:43 +020012972 Returns true if a client certificate is present in an incoming connection over
12973 SSL/TLS transport layer. Useful if 'verify' statement is set to 'optional'.
Emeric Brun9143d372012-12-20 15:44:16 +010012974 Note: on SSL session resumption with Session ID or TLS ticket, client
12975 certificate is not present in the current connection but may be retrieved
12976 from the cache or the ticket. So prefer "ssl_c_used" if you want to check if
12977 current SSL session uses a client certificate.
Emeric Brun2525b6b2012-10-18 15:59:43 +020012978
Willy Tarreau74ca5042013-06-11 23:12:07 +020012979ssl_fc_has_sni : boolean
12980 This checks for the presence of a Server Name Indication TLS extension (SNI)
Willy Tarreauf7bc57c2012-10-03 00:19:48 +020012981 in an incoming connection was made over an SSL/TLS transport layer. Returns
12982 true when the incoming connection presents a TLS SNI field. This requires
12983 that the SSL library is build with support for TLS extensions enabled (check
12984 haproxy -vv).
Willy Tarreau7875d092012-09-10 08:20:03 +020012985
Nenad Merdanovic26ea8222015-05-18 02:28:57 +020012986ssl_fc_is_resumed: boolean
12987 Returns true if the SSL/TLS session has been resumed through the use of
12988 SSL session cache or TLS tickets.
12989
Willy Tarreau74ca5042013-06-11 23:12:07 +020012990ssl_fc_npn : string
Jarno Huuskonen0e82b922014-04-12 18:22:19 +030012991 This extracts the Next Protocol Negotiation field from an incoming connection
Willy Tarreau74ca5042013-06-11 23:12:07 +020012992 made via a TLS transport layer and locally deciphered by haproxy. The result
12993 is a string containing the protocol name advertised by the client. The SSL
12994 library must have been built with support for TLS extensions enabled (check
12995 haproxy -vv). Note that the TLS NPN extension is not advertised unless the
12996 "npn" keyword on the "bind" line specifies a protocol list. Also, nothing
12997 forces the client to pick a protocol from this list, any other one may be
12998 requested. Please note that the TLS NPN extension was replaced with ALPN.
Willy Tarreaua33c6542012-10-15 13:19:06 +020012999
Willy Tarreau74ca5042013-06-11 23:12:07 +020013000ssl_fc_protocol : string
13001 Returns the name of the used protocol when the incoming connection was made
13002 over an SSL/TLS transport layer.
Willy Tarreau7875d092012-09-10 08:20:03 +020013003
Emeric Brunb73a9b02014-04-30 18:49:19 +020013004ssl_fc_unique_id : binary
David Sc1ad52e2014-04-08 18:48:47 -040013005 When the incoming connection was made over an SSL/TLS transport layer,
Emeric Brunb73a9b02014-04-30 18:49:19 +020013006 returns the TLS unique ID as defined in RFC5929 section 3. The unique id
13007 can be encoded to base64 using the converter: "ssl_bc_unique_id,base64".
David Sc1ad52e2014-04-08 18:48:47 -040013008
Willy Tarreau74ca5042013-06-11 23:12:07 +020013009ssl_fc_session_id : binary
13010 Returns the SSL ID of the front connection when the incoming connection was
13011 made over an SSL/TLS transport layer. It is useful to stick a given client to
13012 a server. It is important to note that some browsers refresh their session ID
13013 every few minutes.
Willy Tarreau7875d092012-09-10 08:20:03 +020013014
Willy Tarreau74ca5042013-06-11 23:12:07 +020013015ssl_fc_sni : string
13016 This extracts the Server Name Indication TLS extension (SNI) field from an
13017 incoming connection made via an SSL/TLS transport layer and locally
13018 deciphered by haproxy. The result (when present) typically is a string
13019 matching the HTTPS host name (253 chars or less). The SSL library must have
13020 been built with support for TLS extensions enabled (check haproxy -vv).
13021
13022 This fetch is different from "req_ssl_sni" above in that it applies to the
13023 connection being deciphered by haproxy and not to SSL contents being blindly
13024 forwarded. See also "ssl_fc_sni_end" and "ssl_fc_sni_reg" below. This
Cyril Bonté9c1eb1e2012-10-09 22:45:34 +020013025 requires that the SSL library is build with support for TLS extensions
13026 enabled (check haproxy -vv).
Willy Tarreau62644772008-07-16 18:36:06 +020013027
Willy Tarreau74ca5042013-06-11 23:12:07 +020013028 ACL derivatives :
Willy Tarreau74ca5042013-06-11 23:12:07 +020013029 ssl_fc_sni_end : suffix match
13030 ssl_fc_sni_reg : regex match
Emeric Brun589fcad2012-10-16 14:13:26 +020013031
Willy Tarreau74ca5042013-06-11 23:12:07 +020013032ssl_fc_use_keysize : integer
13033 Returns the symmetric cipher key size used in bits when the incoming
13034 connection was made over an SSL/TLS transport layer.
Willy Tarreaub6fb4202008-07-20 11:18:28 +020013035
Willy Tarreaub6fb4202008-07-20 11:18:28 +020013036
Thierry FOURNIER060762e2014-04-23 13:29:15 +0200130377.3.5. Fetching samples from buffer contents (Layer 6)
Willy Tarreau74ca5042013-06-11 23:12:07 +020013038------------------------------------------------------
Willy Tarreaub6fb4202008-07-20 11:18:28 +020013039
Willy Tarreau74ca5042013-06-11 23:12:07 +020013040Fetching samples from buffer contents is a bit different from the previous
13041sample fetches above because the sampled data are ephemeral. These data can
13042only be used when they're available and will be lost when they're forwarded.
13043For this reason, samples fetched from buffer contents during a request cannot
13044be used in a response for example. Even while the data are being fetched, they
13045can change. Sometimes it is necessary to set some delays or combine multiple
13046sample fetch methods to ensure that the expected data are complete and usable,
13047for example through TCP request content inspection. Please see the "tcp-request
13048content" keyword for more detailed information on the subject.
Willy Tarreau62644772008-07-16 18:36:06 +020013049
Willy Tarreau74ca5042013-06-11 23:12:07 +020013050payload(<offset>,<length>) : binary (deprecated)
13051 This is an alias for "req.payload" when used in the context of a request (eg:
13052 "stick on", "stick match"), and for "res.payload" when used in the context of
13053 a response such as in "stick store response".
Willy Tarreau0ba27502007-12-24 16:55:16 +010013054
Willy Tarreau74ca5042013-06-11 23:12:07 +020013055payload_lv(<offset1>,<length>[,<offset2>]) : binary (deprecated)
13056 This is an alias for "req.payload_lv" when used in the context of a request
13057 (eg: "stick on", "stick match"), and for "res.payload_lv" when used in the
13058 context of a response such as in "stick store response".
Willy Tarreau0ba27502007-12-24 16:55:16 +010013059
Willy Tarreau74ca5042013-06-11 23:12:07 +020013060req.len : integer
13061req_len : integer (deprecated)
13062 Returns an integer value corresponding to the number of bytes present in the
13063 request buffer. This is mostly used in ACL. It is important to understand
13064 that this test does not return false as long as the buffer is changing. This
13065 means that a check with equality to zero will almost always immediately match
13066 at the beginning of the session, while a test for more data will wait for
13067 that data to come in and return false only when haproxy is certain that no
13068 more data will come in. This test was designed to be used with TCP request
13069 content inspection.
Willy Tarreaua7ad50c2012-04-29 15:39:40 +020013070
Willy Tarreau74ca5042013-06-11 23:12:07 +020013071req.payload(<offset>,<length>) : binary
13072 This extracts a binary block of <length> bytes and starting at byte <offset>
Willy Tarreau00f00842013-08-02 11:07:32 +020013073 in the request buffer. As a special case, if the <length> argument is zero,
13074 the the whole buffer from <offset> to the end is extracted. This can be used
13075 with ACLs in order to check for the presence of some content in a buffer at
13076 any location.
Willy Tarreaua7ad50c2012-04-29 15:39:40 +020013077
Willy Tarreau74ca5042013-06-11 23:12:07 +020013078 ACL alternatives :
13079 payload(<offset>,<length>) : hex binary match
Willy Tarreaua7ad50c2012-04-29 15:39:40 +020013080
Willy Tarreau74ca5042013-06-11 23:12:07 +020013081req.payload_lv(<offset1>,<length>[,<offset2>]) : binary
13082 This extracts a binary block whose size is specified at <offset1> for <length>
13083 bytes, and which starts at <offset2> if specified or just after the length in
13084 the request buffer. The <offset2> parameter also supports relative offsets if
13085 prepended with a '+' or '-' sign.
Willy Tarreaua7ad50c2012-04-29 15:39:40 +020013086
Willy Tarreau74ca5042013-06-11 23:12:07 +020013087 ACL alternatives :
13088 payload_lv(<offset1>,<length>[,<offset2>]) : hex binary match
Willy Tarreaua7ad50c2012-04-29 15:39:40 +020013089
Willy Tarreau74ca5042013-06-11 23:12:07 +020013090 Example : please consult the example from the "stick store-response" keyword.
Willy Tarreaua7ad50c2012-04-29 15:39:40 +020013091
Willy Tarreau74ca5042013-06-11 23:12:07 +020013092req.proto_http : boolean
13093req_proto_http : boolean (deprecated)
13094 Returns true when data in the request buffer look like HTTP and correctly
13095 parses as such. It is the same parser as the common HTTP request parser which
13096 is used so there should be no surprises. The test does not match until the
13097 request is complete, failed or timed out. This test may be used to report the
13098 protocol in TCP logs, but the biggest use is to block TCP request analysis
13099 until a complete HTTP request is present in the buffer, for example to track
13100 a header.
Willy Tarreaua7ad50c2012-04-29 15:39:40 +020013101
Willy Tarreau74ca5042013-06-11 23:12:07 +020013102 Example:
13103 # track request counts per "base" (concatenation of Host+URL)
13104 tcp-request inspect-delay 10s
13105 tcp-request content reject if !HTTP
Willy Tarreaube4a3ef2013-06-17 15:04:07 +020013106 tcp-request content track-sc0 base table req-rate
Willy Tarreaua7ad50c2012-04-29 15:39:40 +020013107
Willy Tarreau74ca5042013-06-11 23:12:07 +020013108req.rdp_cookie([<name>]) : string
13109rdp_cookie([<name>]) : string (deprecated)
13110 When the request buffer looks like the RDP protocol, extracts the RDP cookie
13111 <name>, or any cookie if unspecified. The parser only checks for the first
13112 cookie, as illustrated in the RDP protocol specification. The cookie name is
13113 case insensitive. Generally the "MSTS" cookie name will be used, as it can
13114 contain the user name of the client connecting to the server if properly
13115 configured on the client. The "MSTSHASH" cookie is often used as well for
13116 session stickiness to servers.
Willy Tarreau04aa6a92012-04-06 18:57:55 +020013117
Willy Tarreau74ca5042013-06-11 23:12:07 +020013118 This differs from "balance rdp-cookie" in that any balancing algorithm may be
13119 used and thus the distribution of clients to backend servers is not linked to
13120 a hash of the RDP cookie. It is envisaged that using a balancing algorithm
13121 such as "balance roundrobin" or "balance leastconn" will lead to a more even
13122 distribution of clients to backend servers than the hash used by "balance
13123 rdp-cookie".
Willy Tarreau04aa6a92012-04-06 18:57:55 +020013124
Willy Tarreau74ca5042013-06-11 23:12:07 +020013125 ACL derivatives :
13126 req_rdp_cookie([<name>]) : exact string match
Willy Tarreau04aa6a92012-04-06 18:57:55 +020013127
Willy Tarreau74ca5042013-06-11 23:12:07 +020013128 Example :
13129 listen tse-farm
13130 bind 0.0.0.0:3389
13131 # wait up to 5s for an RDP cookie in the request
13132 tcp-request inspect-delay 5s
13133 tcp-request content accept if RDP_COOKIE
13134 # apply RDP cookie persistence
13135 persist rdp-cookie
13136 # Persist based on the mstshash cookie
13137 # This is only useful makes sense if
13138 # balance rdp-cookie is not used
13139 stick-table type string size 204800
13140 stick on req.rdp_cookie(mstshash)
13141 server srv1 1.1.1.1:3389
13142 server srv1 1.1.1.2:3389
Willy Tarreau04aa6a92012-04-06 18:57:55 +020013143
Willy Tarreau74ca5042013-06-11 23:12:07 +020013144 See also : "balance rdp-cookie", "persist rdp-cookie", "tcp-request" and the
13145 "req_rdp_cookie" ACL.
Willy Tarreau04aa6a92012-04-06 18:57:55 +020013146
Willy Tarreau74ca5042013-06-11 23:12:07 +020013147req.rdp_cookie_cnt([name]) : integer
13148rdp_cookie_cnt([name]) : integer (deprecated)
13149 Tries to parse the request buffer as RDP protocol, then returns an integer
13150 corresponding to the number of RDP cookies found. If an optional cookie name
13151 is passed, only cookies matching this name are considered. This is mostly
13152 used in ACL.
Willy Tarreau04aa6a92012-04-06 18:57:55 +020013153
Willy Tarreau74ca5042013-06-11 23:12:07 +020013154 ACL derivatives :
13155 req_rdp_cookie_cnt([<name>]) : integer match
Willy Tarreau04aa6a92012-04-06 18:57:55 +020013156
Nenad Merdanovic5fc7d7e2015-07-07 22:00:17 +020013157req.ssl_ec_ext : boolean
13158 Returns a boolean identifying if client sent the Supported Elliptic Curves
13159 Extension as defined in RFC4492, section 5.1. within the SSL ClientHello
13160 message. This can be used to present ECC compatible clients with EC certificate
13161 and to use RSA for all others, on the same IP address. Note that this only
13162 applies to raw contents found in the request buffer and not to contents
13163 deciphered via an SSL data layer, so this will not work with "bind" lines
13164 having the "ssl" option.
13165
Willy Tarreau74ca5042013-06-11 23:12:07 +020013166req.ssl_hello_type : integer
13167req_ssl_hello_type : integer (deprecated)
13168 Returns an integer value containing the type of the SSL hello message found
13169 in the request buffer if the buffer contains data that parse as a complete
13170 SSL (v3 or superior) client hello message. Note that this only applies to raw
13171 contents found in the request buffer and not to contents deciphered via an
13172 SSL data layer, so this will not work with "bind" lines having the "ssl"
13173 option. This is mostly used in ACL to detect presence of an SSL hello message
13174 that is supposed to contain an SSL session ID usable for stickiness.
Willy Tarreau04aa6a92012-04-06 18:57:55 +020013175
Willy Tarreau74ca5042013-06-11 23:12:07 +020013176req.ssl_sni : string
13177req_ssl_sni : string (deprecated)
13178 Returns a string containing the value of the Server Name TLS extension sent
13179 by a client in a TLS stream passing through the request buffer if the buffer
13180 contains data that parse as a complete SSL (v3 or superior) client hello
13181 message. Note that this only applies to raw contents found in the request
13182 buffer and not to contents deciphered via an SSL data layer, so this will not
13183 work with "bind" lines having the "ssl" option. SNI normally contains the
13184 name of the host the client tries to connect to (for recent browsers). SNI is
13185 useful for allowing or denying access to certain hosts when SSL/TLS is used
13186 by the client. This test was designed to be used with TCP request content
13187 inspection. If content switching is needed, it is recommended to first wait
13188 for a complete client hello (type 1), like in the example below. See also
13189 "ssl_fc_sni".
Willy Tarreau04aa6a92012-04-06 18:57:55 +020013190
Willy Tarreau74ca5042013-06-11 23:12:07 +020013191 ACL derivatives :
13192 req_ssl_sni : exact string match
Willy Tarreau04aa6a92012-04-06 18:57:55 +020013193
Willy Tarreau74ca5042013-06-11 23:12:07 +020013194 Examples :
13195 # Wait for a client hello for at most 5 seconds
13196 tcp-request inspect-delay 5s
13197 tcp-request content accept if { req_ssl_hello_type 1 }
13198 use_backend bk_allow if { req_ssl_sni -f allowed_sites }
13199 default_backend bk_sorry_page
Willy Tarreau04aa6a92012-04-06 18:57:55 +020013200
Willy Tarreau74ca5042013-06-11 23:12:07 +020013201res.ssl_hello_type : integer
13202rep_ssl_hello_type : integer (deprecated)
13203 Returns an integer value containing the type of the SSL hello message found
13204 in the response buffer if the buffer contains data that parses as a complete
13205 SSL (v3 or superior) hello message. Note that this only applies to raw
13206 contents found in the response buffer and not to contents deciphered via an
13207 SSL data layer, so this will not work with "server" lines having the "ssl"
13208 option. This is mostly used in ACL to detect presence of an SSL hello message
13209 that is supposed to contain an SSL session ID usable for stickiness.
Willy Tarreau51539362012-05-08 12:46:28 +020013210
Willy Tarreau74ca5042013-06-11 23:12:07 +020013211req.ssl_ver : integer
13212req_ssl_ver : integer (deprecated)
13213 Returns an integer value containing the version of the SSL/TLS protocol of a
13214 stream present in the request buffer. Both SSLv2 hello messages and SSLv3
13215 messages are supported. TLSv1 is announced as SSL version 3.1. The value is
13216 composed of the major version multiplied by 65536, added to the minor
13217 version. Note that this only applies to raw contents found in the request
13218 buffer and not to contents deciphered via an SSL data layer, so this will not
13219 work with "bind" lines having the "ssl" option. The ACL version of the test
13220 matches against a decimal notation in the form MAJOR.MINOR (eg: 3.1). This
13221 fetch is mostly used in ACL.
Willy Tarreaud63335a2010-02-26 12:56:52 +010013222
Willy Tarreau74ca5042013-06-11 23:12:07 +020013223 ACL derivatives :
13224 req_ssl_ver : decimal match
Willy Tarreaud63335a2010-02-26 12:56:52 +010013225
Willy Tarreau47e8eba2013-09-11 23:28:46 +020013226res.len : integer
13227 Returns an integer value corresponding to the number of bytes present in the
13228 response buffer. This is mostly used in ACL. It is important to understand
13229 that this test does not return false as long as the buffer is changing. This
13230 means that a check with equality to zero will almost always immediately match
13231 at the beginning of the session, while a test for more data will wait for
13232 that data to come in and return false only when haproxy is certain that no
13233 more data will come in. This test was designed to be used with TCP response
13234 content inspection.
13235
Willy Tarreau74ca5042013-06-11 23:12:07 +020013236res.payload(<offset>,<length>) : binary
13237 This extracts a binary block of <length> bytes and starting at byte <offset>
Willy Tarreau00f00842013-08-02 11:07:32 +020013238 in the response buffer. As a special case, if the <length> argument is zero,
13239 the the whole buffer from <offset> to the end is extracted. This can be used
13240 with ACLs in order to check for the presence of some content in a buffer at
13241 any location.
Willy Tarreaud63335a2010-02-26 12:56:52 +010013242
Willy Tarreau74ca5042013-06-11 23:12:07 +020013243res.payload_lv(<offset1>,<length>[,<offset2>]) : binary
13244 This extracts a binary block whose size is specified at <offset1> for <length>
13245 bytes, and which starts at <offset2> if specified or just after the length in
13246 the response buffer. The <offset2> parameter also supports relative offsets
13247 if prepended with a '+' or '-' sign.
Willy Tarreaud63335a2010-02-26 12:56:52 +010013248
Willy Tarreau74ca5042013-06-11 23:12:07 +020013249 Example : please consult the example from the "stick store-response" keyword.
Willy Tarreaud63335a2010-02-26 12:56:52 +010013250
Willy Tarreau74ca5042013-06-11 23:12:07 +020013251wait_end : boolean
13252 This fetch either returns true when the inspection period is over, or does
13253 not fetch. It is only used in ACLs, in conjunction with content analysis to
13254 avoid returning a wrong verdict early. It may also be used to delay some
13255 actions, such as a delayed reject for some special addresses. Since it either
13256 stops the rules evaluation or immediately returns true, it is recommended to
13257 use this acl as the last one in a rule. Please note that the default ACL
13258 "WAIT_END" is always usable without prior declaration. This test was designed
13259 to be used with TCP request content inspection.
Willy Tarreaud63335a2010-02-26 12:56:52 +010013260
Willy Tarreau74ca5042013-06-11 23:12:07 +020013261 Examples :
13262 # delay every incoming request by 2 seconds
13263 tcp-request inspect-delay 2s
13264 tcp-request content accept if WAIT_END
Willy Tarreaud63335a2010-02-26 12:56:52 +010013265
Willy Tarreau74ca5042013-06-11 23:12:07 +020013266 # don't immediately tell bad guys they are rejected
13267 tcp-request inspect-delay 10s
13268 acl goodguys src 10.0.0.0/24
13269 acl badguys src 10.0.1.0/24
13270 tcp-request content accept if goodguys
13271 tcp-request content reject if badguys WAIT_END
13272 tcp-request content reject
13273
13274
Thierry FOURNIER060762e2014-04-23 13:29:15 +0200132757.3.6. Fetching HTTP samples (Layer 7)
Willy Tarreau74ca5042013-06-11 23:12:07 +020013276--------------------------------------
13277
13278It is possible to fetch samples from HTTP contents, requests and responses.
13279This application layer is also called layer 7. It is only possible to fetch the
13280data in this section when a full HTTP request or response has been parsed from
13281its respective request or response buffer. This is always the case with all
13282HTTP specific rules and for sections running with "mode http". When using TCP
13283content inspection, it may be necessary to support an inspection delay in order
13284to let the request or response come in first. These fetches may require a bit
13285more CPU resources than the layer 4 ones, but not much since the request and
13286response are indexed.
13287
13288base : string
13289 This returns the concatenation of the first Host header and the path part of
13290 the request, which starts at the first slash and ends before the question
13291 mark. It can be useful in virtual hosted environments to detect URL abuses as
13292 well as to improve shared caches efficiency. Using this with a limited size
13293 stick table also allows one to collect statistics about most commonly
13294 requested objects by host/path. With ACLs it can allow simple content
13295 switching rules involving the host and the path at the same time, such as
13296 "www.example.com/favicon.ico". See also "path" and "uri".
13297
13298 ACL derivatives :
13299 base : exact string match
13300 base_beg : prefix match
13301 base_dir : subdir match
13302 base_dom : domain match
13303 base_end : suffix match
13304 base_len : length match
13305 base_reg : regex match
13306 base_sub : substring match
13307
13308base32 : integer
13309 This returns a 32-bit hash of the value returned by the "base" fetch method
13310 above. This is useful to track per-URL activity on high traffic sites without
13311 having to store all URLs. Instead a shorter hash is stored, saving a lot of
Willy Tarreau23ec4ca2014-07-15 20:15:37 +020013312 memory. The output type is an unsigned integer. The hash function used is
13313 SDBM with full avalanche on the output. Technically, base32 is exactly equal
13314 to "base,sdbm(1)".
Willy Tarreau74ca5042013-06-11 23:12:07 +020013315
13316base32+src : binary
13317 This returns the concatenation of the base32 fetch above and the src fetch
13318 below. The resulting type is of type binary, with a size of 8 or 20 bytes
13319 depending on the source address family. This can be used to track per-IP,
13320 per-URL counters.
13321
William Lallemand65ad6e12014-01-31 15:08:02 +010013322capture.req.hdr(<idx>) : string
13323 This extracts the content of the header captured by the "capture request
13324 header", idx is the position of the capture keyword in the configuration.
13325 The first entry is an index of 0. See also: "capture request header".
13326
13327capture.req.method : string
13328 This extracts the METHOD of an HTTP request. It can be used in both request
13329 and response. Unlike "method", it can be used in both request and response
13330 because it's allocated.
13331
13332capture.req.uri : string
13333 This extracts the request's URI, which starts at the first slash and ends
13334 before the first space in the request (without the host part). Unlike "path"
13335 and "url", it can be used in both request and response because it's
13336 allocated.
13337
Willy Tarreau3c1b5ec2014-04-24 23:41:57 +020013338capture.req.ver : string
13339 This extracts the request's HTTP version and returns either "HTTP/1.0" or
13340 "HTTP/1.1". Unlike "req.ver", it can be used in both request, response, and
13341 logs because it relies on a persistent flag.
13342
William Lallemand65ad6e12014-01-31 15:08:02 +010013343capture.res.hdr(<idx>) : string
13344 This extracts the content of the header captured by the "capture response
13345 header", idx is the position of the capture keyword in the configuration.
13346 The first entry is an index of 0.
13347 See also: "capture response header"
13348
Willy Tarreau3c1b5ec2014-04-24 23:41:57 +020013349capture.res.ver : string
13350 This extracts the response's HTTP version and returns either "HTTP/1.0" or
13351 "HTTP/1.1". Unlike "res.ver", it can be used in logs because it relies on a
13352 persistent flag.
13353
Willy Tarreaua5910cc2015-05-02 00:46:08 +020013354req.body : binary
13355 This returns the HTTP request's available body as a block of data. It
13356 requires that the request body has been buffered made available using
13357 "option http-buffer-request". In case of chunked-encoded body, currently only
13358 the first chunk is analyzed.
13359
Thierry FOURNIER9826c772015-05-20 15:50:54 +020013360req.body_param([<name>) : string
13361 This fetch assumes that the body of the POST request is url-encoded. The user
13362 can check if the "content-type" contains the value
13363 "application/x-www-form-urlencoded". This extracts the first occurrence of the
13364 parameter <name> in the body, which ends before '&'. The parameter name is
13365 case-sensitive. If no name is given, any parameter will match, and the first
13366 one will be returned. The result is a string corresponding to the value of the
13367 parameter <name> as presented in the request body (no URL decoding is
13368 performed). Note that the ACL version of this fetch iterates over multiple
13369 parameters and will iteratively report all parameters values if no name is
13370 given.
13371
Willy Tarreaua5910cc2015-05-02 00:46:08 +020013372req.body_len : integer
13373 This returns the length of the HTTP request's available body in bytes. It may
13374 be lower than the advertised length if the body is larger than the buffer. It
13375 requires that the request body has been buffered made available using
13376 "option http-buffer-request".
13377
13378req.body_size : integer
13379 This returns the advertised length of the HTTP request's body in bytes. It
13380 will represent the advertised Content-Length header, or the size of the first
13381 chunk in case of chunked encoding. In order to parse the chunks, it requires
13382 that the request body has been buffered made available using
13383 "option http-buffer-request".
13384
Willy Tarreau74ca5042013-06-11 23:12:07 +020013385req.cook([<name>]) : string
13386cook([<name>]) : string (deprecated)
13387 This extracts the last occurrence of the cookie name <name> on a "Cookie"
13388 header line from the request, and returns its value as string. If no name is
13389 specified, the first cookie value is returned. When used with ACLs, all
13390 matching cookies are evaluated. Spaces around the name and the value are
13391 ignored as requested by the Cookie header specification (RFC6265). The cookie
13392 name is case-sensitive. Empty cookies are valid, so an empty cookie may very
13393 well return an empty value if it is present. Use the "found" match to detect
13394 presence. Use the res.cook() variant for response cookies sent by the server.
13395
13396 ACL derivatives :
13397 cook([<name>]) : exact string match
13398 cook_beg([<name>]) : prefix match
13399 cook_dir([<name>]) : subdir match
13400 cook_dom([<name>]) : domain match
13401 cook_end([<name>]) : suffix match
13402 cook_len([<name>]) : length match
13403 cook_reg([<name>]) : regex match
13404 cook_sub([<name>]) : substring match
Willy Tarreaud63335a2010-02-26 12:56:52 +010013405
Willy Tarreau74ca5042013-06-11 23:12:07 +020013406req.cook_cnt([<name>]) : integer
13407cook_cnt([<name>]) : integer (deprecated)
13408 Returns an integer value representing the number of occurrences of the cookie
13409 <name> in the request, or all cookies if <name> is not specified.
Willy Tarreaud63335a2010-02-26 12:56:52 +010013410
Willy Tarreau74ca5042013-06-11 23:12:07 +020013411req.cook_val([<name>]) : integer
13412cook_val([<name>]) : integer (deprecated)
13413 This extracts the last occurrence of the cookie name <name> on a "Cookie"
13414 header line from the request, and converts its value to an integer which is
13415 returned. If no name is specified, the first cookie value is returned. When
13416 used in ACLs, all matching names are iterated over until a value matches.
Willy Tarreau0e698542011-09-16 08:32:32 +020013417
Willy Tarreau74ca5042013-06-11 23:12:07 +020013418cookie([<name>]) : string (deprecated)
13419 This extracts the last occurrence of the cookie name <name> on a "Cookie"
13420 header line from the request, or a "Set-Cookie" header from the response, and
13421 returns its value as a string. A typical use is to get multiple clients
13422 sharing a same profile use the same server. This can be similar to what
Willy Tarreau294d0f02015-08-10 19:40:12 +020013423 "appsession" did with the "request-learn" statement, but with support for
Willy Tarreau74ca5042013-06-11 23:12:07 +020013424 multi-peer synchronization and state keeping across restarts. If no name is
13425 specified, the first cookie value is returned. This fetch should not be used
13426 anymore and should be replaced by req.cook() or res.cook() instead as it
13427 ambiguously uses the direction based on the context where it is used.
Willy Tarreaud63335a2010-02-26 12:56:52 +010013428
Willy Tarreau74ca5042013-06-11 23:12:07 +020013429hdr([<name>[,<occ>]]) : string
13430 This is equivalent to req.hdr() when used on requests, and to res.hdr() when
13431 used on responses. Please refer to these respective fetches for more details.
13432 In case of doubt about the fetch direction, please use the explicit ones.
13433 Note that contrary to the hdr() sample fetch method, the hdr_* ACL keywords
Jarno Huuskonen0e82b922014-04-12 18:22:19 +030013434 unambiguously apply to the request headers.
Willy Tarreaud63335a2010-02-26 12:56:52 +010013435
Willy Tarreau74ca5042013-06-11 23:12:07 +020013436req.fhdr(<name>[,<occ>]) : string
13437 This extracts the last occurrence of header <name> in an HTTP request. When
13438 used from an ACL, all occurrences are iterated over until a match is found.
13439 Optionally, a specific occurrence might be specified as a position number.
13440 Positive values indicate a position from the first occurrence, with 1 being
13441 the first one. Negative values indicate positions relative to the last one,
13442 with -1 being the last one. It differs from req.hdr() in that any commas
13443 present in the value are returned and are not used as delimiters. This is
13444 sometimes useful with headers such as User-Agent.
Willy Tarreaud63335a2010-02-26 12:56:52 +010013445
Willy Tarreau74ca5042013-06-11 23:12:07 +020013446req.fhdr_cnt([<name>]) : integer
13447 Returns an integer value representing the number of occurrences of request
13448 header field name <name>, or the total number of header fields if <name> is
13449 not specified. Contrary to its req.hdr_cnt() cousin, this function returns
13450 the number of full line headers and does not stop on commas.
Willy Tarreaud63335a2010-02-26 12:56:52 +010013451
Willy Tarreau74ca5042013-06-11 23:12:07 +020013452req.hdr([<name>[,<occ>]]) : string
13453 This extracts the last occurrence of header <name> in an HTTP request. When
13454 used from an ACL, all occurrences are iterated over until a match is found.
13455 Optionally, a specific occurrence might be specified as a position number.
13456 Positive values indicate a position from the first occurrence, with 1 being
13457 the first one. Negative values indicate positions relative to the last one,
13458 with -1 being the last one. A typical use is with the X-Forwarded-For header
13459 once converted to IP, associated with an IP stick-table. The function
13460 considers any comma as a delimiter for distinct values. If full-line headers
13461 are desired instead, use req.fhdr(). Please carefully check RFC2616 to know
13462 how certain headers are supposed to be parsed. Also, some of them are case
13463 insensitive (eg: Connection).
Willy Tarreaud63335a2010-02-26 12:56:52 +010013464
Willy Tarreau74ca5042013-06-11 23:12:07 +020013465 ACL derivatives :
13466 hdr([<name>[,<occ>]]) : exact string match
13467 hdr_beg([<name>[,<occ>]]) : prefix match
13468 hdr_dir([<name>[,<occ>]]) : subdir match
13469 hdr_dom([<name>[,<occ>]]) : domain match
13470 hdr_end([<name>[,<occ>]]) : suffix match
13471 hdr_len([<name>[,<occ>]]) : length match
13472 hdr_reg([<name>[,<occ>]]) : regex match
13473 hdr_sub([<name>[,<occ>]]) : substring match
13474
13475req.hdr_cnt([<name>]) : integer
13476hdr_cnt([<header>]) : integer (deprecated)
13477 Returns an integer value representing the number of occurrences of request
13478 header field name <name>, or the total number of header field values if
13479 <name> is not specified. It is important to remember that one header line may
13480 count as several headers if it has several values. The function considers any
13481 comma as a delimiter for distinct values. If full-line headers are desired
13482 instead, req.fhdr_cnt() should be used instead. With ACLs, it can be used to
13483 detect presence, absence or abuse of a specific header, as well as to block
13484 request smuggling attacks by rejecting requests which contain more than one
13485 of certain headers. See "req.hdr" for more information on header matching.
13486
13487req.hdr_ip([<name>[,<occ>]]) : ip
13488hdr_ip([<name>[,<occ>]]) : ip (deprecated)
13489 This extracts the last occurrence of header <name> in an HTTP request,
13490 converts it to an IPv4 or IPv6 address and returns this address. When used
13491 with ACLs, all occurrences are checked, and if <name> is omitted, every value
13492 of every header is checked. Optionally, a specific occurrence might be
13493 specified as a position number. Positive values indicate a position from the
13494 first occurrence, with 1 being the first one. Negative values indicate
13495 positions relative to the last one, with -1 being the last one. A typical use
13496 is with the X-Forwarded-For and X-Client-IP headers.
13497
13498req.hdr_val([<name>[,<occ>]]) : integer
13499hdr_val([<name>[,<occ>]]) : integer (deprecated)
13500 This extracts the last occurrence of header <name> in an HTTP request, and
13501 converts it to an integer value. When used with ACLs, all occurrences are
13502 checked, and if <name> is omitted, every value of every header is checked.
13503 Optionally, a specific occurrence might be specified as a position number.
13504 Positive values indicate a position from the first occurrence, with 1 being
13505 the first one. Negative values indicate positions relative to the last one,
13506 with -1 being the last one. A typical use is with the X-Forwarded-For header.
13507
13508http_auth(<userlist>) : boolean
13509 Returns a boolean indicating whether the authentication data received from
13510 the client match a username & password stored in the specified userlist. This
13511 fetch function is not really useful outside of ACLs. Currently only http
13512 basic auth is supported.
13513
Thierry FOURNIER9eec0a62014-01-22 18:38:02 +010013514http_auth_group(<userlist>) : string
13515 Returns a string corresponding to the user name found in the authentication
13516 data received from the client if both the user name and password are valid
13517 according to the specified userlist. The main purpose is to use it in ACLs
13518 where it is then checked whether the user belongs to any group within a list.
Willy Tarreau74ca5042013-06-11 23:12:07 +020013519 This fetch function is not really useful outside of ACLs. Currently only http
13520 basic auth is supported.
13521
13522 ACL derivatives :
Thierry FOURNIER9eec0a62014-01-22 18:38:02 +010013523 http_auth_group(<userlist>) : group ...
13524 Returns true when the user extracted from the request and whose password is
13525 valid according to the specified userlist belongs to at least one of the
13526 groups.
Willy Tarreau74ca5042013-06-11 23:12:07 +020013527
13528http_first_req : boolean
Willy Tarreau7f18e522010-10-22 20:04:13 +020013529 Returns true when the request being processed is the first one of the
13530 connection. This can be used to add or remove headers that may be missing
Willy Tarreau74ca5042013-06-11 23:12:07 +020013531 from some requests when a request is not the first one, or to help grouping
13532 requests in the logs.
Willy Tarreau7f18e522010-10-22 20:04:13 +020013533
Willy Tarreau74ca5042013-06-11 23:12:07 +020013534method : integer + string
13535 Returns an integer value corresponding to the method in the HTTP request. For
13536 example, "GET" equals 1 (check sources to establish the matching). Value 9
13537 means "other method" and may be converted to a string extracted from the
13538 stream. This should not be used directly as a sample, this is only meant to
13539 be used from ACLs, which transparently convert methods from patterns to these
13540 integer + string values. Some predefined ACL already check for most common
13541 methods.
Willy Tarreau6a06a402007-07-15 20:15:28 +020013542
Willy Tarreau74ca5042013-06-11 23:12:07 +020013543 ACL derivatives :
13544 method : case insensitive method match
Willy Tarreau6a06a402007-07-15 20:15:28 +020013545
Willy Tarreau74ca5042013-06-11 23:12:07 +020013546 Example :
13547 # only accept GET and HEAD requests
13548 acl valid_method method GET HEAD
13549 http-request deny if ! valid_method
Willy Tarreau6a06a402007-07-15 20:15:28 +020013550
Willy Tarreau74ca5042013-06-11 23:12:07 +020013551path : string
13552 This extracts the request's URL path, which starts at the first slash and
13553 ends before the question mark (without the host part). A typical use is with
13554 prefetch-capable caches, and with portals which need to aggregate multiple
13555 information from databases and keep them in caches. Note that with outgoing
13556 caches, it would be wiser to use "url" instead. With ACLs, it's typically
13557 used to match exact file names (eg: "/login.php"), or directory parts using
13558 the derivative forms. See also the "url" and "base" fetch methods.
Willy Tarreau6a06a402007-07-15 20:15:28 +020013559
Willy Tarreau74ca5042013-06-11 23:12:07 +020013560 ACL derivatives :
13561 path : exact string match
13562 path_beg : prefix match
13563 path_dir : subdir match
13564 path_dom : domain match
13565 path_end : suffix match
13566 path_len : length match
13567 path_reg : regex match
13568 path_sub : substring match
Willy Tarreau6a06a402007-07-15 20:15:28 +020013569
Willy Tarreau49ad95c2015-01-19 15:06:26 +010013570query : string
13571 This extracts the request's query string, which starts after the first
13572 question mark. If no question mark is present, this fetch returns nothing. If
13573 a question mark is present but nothing follows, it returns an empty string.
13574 This means it's possible to easily know whether a query string is present
13575 using the "found" matching method. This fetch is the completemnt of "path"
13576 which stops before the question mark.
13577
Willy Tarreaueb27ec72015-02-20 13:55:29 +010013578req.hdr_names([<delim>]) : string
13579 This builds a string made from the concatenation of all header names as they
13580 appear in the request when the rule is evaluated. The default delimiter is
13581 the comma (',') but it may be overridden as an optional argument <delim>. In
13582 this case, only the first character of <delim> is considered.
13583
Willy Tarreau74ca5042013-06-11 23:12:07 +020013584req.ver : string
13585req_ver : string (deprecated)
13586 Returns the version string from the HTTP request, for example "1.1". This can
13587 be useful for logs, but is mostly there for ACL. Some predefined ACL already
13588 check for versions 1.0 and 1.1.
Willy Tarreaud63335a2010-02-26 12:56:52 +010013589
Willy Tarreau74ca5042013-06-11 23:12:07 +020013590 ACL derivatives :
13591 req_ver : exact string match
Willy Tarreau0e698542011-09-16 08:32:32 +020013592
Willy Tarreau74ca5042013-06-11 23:12:07 +020013593res.comp : boolean
13594 Returns the boolean "true" value if the response has been compressed by
13595 HAProxy, otherwise returns boolean "false". This may be used to add
13596 information in the logs.
Willy Tarreau6a06a402007-07-15 20:15:28 +020013597
Willy Tarreau74ca5042013-06-11 23:12:07 +020013598res.comp_algo : string
13599 Returns a string containing the name of the algorithm used if the response
13600 was compressed by HAProxy, for example : "deflate". This may be used to add
13601 some information in the logs.
Willy Tarreaud63335a2010-02-26 12:56:52 +010013602
Willy Tarreau74ca5042013-06-11 23:12:07 +020013603res.cook([<name>]) : string
13604scook([<name>]) : string (deprecated)
13605 This extracts the last occurrence of the cookie name <name> on a "Set-Cookie"
13606 header line from the response, and returns its value as string. If no name is
13607 specified, the first cookie value is returned.
Willy Tarreau0ce3aa02012-04-25 18:46:33 +020013608
Willy Tarreau74ca5042013-06-11 23:12:07 +020013609 ACL derivatives :
13610 scook([<name>] : exact string match
Willy Tarreau0ce3aa02012-04-25 18:46:33 +020013611
Willy Tarreau74ca5042013-06-11 23:12:07 +020013612res.cook_cnt([<name>]) : integer
13613scook_cnt([<name>]) : integer (deprecated)
13614 Returns an integer value representing the number of occurrences of the cookie
13615 <name> in the response, or all cookies if <name> is not specified. This is
13616 mostly useful when combined with ACLs to detect suspicious responses.
Willy Tarreaud63335a2010-02-26 12:56:52 +010013617
Willy Tarreau74ca5042013-06-11 23:12:07 +020013618res.cook_val([<name>]) : integer
13619scook_val([<name>]) : integer (deprecated)
13620 This extracts the last occurrence of the cookie name <name> on a "Set-Cookie"
13621 header line from the response, and converts its value to an integer which is
13622 returned. If no name is specified, the first cookie value is returned.
Willy Tarreaud63335a2010-02-26 12:56:52 +010013623
Willy Tarreau74ca5042013-06-11 23:12:07 +020013624res.fhdr([<name>[,<occ>]]) : string
13625 This extracts the last occurrence of header <name> in an HTTP response, or of
13626 the last header if no <name> is specified. Optionally, a specific occurrence
13627 might be specified as a position number. Positive values indicate a position
13628 from the first occurrence, with 1 being the first one. Negative values
13629 indicate positions relative to the last one, with -1 being the last one. It
13630 differs from res.hdr() in that any commas present in the value are returned
13631 and are not used as delimiters. If this is not desired, the res.hdr() fetch
13632 should be used instead. This is sometimes useful with headers such as Date or
13633 Expires.
Willy Tarreau6a06a402007-07-15 20:15:28 +020013634
Willy Tarreau74ca5042013-06-11 23:12:07 +020013635res.fhdr_cnt([<name>]) : integer
13636 Returns an integer value representing the number of occurrences of response
13637 header field name <name>, or the total number of header fields if <name> is
13638 not specified. Contrary to its res.hdr_cnt() cousin, this function returns
13639 the number of full line headers and does not stop on commas. If this is not
13640 desired, the res.hdr_cnt() fetch should be used instead.
Willy Tarreau6a06a402007-07-15 20:15:28 +020013641
Willy Tarreau74ca5042013-06-11 23:12:07 +020013642res.hdr([<name>[,<occ>]]) : string
13643shdr([<name>[,<occ>]]) : string (deprecated)
13644 This extracts the last occurrence of header <name> in an HTTP response, or of
13645 the last header if no <name> is specified. Optionally, a specific occurrence
13646 might be specified as a position number. Positive values indicate a position
13647 from the first occurrence, with 1 being the first one. Negative values
13648 indicate positions relative to the last one, with -1 being the last one. This
13649 can be useful to learn some data into a stick-table. The function considers
13650 any comma as a delimiter for distinct values. If this is not desired, the
13651 res.fhdr() fetch should be used instead.
Willy Tarreau6a06a402007-07-15 20:15:28 +020013652
Willy Tarreau74ca5042013-06-11 23:12:07 +020013653 ACL derivatives :
13654 shdr([<name>[,<occ>]]) : exact string match
13655 shdr_beg([<name>[,<occ>]]) : prefix match
13656 shdr_dir([<name>[,<occ>]]) : subdir match
13657 shdr_dom([<name>[,<occ>]]) : domain match
13658 shdr_end([<name>[,<occ>]]) : suffix match
13659 shdr_len([<name>[,<occ>]]) : length match
13660 shdr_reg([<name>[,<occ>]]) : regex match
13661 shdr_sub([<name>[,<occ>]]) : substring match
13662
13663res.hdr_cnt([<name>]) : integer
13664shdr_cnt([<name>]) : integer (deprecated)
13665 Returns an integer value representing the number of occurrences of response
13666 header field name <name>, or the total number of header fields if <name> is
13667 not specified. The function considers any comma as a delimiter for distinct
13668 values. If this is not desired, the res.fhdr_cnt() fetch should be used
13669 instead.
Willy Tarreau6a06a402007-07-15 20:15:28 +020013670
Willy Tarreau74ca5042013-06-11 23:12:07 +020013671res.hdr_ip([<name>[,<occ>]]) : ip
13672shdr_ip([<name>[,<occ>]]) : ip (deprecated)
13673 This extracts the last occurrence of header <name> in an HTTP response,
13674 convert it to an IPv4 or IPv6 address and returns this address. Optionally, a
13675 specific occurrence might be specified as a position number. Positive values
13676 indicate a position from the first occurrence, with 1 being the first one.
13677 Negative values indicate positions relative to the last one, with -1 being
13678 the last one. This can be useful to learn some data into a stick table.
Willy Tarreau6a06a402007-07-15 20:15:28 +020013679
Willy Tarreaueb27ec72015-02-20 13:55:29 +010013680res.hdr_names([<delim>]) : string
13681 This builds a string made from the concatenation of all header names as they
13682 appear in the response when the rule is evaluated. The default delimiter is
13683 the comma (',') but it may be overridden as an optional argument <delim>. In
13684 this case, only the first character of <delim> is considered.
13685
Willy Tarreau74ca5042013-06-11 23:12:07 +020013686res.hdr_val([<name>[,<occ>]]) : integer
13687shdr_val([<name>[,<occ>]]) : integer (deprecated)
13688 This extracts the last occurrence of header <name> in an HTTP response, and
13689 converts it to an integer value. Optionally, a specific occurrence might be
13690 specified as a position number. Positive values indicate a position from the
13691 first occurrence, with 1 being the first one. Negative values indicate
13692 positions relative to the last one, with -1 being the last one. This can be
13693 useful to learn some data into a stick table.
Alexandre Cassen5eb1a902007-11-29 15:43:32 +010013694
Willy Tarreau74ca5042013-06-11 23:12:07 +020013695res.ver : string
13696resp_ver : string (deprecated)
13697 Returns the version string from the HTTP response, for example "1.1". This
13698 can be useful for logs, but is mostly there for ACL.
Willy Tarreau0e698542011-09-16 08:32:32 +020013699
Willy Tarreau74ca5042013-06-11 23:12:07 +020013700 ACL derivatives :
13701 resp_ver : exact string match
Alexandre Cassen5eb1a902007-11-29 15:43:32 +010013702
Willy Tarreau74ca5042013-06-11 23:12:07 +020013703set-cookie([<name>]) : string (deprecated)
13704 This extracts the last occurrence of the cookie name <name> on a "Set-Cookie"
13705 header line from the response and uses the corresponding value to match. This
Willy Tarreau294d0f02015-08-10 19:40:12 +020013706 can be comparable to what "appsession" did with default options, but with
Willy Tarreau74ca5042013-06-11 23:12:07 +020013707 support for multi-peer synchronization and state keeping across restarts.
Krzysztof Piotr Oledzki6b35ce12010-02-01 23:35:44 +010013708
Willy Tarreau74ca5042013-06-11 23:12:07 +020013709 This fetch function is deprecated and has been superseded by the "res.cook"
13710 fetch. This keyword will disappear soon.
Krzysztof Piotr Oledzki6b35ce12010-02-01 23:35:44 +010013711
Willy Tarreau74ca5042013-06-11 23:12:07 +020013712status : integer
13713 Returns an integer containing the HTTP status code in the HTTP response, for
13714 example, 302. It is mostly used within ACLs and integer ranges, for example,
13715 to remove any Location header if the response is not a 3xx.
Willy Tarreau25c1ebc2012-04-25 16:21:44 +020013716
Willy Tarreau74ca5042013-06-11 23:12:07 +020013717url : string
13718 This extracts the request's URL as presented in the request. A typical use is
13719 with prefetch-capable caches, and with portals which need to aggregate
13720 multiple information from databases and keep them in caches. With ACLs, using
13721 "path" is preferred over using "url", because clients may send a full URL as
13722 is normally done with proxies. The only real use is to match "*" which does
13723 not match in "path", and for which there is already a predefined ACL. See
13724 also "path" and "base".
Willy Tarreau25c1ebc2012-04-25 16:21:44 +020013725
Willy Tarreau74ca5042013-06-11 23:12:07 +020013726 ACL derivatives :
13727 url : exact string match
13728 url_beg : prefix match
13729 url_dir : subdir match
13730 url_dom : domain match
13731 url_end : suffix match
13732 url_len : length match
13733 url_reg : regex match
13734 url_sub : substring match
Willy Tarreau25c1ebc2012-04-25 16:21:44 +020013735
Willy Tarreau74ca5042013-06-11 23:12:07 +020013736url_ip : ip
13737 This extracts the IP address from the request's URL when the host part is
13738 presented as an IP address. Its use is very limited. For instance, a
13739 monitoring system might use this field as an alternative for the source IP in
13740 order to test what path a given source address would follow, or to force an
13741 entry in a table for a given source address. With ACLs it can be used to
13742 restrict access to certain systems through a proxy, for example when combined
13743 with option "http_proxy".
Willy Tarreau25c1ebc2012-04-25 16:21:44 +020013744
Willy Tarreau74ca5042013-06-11 23:12:07 +020013745url_port : integer
13746 This extracts the port part from the request's URL. Note that if the port is
13747 not specified in the request, port 80 is assumed. With ACLs it can be used to
13748 restrict access to certain systems through a proxy, for example when combined
13749 with option "http_proxy".
Willy Tarreau25c1ebc2012-04-25 16:21:44 +020013750
Willy Tarreau1ede1da2015-05-07 16:06:18 +020013751urlp([<name>[,<delim>]]) : string
13752url_param([<name>[,<delim>]]) : string
Willy Tarreau74ca5042013-06-11 23:12:07 +020013753 This extracts the first occurrence of the parameter <name> in the query
13754 string, which begins after either '?' or <delim>, and which ends before '&',
Willy Tarreau1ede1da2015-05-07 16:06:18 +020013755 ';' or <delim>. The parameter name is case-sensitive. If no name is given,
13756 any parameter will match, and the first one will be returned. The result is
13757 a string corresponding to the value of the parameter <name> as presented in
13758 the request (no URL decoding is performed). This can be used for session
Willy Tarreau74ca5042013-06-11 23:12:07 +020013759 stickiness based on a client ID, to extract an application cookie passed as a
13760 URL parameter, or in ACLs to apply some checks. Note that the ACL version of
Willy Tarreau1ede1da2015-05-07 16:06:18 +020013761 this fetch iterates over multiple parameters and will iteratively report all
13762 parameters values if no name is given
Willy Tarreau25c1ebc2012-04-25 16:21:44 +020013763
Willy Tarreau74ca5042013-06-11 23:12:07 +020013764 ACL derivatives :
13765 urlp(<name>[,<delim>]) : exact string match
13766 urlp_beg(<name>[,<delim>]) : prefix match
13767 urlp_dir(<name>[,<delim>]) : subdir match
13768 urlp_dom(<name>[,<delim>]) : domain match
13769 urlp_end(<name>[,<delim>]) : suffix match
13770 urlp_len(<name>[,<delim>]) : length match
13771 urlp_reg(<name>[,<delim>]) : regex match
13772 urlp_sub(<name>[,<delim>]) : substring match
Willy Tarreau25c1ebc2012-04-25 16:21:44 +020013773
Willy Tarreau25c1ebc2012-04-25 16:21:44 +020013774
Willy Tarreau74ca5042013-06-11 23:12:07 +020013775 Example :
13776 # match http://example.com/foo?PHPSESSIONID=some_id
13777 stick on urlp(PHPSESSIONID)
13778 # match http://example.com/foo;JSESSIONID=some_id
13779 stick on urlp(JSESSIONID,;)
Willy Tarreau25c1ebc2012-04-25 16:21:44 +020013780
Willy Tarreau1ede1da2015-05-07 16:06:18 +020013781urlp_val([<name>[,<delim>])] : integer
Willy Tarreau74ca5042013-06-11 23:12:07 +020013782 See "urlp" above. This one extracts the URL parameter <name> in the request
13783 and converts it to an integer value. This can be used for session stickiness
13784 based on a user ID for example, or with ACLs to match a page number or price.
Willy Tarreaua9fddca2012-07-31 07:51:48 +020013785
Willy Tarreau198a7442008-01-17 12:05:32 +010013786
Willy Tarreau74ca5042013-06-11 23:12:07 +0200137877.4. Pre-defined ACLs
Willy Tarreauc57f0e22009-05-10 13:12:33 +020013788---------------------
Willy Tarreauced27012008-01-17 20:35:34 +010013789
Willy Tarreauc57f0e22009-05-10 13:12:33 +020013790Some predefined ACLs are hard-coded so that they do not have to be declared in
13791every frontend which needs them. They all have their names in upper case in
Patrick Mézard2382ad62010-05-09 10:43:32 +020013792order to avoid confusion. Their equivalence is provided below.
Willy Tarreauced27012008-01-17 20:35:34 +010013793
Willy Tarreauc57f0e22009-05-10 13:12:33 +020013794ACL name Equivalent to Usage
13795---------------+-----------------------------+---------------------------------
Willy Tarreauc57f0e22009-05-10 13:12:33 +020013796FALSE always_false never match
Willy Tarreau2492d5b2009-07-11 00:06:00 +020013797HTTP req_proto_http match if protocol is valid HTTP
Willy Tarreauc57f0e22009-05-10 13:12:33 +020013798HTTP_1.0 req_ver 1.0 match HTTP version 1.0
13799HTTP_1.1 req_ver 1.1 match HTTP version 1.1
Willy Tarreaud63335a2010-02-26 12:56:52 +010013800HTTP_CONTENT hdr_val(content-length) gt 0 match an existing content-length
13801HTTP_URL_ABS url_reg ^[^/:]*:// match absolute URL with scheme
13802HTTP_URL_SLASH url_beg / match URL beginning with "/"
13803HTTP_URL_STAR url * match URL equal to "*"
13804LOCALHOST src 127.0.0.1/8 match connection from local host
Willy Tarreauc57f0e22009-05-10 13:12:33 +020013805METH_CONNECT method CONNECT match HTTP CONNECT method
13806METH_GET method GET HEAD match HTTP GET or HEAD method
13807METH_HEAD method HEAD match HTTP HEAD method
13808METH_OPTIONS method OPTIONS match HTTP OPTIONS method
13809METH_POST method POST match HTTP POST method
13810METH_TRACE method TRACE match HTTP TRACE method
Emeric Brunbede3d02009-06-30 17:54:00 +020013811RDP_COOKIE req_rdp_cookie_cnt gt 0 match presence of an RDP cookie
Willy Tarreauc57f0e22009-05-10 13:12:33 +020013812REQ_CONTENT req_len gt 0 match data in the request buffer
Willy Tarreaud63335a2010-02-26 12:56:52 +010013813TRUE always_true always match
Willy Tarreauc57f0e22009-05-10 13:12:33 +020013814WAIT_END wait_end wait for end of content analysis
13815---------------+-----------------------------+---------------------------------
Willy Tarreauced27012008-01-17 20:35:34 +010013816
Willy Tarreaub937b7e2010-01-12 15:27:54 +010013817
Willy Tarreauc57f0e22009-05-10 13:12:33 +0200138188. Logging
13819----------
Willy Tarreau844e3c52008-01-11 16:28:18 +010013820
Willy Tarreaucc6c8912009-02-22 10:53:55 +010013821One of HAProxy's strong points certainly lies is its precise logs. It probably
13822provides the finest level of information available for such a product, which is
13823very important for troubleshooting complex environments. Standard information
13824provided in logs include client ports, TCP/HTTP state timers, precise session
13825state at termination and precise termination cause, information about decisions
Krzysztof Piotr Oledzkif8645332009-12-13 21:55:50 +010013826to direct traffic to a server, and of course the ability to capture arbitrary
Willy Tarreaucc6c8912009-02-22 10:53:55 +010013827headers.
13828
13829In order to improve administrators reactivity, it offers a great transparency
13830about encountered problems, both internal and external, and it is possible to
13831send logs to different sources at the same time with different level filters :
13832
13833 - global process-level logs (system errors, start/stop, etc..)
13834 - per-instance system and internal errors (lack of resource, bugs, ...)
13835 - per-instance external troubles (servers up/down, max connections)
13836 - per-instance activity (client connections), either at the establishment or
13837 at the termination.
Jim Freeman9e8714b2015-05-26 09:16:34 -060013838 - per-request control of log-level, eg:
13839 http-request set-log-level silent if sensitive_request
Willy Tarreaucc6c8912009-02-22 10:53:55 +010013840
13841The ability to distribute different levels of logs to different log servers
13842allow several production teams to interact and to fix their problems as soon
13843as possible. For example, the system team might monitor system-wide errors,
13844while the application team might be monitoring the up/down for their servers in
13845real time, and the security team might analyze the activity logs with one hour
13846delay.
13847
13848
Willy Tarreauc57f0e22009-05-10 13:12:33 +0200138498.1. Log levels
13850---------------
Willy Tarreaucc6c8912009-02-22 10:53:55 +010013851
Simon Hormandf791f52011-05-29 15:01:10 +090013852TCP and HTTP connections can be logged with information such as the date, time,
Willy Tarreaucc6c8912009-02-22 10:53:55 +010013853source IP address, destination address, connection duration, response times,
Simon Hormandf791f52011-05-29 15:01:10 +090013854HTTP request, HTTP return code, number of bytes transmitted, conditions
13855in which the session ended, and even exchanged cookies values. For example
13856track a particular user's problems. All messages may be sent to up to two
13857syslog servers. Check the "log" keyword in section 4.2 for more information
13858about log facilities.
Willy Tarreaucc6c8912009-02-22 10:53:55 +010013859
13860
Willy Tarreauc57f0e22009-05-10 13:12:33 +0200138618.2. Log formats
13862----------------
Willy Tarreaucc6c8912009-02-22 10:53:55 +010013863
William Lallemand48940402012-01-30 16:47:22 +010013864HAProxy supports 5 log formats. Several fields are common between these formats
Simon Hormandf791f52011-05-29 15:01:10 +090013865and will be detailed in the following sections. A few of them may vary
13866slightly with the configuration, due to indicators specific to certain
13867options. The supported formats are as follows :
Willy Tarreaucc6c8912009-02-22 10:53:55 +010013868
13869 - the default format, which is very basic and very rarely used. It only
13870 provides very basic information about the incoming connection at the moment
13871 it is accepted : source IP:port, destination IP:port, and frontend-name.
13872 This mode will eventually disappear so it will not be described to great
13873 extents.
13874
13875 - the TCP format, which is more advanced. This format is enabled when "option
13876 tcplog" is set on the frontend. HAProxy will then usually wait for the
13877 connection to terminate before logging. This format provides much richer
13878 information, such as timers, connection counts, queue size, etc... This
13879 format is recommended for pure TCP proxies.
13880
13881 - the HTTP format, which is the most advanced for HTTP proxying. This format
13882 is enabled when "option httplog" is set on the frontend. It provides the
13883 same information as the TCP format with some HTTP-specific fields such as
13884 the request, the status code, and captures of headers and cookies. This
13885 format is recommended for HTTP proxies.
13886
Emeric Brun3a058f32009-06-30 18:26:00 +020013887 - the CLF HTTP format, which is equivalent to the HTTP format, but with the
13888 fields arranged in the same order as the CLF format. In this mode, all
13889 timers, captures, flags, etc... appear one per field after the end of the
13890 common fields, in the same order they appear in the standard HTTP format.
13891
William Lallemand48940402012-01-30 16:47:22 +010013892 - the custom log format, allows you to make your own log line.
13893
Willy Tarreaucc6c8912009-02-22 10:53:55 +010013894Next sections will go deeper into details for each of these formats. Format
13895specification will be performed on a "field" basis. Unless stated otherwise, a
13896field is a portion of text delimited by any number of spaces. Since syslog
13897servers are susceptible of inserting fields at the beginning of a line, it is
13898always assumed that the first field is the one containing the process name and
13899identifier.
13900
13901Note : Since log lines may be quite long, the log examples in sections below
13902 might be broken into multiple lines. The example log lines will be
13903 prefixed with 3 closing angle brackets ('>>>') and each time a log is
13904 broken into multiple lines, each non-final line will end with a
13905 backslash ('\') and the next line will start indented by two characters.
13906
13907
Willy Tarreauc57f0e22009-05-10 13:12:33 +0200139088.2.1. Default log format
13909-------------------------
Willy Tarreaucc6c8912009-02-22 10:53:55 +010013910
13911This format is used when no specific option is set. The log is emitted as soon
13912as the connection is accepted. One should note that this currently is the only
13913format which logs the request's destination IP and ports.
13914
13915 Example :
13916 listen www
13917 mode http
13918 log global
13919 server srv1 127.0.0.1:8000
13920
13921 >>> Feb 6 12:12:09 localhost \
13922 haproxy[14385]: Connect from 10.0.1.2:33312 to 10.0.3.31:8012 \
13923 (www/HTTP)
13924
13925 Field Format Extract from the example above
13926 1 process_name '[' pid ']:' haproxy[14385]:
13927 2 'Connect from' Connect from
13928 3 source_ip ':' source_port 10.0.1.2:33312
13929 4 'to' to
13930 5 destination_ip ':' destination_port 10.0.3.31:8012
13931 6 '(' frontend_name '/' mode ')' (www/HTTP)
13932
13933Detailed fields description :
13934 - "source_ip" is the IP address of the client which initiated the connection.
13935 - "source_port" is the TCP port of the client which initiated the connection.
13936 - "destination_ip" is the IP address the client connected to.
13937 - "destination_port" is the TCP port the client connected to.
13938 - "frontend_name" is the name of the frontend (or listener) which received
13939 and processed the connection.
13940 - "mode is the mode the frontend is operating (TCP or HTTP).
13941
Willy Tarreauceb24bc2010-11-09 12:46:41 +010013942In case of a UNIX socket, the source and destination addresses are marked as
13943"unix:" and the ports reflect the internal ID of the socket which accepted the
13944connection (the same ID as reported in the stats).
13945
Willy Tarreaucc6c8912009-02-22 10:53:55 +010013946It is advised not to use this deprecated format for newer installations as it
13947will eventually disappear.
13948
13949
Willy Tarreauc57f0e22009-05-10 13:12:33 +0200139508.2.2. TCP log format
13951---------------------
Willy Tarreaucc6c8912009-02-22 10:53:55 +010013952
13953The TCP format is used when "option tcplog" is specified in the frontend, and
13954is the recommended format for pure TCP proxies. It provides a lot of precious
13955information for troubleshooting. Since this format includes timers and byte
13956counts, the log is normally emitted at the end of the session. It can be
13957emitted earlier if "option logasap" is specified, which makes sense in most
13958environments with long sessions such as remote terminals. Sessions which match
13959the "monitor" rules are never logged. It is also possible not to emit logs for
13960sessions for which no data were exchanged between the client and the server, by
Willy Tarreauc9bd0cc2009-05-10 11:57:02 +020013961specifying "option dontlognull" in the frontend. Successful connections will
13962not be logged if "option dontlog-normal" is specified in the frontend. A few
13963fields may slightly vary depending on some configuration options, those are
13964marked with a star ('*') after the field name below.
Willy Tarreaucc6c8912009-02-22 10:53:55 +010013965
13966 Example :
13967 frontend fnt
13968 mode tcp
13969 option tcplog
13970 log global
13971 default_backend bck
13972
13973 backend bck
13974 server srv1 127.0.0.1:8000
13975
13976 >>> Feb 6 12:12:56 localhost \
13977 haproxy[14387]: 10.0.1.2:33313 [06/Feb/2009:12:12:51.443] fnt \
13978 bck/srv1 0/0/5007 212 -- 0/0/0/0/3 0/0
13979
13980 Field Format Extract from the example above
13981 1 process_name '[' pid ']:' haproxy[14387]:
13982 2 client_ip ':' client_port 10.0.1.2:33313
13983 3 '[' accept_date ']' [06/Feb/2009:12:12:51.443]
13984 4 frontend_name fnt
13985 5 backend_name '/' server_name bck/srv1
13986 6 Tw '/' Tc '/' Tt* 0/0/5007
13987 7 bytes_read* 212
13988 8 termination_state --
13989 9 actconn '/' feconn '/' beconn '/' srv_conn '/' retries* 0/0/0/0/3
13990 10 srv_queue '/' backend_queue 0/0
13991
13992Detailed fields description :
13993 - "client_ip" is the IP address of the client which initiated the TCP
Willy Tarreauceb24bc2010-11-09 12:46:41 +010013994 connection to haproxy. If the connection was accepted on a UNIX socket
13995 instead, the IP address would be replaced with the word "unix". Note that
13996 when the connection is accepted on a socket configured with "accept-proxy"
13997 and the PROXY protocol is correctly used, then the logs will reflect the
13998 forwarded connection's information.
Willy Tarreaucc6c8912009-02-22 10:53:55 +010013999
14000 - "client_port" is the TCP port of the client which initiated the connection.
Willy Tarreauceb24bc2010-11-09 12:46:41 +010014001 If the connection was accepted on a UNIX socket instead, the port would be
14002 replaced with the ID of the accepting socket, which is also reported in the
14003 stats interface.
Willy Tarreaucc6c8912009-02-22 10:53:55 +010014004
14005 - "accept_date" is the exact date when the connection was received by haproxy
14006 (which might be very slightly different from the date observed on the
14007 network if there was some queuing in the system's backlog). This is usually
14008 the same date which may appear in any upstream firewall's log.
14009
14010 - "frontend_name" is the name of the frontend (or listener) which received
14011 and processed the connection.
14012
14013 - "backend_name" is the name of the backend (or listener) which was selected
14014 to manage the connection to the server. This will be the same as the
14015 frontend if no switching rule has been applied, which is common for TCP
14016 applications.
14017
14018 - "server_name" is the name of the last server to which the connection was
14019 sent, which might differ from the first one if there were connection errors
14020 and a redispatch occurred. Note that this server belongs to the backend
14021 which processed the request. If the connection was aborted before reaching
14022 a server, "<NOSRV>" is indicated instead of a server name.
14023
14024 - "Tw" is the total time in milliseconds spent waiting in the various queues.
14025 It can be "-1" if the connection was aborted before reaching the queue.
14026 See "Timers" below for more details.
14027
14028 - "Tc" is the total time in milliseconds spent waiting for the connection to
14029 establish to the final server, including retries. It can be "-1" if the
14030 connection was aborted before a connection could be established. See
14031 "Timers" below for more details.
14032
14033 - "Tt" is the total time in milliseconds elapsed between the accept and the
Jarno Huuskonen0e82b922014-04-12 18:22:19 +030014034 last close. It covers all possible processing. There is one exception, if
Willy Tarreaucc6c8912009-02-22 10:53:55 +010014035 "option logasap" was specified, then the time counting stops at the moment
14036 the log is emitted. In this case, a '+' sign is prepended before the value,
14037 indicating that the final one will be larger. See "Timers" below for more
14038 details.
14039
14040 - "bytes_read" is the total number of bytes transmitted from the server to
14041 the client when the log is emitted. If "option logasap" is specified, the
14042 this value will be prefixed with a '+' sign indicating that the final one
14043 may be larger. Please note that this value is a 64-bit counter, so log
14044 analysis tools must be able to handle it without overflowing.
14045
14046 - "termination_state" is the condition the session was in when the session
14047 ended. This indicates the session state, which side caused the end of
14048 session to happen, and for what reason (timeout, error, ...). The normal
14049 flags should be "--", indicating the session was closed by either end with
14050 no data remaining in buffers. See below "Session state at disconnection"
14051 for more details.
14052
14053 - "actconn" is the total number of concurrent connections on the process when
Jamie Gloudonaaa21002012-08-25 00:18:33 -040014054 the session was logged. It is useful to detect when some per-process system
Willy Tarreaucc6c8912009-02-22 10:53:55 +010014055 limits have been reached. For instance, if actconn is close to 512 when
14056 multiple connection errors occur, chances are high that the system limits
14057 the process to use a maximum of 1024 file descriptors and that all of them
Willy Tarreauc57f0e22009-05-10 13:12:33 +020014058 are used. See section 3 "Global parameters" to find how to tune the system.
Willy Tarreaucc6c8912009-02-22 10:53:55 +010014059
14060 - "feconn" is the total number of concurrent connections on the frontend when
14061 the session was logged. It is useful to estimate the amount of resource
14062 required to sustain high loads, and to detect when the frontend's "maxconn"
14063 has been reached. Most often when this value increases by huge jumps, it is
14064 because there is congestion on the backend servers, but sometimes it can be
14065 caused by a denial of service attack.
14066
14067 - "beconn" is the total number of concurrent connections handled by the
14068 backend when the session was logged. It includes the total number of
14069 concurrent connections active on servers as well as the number of
14070 connections pending in queues. It is useful to estimate the amount of
14071 additional servers needed to support high loads for a given application.
14072 Most often when this value increases by huge jumps, it is because there is
14073 congestion on the backend servers, but sometimes it can be caused by a
14074 denial of service attack.
14075
14076 - "srv_conn" is the total number of concurrent connections still active on
14077 the server when the session was logged. It can never exceed the server's
14078 configured "maxconn" parameter. If this value is very often close or equal
14079 to the server's "maxconn", it means that traffic regulation is involved a
14080 lot, meaning that either the server's maxconn value is too low, or that
14081 there aren't enough servers to process the load with an optimal response
14082 time. When only one of the server's "srv_conn" is high, it usually means
14083 that this server has some trouble causing the connections to take longer to
14084 be processed than on other servers.
14085
14086 - "retries" is the number of connection retries experienced by this session
14087 when trying to connect to the server. It must normally be zero, unless a
14088 server is being stopped at the same moment the connection was attempted.
14089 Frequent retries generally indicate either a network problem between
14090 haproxy and the server, or a misconfigured system backlog on the server
14091 preventing new connections from being queued. This field may optionally be
14092 prefixed with a '+' sign, indicating that the session has experienced a
14093 redispatch after the maximal retry count has been reached on the initial
14094 server. In this case, the server name appearing in the log is the one the
14095 connection was redispatched to, and not the first one, though both may
14096 sometimes be the same in case of hashing for instance. So as a general rule
14097 of thumb, when a '+' is present in front of the retry count, this count
14098 should not be attributed to the logged server.
14099
14100 - "srv_queue" is the total number of requests which were processed before
14101 this one in the server queue. It is zero when the request has not gone
14102 through the server queue. It makes it possible to estimate the approximate
14103 server's response time by dividing the time spent in queue by the number of
14104 requests in the queue. It is worth noting that if a session experiences a
14105 redispatch and passes through two server queues, their positions will be
14106 cumulated. A request should not pass through both the server queue and the
14107 backend queue unless a redispatch occurs.
14108
14109 - "backend_queue" is the total number of requests which were processed before
14110 this one in the backend's global queue. It is zero when the request has not
14111 gone through the global queue. It makes it possible to estimate the average
14112 queue length, which easily translates into a number of missing servers when
14113 divided by a server's "maxconn" parameter. It is worth noting that if a
14114 session experiences a redispatch, it may pass twice in the backend's queue,
14115 and then both positions will be cumulated. A request should not pass
14116 through both the server queue and the backend queue unless a redispatch
14117 occurs.
14118
14119
Willy Tarreauc57f0e22009-05-10 13:12:33 +0200141208.2.3. HTTP log format
14121----------------------
Willy Tarreaucc6c8912009-02-22 10:53:55 +010014122
14123The HTTP format is the most complete and the best suited for HTTP proxies. It
14124is enabled by when "option httplog" is specified in the frontend. It provides
14125the same level of information as the TCP format with additional features which
14126are specific to the HTTP protocol. Just like the TCP format, the log is usually
14127emitted at the end of the session, unless "option logasap" is specified, which
14128generally only makes sense for download sites. A session which matches the
14129"monitor" rules will never logged. It is also possible not to log sessions for
14130which no data were sent by the client by specifying "option dontlognull" in the
Willy Tarreauc9bd0cc2009-05-10 11:57:02 +020014131frontend. Successful connections will not be logged if "option dontlog-normal"
14132is specified in the frontend.
Willy Tarreaucc6c8912009-02-22 10:53:55 +010014133
14134Most fields are shared with the TCP log, some being different. A few fields may
14135slightly vary depending on some configuration options. Those ones are marked
14136with a star ('*') after the field name below.
14137
14138 Example :
14139 frontend http-in
14140 mode http
14141 option httplog
14142 log global
14143 default_backend bck
14144
14145 backend static
14146 server srv1 127.0.0.1:8000
14147
14148 >>> Feb 6 12:14:14 localhost \
14149 haproxy[14389]: 10.0.1.2:33317 [06/Feb/2009:12:14:14.655] http-in \
14150 static/srv1 10/0/30/69/109 200 2750 - - ---- 1/1/1/1/0 0/0 {1wt.eu} \
Willy Tarreaud72758d2010-01-12 10:42:19 +010014151 {} "GET /index.html HTTP/1.1"
Willy Tarreaucc6c8912009-02-22 10:53:55 +010014152
14153 Field Format Extract from the example above
14154 1 process_name '[' pid ']:' haproxy[14389]:
14155 2 client_ip ':' client_port 10.0.1.2:33317
14156 3 '[' accept_date ']' [06/Feb/2009:12:14:14.655]
14157 4 frontend_name http-in
14158 5 backend_name '/' server_name static/srv1
14159 6 Tq '/' Tw '/' Tc '/' Tr '/' Tt* 10/0/30/69/109
14160 7 status_code 200
14161 8 bytes_read* 2750
14162 9 captured_request_cookie -
14163 10 captured_response_cookie -
14164 11 termination_state ----
14165 12 actconn '/' feconn '/' beconn '/' srv_conn '/' retries* 1/1/1/1/0
14166 13 srv_queue '/' backend_queue 0/0
14167 14 '{' captured_request_headers* '}' {haproxy.1wt.eu}
14168 15 '{' captured_response_headers* '}' {}
14169 16 '"' http_request '"' "GET /index.html HTTP/1.1"
Willy Tarreaud72758d2010-01-12 10:42:19 +010014170
Willy Tarreaucc6c8912009-02-22 10:53:55 +010014171
14172Detailed fields description :
14173 - "client_ip" is the IP address of the client which initiated the TCP
Willy Tarreauceb24bc2010-11-09 12:46:41 +010014174 connection to haproxy. If the connection was accepted on a UNIX socket
14175 instead, the IP address would be replaced with the word "unix". Note that
14176 when the connection is accepted on a socket configured with "accept-proxy"
14177 and the PROXY protocol is correctly used, then the logs will reflect the
14178 forwarded connection's information.
Willy Tarreaucc6c8912009-02-22 10:53:55 +010014179
14180 - "client_port" is the TCP port of the client which initiated the connection.
Willy Tarreauceb24bc2010-11-09 12:46:41 +010014181 If the connection was accepted on a UNIX socket instead, the port would be
14182 replaced with the ID of the accepting socket, which is also reported in the
14183 stats interface.
Willy Tarreaucc6c8912009-02-22 10:53:55 +010014184
14185 - "accept_date" is the exact date when the TCP connection was received by
14186 haproxy (which might be very slightly different from the date observed on
14187 the network if there was some queuing in the system's backlog). This is
14188 usually the same date which may appear in any upstream firewall's log. This
14189 does not depend on the fact that the client has sent the request or not.
14190
14191 - "frontend_name" is the name of the frontend (or listener) which received
14192 and processed the connection.
14193
14194 - "backend_name" is the name of the backend (or listener) which was selected
14195 to manage the connection to the server. This will be the same as the
14196 frontend if no switching rule has been applied.
14197
14198 - "server_name" is the name of the last server to which the connection was
14199 sent, which might differ from the first one if there were connection errors
14200 and a redispatch occurred. Note that this server belongs to the backend
14201 which processed the request. If the request was aborted before reaching a
14202 server, "<NOSRV>" is indicated instead of a server name. If the request was
14203 intercepted by the stats subsystem, "<STATS>" is indicated instead.
14204
14205 - "Tq" is the total time in milliseconds spent waiting for the client to send
14206 a full HTTP request, not counting data. It can be "-1" if the connection
14207 was aborted before a complete request could be received. It should always
14208 be very small because a request generally fits in one single packet. Large
14209 times here generally indicate network trouble between the client and
14210 haproxy. See "Timers" below for more details.
14211
14212 - "Tw" is the total time in milliseconds spent waiting in the various queues.
14213 It can be "-1" if the connection was aborted before reaching the queue.
14214 See "Timers" below for more details.
14215
14216 - "Tc" is the total time in milliseconds spent waiting for the connection to
14217 establish to the final server, including retries. It can be "-1" if the
14218 request was aborted before a connection could be established. See "Timers"
14219 below for more details.
14220
14221 - "Tr" is the total time in milliseconds spent waiting for the server to send
14222 a full HTTP response, not counting data. It can be "-1" if the request was
14223 aborted before a complete response could be received. It generally matches
14224 the server's processing time for the request, though it may be altered by
14225 the amount of data sent by the client to the server. Large times here on
14226 "GET" requests generally indicate an overloaded server. See "Timers" below
14227 for more details.
14228
14229 - "Tt" is the total time in milliseconds elapsed between the accept and the
Jarno Huuskonen0e82b922014-04-12 18:22:19 +030014230 last close. It covers all possible processing. There is one exception, if
Willy Tarreaucc6c8912009-02-22 10:53:55 +010014231 "option logasap" was specified, then the time counting stops at the moment
14232 the log is emitted. In this case, a '+' sign is prepended before the value,
14233 indicating that the final one will be larger. See "Timers" below for more
14234 details.
14235
14236 - "status_code" is the HTTP status code returned to the client. This status
14237 is generally set by the server, but it might also be set by haproxy when
14238 the server cannot be reached or when its response is blocked by haproxy.
14239
14240 - "bytes_read" is the total number of bytes transmitted to the client when
14241 the log is emitted. This does include HTTP headers. If "option logasap" is
14242 specified, the this value will be prefixed with a '+' sign indicating that
14243 the final one may be larger. Please note that this value is a 64-bit
14244 counter, so log analysis tools must be able to handle it without
14245 overflowing.
14246
14247 - "captured_request_cookie" is an optional "name=value" entry indicating that
14248 the client had this cookie in the request. The cookie name and its maximum
14249 length are defined by the "capture cookie" statement in the frontend
14250 configuration. The field is a single dash ('-') when the option is not
14251 set. Only one cookie may be captured, it is generally used to track session
14252 ID exchanges between a client and a server to detect session crossing
14253 between clients due to application bugs. For more details, please consult
14254 the section "Capturing HTTP headers and cookies" below.
14255
14256 - "captured_response_cookie" is an optional "name=value" entry indicating
14257 that the server has returned a cookie with its response. The cookie name
14258 and its maximum length are defined by the "capture cookie" statement in the
14259 frontend configuration. The field is a single dash ('-') when the option is
14260 not set. Only one cookie may be captured, it is generally used to track
14261 session ID exchanges between a client and a server to detect session
14262 crossing between clients due to application bugs. For more details, please
14263 consult the section "Capturing HTTP headers and cookies" below.
14264
14265 - "termination_state" is the condition the session was in when the session
14266 ended. This indicates the session state, which side caused the end of
14267 session to happen, for what reason (timeout, error, ...), just like in TCP
14268 logs, and information about persistence operations on cookies in the last
14269 two characters. The normal flags should begin with "--", indicating the
14270 session was closed by either end with no data remaining in buffers. See
14271 below "Session state at disconnection" for more details.
14272
14273 - "actconn" is the total number of concurrent connections on the process when
Jamie Gloudonaaa21002012-08-25 00:18:33 -040014274 the session was logged. It is useful to detect when some per-process system
Willy Tarreaucc6c8912009-02-22 10:53:55 +010014275 limits have been reached. For instance, if actconn is close to 512 or 1024
14276 when multiple connection errors occur, chances are high that the system
14277 limits the process to use a maximum of 1024 file descriptors and that all
Willy Tarreauc57f0e22009-05-10 13:12:33 +020014278 of them are used. See section 3 "Global parameters" to find how to tune the
Willy Tarreaucc6c8912009-02-22 10:53:55 +010014279 system.
14280
14281 - "feconn" is the total number of concurrent connections on the frontend when
14282 the session was logged. It is useful to estimate the amount of resource
14283 required to sustain high loads, and to detect when the frontend's "maxconn"
14284 has been reached. Most often when this value increases by huge jumps, it is
14285 because there is congestion on the backend servers, but sometimes it can be
14286 caused by a denial of service attack.
14287
14288 - "beconn" is the total number of concurrent connections handled by the
14289 backend when the session was logged. It includes the total number of
14290 concurrent connections active on servers as well as the number of
14291 connections pending in queues. It is useful to estimate the amount of
14292 additional servers needed to support high loads for a given application.
14293 Most often when this value increases by huge jumps, it is because there is
14294 congestion on the backend servers, but sometimes it can be caused by a
14295 denial of service attack.
14296
14297 - "srv_conn" is the total number of concurrent connections still active on
14298 the server when the session was logged. It can never exceed the server's
14299 configured "maxconn" parameter. If this value is very often close or equal
14300 to the server's "maxconn", it means that traffic regulation is involved a
14301 lot, meaning that either the server's maxconn value is too low, or that
14302 there aren't enough servers to process the load with an optimal response
14303 time. When only one of the server's "srv_conn" is high, it usually means
14304 that this server has some trouble causing the requests to take longer to be
14305 processed than on other servers.
14306
14307 - "retries" is the number of connection retries experienced by this session
14308 when trying to connect to the server. It must normally be zero, unless a
14309 server is being stopped at the same moment the connection was attempted.
14310 Frequent retries generally indicate either a network problem between
14311 haproxy and the server, or a misconfigured system backlog on the server
14312 preventing new connections from being queued. This field may optionally be
14313 prefixed with a '+' sign, indicating that the session has experienced a
14314 redispatch after the maximal retry count has been reached on the initial
14315 server. In this case, the server name appearing in the log is the one the
14316 connection was redispatched to, and not the first one, though both may
14317 sometimes be the same in case of hashing for instance. So as a general rule
14318 of thumb, when a '+' is present in front of the retry count, this count
14319 should not be attributed to the logged server.
14320
14321 - "srv_queue" is the total number of requests which were processed before
14322 this one in the server queue. It is zero when the request has not gone
14323 through the server queue. It makes it possible to estimate the approximate
14324 server's response time by dividing the time spent in queue by the number of
14325 requests in the queue. It is worth noting that if a session experiences a
14326 redispatch and passes through two server queues, their positions will be
14327 cumulated. A request should not pass through both the server queue and the
14328 backend queue unless a redispatch occurs.
14329
14330 - "backend_queue" is the total number of requests which were processed before
14331 this one in the backend's global queue. It is zero when the request has not
14332 gone through the global queue. It makes it possible to estimate the average
14333 queue length, which easily translates into a number of missing servers when
14334 divided by a server's "maxconn" parameter. It is worth noting that if a
14335 session experiences a redispatch, it may pass twice in the backend's queue,
14336 and then both positions will be cumulated. A request should not pass
14337 through both the server queue and the backend queue unless a redispatch
14338 occurs.
14339
14340 - "captured_request_headers" is a list of headers captured in the request due
14341 to the presence of the "capture request header" statement in the frontend.
14342 Multiple headers can be captured, they will be delimited by a vertical bar
14343 ('|'). When no capture is enabled, the braces do not appear, causing a
14344 shift of remaining fields. It is important to note that this field may
14345 contain spaces, and that using it requires a smarter log parser than when
14346 it's not used. Please consult the section "Capturing HTTP headers and
14347 cookies" below for more details.
14348
14349 - "captured_response_headers" is a list of headers captured in the response
14350 due to the presence of the "capture response header" statement in the
14351 frontend. Multiple headers can be captured, they will be delimited by a
14352 vertical bar ('|'). When no capture is enabled, the braces do not appear,
14353 causing a shift of remaining fields. It is important to note that this
14354 field may contain spaces, and that using it requires a smarter log parser
14355 than when it's not used. Please consult the section "Capturing HTTP headers
14356 and cookies" below for more details.
14357
14358 - "http_request" is the complete HTTP request line, including the method,
14359 request and HTTP version string. Non-printable characters are encoded (see
14360 below the section "Non-printable characters"). This is always the last
14361 field, and it is always delimited by quotes and is the only one which can
14362 contain quotes. If new fields are added to the log format, they will be
14363 added before this field. This field might be truncated if the request is
14364 huge and does not fit in the standard syslog buffer (1024 characters). This
14365 is the reason why this field must always remain the last one.
14366
14367
Cyril Bontédc4d9032012-04-08 21:57:39 +0200143688.2.4. Custom log format
14369------------------------
William Lallemand48940402012-01-30 16:47:22 +010014370
Willy Tarreau2beef582012-12-20 17:22:52 +010014371The directive log-format allows you to customize the logs in http mode and tcp
William Lallemandbddd4fd2012-02-27 11:23:10 +010014372mode. It takes a string as argument.
William Lallemand48940402012-01-30 16:47:22 +010014373
14374HAproxy understands some log format variables. % precedes log format variables.
14375Variables can take arguments using braces ('{}'), and multiple arguments are
14376separated by commas within the braces. Flags may be added or removed by
14377prefixing them with a '+' or '-' sign.
14378
14379Special variable "%o" may be used to propagate its flags to all other
14380variables on the same format string. This is particularly handy with quoted
14381string formats ("Q").
14382
Willy Tarreauc8368452012-12-21 00:09:23 +010014383If a variable is named between square brackets ('[' .. ']') then it is used
Willy Tarreaube722a22014-06-13 16:31:59 +020014384as a sample expression rule (see section 7.3). This it useful to add some
Willy Tarreauc8368452012-12-21 00:09:23 +010014385less common information such as the client's SSL certificate's DN, or to log
14386the key that would be used to store an entry into a stick table.
14387
William Lallemand48940402012-01-30 16:47:22 +010014388Note: spaces must be escaped. A space character is considered as a separator.
Jarno Huuskonen0e82b922014-04-12 18:22:19 +030014389In order to emit a verbatim '%', it must be preceded by another '%' resulting
Willy Tarreau06d97f92013-12-02 17:45:48 +010014390in '%%'. HAProxy will automatically merge consecutive separators.
William Lallemand48940402012-01-30 16:47:22 +010014391
14392Flags are :
14393 * Q: quote a string
Jamie Gloudonaaa21002012-08-25 00:18:33 -040014394 * X: hexadecimal representation (IPs, Ports, %Ts, %rt, %pid)
William Lallemand48940402012-01-30 16:47:22 +010014395
14396 Example:
14397
14398 log-format %T\ %t\ Some\ Text
14399 log-format %{+Q}o\ %t\ %s\ %{-Q}r
14400
14401At the moment, the default HTTP format is defined this way :
14402
Willy Tarreau2beef582012-12-20 17:22:52 +010014403 log-format %ci:%cp\ [%t]\ %ft\ %b/%s\ %Tq/%Tw/%Tc/%Tr/%Tt\ %ST\ %B\ %CC\ \
14404 %CS\ %tsc\ %ac/%fc/%bc/%sc/%rc\ %sq/%bq\ %hr\ %hs\ %{+Q}r
William Lallemand48940402012-01-30 16:47:22 +010014405
William Lallemandbddd4fd2012-02-27 11:23:10 +010014406the default CLF format is defined this way :
William Lallemand48940402012-01-30 16:47:22 +010014407
Willy Tarreau2beef582012-12-20 17:22:52 +010014408 log-format %{+Q}o\ %{-Q}ci\ -\ -\ [%T]\ %r\ %ST\ %B\ \"\"\ \"\"\ %cp\ \
Willy Tarreau773d65f2012-10-12 14:56:11 +020014409 %ms\ %ft\ %b\ %s\ \%Tq\ %Tw\ %Tc\ %Tr\ %Tt\ %tsc\ %ac\ %fc\ \
Willy Tarreau2beef582012-12-20 17:22:52 +010014410 %bc\ %sc\ %rc\ %sq\ %bq\ %CC\ %CS\ \%hrl\ %hsl
William Lallemand48940402012-01-30 16:47:22 +010014411
William Lallemandbddd4fd2012-02-27 11:23:10 +010014412and the default TCP format is defined this way :
14413
Willy Tarreau2beef582012-12-20 17:22:52 +010014414 log-format %ci:%cp\ [%t]\ %ft\ %b/%s\ %Tw/%Tc/%Tt\ %B\ %ts\ \
William Lallemandbddd4fd2012-02-27 11:23:10 +010014415 %ac/%fc/%bc/%sc/%rc\ %sq/%bq
14416
William Lallemand48940402012-01-30 16:47:22 +010014417Please refer to the table below for currently defined variables :
14418
William Lallemandbddd4fd2012-02-27 11:23:10 +010014419 +---+------+-----------------------------------------------+-------------+
Willy Tarreauffc3fcd2012-10-12 20:17:54 +020014420 | R | var | field name (8.2.2 and 8.2.3 for description) | type |
William Lallemandbddd4fd2012-02-27 11:23:10 +010014421 +---+------+-----------------------------------------------+-------------+
14422 | | %o | special variable, apply flags on all next var | |
14423 +---+------+-----------------------------------------------+-------------+
Willy Tarreau2beef582012-12-20 17:22:52 +010014424 | | %B | bytes_read (from server to client) | numeric |
14425 | H | %CC | captured_request_cookie | string |
14426 | H | %CS | captured_response_cookie | string |
William Lallemand5f232402012-04-05 18:02:55 +020014427 | | %H | hostname | string |
Andrew Hayworth0ebc55f2015-04-27 21:37:03 +000014428 | H | %HM | HTTP method (ex: POST) | string |
14429 | H | %HP | HTTP request URI without query string (path) | string |
Andrew Hayworthe63ac872015-07-31 16:14:16 +000014430 | H | %HQ | HTTP request URI query string (ex: ?bar=baz) | string |
Andrew Hayworth0ebc55f2015-04-27 21:37:03 +000014431 | H | %HU | HTTP request URI (ex: /foo?bar=baz) | string |
14432 | H | %HV | HTTP version (ex: HTTP/1.0) | string |
William Lallemanda73203e2012-03-12 12:48:57 +010014433 | | %ID | unique-id | string |
Willy Tarreau4bf99632014-06-13 12:21:40 +020014434 | | %ST | status_code | numeric |
William Lallemand5f232402012-04-05 18:02:55 +020014435 | | %T | gmt_date_time | date |
William Lallemandbddd4fd2012-02-27 11:23:10 +010014436 | | %Tc | Tc | numeric |
Yuxans Yao4e25b012012-10-19 10:36:09 +080014437 | | %Tl | local_date_time | date |
Willy Tarreauffc3fcd2012-10-12 20:17:54 +020014438 | H | %Tq | Tq | numeric |
14439 | H | %Tr | Tr | numeric |
William Lallemand5f232402012-04-05 18:02:55 +020014440 | | %Ts | timestamp | numeric |
William Lallemandbddd4fd2012-02-27 11:23:10 +010014441 | | %Tt | Tt | numeric |
14442 | | %Tw | Tw | numeric |
Willy Tarreau2beef582012-12-20 17:22:52 +010014443 | | %U | bytes_uploaded (from client to server) | numeric |
William Lallemandbddd4fd2012-02-27 11:23:10 +010014444 | | %ac | actconn | numeric |
14445 | | %b | backend_name | string |
Willy Tarreau2beef582012-12-20 17:22:52 +010014446 | | %bc | beconn (backend concurrent connections) | numeric |
14447 | | %bi | backend_source_ip (connecting address) | IP |
14448 | | %bp | backend_source_port (connecting address) | numeric |
William Lallemandbddd4fd2012-02-27 11:23:10 +010014449 | | %bq | backend_queue | numeric |
Willy Tarreau2beef582012-12-20 17:22:52 +010014450 | | %ci | client_ip (accepted address) | IP |
14451 | | %cp | client_port (accepted address) | numeric |
William Lallemandbddd4fd2012-02-27 11:23:10 +010014452 | | %f | frontend_name | string |
Willy Tarreau2beef582012-12-20 17:22:52 +010014453 | | %fc | feconn (frontend concurrent connections) | numeric |
14454 | | %fi | frontend_ip (accepting address) | IP |
14455 | | %fp | frontend_port (accepting address) | numeric |
Willy Tarreau773d65f2012-10-12 14:56:11 +020014456 | | %ft | frontend_name_transport ('~' suffix for SSL) | string |
Willy Tarreau7346acb2014-08-28 15:03:15 +020014457 | | %lc | frontend_log_counter | numeric |
Willy Tarreaud9ed3d22014-06-13 12:23:06 +020014458 | | %hr | captured_request_headers default style | string |
14459 | | %hrl | captured_request_headers CLF style | string list |
14460 | | %hs | captured_response_headers default style | string |
14461 | | %hsl | captured_response_headers CLF style | string list |
Willy Tarreau812c88e2015-08-09 10:56:35 +020014462 | | %ms | accept date milliseconds (left-padded with 0) | numeric |
William Lallemand5f232402012-04-05 18:02:55 +020014463 | | %pid | PID | numeric |
Willy Tarreauffc3fcd2012-10-12 20:17:54 +020014464 | H | %r | http_request | string |
William Lallemandbddd4fd2012-02-27 11:23:10 +010014465 | | %rc | retries | numeric |
Willy Tarreau1f0da242014-01-25 11:01:50 +010014466 | | %rt | request_counter (HTTP req or TCP session) | numeric |
William Lallemandbddd4fd2012-02-27 11:23:10 +010014467 | | %s | server_name | string |
Willy Tarreau2beef582012-12-20 17:22:52 +010014468 | | %sc | srv_conn (server concurrent connections) | numeric |
14469 | | %si | server_IP (target address) | IP |
14470 | | %sp | server_port (target address) | numeric |
William Lallemandbddd4fd2012-02-27 11:23:10 +010014471 | | %sq | srv_queue | numeric |
Willy Tarreauffc3fcd2012-10-12 20:17:54 +020014472 | S | %sslc| ssl_ciphers (ex: AES-SHA) | string |
14473 | S | %sslv| ssl_version (ex: TLSv1) | string |
Willy Tarreau2beef582012-12-20 17:22:52 +010014474 | | %t | date_time (with millisecond resolution) | date |
William Lallemandbddd4fd2012-02-27 11:23:10 +010014475 | | %ts | termination_state | string |
Willy Tarreauffc3fcd2012-10-12 20:17:54 +020014476 | H | %tsc | termination_state with cookie status | string |
William Lallemandbddd4fd2012-02-27 11:23:10 +010014477 +---+------+-----------------------------------------------+-------------+
William Lallemand48940402012-01-30 16:47:22 +010014478
Willy Tarreauffc3fcd2012-10-12 20:17:54 +020014479 R = Restrictions : H = mode http only ; S = SSL only
William Lallemand48940402012-01-30 16:47:22 +010014480
Willy Tarreau5f51e1a2012-12-03 18:40:10 +010014481
144828.2.5. Error log format
14483-----------------------
14484
14485When an incoming connection fails due to an SSL handshake or an invalid PROXY
14486protocol header, haproxy will log the event using a shorter, fixed line format.
14487By default, logs are emitted at the LOG_INFO level, unless the option
14488"log-separate-errors" is set in the backend, in which case the LOG_ERR level
14489will be used. Connections on which no data are exchanged (eg: probes) are not
14490logged if the "dontlognull" option is set.
14491
14492The format looks like this :
14493
14494 >>> Dec 3 18:27:14 localhost \
14495 haproxy[6103]: 127.0.0.1:56059 [03/Dec/2012:17:35:10.380] frt/f1: \
14496 Connection error during SSL handshake
14497
14498 Field Format Extract from the example above
14499 1 process_name '[' pid ']:' haproxy[6103]:
14500 2 client_ip ':' client_port 127.0.0.1:56059
14501 3 '[' accept_date ']' [03/Dec/2012:17:35:10.380]
14502 4 frontend_name "/" bind_name ":" frt/f1:
14503 5 message Connection error during SSL handshake
14504
14505These fields just provide minimal information to help debugging connection
14506failures.
14507
14508
Willy Tarreauc57f0e22009-05-10 13:12:33 +0200145098.3. Advanced logging options
14510-----------------------------
Willy Tarreaucc6c8912009-02-22 10:53:55 +010014511
14512Some advanced logging options are often looked for but are not easy to find out
14513just by looking at the various options. Here is an entry point for the few
14514options which can enable better logging. Please refer to the keywords reference
14515for more information about their usage.
14516
14517
Willy Tarreauc57f0e22009-05-10 13:12:33 +0200145188.3.1. Disabling logging of external tests
14519------------------------------------------
Willy Tarreaucc6c8912009-02-22 10:53:55 +010014520
14521It is quite common to have some monitoring tools perform health checks on
14522haproxy. Sometimes it will be a layer 3 load-balancer such as LVS or any
14523commercial load-balancer, and sometimes it will simply be a more complete
14524monitoring system such as Nagios. When the tests are very frequent, users often
14525ask how to disable logging for those checks. There are three possibilities :
14526
14527 - if connections come from everywhere and are just TCP probes, it is often
14528 desired to simply disable logging of connections without data exchange, by
14529 setting "option dontlognull" in the frontend. It also disables logging of
14530 port scans, which may or may not be desired.
14531
14532 - if the connection come from a known source network, use "monitor-net" to
14533 declare this network as monitoring only. Any host in this network will then
14534 only be able to perform health checks, and their requests will not be
Jarno Huuskonen0e82b922014-04-12 18:22:19 +030014535 logged. This is generally appropriate to designate a list of equipment
Willy Tarreaucc6c8912009-02-22 10:53:55 +010014536 such as other load-balancers.
14537
14538 - if the tests are performed on a known URI, use "monitor-uri" to declare
14539 this URI as dedicated to monitoring. Any host sending this request will
14540 only get the result of a health-check, and the request will not be logged.
14541
14542
Willy Tarreauc57f0e22009-05-10 13:12:33 +0200145438.3.2. Logging before waiting for the session to terminate
14544----------------------------------------------------------
Willy Tarreaucc6c8912009-02-22 10:53:55 +010014545
14546The problem with logging at end of connection is that you have no clue about
14547what is happening during very long sessions, such as remote terminal sessions
14548or large file downloads. This problem can be worked around by specifying
14549"option logasap" in the frontend. Haproxy will then log as soon as possible,
14550just before data transfer begins. This means that in case of TCP, it will still
14551log the connection status to the server, and in case of HTTP, it will log just
14552after processing the server headers. In this case, the number of bytes reported
14553is the number of header bytes sent to the client. In order to avoid confusion
14554with normal logs, the total time field and the number of bytes are prefixed
14555with a '+' sign which means that real numbers are certainly larger.
14556
14557
Willy Tarreauc57f0e22009-05-10 13:12:33 +0200145588.3.3. Raising log level upon errors
14559------------------------------------
Willy Tarreauc9bd0cc2009-05-10 11:57:02 +020014560
14561Sometimes it is more convenient to separate normal traffic from errors logs,
14562for instance in order to ease error monitoring from log files. When the option
14563"log-separate-errors" is used, connections which experience errors, timeouts,
14564retries, redispatches or HTTP status codes 5xx will see their syslog level
14565raised from "info" to "err". This will help a syslog daemon store the log in
14566a separate file. It is very important to keep the errors in the normal traffic
14567file too, so that log ordering is not altered. You should also be careful if
14568you already have configured your syslog daemon to store all logs higher than
14569"notice" in an "admin" file, because the "err" level is higher than "notice".
14570
14571
Willy Tarreauc57f0e22009-05-10 13:12:33 +0200145728.3.4. Disabling logging of successful connections
14573--------------------------------------------------
Willy Tarreauc9bd0cc2009-05-10 11:57:02 +020014574
14575Although this may sound strange at first, some large sites have to deal with
14576multiple thousands of logs per second and are experiencing difficulties keeping
14577them intact for a long time or detecting errors within them. If the option
14578"dontlog-normal" is set on the frontend, all normal connections will not be
14579logged. In this regard, a normal connection is defined as one without any
14580error, timeout, retry nor redispatch. In HTTP, the status code is checked too,
14581and a response with a status 5xx is not considered normal and will be logged
14582too. Of course, doing is is really discouraged as it will remove most of the
14583useful information from the logs. Do this only if you have no other
14584alternative.
14585
14586
Willy Tarreauc57f0e22009-05-10 13:12:33 +0200145878.4. Timing events
14588------------------
Willy Tarreaucc6c8912009-02-22 10:53:55 +010014589
14590Timers provide a great help in troubleshooting network problems. All values are
14591reported in milliseconds (ms). These timers should be used in conjunction with
14592the session termination flags. In TCP mode with "option tcplog" set on the
14593frontend, 3 control points are reported under the form "Tw/Tc/Tt", and in HTTP
14594mode, 5 control points are reported under the form "Tq/Tw/Tc/Tr/Tt" :
14595
14596 - Tq: total time to get the client request (HTTP mode only). It's the time
14597 elapsed between the moment the client connection was accepted and the
14598 moment the proxy received the last HTTP header. The value "-1" indicates
14599 that the end of headers (empty line) has never been seen. This happens when
14600 the client closes prematurely or times out.
14601
14602 - Tw: total time spent in the queues waiting for a connection slot. It
14603 accounts for backend queue as well as the server queues, and depends on the
14604 queue size, and the time needed for the server to complete previous
14605 requests. The value "-1" means that the request was killed before reaching
14606 the queue, which is generally what happens with invalid or denied requests.
14607
14608 - Tc: total time to establish the TCP connection to the server. It's the time
14609 elapsed between the moment the proxy sent the connection request, and the
14610 moment it was acknowledged by the server, or between the TCP SYN packet and
14611 the matching SYN/ACK packet in return. The value "-1" means that the
14612 connection never established.
14613
14614 - Tr: server response time (HTTP mode only). It's the time elapsed between
14615 the moment the TCP connection was established to the server and the moment
14616 the server sent its complete response headers. It purely shows its request
14617 processing time, without the network overhead due to the data transmission.
14618 It is worth noting that when the client has data to send to the server, for
14619 instance during a POST request, the time already runs, and this can distort
14620 apparent response time. For this reason, it's generally wise not to trust
14621 too much this field for POST requests initiated from clients behind an
14622 untrusted network. A value of "-1" here means that the last the response
14623 header (empty line) was never seen, most likely because the server timeout
14624 stroke before the server managed to process the request.
14625
14626 - Tt: total session duration time, between the moment the proxy accepted it
14627 and the moment both ends were closed. The exception is when the "logasap"
14628 option is specified. In this case, it only equals (Tq+Tw+Tc+Tr), and is
14629 prefixed with a '+' sign. From this field, we can deduce "Td", the data
Jarno Huuskonen0e82b922014-04-12 18:22:19 +030014630 transmission time, by subtracting other timers when valid :
Willy Tarreaucc6c8912009-02-22 10:53:55 +010014631
14632 Td = Tt - (Tq + Tw + Tc + Tr)
14633
14634 Timers with "-1" values have to be excluded from this equation. In TCP
14635 mode, "Tq" and "Tr" have to be excluded too. Note that "Tt" can never be
14636 negative.
14637
14638These timers provide precious indications on trouble causes. Since the TCP
14639protocol defines retransmit delays of 3, 6, 12... seconds, we know for sure
14640that timers close to multiples of 3s are nearly always related to lost packets
Krzysztof Piotr Oledzkif8645332009-12-13 21:55:50 +010014641due to network problems (wires, negotiation, congestion). Moreover, if "Tt" is
Willy Tarreaucc6c8912009-02-22 10:53:55 +010014642close to a timeout value specified in the configuration, it often means that a
14643session has been aborted on timeout.
14644
14645Most common cases :
14646
14647 - If "Tq" is close to 3000, a packet has probably been lost between the
14648 client and the proxy. This is very rare on local networks but might happen
14649 when clients are on far remote networks and send large requests. It may
14650 happen that values larger than usual appear here without any network cause.
14651 Sometimes, during an attack or just after a resource starvation has ended,
14652 haproxy may accept thousands of connections in a few milliseconds. The time
14653 spent accepting these connections will inevitably slightly delay processing
14654 of other connections, and it can happen that request times in the order of
14655 a few tens of milliseconds are measured after a few thousands of new
Patrick Mezard105faca2010-06-12 17:02:46 +020014656 connections have been accepted at once. Setting "option http-server-close"
14657 may display larger request times since "Tq" also measures the time spent
14658 waiting for additional requests.
Willy Tarreaucc6c8912009-02-22 10:53:55 +010014659
14660 - If "Tc" is close to 3000, a packet has probably been lost between the
14661 server and the proxy during the server connection phase. This value should
14662 always be very low, such as 1 ms on local networks and less than a few tens
14663 of ms on remote networks.
14664
Willy Tarreau55165fe2009-05-10 12:02:55 +020014665 - If "Tr" is nearly always lower than 3000 except some rare values which seem
14666 to be the average majored by 3000, there are probably some packets lost
14667 between the proxy and the server.
Willy Tarreaucc6c8912009-02-22 10:53:55 +010014668
14669 - If "Tt" is large even for small byte counts, it generally is because
14670 neither the client nor the server decides to close the connection, for
14671 instance because both have agreed on a keep-alive connection mode. In order
14672 to solve this issue, it will be needed to specify "option httpclose" on
14673 either the frontend or the backend. If the problem persists, it means that
14674 the server ignores the "close" connection mode and expects the client to
14675 close. Then it will be required to use "option forceclose". Having the
14676 smallest possible 'Tt' is important when connection regulation is used with
14677 the "maxconn" option on the servers, since no new connection will be sent
14678 to the server until another one is released.
14679
14680Other noticeable HTTP log cases ('xx' means any value to be ignored) :
14681
14682 Tq/Tw/Tc/Tr/+Tt The "option logasap" is present on the frontend and the log
14683 was emitted before the data phase. All the timers are valid
14684 except "Tt" which is shorter than reality.
14685
14686 -1/xx/xx/xx/Tt The client was not able to send a complete request in time
14687 or it aborted too early. Check the session termination flags
14688 then "timeout http-request" and "timeout client" settings.
14689
14690 Tq/-1/xx/xx/Tt It was not possible to process the request, maybe because
14691 servers were out of order, because the request was invalid
14692 or forbidden by ACL rules. Check the session termination
14693 flags.
14694
14695 Tq/Tw/-1/xx/Tt The connection could not establish on the server. Either it
14696 actively refused it or it timed out after Tt-(Tq+Tw) ms.
14697 Check the session termination flags, then check the
14698 "timeout connect" setting. Note that the tarpit action might
14699 return similar-looking patterns, with "Tw" equal to the time
14700 the client connection was maintained open.
14701
14702 Tq/Tw/Tc/-1/Tt The server has accepted the connection but did not return
Jarno Huuskonen0e82b922014-04-12 18:22:19 +030014703 a complete response in time, or it closed its connection
Willy Tarreaucc6c8912009-02-22 10:53:55 +010014704 unexpectedly after Tt-(Tq+Tw+Tc) ms. Check the session
14705 termination flags, then check the "timeout server" setting.
14706
14707
Willy Tarreauc57f0e22009-05-10 13:12:33 +0200147088.5. Session state at disconnection
14709-----------------------------------
Willy Tarreaucc6c8912009-02-22 10:53:55 +010014710
14711TCP and HTTP logs provide a session termination indicator in the
14712"termination_state" field, just before the number of active connections. It is
147132-characters long in TCP mode, and is extended to 4 characters in HTTP mode,
14714each of which has a special meaning :
14715
14716 - On the first character, a code reporting the first event which caused the
14717 session to terminate :
14718
14719 C : the TCP session was unexpectedly aborted by the client.
14720
14721 S : the TCP session was unexpectedly aborted by the server, or the
14722 server explicitly refused it.
14723
14724 P : the session was prematurely aborted by the proxy, because of a
14725 connection limit enforcement, because a DENY filter was matched,
14726 because of a security check which detected and blocked a dangerous
14727 error in server response which might have caused information leak
Willy Tarreau570f2212013-06-10 16:42:09 +020014728 (eg: cacheable cookie).
14729
14730 L : the session was locally processed by haproxy and was not passed to
14731 a server. This is what happens for stats and redirects.
Willy Tarreaucc6c8912009-02-22 10:53:55 +010014732
14733 R : a resource on the proxy has been exhausted (memory, sockets, source
14734 ports, ...). Usually, this appears during the connection phase, and
14735 system logs should contain a copy of the precise error. If this
14736 happens, it must be considered as a very serious anomaly which
14737 should be fixed as soon as possible by any means.
14738
14739 I : an internal error was identified by the proxy during a self-check.
14740 This should NEVER happen, and you are encouraged to report any log
14741 containing this, because this would almost certainly be a bug. It
14742 would be wise to preventively restart the process after such an
14743 event too, in case it would be caused by memory corruption.
14744
Simon Horman752dc4a2011-06-21 14:34:59 +090014745 D : the session was killed by haproxy because the server was detected
14746 as down and was configured to kill all connections when going down.
14747
Justin Karnegeseb2c24a2012-05-24 15:28:52 -070014748 U : the session was killed by haproxy on this backup server because an
14749 active server was detected as up and was configured to kill all
14750 backup connections when going up.
14751
Willy Tarreaua2a64e92011-09-07 23:01:56 +020014752 K : the session was actively killed by an admin operating on haproxy.
14753
Willy Tarreaucc6c8912009-02-22 10:53:55 +010014754 c : the client-side timeout expired while waiting for the client to
14755 send or receive data.
14756
14757 s : the server-side timeout expired while waiting for the server to
14758 send or receive data.
14759
14760 - : normal session completion, both the client and the server closed
14761 with nothing left in the buffers.
14762
14763 - on the second character, the TCP or HTTP session state when it was closed :
14764
Willy Tarreauf7b30a92010-12-06 22:59:17 +010014765 R : the proxy was waiting for a complete, valid REQUEST from the client
Willy Tarreaucc6c8912009-02-22 10:53:55 +010014766 (HTTP mode only). Nothing was sent to any server.
14767
14768 Q : the proxy was waiting in the QUEUE for a connection slot. This can
14769 only happen when servers have a 'maxconn' parameter set. It can
14770 also happen in the global queue after a redispatch consecutive to
14771 a failed attempt to connect to a dying server. If no redispatch is
14772 reported, then no connection attempt was made to any server.
14773
14774 C : the proxy was waiting for the CONNECTION to establish on the
14775 server. The server might at most have noticed a connection attempt.
14776
14777 H : the proxy was waiting for complete, valid response HEADERS from the
14778 server (HTTP only).
14779
14780 D : the session was in the DATA phase.
14781
14782 L : the proxy was still transmitting LAST data to the client while the
14783 server had already finished. This one is very rare as it can only
14784 happen when the client dies while receiving the last packets.
14785
14786 T : the request was tarpitted. It has been held open with the client
14787 during the whole "timeout tarpit" duration or until the client
14788 closed, both of which will be reported in the "Tw" timer.
14789
14790 - : normal session completion after end of data transfer.
14791
14792 - the third character tells whether the persistence cookie was provided by
14793 the client (only in HTTP mode) :
14794
14795 N : the client provided NO cookie. This is usually the case for new
14796 visitors, so counting the number of occurrences of this flag in the
14797 logs generally indicate a valid trend for the site frequentation.
14798
14799 I : the client provided an INVALID cookie matching no known server.
14800 This might be caused by a recent configuration change, mixed
Cyril Bontéa8e7bbc2010-04-25 22:29:29 +020014801 cookies between HTTP/HTTPS sites, persistence conditionally
14802 ignored, or an attack.
Willy Tarreaucc6c8912009-02-22 10:53:55 +010014803
14804 D : the client provided a cookie designating a server which was DOWN,
14805 so either "option persist" was used and the client was sent to
14806 this server, or it was not set and the client was redispatched to
14807 another server.
14808
Willy Tarreau996a92c2010-10-13 19:30:47 +020014809 V : the client provided a VALID cookie, and was sent to the associated
Willy Tarreaucc6c8912009-02-22 10:53:55 +010014810 server.
14811
Willy Tarreau996a92c2010-10-13 19:30:47 +020014812 E : the client provided a valid cookie, but with a last date which was
14813 older than what is allowed by the "maxidle" cookie parameter, so
14814 the cookie is consider EXPIRED and is ignored. The request will be
14815 redispatched just as if there was no cookie.
14816
14817 O : the client provided a valid cookie, but with a first date which was
14818 older than what is allowed by the "maxlife" cookie parameter, so
14819 the cookie is consider too OLD and is ignored. The request will be
14820 redispatched just as if there was no cookie.
14821
Willy Tarreauc89ccb62012-04-05 21:18:22 +020014822 U : a cookie was present but was not used to select the server because
14823 some other server selection mechanism was used instead (typically a
14824 "use-server" rule).
14825
Willy Tarreaucc6c8912009-02-22 10:53:55 +010014826 - : does not apply (no cookie set in configuration).
14827
14828 - the last character reports what operations were performed on the persistence
14829 cookie returned by the server (only in HTTP mode) :
14830
14831 N : NO cookie was provided by the server, and none was inserted either.
14832
14833 I : no cookie was provided by the server, and the proxy INSERTED one.
14834 Note that in "cookie insert" mode, if the server provides a cookie,
14835 it will still be overwritten and reported as "I" here.
14836
Willy Tarreau996a92c2010-10-13 19:30:47 +020014837 U : the proxy UPDATED the last date in the cookie that was presented by
14838 the client. This can only happen in insert mode with "maxidle". It
Jarno Huuskonen0e82b922014-04-12 18:22:19 +030014839 happens every time there is activity at a different date than the
Willy Tarreau996a92c2010-10-13 19:30:47 +020014840 date indicated in the cookie. If any other change happens, such as
14841 a redispatch, then the cookie will be marked as inserted instead.
14842
Willy Tarreaucc6c8912009-02-22 10:53:55 +010014843 P : a cookie was PROVIDED by the server and transmitted as-is.
14844
14845 R : the cookie provided by the server was REWRITTEN by the proxy, which
14846 happens in "cookie rewrite" or "cookie prefix" modes.
14847
14848 D : the cookie provided by the server was DELETED by the proxy.
14849
14850 - : does not apply (no cookie set in configuration).
14851
Willy Tarreau996a92c2010-10-13 19:30:47 +020014852The combination of the two first flags gives a lot of information about what
14853was happening when the session terminated, and why it did terminate. It can be
Willy Tarreaucc6c8912009-02-22 10:53:55 +010014854helpful to detect server saturation, network troubles, local system resource
14855starvation, attacks, etc...
14856
14857The most common termination flags combinations are indicated below. They are
14858alphabetically sorted, with the lowercase set just after the upper case for
14859easier finding and understanding.
14860
14861 Flags Reason
14862
14863 -- Normal termination.
14864
14865 CC The client aborted before the connection could be established to the
14866 server. This can happen when haproxy tries to connect to a recently
14867 dead (or unchecked) server, and the client aborts while haproxy is
14868 waiting for the server to respond or for "timeout connect" to expire.
14869
14870 CD The client unexpectedly aborted during data transfer. This can be
14871 caused by a browser crash, by an intermediate equipment between the
14872 client and haproxy which decided to actively break the connection,
14873 by network routing issues between the client and haproxy, or by a
14874 keep-alive session between the server and the client terminated first
14875 by the client.
Willy Tarreaud72758d2010-01-12 10:42:19 +010014876
Willy Tarreaucc6c8912009-02-22 10:53:55 +010014877 cD The client did not send nor acknowledge any data for as long as the
14878 "timeout client" delay. This is often caused by network failures on
Cyril Bontédc4d9032012-04-08 21:57:39 +020014879 the client side, or the client simply leaving the net uncleanly.
Willy Tarreaucc6c8912009-02-22 10:53:55 +010014880
14881 CH The client aborted while waiting for the server to start responding.
14882 It might be the server taking too long to respond or the client
14883 clicking the 'Stop' button too fast.
14884
14885 cH The "timeout client" stroke while waiting for client data during a
14886 POST request. This is sometimes caused by too large TCP MSS values
14887 for PPPoE networks which cannot transport full-sized packets. It can
14888 also happen when client timeout is smaller than server timeout and
14889 the server takes too long to respond.
14890
14891 CQ The client aborted while its session was queued, waiting for a server
14892 with enough empty slots to accept it. It might be that either all the
14893 servers were saturated or that the assigned server was taking too
14894 long a time to respond.
14895
14896 CR The client aborted before sending a full HTTP request. Most likely
14897 the request was typed by hand using a telnet client, and aborted
14898 too early. The HTTP status code is likely a 400 here. Sometimes this
14899 might also be caused by an IDS killing the connection between haproxy
Willy Tarreau0f228a02015-05-01 15:37:53 +020014900 and the client. "option http-ignore-probes" can be used to ignore
14901 connections without any data transfer.
Willy Tarreaucc6c8912009-02-22 10:53:55 +010014902
14903 cR The "timeout http-request" stroke before the client sent a full HTTP
14904 request. This is sometimes caused by too large TCP MSS values on the
14905 client side for PPPoE networks which cannot transport full-sized
14906 packets, or by clients sending requests by hand and not typing fast
14907 enough, or forgetting to enter the empty line at the end of the
Willy Tarreau2705a612014-05-23 17:38:34 +020014908 request. The HTTP status code is likely a 408 here. Note: recently,
Willy Tarreau0f228a02015-05-01 15:37:53 +020014909 some browsers started to implement a "pre-connect" feature consisting
14910 in speculatively connecting to some recently visited web sites just
14911 in case the user would like to visit them. This results in many
14912 connections being established to web sites, which end up in 408
14913 Request Timeout if the timeout strikes first, or 400 Bad Request when
14914 the browser decides to close them first. These ones pollute the log
14915 and feed the error counters. Some versions of some browsers have even
14916 been reported to display the error code. It is possible to work
14917 around the undesirable effects of this behaviour by adding "option
14918 http-ignore-probes" in the frontend, resulting in connections with
14919 zero data transfer to be totally ignored. This will definitely hide
14920 the errors of people experiencing connectivity issues though.
Willy Tarreaucc6c8912009-02-22 10:53:55 +010014921
14922 CT The client aborted while its session was tarpitted. It is important to
14923 check if this happens on valid requests, in order to be sure that no
Willy Tarreau55165fe2009-05-10 12:02:55 +020014924 wrong tarpit rules have been written. If a lot of them happen, it
14925 might make sense to lower the "timeout tarpit" value to something
14926 closer to the average reported "Tw" timer, in order not to consume
14927 resources for just a few attackers.
Willy Tarreaucc6c8912009-02-22 10:53:55 +010014928
Willy Tarreau570f2212013-06-10 16:42:09 +020014929 LR The request was intercepted and locally handled by haproxy. Generally
14930 it means that this was a redirect or a stats request.
14931
Krzysztof Piotr Oledzkif8645332009-12-13 21:55:50 +010014932 SC The server or an equipment between it and haproxy explicitly refused
Willy Tarreaucc6c8912009-02-22 10:53:55 +010014933 the TCP connection (the proxy received a TCP RST or an ICMP message
14934 in return). Under some circumstances, it can also be the network
14935 stack telling the proxy that the server is unreachable (eg: no route,
14936 or no ARP response on local network). When this happens in HTTP mode,
14937 the status code is likely a 502 or 503 here.
14938
14939 sC The "timeout connect" stroke before a connection to the server could
14940 complete. When this happens in HTTP mode, the status code is likely a
14941 503 or 504 here.
14942
14943 SD The connection to the server died with an error during the data
14944 transfer. This usually means that haproxy has received an RST from
14945 the server or an ICMP message from an intermediate equipment while
14946 exchanging data with the server. This can be caused by a server crash
14947 or by a network issue on an intermediate equipment.
14948
14949 sD The server did not send nor acknowledge any data for as long as the
14950 "timeout server" setting during the data phase. This is often caused
Krzysztof Piotr Oledzkif8645332009-12-13 21:55:50 +010014951 by too short timeouts on L4 equipments before the server (firewalls,
Willy Tarreaucc6c8912009-02-22 10:53:55 +010014952 load-balancers, ...), as well as keep-alive sessions maintained
14953 between the client and the server expiring first on haproxy.
14954
14955 SH The server aborted before sending its full HTTP response headers, or
14956 it crashed while processing the request. Since a server aborting at
14957 this moment is very rare, it would be wise to inspect its logs to
14958 control whether it crashed and why. The logged request may indicate a
14959 small set of faulty requests, demonstrating bugs in the application.
14960 Sometimes this might also be caused by an IDS killing the connection
14961 between haproxy and the server.
14962
14963 sH The "timeout server" stroke before the server could return its
14964 response headers. This is the most common anomaly, indicating too
14965 long transactions, probably caused by server or database saturation.
14966 The immediate workaround consists in increasing the "timeout server"
14967 setting, but it is important to keep in mind that the user experience
14968 will suffer from these long response times. The only long term
14969 solution is to fix the application.
14970
14971 sQ The session spent too much time in queue and has been expired. See
14972 the "timeout queue" and "timeout connect" settings to find out how to
14973 fix this if it happens too often. If it often happens massively in
14974 short periods, it may indicate general problems on the affected
14975 servers due to I/O or database congestion, or saturation caused by
14976 external attacks.
14977
14978 PC The proxy refused to establish a connection to the server because the
14979 process' socket limit has been reached while attempting to connect.
Cyril Bontédc4d9032012-04-08 21:57:39 +020014980 The global "maxconn" parameter may be increased in the configuration
Willy Tarreaucc6c8912009-02-22 10:53:55 +010014981 so that it does not happen anymore. This status is very rare and
14982 might happen when the global "ulimit-n" parameter is forced by hand.
14983
Willy Tarreaued2fd2d2010-12-29 11:23:27 +010014984 PD The proxy blocked an incorrectly formatted chunked encoded message in
14985 a request or a response, after the server has emitted its headers. In
14986 most cases, this will indicate an invalid message from the server to
Willy Tarreauf3a3e132013-08-31 08:16:26 +020014987 the client. Haproxy supports chunk sizes of up to 2GB - 1 (2147483647
14988 bytes). Any larger size will be considered as an error.
Willy Tarreaued2fd2d2010-12-29 11:23:27 +010014989
Willy Tarreaucc6c8912009-02-22 10:53:55 +010014990 PH The proxy blocked the server's response, because it was invalid,
14991 incomplete, dangerous (cache control), or matched a security filter.
14992 In any case, an HTTP 502 error is sent to the client. One possible
14993 cause for this error is an invalid syntax in an HTTP header name
Willy Tarreaued2fd2d2010-12-29 11:23:27 +010014994 containing unauthorized characters. It is also possible but quite
14995 rare, that the proxy blocked a chunked-encoding request from the
14996 client due to an invalid syntax, before the server responded. In this
14997 case, an HTTP 400 error is sent to the client and reported in the
14998 logs.
Willy Tarreaucc6c8912009-02-22 10:53:55 +010014999
15000 PR The proxy blocked the client's HTTP request, either because of an
15001 invalid HTTP syntax, in which case it returned an HTTP 400 error to
15002 the client, or because a deny filter matched, in which case it
15003 returned an HTTP 403 error.
15004
15005 PT The proxy blocked the client's request and has tarpitted its
15006 connection before returning it a 500 server error. Nothing was sent
15007 to the server. The connection was maintained open for as long as
15008 reported by the "Tw" timer field.
15009
15010 RC A local resource has been exhausted (memory, sockets, source ports)
15011 preventing the connection to the server from establishing. The error
15012 logs will tell precisely what was missing. This is very rare and can
15013 only be solved by proper system tuning.
15014
Willy Tarreau996a92c2010-10-13 19:30:47 +020015015The combination of the two last flags gives a lot of information about how
15016persistence was handled by the client, the server and by haproxy. This is very
15017important to troubleshoot disconnections, when users complain they have to
15018re-authenticate. The commonly encountered flags are :
15019
15020 -- Persistence cookie is not enabled.
15021
15022 NN No cookie was provided by the client, none was inserted in the
15023 response. For instance, this can be in insert mode with "postonly"
15024 set on a GET request.
15025
15026 II A cookie designating an invalid server was provided by the client,
15027 a valid one was inserted in the response. This typically happens when
Jamie Gloudonaaa21002012-08-25 00:18:33 -040015028 a "server" entry is removed from the configuration, since its cookie
Willy Tarreau996a92c2010-10-13 19:30:47 +020015029 value can be presented by a client when no other server knows it.
15030
15031 NI No cookie was provided by the client, one was inserted in the
15032 response. This typically happens for first requests from every user
15033 in "insert" mode, which makes it an easy way to count real users.
15034
15035 VN A cookie was provided by the client, none was inserted in the
15036 response. This happens for most responses for which the client has
15037 already got a cookie.
15038
15039 VU A cookie was provided by the client, with a last visit date which is
15040 not completely up-to-date, so an updated cookie was provided in
15041 response. This can also happen if there was no date at all, or if
15042 there was a date but the "maxidle" parameter was not set, so that the
15043 cookie can be switched to unlimited time.
15044
15045 EI A cookie was provided by the client, with a last visit date which is
15046 too old for the "maxidle" parameter, so the cookie was ignored and a
15047 new cookie was inserted in the response.
15048
15049 OI A cookie was provided by the client, with a first visit date which is
15050 too old for the "maxlife" parameter, so the cookie was ignored and a
15051 new cookie was inserted in the response.
15052
15053 DI The server designated by the cookie was down, a new server was
15054 selected and a new cookie was emitted in the response.
15055
15056 VI The server designated by the cookie was not marked dead but could not
15057 be reached. A redispatch happened and selected another one, which was
15058 then advertised in the response.
15059
Willy Tarreaucc6c8912009-02-22 10:53:55 +010015060
Willy Tarreauc57f0e22009-05-10 13:12:33 +0200150618.6. Non-printable characters
15062-----------------------------
Willy Tarreaucc6c8912009-02-22 10:53:55 +010015063
15064In order not to cause trouble to log analysis tools or terminals during log
15065consulting, non-printable characters are not sent as-is into log files, but are
15066converted to the two-digits hexadecimal representation of their ASCII code,
15067prefixed by the character '#'. The only characters that can be logged without
15068being escaped are comprised between 32 and 126 (inclusive). Obviously, the
15069escape character '#' itself is also encoded to avoid any ambiguity ("#23"). It
15070is the same for the character '"' which becomes "#22", as well as '{', '|' and
15071'}' when logging headers.
15072
15073Note that the space character (' ') is not encoded in headers, which can cause
15074issues for tools relying on space count to locate fields. A typical header
15075containing spaces is "User-Agent".
15076
15077Last, it has been observed that some syslog daemons such as syslog-ng escape
15078the quote ('"') with a backslash ('\'). The reverse operation can safely be
15079performed since no quote may appear anywhere else in the logs.
15080
15081
Willy Tarreauc57f0e22009-05-10 13:12:33 +0200150828.7. Capturing HTTP cookies
15083---------------------------
Willy Tarreaucc6c8912009-02-22 10:53:55 +010015084
15085Cookie capture simplifies the tracking a complete user session. This can be
15086achieved using the "capture cookie" statement in the frontend. Please refer to
Willy Tarreauc57f0e22009-05-10 13:12:33 +020015087section 4.2 for more details. Only one cookie can be captured, and the same
Willy Tarreaucc6c8912009-02-22 10:53:55 +010015088cookie will simultaneously be checked in the request ("Cookie:" header) and in
15089the response ("Set-Cookie:" header). The respective values will be reported in
15090the HTTP logs at the "captured_request_cookie" and "captured_response_cookie"
Willy Tarreauc57f0e22009-05-10 13:12:33 +020015091locations (see section 8.2.3 about HTTP log format). When either cookie is
Willy Tarreaucc6c8912009-02-22 10:53:55 +010015092not seen, a dash ('-') replaces the value. This way, it's easy to detect when a
15093user switches to a new session for example, because the server will reassign it
15094a new cookie. It is also possible to detect if a server unexpectedly sets a
15095wrong cookie to a client, leading to session crossing.
15096
15097 Examples :
15098 # capture the first cookie whose name starts with "ASPSESSION"
15099 capture cookie ASPSESSION len 32
15100
15101 # capture the first cookie whose name is exactly "vgnvisitor"
15102 capture cookie vgnvisitor= len 32
15103
15104
Willy Tarreauc57f0e22009-05-10 13:12:33 +0200151058.8. Capturing HTTP headers
15106---------------------------
Willy Tarreaucc6c8912009-02-22 10:53:55 +010015107
15108Header captures are useful to track unique request identifiers set by an upper
15109proxy, virtual host names, user-agents, POST content-length, referrers, etc. In
15110the response, one can search for information about the response length, how the
15111server asked the cache to behave, or an object location during a redirection.
15112
15113Header captures are performed using the "capture request header" and "capture
15114response header" statements in the frontend. Please consult their definition in
Willy Tarreauc57f0e22009-05-10 13:12:33 +020015115section 4.2 for more details.
Willy Tarreaucc6c8912009-02-22 10:53:55 +010015116
15117It is possible to include both request headers and response headers at the same
Krzysztof Piotr Oledzkif8645332009-12-13 21:55:50 +010015118time. Non-existent headers are logged as empty strings, and if one header
15119appears more than once, only its last occurrence will be logged. Request headers
Willy Tarreaucc6c8912009-02-22 10:53:55 +010015120are grouped within braces '{' and '}' in the same order as they were declared,
15121and delimited with a vertical bar '|' without any space. Response headers
15122follow the same representation, but are displayed after a space following the
15123request headers block. These blocks are displayed just before the HTTP request
15124in the logs.
15125
Willy Tarreaud9ed3d22014-06-13 12:23:06 +020015126As a special case, it is possible to specify an HTTP header capture in a TCP
15127frontend. The purpose is to enable logging of headers which will be parsed in
15128an HTTP backend if the request is then switched to this HTTP backend.
15129
Willy Tarreaucc6c8912009-02-22 10:53:55 +010015130 Example :
15131 # This instance chains to the outgoing proxy
15132 listen proxy-out
15133 mode http
15134 option httplog
15135 option logasap
15136 log global
15137 server cache1 192.168.1.1:3128
15138
15139 # log the name of the virtual server
15140 capture request header Host len 20
15141
15142 # log the amount of data uploaded during a POST
15143 capture request header Content-Length len 10
15144
15145 # log the beginning of the referrer
15146 capture request header Referer len 20
15147
15148 # server name (useful for outgoing proxies only)
15149 capture response header Server len 20
15150
15151 # logging the content-length is useful with "option logasap"
15152 capture response header Content-Length len 10
15153
15154 # log the expected cache behaviour on the response
15155 capture response header Cache-Control len 8
15156
15157 # the Via header will report the next proxy's name
15158 capture response header Via len 20
15159
15160 # log the URL location during a redirection
15161 capture response header Location len 20
15162
15163 >>> Aug 9 20:26:09 localhost \
15164 haproxy[2022]: 127.0.0.1:34014 [09/Aug/2004:20:26:09] proxy-out \
15165 proxy-out/cache1 0/0/0/162/+162 200 +350 - - ---- 0/0/0/0/0 0/0 \
15166 {fr.adserver.yahoo.co||http://fr.f416.mail.} {|864|private||} \
15167 "GET http://fr.adserver.yahoo.com/"
15168
15169 >>> Aug 9 20:30:46 localhost \
15170 haproxy[2022]: 127.0.0.1:34020 [09/Aug/2004:20:30:46] proxy-out \
15171 proxy-out/cache1 0/0/0/182/+182 200 +279 - - ---- 0/0/0/0/0 0/0 \
15172 {w.ods.org||} {Formilux/0.1.8|3495|||} \
Willy Tarreaud72758d2010-01-12 10:42:19 +010015173 "GET http://trafic.1wt.eu/ HTTP/1.1"
Willy Tarreaucc6c8912009-02-22 10:53:55 +010015174
15175 >>> Aug 9 20:30:46 localhost \
15176 haproxy[2022]: 127.0.0.1:34028 [09/Aug/2004:20:30:46] proxy-out \
15177 proxy-out/cache1 0/0/2/126/+128 301 +223 - - ---- 0/0/0/0/0 0/0 \
15178 {www.sytadin.equipement.gouv.fr||http://trafic.1wt.eu/} \
15179 {Apache|230|||http://www.sytadin.} \
Willy Tarreaud72758d2010-01-12 10:42:19 +010015180 "GET http://www.sytadin.equipement.gouv.fr/ HTTP/1.1"
Willy Tarreaucc6c8912009-02-22 10:53:55 +010015181
15182
Willy Tarreauc57f0e22009-05-10 13:12:33 +0200151838.9. Examples of logs
15184---------------------
Willy Tarreaucc6c8912009-02-22 10:53:55 +010015185
15186These are real-world examples of logs accompanied with an explanation. Some of
15187them have been made up by hand. The syslog part has been removed for better
15188reading. Their sole purpose is to explain how to decipher them.
15189
15190 >>> haproxy[674]: 127.0.0.1:33318 [15/Oct/2003:08:31:57.130] px-http \
15191 px-http/srv1 6559/0/7/147/6723 200 243 - - ---- 5/3/3/1/0 0/0 \
15192 "HEAD / HTTP/1.0"
15193
15194 => long request (6.5s) entered by hand through 'telnet'. The server replied
15195 in 147 ms, and the session ended normally ('----')
15196
15197 >>> haproxy[674]: 127.0.0.1:33319 [15/Oct/2003:08:31:57.149] px-http \
15198 px-http/srv1 6559/1230/7/147/6870 200 243 - - ---- 324/239/239/99/0 \
15199 0/9 "HEAD / HTTP/1.0"
15200
15201 => Idem, but the request was queued in the global queue behind 9 other
15202 requests, and waited there for 1230 ms.
15203
15204 >>> haproxy[674]: 127.0.0.1:33320 [15/Oct/2003:08:32:17.654] px-http \
15205 px-http/srv1 9/0/7/14/+30 200 +243 - - ---- 3/3/3/1/0 0/0 \
15206 "GET /image.iso HTTP/1.0"
15207
15208 => request for a long data transfer. The "logasap" option was specified, so
Krzysztof Piotr Oledzkif8645332009-12-13 21:55:50 +010015209 the log was produced just before transferring data. The server replied in
Willy Tarreaucc6c8912009-02-22 10:53:55 +010015210 14 ms, 243 bytes of headers were sent to the client, and total time from
15211 accept to first data byte is 30 ms.
15212
15213 >>> haproxy[674]: 127.0.0.1:33320 [15/Oct/2003:08:32:17.925] px-http \
15214 px-http/srv1 9/0/7/14/30 502 243 - - PH-- 3/2/2/0/0 0/0 \
15215 "GET /cgi-bin/bug.cgi? HTTP/1.0"
15216
15217 => the proxy blocked a server response either because of an "rspdeny" or
15218 "rspideny" filter, or because the response was improperly formatted and
Willy Tarreau3c92c5f2011-08-28 09:45:47 +020015219 not HTTP-compliant, or because it blocked sensitive information which
Willy Tarreaucc6c8912009-02-22 10:53:55 +010015220 risked being cached. In this case, the response is replaced with a "502
15221 bad gateway". The flags ("PH--") tell us that it was haproxy who decided
15222 to return the 502 and not the server.
15223
15224 >>> haproxy[18113]: 127.0.0.1:34548 [15/Oct/2003:15:18:55.798] px-http \
Willy Tarreaud72758d2010-01-12 10:42:19 +010015225 px-http/<NOSRV> -1/-1/-1/-1/8490 -1 0 - - CR-- 2/2/2/0/0 0/0 ""
Willy Tarreaucc6c8912009-02-22 10:53:55 +010015226
15227 => the client never completed its request and aborted itself ("C---") after
15228 8.5s, while the proxy was waiting for the request headers ("-R--").
15229 Nothing was sent to any server.
15230
15231 >>> haproxy[18113]: 127.0.0.1:34549 [15/Oct/2003:15:19:06.103] px-http \
15232 px-http/<NOSRV> -1/-1/-1/-1/50001 408 0 - - cR-- 2/2/2/0/0 0/0 ""
15233
15234 => The client never completed its request, which was aborted by the
15235 time-out ("c---") after 50s, while the proxy was waiting for the request
15236 headers ("-R--"). Nothing was sent to any server, but the proxy could
15237 send a 408 return code to the client.
15238
15239 >>> haproxy[18989]: 127.0.0.1:34550 [15/Oct/2003:15:24:28.312] px-tcp \
15240 px-tcp/srv1 0/0/5007 0 cD 0/0/0/0/0 0/0
15241
15242 => This log was produced with "option tcplog". The client timed out after
15243 5 seconds ("c----").
15244
15245 >>> haproxy[18989]: 10.0.0.1:34552 [15/Oct/2003:15:26:31.462] px-http \
15246 px-http/srv1 3183/-1/-1/-1/11215 503 0 - - SC-- 205/202/202/115/3 \
Willy Tarreaud72758d2010-01-12 10:42:19 +010015247 0/0 "HEAD / HTTP/1.0"
Willy Tarreaucc6c8912009-02-22 10:53:55 +010015248
15249 => The request took 3s to complete (probably a network problem), and the
Willy Tarreauc57f0e22009-05-10 13:12:33 +020015250 connection to the server failed ('SC--') after 4 attempts of 2 seconds
Willy Tarreaucc6c8912009-02-22 10:53:55 +010015251 (config says 'retries 3'), and no redispatch (otherwise we would have
15252 seen "/+3"). Status code 503 was returned to the client. There were 115
15253 connections on this server, 202 connections on this proxy, and 205 on
15254 the global process. It is possible that the server refused the
15255 connection because of too many already established.
Willy Tarreau844e3c52008-01-11 16:28:18 +010015256
Willy Tarreau3dfe6cd2008-12-07 22:29:48 +010015257
Willy Tarreauc57f0e22009-05-10 13:12:33 +0200152589. Statistics and monitoring
15259----------------------------
15260
15261It is possible to query HAProxy about its status. The most commonly used
15262mechanism is the HTTP statistics page. This page also exposes an alternative
15263CSV output format for monitoring tools. The same format is provided on the
15264Unix socket.
15265
15266
152679.1. CSV format
Willy Tarreau3dfe6cd2008-12-07 22:29:48 +010015268---------------
Krzysztof Piotr Oledzkif58a9622008-02-23 01:19:10 +010015269
Willy Tarreau7f062c42009-03-05 18:43:00 +010015270The statistics may be consulted either from the unix socket or from the HTTP
Willy Tarreaua3310dc2014-06-16 15:43:21 +020015271page. Both means provide a CSV format whose fields follow. The first line
15272begins with a sharp ('#') and has one word per comma-delimited field which
15273represents the title of the column. All other lines starting at the second one
15274use a classical CSV format using a comma as the delimiter, and the double quote
15275('"') as an optional text delimiter, but only if the enclosed text is ambiguous
15276(if it contains a quote or a comma). The double-quote character ('"') in the
15277text is doubled ('""'), which is the format that most tools recognize. Please
15278do not insert any column before these ones in order not to break tools which
15279use hard-coded column positions.
Willy Tarreau7f062c42009-03-05 18:43:00 +010015280
James Westbyebe62d62014-07-08 10:14:57 -040015281In brackets after each field name are the types which may have a value for
15282that field. The types are L (Listeners), F (Frontends), B (Backends), and
15283S (Servers).
15284
15285 0. pxname [LFBS]: proxy name
15286 1. svname [LFBS]: service name (FRONTEND for frontend, BACKEND for backend,
15287 any name for server/listener)
15288 2. qcur [..BS]: current queued requests. For the backend this reports the
15289 number queued without a server assigned.
15290 3. qmax [..BS]: max value of qcur
15291 4. scur [LFBS]: current sessions
15292 5. smax [LFBS]: max sessions
15293 6. slim [LFBS]: configured session limit
15294 7. stot [LFBS]: cumulative number of connections
15295 8. bin [LFBS]: bytes in
15296 9. bout [LFBS]: bytes out
15297 10. dreq [LFB.]: requests denied because of security concerns.
15298 - For tcp this is because of a matched tcp-request content rule.
15299 - For http this is because of a matched http-request or tarpit rule.
15300 11. dresp [LFBS]: responses denied because of security concerns.
15301 - For http this is because of a matched http-request rule, or
15302 "option checkcache".
15303 12. ereq [LF..]: request errors. Some of the possible causes are:
15304 - early termination from the client, before the request has been sent.
15305 - read error from the client
15306 - client timeout
15307 - client closed connection
15308 - various bad requests from the client.
15309 - request was tarpitted.
15310 13. econ [..BS]: number of requests that encountered an error trying to
15311 connect to a backend server. The backend stat is the sum of the stat
15312 for all servers of that backend, plus any connection errors not
15313 associated with a particular server (such as the backend having no
15314 active servers).
15315 14. eresp [..BS]: response errors. srv_abrt will be counted here also.
15316 Some other errors are:
15317 - write error on the client socket (won't be counted for the server stat)
15318 - failure applying filters to the response.
15319 15. wretr [..BS]: number of times a connection to a server was retried.
15320 16. wredis [..BS]: number of times a request was redispatched to another
15321 server. The server value counts the number of times that server was
15322 switched away from.
15323 17. status [LFBS]: status (UP/DOWN/NOLB/MAINT/MAINT(via)...)
Pavlos Parissis1f673c72015-05-02 20:30:44 +020015324 18. weight [..BS]: total weight (backend), server weight (server)
15325 19. act [..BS]: number of active servers (backend), server is active (server)
15326 20. bck [..BS]: number of backup servers (backend), server is backup (server)
James Westbyebe62d62014-07-08 10:14:57 -040015327 21. chkfail [...S]: number of failed checks. (Only counts checks failed when
15328 the server is up.)
15329 22. chkdown [..BS]: number of UP->DOWN transitions. The backend counter counts
15330 transitions to the whole backend being down, rather than the sum of the
15331 counters for each server.
15332 23. lastchg [..BS]: number of seconds since the last UP<->DOWN transition
15333 24. downtime [..BS]: total downtime (in seconds). The value for the backend
15334 is the downtime for the whole backend, not the sum of the server downtime.
15335 25. qlimit [...S]: configured maxqueue for the server, or nothing in the
15336 value is 0 (default, meaning no limit)
15337 26. pid [LFBS]: process id (0 for first instance, 1 for second, ...)
15338 27. iid [LFBS]: unique proxy id
15339 28. sid [L..S]: server id (unique inside a proxy)
15340 29. throttle [...S]: current throttle percentage for the server, when
15341 slowstart is active, or no value if not in slowstart.
15342 30. lbtot [..BS]: total number of times a server was selected, either for new
15343 sessions, or when re-dispatching. The server counter is the number
15344 of times that server was selected.
15345 31. tracked [...S]: id of proxy/server if tracking is enabled.
15346 32. type [LFBS]: (0=frontend, 1=backend, 2=server, 3=socket/listener)
15347 33. rate [.FBS]: number of sessions per second over last elapsed second
15348 34. rate_lim [.F..]: configured limit on new sessions per second
15349 35. rate_max [.FBS]: max number of new sessions per second
15350 36. check_status [...S]: status of last health check, one of:
Cyril Bontéf0c60612010-02-06 14:44:47 +010015351 UNK -> unknown
15352 INI -> initializing
15353 SOCKERR -> socket error
15354 L4OK -> check passed on layer 4, no upper layers testing enabled
Jason Harvey83104802015-04-16 11:13:21 -080015355 L4TOUT -> layer 1-4 timeout
Cyril Bontéf0c60612010-02-06 14:44:47 +010015356 L4CON -> layer 1-4 connection problem, for example
15357 "Connection refused" (tcp rst) or "No route to host" (icmp)
15358 L6OK -> check passed on layer 6
15359 L6TOUT -> layer 6 (SSL) timeout
15360 L6RSP -> layer 6 invalid response - protocol error
15361 L7OK -> check passed on layer 7
15362 L7OKC -> check conditionally passed on layer 7, for example 404 with
15363 disable-on-404
15364 L7TOUT -> layer 7 (HTTP/SMTP) timeout
15365 L7RSP -> layer 7 invalid response - protocol error
15366 L7STS -> layer 7 response error, for example HTTP 5xx
James Westbyebe62d62014-07-08 10:14:57 -040015367 37. check_code [...S]: layer5-7 code, if available
15368 38. check_duration [...S]: time in ms took to finish last health check
15369 39. hrsp_1xx [.FBS]: http responses with 1xx code
15370 40. hrsp_2xx [.FBS]: http responses with 2xx code
15371 41. hrsp_3xx [.FBS]: http responses with 3xx code
15372 42. hrsp_4xx [.FBS]: http responses with 4xx code
15373 43. hrsp_5xx [.FBS]: http responses with 5xx code
15374 44. hrsp_other [.FBS]: http responses with other codes (protocol error)
15375 45. hanafail [...S]: failed health checks details
15376 46. req_rate [.F..]: HTTP requests per second over last elapsed second
15377 47. req_rate_max [.F..]: max number of HTTP requests per second observed
15378 48. req_tot [.F..]: total number of HTTP requests received
15379 49. cli_abrt [..BS]: number of data transfers aborted by the client
15380 50. srv_abrt [..BS]: number of data transfers aborted by the server
15381 (inc. in eresp)
15382 51. comp_in [.FB.]: number of HTTP response bytes fed to the compressor
15383 52. comp_out [.FB.]: number of HTTP response bytes emitted by the compressor
15384 53. comp_byp [.FB.]: number of bytes that bypassed the HTTP compressor
15385 (CPU/BW limit)
15386 54. comp_rsp [.FB.]: number of HTTP responses that were compressed
15387 55. lastsess [..BS]: number of seconds since last session assigned to
15388 server/backend
15389 56. last_chk [...S]: last health check contents or textual error
15390 57. last_agt [...S]: last agent check contents or textual error
15391 58. qtime [..BS]: the average queue time in ms over the 1024 last requests
15392 59. ctime [..BS]: the average connect time in ms over the 1024 last requests
15393 60. rtime [..BS]: the average response time in ms over the 1024 last requests
15394 (0 for TCP)
15395 61. ttime [..BS]: the average total session time in ms over the 1024 last
15396 requests
Willy Tarreau844e3c52008-01-11 16:28:18 +010015397
Willy Tarreau3dfe6cd2008-12-07 22:29:48 +010015398
Willy Tarreauc57f0e22009-05-10 13:12:33 +0200153999.2. Unix Socket commands
Willy Tarreau3dfe6cd2008-12-07 22:29:48 +010015400-------------------------
Krzysztof Piotr Oledzki2c6962c2008-03-02 02:42:14 +010015401
Willy Tarreau468f4932013-08-01 16:50:16 +020015402The stats socket is not enabled by default. In order to enable it, it is
15403necessary to add one line in the global section of the haproxy configuration.
15404A second line is recommended to set a larger timeout, always appreciated when
15405issuing commands by hand :
15406
15407 global
15408 stats socket /var/run/haproxy.sock mode 600 level admin
15409 stats timeout 2m
15410
15411It is also possible to add multiple instances of the stats socket by repeating
15412the line, and make them listen to a TCP port instead of a UNIX socket. This is
15413never done by default because this is dangerous, but can be handy in some
15414situations :
15415
15416 global
15417 stats socket /var/run/haproxy.sock mode 600 level admin
15418 stats socket ipv4@192.168.0.1:9999 level admin
15419 stats timeout 2m
15420
15421To access the socket, an external utility such as "socat" is required. Socat is a
15422swiss-army knife to connect anything to anything. We use it to connect terminals
15423to the socket, or a couple of stdin/stdout pipes to it for scripts. The two main
15424syntaxes we'll use are the following :
15425
15426 # socat /var/run/haproxy.sock stdio
15427 # socat /var/run/haproxy.sock readline
15428
15429The first one is used with scripts. It is possible to send the output of a
15430script to haproxy, and pass haproxy's output to another script. That's useful
15431for retrieving counters or attack traces for example.
15432
15433The second one is only useful for issuing commands by hand. It has the benefit
15434that the terminal is handled by the readline library which supports line
15435editing and history, which is very convenient when issuing repeated commands
15436(eg: watch a counter).
15437
15438The socket supports two operation modes :
15439 - interactive
15440 - non-interactive
15441
15442The non-interactive mode is the default when socat connects to the socket. In
15443this mode, a single line may be sent. It is processed as a whole, responses are
15444sent back, and the connection closes after the end of the response. This is the
15445mode that scripts and monitoring tools use. It is possible to send multiple
15446commands in this mode, they need to be delimited by a semi-colon (';'). For
15447example :
15448
15449 # echo "show info;show stat;show table" | socat /var/run/haproxy stdio
15450
15451The interactive mode displays a prompt ('>') and waits for commands to be
15452entered on the line, then processes them, and displays the prompt again to wait
15453for a new command. This mode is entered via the "prompt" command which must be
15454sent on the first line in non-interactive mode. The mode is a flip switch, if
15455"prompt" is sent in interactive mode, it is disabled and the connection closes
15456after processing the last command of the same line.
15457
15458For this reason, when debugging by hand, it's quite common to start with the
15459"prompt" command :
15460
15461 # socat /var/run/haproxy readline
15462 prompt
15463 > show info
15464 ...
15465 >
15466
15467Since multiple commands may be issued at once, haproxy uses the empty line as a
15468delimiter to mark an end of output for each command, and takes care of ensuring
15469that no command can emit an empty line on output. A script can thus easily
15470parse the output even when multiple commands were pipelined on a single line.
Willy Tarreau3dfe6cd2008-12-07 22:29:48 +010015471
Willy Tarreau9a42c0d2009-09-22 19:31:03 +020015472It is important to understand that when multiple haproxy processes are started
15473on the same sockets, any process may pick up the request and will output its
15474own stats.
Willy Tarreau3dfe6cd2008-12-07 22:29:48 +010015475
Willy Tarreau468f4932013-08-01 16:50:16 +020015476The list of commands currently supported on the stats socket is provided below.
15477If an unknown command is sent, haproxy displays the usage message which reminds
15478all supported commands. Some commands support a more complex syntax, generally
15479it will explain what part of the command is invalid when this happens.
15480
Thierry FOURNIERd32079e2014-01-29 20:02:04 +010015481add acl <acl> <pattern>
Thierry FOURNIER65ce6132014-03-20 11:42:45 +010015482 Add an entry into the acl <acl>. <acl> is the #<id> or the <file> returned by
15483 "show acl". This command does not verify if the entry already exists. This
15484 command cannot be used if the reference <acl> is a file also used with a map.
15485 In this case, you must use the command "add map" in place of "add acl".
Thierry FOURNIERd32079e2014-01-29 20:02:04 +010015486
Thierry FOURNIERc0e0d7b2013-12-11 16:55:52 +010015487add map <map> <key> <value>
15488 Add an entry into the map <map> to associate the value <value> to the key
15489 <key>. This command does not verify if the entry already exists. It is
Thierry FOURNIERd32079e2014-01-29 20:02:04 +010015490 mainly used to fill a map after a clear operation. Note that if the reference
15491 <map> is a file and is shared with a map, this map will contain also a new
15492 pattern entry.
Thierry FOURNIERc0e0d7b2013-12-11 16:55:52 +010015493
Willy Tarreaud63335a2010-02-26 12:56:52 +010015494clear counters
15495 Clear the max values of the statistics counters in each proxy (frontend &
15496 backend) and in each server. The cumulated counters are not affected. This
15497 can be used to get clean counters after an incident, without having to
15498 restart nor to clear traffic counters. This command is restricted and can
15499 only be issued on sockets configured for levels "operator" or "admin".
15500
15501clear counters all
15502 Clear all statistics counters in each proxy (frontend & backend) and in each
15503 server. This has the same effect as restarting. This command is restricted
15504 and can only be issued on sockets configured for level "admin".
15505
Thierry FOURNIERd32079e2014-01-29 20:02:04 +010015506clear acl <acl>
Thierry FOURNIER65ce6132014-03-20 11:42:45 +010015507 Remove all entries from the acl <acl>. <acl> is the #<id> or the <file>
15508 returned by "show acl". Note that if the reference <acl> is a file and is
15509 shared with a map, this map will be also cleared.
Thierry FOURNIERd32079e2014-01-29 20:02:04 +010015510
Thierry FOURNIERc0e0d7b2013-12-11 16:55:52 +010015511clear map <map>
Thierry FOURNIER65ce6132014-03-20 11:42:45 +010015512 Remove all entries from the map <map>. <map> is the #<id> or the <file>
15513 returned by "show map". Note that if the reference <map> is a file and is
15514 shared with a acl, this acl will be also cleared.
Thierry FOURNIERc0e0d7b2013-12-11 16:55:52 +010015515
Simon Hormanc88b8872011-06-15 15:18:49 +090015516clear table <table> [ data.<type> <operator> <value> ] | [ key <key> ]
15517 Remove entries from the stick-table <table>.
15518
15519 This is typically used to unblock some users complaining they have been
15520 abusively denied access to a service, but this can also be used to clear some
15521 stickiness entries matching a server that is going to be replaced (see "show
15522 table" below for details). Note that sometimes, removal of an entry will be
15523 refused because it is currently tracked by a session. Retrying a few seconds
15524 later after the session ends is usual enough.
15525
15526 In the case where no options arguments are given all entries will be removed.
15527
15528 When the "data." form is used entries matching a filter applied using the
15529 stored data (see "stick-table" in section 4.2) are removed. A stored data
15530 type must be specified in <type>, and this data type must be stored in the
15531 table otherwise an error is reported. The data is compared according to
15532 <operator> with the 64-bit integer <value>. Operators are the same as with
15533 the ACLs :
15534
15535 - eq : match entries whose data is equal to this value
15536 - ne : match entries whose data is not equal to this value
15537 - le : match entries whose data is less than or equal to this value
15538 - ge : match entries whose data is greater than or equal to this value
15539 - lt : match entries whose data is less than this value
15540 - gt : match entries whose data is greater than this value
15541
15542 When the key form is used the entry <key> is removed. The key must be of the
Simon Horman619e3cc2011-06-15 15:18:52 +090015543 same type as the table, which currently is limited to IPv4, IPv6, integer and
15544 string.
Willy Tarreau88bc4ec2010-08-01 07:58:48 +020015545
15546 Example :
Willy Tarreau62a36c42010-08-17 15:53:10 +020015547 $ echo "show table http_proxy" | socat stdio /tmp/sock1
Emeric Brun7c6b82e2010-09-24 16:34:28 +020015548 >>> # table: http_proxy, type: ip, size:204800, used:2
Willy Tarreau62a36c42010-08-17 15:53:10 +020015549 >>> 0x80e6a4c: key=127.0.0.1 use=0 exp=3594729 gpc0=0 conn_rate(30000)=1 \
15550 bytes_out_rate(60000)=187
15551 >>> 0x80e6a80: key=127.0.0.2 use=0 exp=3594740 gpc0=1 conn_rate(30000)=10 \
15552 bytes_out_rate(60000)=191
Willy Tarreau88bc4ec2010-08-01 07:58:48 +020015553
15554 $ echo "clear table http_proxy key 127.0.0.1" | socat stdio /tmp/sock1
15555
15556 $ echo "show table http_proxy" | socat stdio /tmp/sock1
Emeric Brun7c6b82e2010-09-24 16:34:28 +020015557 >>> # table: http_proxy, type: ip, size:204800, used:1
Willy Tarreau62a36c42010-08-17 15:53:10 +020015558 >>> 0x80e6a80: key=127.0.0.2 use=0 exp=3594740 gpc0=1 conn_rate(30000)=10 \
15559 bytes_out_rate(60000)=191
Simon Hormanc88b8872011-06-15 15:18:49 +090015560 $ echo "clear table http_proxy data.gpc0 eq 1" | socat stdio /tmp/sock1
15561 $ echo "show table http_proxy" | socat stdio /tmp/sock1
15562 >>> # table: http_proxy, type: ip, size:204800, used:1
Willy Tarreau88bc4ec2010-08-01 07:58:48 +020015563
Thierry FOURNIERd32079e2014-01-29 20:02:04 +010015564del acl <acl> [<key>|#<ref>]
15565 Delete all the acl entries from the acl <acl> corresponding to the key <key>.
Thierry FOURNIER65ce6132014-03-20 11:42:45 +010015566 <acl> is the #<id> or the <file> returned by "show acl". If the <ref> is used,
15567 this command delete only the listed reference. The reference can be found with
15568 listing the content of the acl. Note that if the reference <acl> is a file and
15569 is shared with a map, the entry will be also deleted in the map.
Thierry FOURNIERd32079e2014-01-29 20:02:04 +010015570
15571del map <map> [<key>|#<ref>]
Thierry FOURNIER0b90f312014-01-29 20:40:18 +010015572 Delete all the map entries from the map <map> corresponding to the key <key>.
Thierry FOURNIER65ce6132014-03-20 11:42:45 +010015573 <map> is the #<id> or the <file> returned by "show map". If the <ref> is used,
15574 this command delete only the listed reference. The reference can be found with
15575 listing the content of the map. Note that if the reference <map> is a file and
15576 is shared with a acl, the entry will be also deleted in the map.
Thierry FOURNIER0b90f312014-01-29 20:40:18 +010015577
15578disable agent <backend>/<server>
Simon Horman671b6f02013-11-25 10:46:39 +090015579 Mark the auxiliary agent check as temporarily stopped.
15580
15581 In the case where an agent check is being run as a auxiliary check, due
15582 to the agent-check parameter of a server directive, new checks are only
15583 initialised when the agent is in the enabled. Thus, disable agent will
15584 prevent any new agent checks from begin initiated until the agent
15585 re-enabled using enable agent.
15586
15587 When an agent is disabled the processing of an auxiliary agent check that
15588 was initiated while the agent was set as enabled is as follows: All
15589 results that would alter the weight, specifically "drain" or a weight
15590 returned by the agent, are ignored. The processing of agent check is
15591 otherwise unchanged.
15592
15593 The motivation for this feature is to allow the weight changing effects
15594 of the agent checks to be paused to allow the weight of a server to be
15595 configured using set weight without being overridden by the agent.
15596
15597 This command is restricted and can only be issued on sockets configured for
15598 level "admin".
15599
Willy Tarreau532a4502011-09-07 22:37:44 +020015600disable frontend <frontend>
15601 Mark the frontend as temporarily stopped. This corresponds to the mode which
15602 is used during a soft restart : the frontend releases the port but can be
15603 enabled again if needed. This should be used with care as some non-Linux OSes
15604 are unable to enable it back. This is intended to be used in environments
15605 where stopping a proxy is not even imaginable but a misconfigured proxy must
15606 be fixed. That way it's possible to release the port and bind it into another
15607 process to restore operations. The frontend will appear with status "STOP"
15608 on the stats page.
15609
15610 The frontend may be specified either by its name or by its numeric ID,
15611 prefixed with a sharp ('#').
15612
15613 This command is restricted and can only be issued on sockets configured for
15614 level "admin".
15615
Willy Tarreau9b5aecd2014-05-23 11:53:10 +020015616disable health <backend>/<server>
15617 Mark the primary health check as temporarily stopped. This will disable
15618 sending of health checks, and the last health check result will be ignored.
15619 The server will be in unchecked state and considered UP unless an auxiliary
15620 agent check forces it down.
15621
15622 This command is restricted and can only be issued on sockets configured for
15623 level "admin".
15624
Willy Tarreaud63335a2010-02-26 12:56:52 +010015625disable server <backend>/<server>
15626 Mark the server DOWN for maintenance. In this mode, no more checks will be
15627 performed on the server until it leaves maintenance.
15628 If the server is tracked by other servers, those servers will be set to DOWN
15629 during the maintenance.
15630
15631 In the statistics page, a server DOWN for maintenance will appear with a
15632 "MAINT" status, its tracking servers with the "MAINT(via)" one.
15633
15634 Both the backend and the server may be specified either by their name or by
Willy Tarreauf5f31922011-08-02 11:32:07 +020015635 their numeric ID, prefixed with a sharp ('#').
Willy Tarreaud63335a2010-02-26 12:56:52 +010015636
15637 This command is restricted and can only be issued on sockets configured for
15638 level "admin".
15639
Simon Horman671b6f02013-11-25 10:46:39 +090015640enable agent <backend>/<server>
15641 Resume auxiliary agent check that was temporarily stopped.
15642
15643 See "disable agent" for details of the effect of temporarily starting
15644 and stopping an auxiliary agent.
15645
15646 This command is restricted and can only be issued on sockets configured for
15647 level "admin".
15648
Willy Tarreau532a4502011-09-07 22:37:44 +020015649enable frontend <frontend>
15650 Resume a frontend which was temporarily stopped. It is possible that some of
15651 the listening ports won't be able to bind anymore (eg: if another process
15652 took them since the 'disable frontend' operation). If this happens, an error
15653 is displayed. Some operating systems might not be able to resume a frontend
15654 which was disabled.
15655
15656 The frontend may be specified either by its name or by its numeric ID,
15657 prefixed with a sharp ('#').
15658
15659 This command is restricted and can only be issued on sockets configured for
15660 level "admin".
15661
Willy Tarreau9b5aecd2014-05-23 11:53:10 +020015662enable health <backend>/<server>
15663 Resume a primary health check that was temporarily stopped. This will enable
15664 sending of health checks again. Please see "disable health" for details.
15665
15666 This command is restricted and can only be issued on sockets configured for
15667 level "admin".
15668
Willy Tarreaud63335a2010-02-26 12:56:52 +010015669enable server <backend>/<server>
15670 If the server was previously marked as DOWN for maintenance, this marks the
15671 server UP and checks are re-enabled.
15672
15673 Both the backend and the server may be specified either by their name or by
Willy Tarreauf5f31922011-08-02 11:32:07 +020015674 their numeric ID, prefixed with a sharp ('#').
Willy Tarreaud63335a2010-02-26 12:56:52 +010015675
15676 This command is restricted and can only be issued on sockets configured for
15677 level "admin".
15678
Thierry FOURNIER5b16df72014-02-26 18:07:38 +010015679get map <map> <value>
Thierry FOURNIER65ce6132014-03-20 11:42:45 +010015680get acl <acl> <value>
15681 Lookup the value <value> in the map <map> or in the ACL <acl>. <map> or <acl>
15682 are the #<id> or the <file> returned by "show map" or "show acl". This command
15683 returns all the matching patterns associated with this map. This is useful for
15684 debugging maps and ACLs. The output format is composed by one line par
15685 matching type. Each line is composed by space-delimited series of words.
Thierry FOURNIER5b16df72014-02-26 18:07:38 +010015686
15687 The first two words are:
15688
15689 <match method>: The match method applied. It can be "found", "bool",
15690 "int", "ip", "bin", "len", "str", "beg", "sub", "dir",
15691 "dom", "end" or "reg".
15692
15693 <match result>: The result. Can be "match" or "no-match".
15694
15695 The following words are returned only if the pattern matches an entry.
15696
15697 <index type>: "tree" or "list". The internal lookup algorithm.
15698
15699 <case>: "case-insensitive" or "case-sensitive". The
15700 interpretation of the case.
15701
15702 <entry matched>: match="<entry>". Return the matched pattern. It is
15703 useful with regular expressions.
15704
15705 The two last word are used to show the returned value and its type. With the
15706 "acl" case, the pattern doesn't exist.
15707
15708 return=nothing: No return because there are no "map".
15709 return="<value>": The value returned in the string format.
15710 return=cannot-display: The value cannot be converted as string.
15711
15712 type="<type>": The type of the returned sample.
15713
Willy Tarreaud63335a2010-02-26 12:56:52 +010015714get weight <backend>/<server>
15715 Report the current weight and the initial weight of server <server> in
15716 backend <backend> or an error if either doesn't exist. The initial weight is
15717 the one that appears in the configuration file. Both are normally equal
15718 unless the current weight has been changed. Both the backend and the server
15719 may be specified either by their name or by their numeric ID, prefixed with a
Willy Tarreauf5f31922011-08-02 11:32:07 +020015720 sharp ('#').
Willy Tarreaud63335a2010-02-26 12:56:52 +010015721
Willy Tarreau9a42c0d2009-09-22 19:31:03 +020015722help
15723 Print the list of known keywords and their basic usage. The same help screen
15724 is also displayed for unknown commands.
Willy Tarreau3dfe6cd2008-12-07 22:29:48 +010015725
Willy Tarreau9a42c0d2009-09-22 19:31:03 +020015726prompt
15727 Toggle the prompt at the beginning of the line and enter or leave interactive
15728 mode. In interactive mode, the connection is not closed after a command
15729 completes. Instead, the prompt will appear again, indicating the user that
15730 the interpreter is waiting for a new command. The prompt consists in a right
15731 angle bracket followed by a space "> ". This mode is particularly convenient
15732 when one wants to periodically check information such as stats or errors.
15733 It is also a good idea to enter interactive mode before issuing a "help"
15734 command.
15735
15736quit
15737 Close the connection when in interactive mode.
Krzysztof Piotr Oledzki2c6962c2008-03-02 02:42:14 +010015738
Thierry FOURNIERd32079e2014-01-29 20:02:04 +010015739set map <map> [<key>|#<ref>] <value>
Thierry FOURNIER65ce6132014-03-20 11:42:45 +010015740 Modify the value corresponding to each key <key> in a map <map>. <map> is the
15741 #<id> or <file> returned by "show map". If the <ref> is used in place of
15742 <key>, only the entry pointed by <ref> is changed. The new value is <value>.
Thierry FOURNIERc0e0d7b2013-12-11 16:55:52 +010015743
Willy Tarreau2a0f4d22011-08-02 11:49:05 +020015744set maxconn frontend <frontend> <value>
Willy Tarreau3c7a79d2012-09-26 21:07:15 +020015745 Dynamically change the specified frontend's maxconn setting. Any positive
15746 value is allowed including zero, but setting values larger than the global
15747 maxconn does not make much sense. If the limit is increased and connections
15748 were pending, they will immediately be accepted. If it is lowered to a value
15749 below the current number of connections, new connections acceptation will be
Willy Tarreau2a0f4d22011-08-02 11:49:05 +020015750 delayed until the threshold is reached. The frontend might be specified by
15751 either its name or its numeric ID prefixed with a sharp ('#').
15752
Willy Tarreau91886b62011-09-07 14:38:31 +020015753set maxconn global <maxconn>
15754 Dynamically change the global maxconn setting within the range defined by the
15755 initial global maxconn setting. If it is increased and connections were
15756 pending, they will immediately be accepted. If it is lowered to a value below
15757 the current number of connections, new connections acceptation will be
15758 delayed until the threshold is reached. A value of zero restores the initial
15759 setting.
15760
Willy Tarreauf5b22872011-09-07 16:13:44 +020015761set rate-limit connections global <value>
15762 Change the process-wide connection rate limit, which is set by the global
15763 'maxconnrate' setting. A value of zero disables the limitation. This limit
15764 applies to all frontends and the change has an immediate effect. The value
15765 is passed in number of connections per second.
15766
William Lallemandd85f9172012-11-09 17:05:39 +010015767set rate-limit http-compression global <value>
15768 Change the maximum input compression rate, which is set by the global
15769 'maxcomprate' setting. A value of zero disables the limitation. The value is
William Lallemand096f5542012-11-19 17:26:05 +010015770 passed in number of kilobytes per second. The value is available in the "show
15771 info" on the line "CompressBpsRateLim" in bytes.
William Lallemandd85f9172012-11-09 17:05:39 +010015772
Willy Tarreau93e7c002013-10-07 18:51:07 +020015773set rate-limit sessions global <value>
15774 Change the process-wide session rate limit, which is set by the global
15775 'maxsessrate' setting. A value of zero disables the limitation. This limit
15776 applies to all frontends and the change has an immediate effect. The value
15777 is passed in number of sessions per second.
15778
Willy Tarreaue43d5322013-10-07 20:01:52 +020015779set rate-limit ssl-sessions global <value>
15780 Change the process-wide SSL session rate limit, which is set by the global
15781 'maxsslrate' setting. A value of zero disables the limitation. This limit
15782 applies to all frontends and the change has an immediate effect. The value
15783 is passed in number of sessions per second sent to the SSL stack. It applies
15784 before the handshake in order to protect the stack against handshake abuses.
15785
Baptiste Assmann3d8f8312015-04-13 22:54:33 +020015786set server <backend>/<server> addr <ip4 or ip6 address>
15787 Replace the current IP address of a server by the one provided.
15788
Willy Tarreau2a4b70f2014-05-22 18:42:35 +020015789set server <backend>/<server> agent [ up | down ]
15790 Force a server's agent to a new state. This can be useful to immediately
15791 switch a server's state regardless of some slow agent checks for example.
15792 Note that the change is propagated to tracking servers if any.
15793
15794set server <backend>/<server> health [ up | stopping | down ]
15795 Force a server's health to a new state. This can be useful to immediately
15796 switch a server's state regardless of some slow health checks for example.
15797 Note that the change is propagated to tracking servers if any.
15798
15799set server <backend>/<server> state [ ready | drain | maint ]
15800 Force a server's administrative state to a new state. This can be useful to
15801 disable load balancing and/or any traffic to a server. Setting the state to
15802 "ready" puts the server in normal mode, and the command is the equivalent of
15803 the "enable server" command. Setting the state to "maint" disables any traffic
15804 to the server as well as any health checks. This is the equivalent of the
15805 "disable server" command. Setting the mode to "drain" only removes the server
15806 from load balancing but still allows it to be checked and to accept new
15807 persistent connections. Changes are propagated to tracking servers if any.
15808
15809set server <backend>/<server> weight <weight>[%]
15810 Change a server's weight to the value passed in argument. This is the exact
15811 equivalent of the "set weight" command below.
15812
Emeric Brun4147b2e2014-06-16 18:36:30 +020015813set ssl ocsp-response <response>
15814 This command is used to update an OCSP Response for a certificate (see "crt"
15815 on "bind" lines). Same controls are performed as during the initial loading of
15816 the response. The <response> must be passed as a base64 encoded string of the
15817 DER encoded response from the OCSP server.
15818
15819 Example:
15820 openssl ocsp -issuer issuer.pem -cert server.pem \
15821 -host ocsp.issuer.com:80 -respout resp.der
15822 echo "set ssl ocsp-response $(base64 -w 10000 resp.der)" | \
15823 socat stdio /var/run/haproxy.stat
15824
Nenad Merdanovicc6985f02015-05-09 08:46:02 +020015825set ssl tls-key <id> <tlskey>
15826 Set the next TLS key for the <id> listener to <tlskey>. This key becomes the
15827 ultimate key, while the penultimate one is used for encryption (others just
15828 decrypt). The oldest TLS key present is overwritten. <id> is either a numeric
15829 #<id> or <file> returned by "show tls-keys". <tlskey> is a base64 encoded 48
15830 bit TLS ticket key (ex. openssl rand -base64 48).
15831
Willy Tarreau47060b62013-08-01 21:11:42 +020015832set table <table> key <key> [data.<data_type> <value>]*
Willy Tarreau654694e2012-06-07 01:03:16 +020015833 Create or update a stick-table entry in the table. If the key is not present,
15834 an entry is inserted. See stick-table in section 4.2 to find all possible
15835 values for <data_type>. The most likely use consists in dynamically entering
15836 entries for source IP addresses, with a flag in gpc0 to dynamically block an
Willy Tarreau47060b62013-08-01 21:11:42 +020015837 IP address or affect its quality of service. It is possible to pass multiple
15838 data_types in a single call.
Willy Tarreau654694e2012-06-07 01:03:16 +020015839
Willy Tarreaud63335a2010-02-26 12:56:52 +010015840set timeout cli <delay>
15841 Change the CLI interface timeout for current connection. This can be useful
15842 during long debugging sessions where the user needs to constantly inspect
15843 some indicators without being disconnected. The delay is passed in seconds.
15844
15845set weight <backend>/<server> <weight>[%]
15846 Change a server's weight to the value passed in argument. If the value ends
15847 with the '%' sign, then the new weight will be relative to the initially
Simon Horman58b5d292013-02-12 10:45:52 +090015848 configured weight. Absolute weights are permitted between 0 and 256.
15849 Relative weights must be positive with the resulting absolute weight is
15850 capped at 256. Servers which are part of a farm running a static
15851 load-balancing algorithm have stricter limitations because the weight
15852 cannot change once set. Thus for these servers, the only accepted values
15853 are 0 and 100% (or 0 and the initial weight). Changes take effect
15854 immediately, though certain LB algorithms require a certain amount of
15855 requests to consider changes. A typical usage of this command is to
15856 disable a server during an update by setting its weight to zero, then to
15857 enable it again after the update by setting it back to 100%. This command
15858 is restricted and can only be issued on sockets configured for level
15859 "admin". Both the backend and the server may be specified either by their
15860 name or by their numeric ID, prefixed with a sharp ('#').
Willy Tarreaud63335a2010-02-26 12:56:52 +010015861
Willy Tarreaue0c8a1a2009-03-04 16:33:10 +010015862show errors [<iid>]
15863 Dump last known request and response errors collected by frontends and
15864 backends. If <iid> is specified, the limit the dump to errors concerning
Willy Tarreau6162db22009-10-10 17:13:00 +020015865 either frontend or backend whose ID is <iid>. This command is restricted
15866 and can only be issued on sockets configured for levels "operator" or
15867 "admin".
Willy Tarreaue0c8a1a2009-03-04 16:33:10 +010015868
15869 The errors which may be collected are the last request and response errors
15870 caused by protocol violations, often due to invalid characters in header
15871 names. The report precisely indicates what exact character violated the
15872 protocol. Other important information such as the exact date the error was
15873 detected, frontend and backend names, the server name (when known), the
15874 internal session ID and the source address which has initiated the session
15875 are reported too.
15876
15877 All characters are returned, and non-printable characters are encoded. The
15878 most common ones (\t = 9, \n = 10, \r = 13 and \e = 27) are encoded as one
15879 letter following a backslash. The backslash itself is encoded as '\\' to
15880 avoid confusion. Other non-printable characters are encoded '\xNN' where
15881 NN is the two-digits hexadecimal representation of the character's ASCII
15882 code.
15883
15884 Lines are prefixed with the position of their first character, starting at 0
15885 for the beginning of the buffer. At most one input line is printed per line,
15886 and large lines will be broken into multiple consecutive output lines so that
15887 the output never goes beyond 79 characters wide. It is easy to detect if a
15888 line was broken, because it will not end with '\n' and the next line's offset
15889 will be followed by a '+' sign, indicating it is a continuation of previous
15890 line.
15891
15892 Example :
Willy Tarreau62a36c42010-08-17 15:53:10 +020015893 $ echo "show errors" | socat stdio /tmp/sock1
15894 >>> [04/Mar/2009:15:46:56.081] backend http-in (#2) : invalid response
Willy Tarreaue0c8a1a2009-03-04 16:33:10 +010015895 src 127.0.0.1, session #54, frontend fe-eth0 (#1), server s2 (#1)
15896 response length 213 bytes, error at position 23:
15897
15898 00000 HTTP/1.0 200 OK\r\n
15899 00017 header/bizarre:blah\r\n
15900 00038 Location: blah\r\n
15901 00054 Long-line: this is a very long line which should b
15902 00104+ e broken into multiple lines on the output buffer,
15903 00154+ otherwise it would be too large to print in a ter
15904 00204+ minal\r\n
15905 00211 \r\n
15906
Willy Tarreauc57f0e22009-05-10 13:12:33 +020015907 In the example above, we see that the backend "http-in" which has internal
Willy Tarreaue0c8a1a2009-03-04 16:33:10 +010015908 ID 2 has blocked an invalid response from its server s2 which has internal
15909 ID 1. The request was on session 54 initiated by source 127.0.0.1 and
15910 received by frontend fe-eth0 whose ID is 1. The total response length was
15911 213 bytes when the error was detected, and the error was at byte 23. This
15912 is the slash ('/') in header name "header/bizarre", which is not a valid
15913 HTTP character for a header name.
Krzysztof Piotr Oledzki2c6962c2008-03-02 02:42:14 +010015914
Baptiste Assmann9b6857e2015-09-18 14:49:12 +020015915show backend
15916 Dump the list of backends available in the running process
15917
Willy Tarreau9a42c0d2009-09-22 19:31:03 +020015918show info
15919 Dump info about haproxy status on current process.
15920
Thierry FOURNIERc0e0d7b2013-12-11 16:55:52 +010015921show map [<map>]
15922 Dump info about map converters. Without argument, the list of all available
Thierry FOURNIER65ce6132014-03-20 11:42:45 +010015923 maps is returned. If a <map> is specified, its contents are dumped. <map> is
15924 the #<id> or <file>. The first column is a unique identifier. It can be used
15925 as reference for the operation "del map" and "set map". The second column is
15926 the pattern and the third column is the sample if available. The data returned
15927 are not directly a list of available maps, but are the list of all patterns
15928 composing any map. Many of these patterns can be shared with ACL.
Thierry FOURNIERd32079e2014-01-29 20:02:04 +010015929
15930show acl [<acl>]
15931 Dump info about acl converters. Without argument, the list of all available
Thierry FOURNIER65ce6132014-03-20 11:42:45 +010015932 acls is returned. If a <acl> is specified, its contents are dumped. <acl> if
15933 the #<id> or <file>. The dump format is the same than the map even for the
15934 sample value. The data returned are not a list of available ACL, but are the
15935 list of all patterns composing any ACL. Many of these patterns can be shared
15936 with maps.
Thierry FOURNIERc0e0d7b2013-12-11 16:55:52 +010015937
Willy Tarreau12833bb2014-01-28 16:49:56 +010015938show pools
15939 Dump the status of internal memory pools. This is useful to track memory
15940 usage when suspecting a memory leak for example. It does exactly the same
15941 as the SIGQUIT when running in foreground except that it does not flush
15942 the pools.
15943
Baptiste Assmann6f9225a2015-05-08 19:35:08 +020015944show servers state [<backend>]
15945 Dump the state of the servers found in the running configuration. A backend
15946 name or identifier may be provided to limit the output to this backend only.
15947
15948 The dump has the following format:
15949 - first line contains the format version (1 in this specification);
15950 - second line contains the column headers, prefixed by a sharp ('#');
15951 - third line and next ones contain data;
15952 - each line starting by a sharp ('#') is considered as a comment.
15953
15954 Since multiple versions of the ouptput may co-exist, below is the list of
15955 fields and their order per file format version :
15956 1:
15957 be_id: Backend unique id.
15958 be_name: Backend label.
15959 srv_id: Server unique id (in the backend).
15960 srv_name: Server label.
15961 srv_addr: Server IP address.
15962 srv_op_state: Server operational state (UP/DOWN/...).
15963 In source code: SRV_ST_*.
15964 srv_admin_state: Server administrative state (MAINT/DRAIN/...).
15965 In source code: SRV_ADMF_*.
15966 srv_uweight: User visible server's weight.
15967 srv_iweight: Server's initial weight.
15968 srv_time_since_last_change: Time since last operational change.
15969 srv_check_status: Last health check status.
15970 srv_check_result: Last check result (FAILED/PASSED/...).
15971 In source code: CHK_RES_*.
15972 srv_check_health: Checks rise / fall current counter.
15973 srv_check_state: State of the check (ENABLED/PAUSED/...).
15974 In source code: CHK_ST_*.
15975 srv_agent_state: State of the agent check (ENABLED/PAUSED/...).
15976 In source code: CHK_ST_*.
15977 bk_f_forced_id: Flag to know if the backend ID is forced by
15978 configuration.
15979 srv_f_forced_id: Flag to know if the server's ID is forced by
15980 configuration.
15981
Willy Tarreau9a42c0d2009-09-22 19:31:03 +020015982show sess
15983 Dump all known sessions. Avoid doing this on slow connections as this can
Willy Tarreau6162db22009-10-10 17:13:00 +020015984 be huge. This command is restricted and can only be issued on sockets
15985 configured for levels "operator" or "admin".
15986
Willy Tarreau66dc20a2010-03-05 17:53:32 +010015987show sess <id>
15988 Display a lot of internal information about the specified session identifier.
15989 This identifier is the first field at the beginning of the lines in the dumps
15990 of "show sess" (it corresponds to the session pointer). Those information are
15991 useless to most users but may be used by haproxy developers to troubleshoot a
15992 complex bug. The output format is intentionally not documented so that it can
Olivierce31e6e2014-09-05 18:49:10 +020015993 freely evolve depending on demands. You may find a description of all fields
15994 returned in src/dumpstats.c
15995
15996 The special id "all" dumps the states of all sessions, which must be avoided
15997 as much as possible as it is highly CPU intensive and can take a lot of time.
Willy Tarreau9a42c0d2009-09-22 19:31:03 +020015998
15999show stat [<iid> <type> <sid>]
16000 Dump statistics in the CSV format. By passing <id>, <type> and <sid>, it is
16001 possible to dump only selected items :
16002 - <iid> is a proxy ID, -1 to dump everything
16003 - <type> selects the type of dumpable objects : 1 for frontends, 2 for
16004 backends, 4 for servers, -1 for everything. These values can be ORed,
16005 for example:
16006 1 + 2 = 3 -> frontend + backend.
16007 1 + 2 + 4 = 7 -> frontend + backend + server.
16008 - <sid> is a server ID, -1 to dump everything from the selected proxy.
16009
16010 Example :
Willy Tarreau62a36c42010-08-17 15:53:10 +020016011 $ echo "show info;show stat" | socat stdio unix-connect:/tmp/sock1
16012 >>> Name: HAProxy
Willy Tarreau9a42c0d2009-09-22 19:31:03 +020016013 Version: 1.4-dev2-49
16014 Release_date: 2009/09/23
16015 Nbproc: 1
16016 Process_num: 1
16017 (...)
16018
16019 # pxname,svname,qcur,qmax,scur,smax,slim,stot,bin,bout,dreq, (...)
16020 stats,FRONTEND,,,0,0,1000,0,0,0,0,0,0,,,,,OPEN,,,,,,,,,1,1,0, (...)
16021 stats,BACKEND,0,0,0,0,1000,0,0,0,0,0,,0,0,0,0,UP,0,0,0,,0,250,(...)
16022 (...)
16023 www1,BACKEND,0,0,0,0,1000,0,0,0,0,0,,0,0,0,0,UP,1,1,0,,0,250, (...)
16024
16025 $
16026
16027 Here, two commands have been issued at once. That way it's easy to find
16028 which process the stats apply to in multi-process mode. Notice the empty
16029 line after the information output which marks the end of the first block.
16030 A similar empty line appears at the end of the second block (stats) so that
Krzysztof Piotr Oledzkif8645332009-12-13 21:55:50 +010016031 the reader knows the output has not been truncated.
Willy Tarreau9a42c0d2009-09-22 19:31:03 +020016032
Baptiste Assmann3863f972015-05-17 00:33:24 +020016033show stat resolvers <resolvers section id>
16034 Dump statistics for the given resolvers section.
16035 For each name server, the following counters are reported:
16036 sent: number of DNS requests sent to this server
16037 valid: number of DNS valid responses received from this server
16038 update: number of DNS responses used to update the server's IP address
16039 cname: number of CNAME responses
16040 cname_error: CNAME errors encountered with this server
16041 any_err: number of empty response (IE: server does not support ANY type)
16042 nx: non existent domain response received from this server
16043 timeout: how many time this server did not answer in time
16044 refused: number of requests refused by this server
16045 other: any other DNS errors
16046 invalid: invalid DNS response (from a protocol point of view)
16047 too_big: too big response
16048 outdated: number of response arrived too late (after an other name server)
16049
Willy Tarreau88bc4ec2010-08-01 07:58:48 +020016050show table
16051 Dump general information on all known stick-tables. Their name is returned
16052 (the name of the proxy which holds them), their type (currently zero, always
16053 IP), their size in maximum possible number of entries, and the number of
16054 entries currently in use.
16055
16056 Example :
Willy Tarreau62a36c42010-08-17 15:53:10 +020016057 $ echo "show table" | socat stdio /tmp/sock1
Simon Horman64b28d02011-08-13 08:03:50 +090016058 >>> # table: front_pub, type: ip, size:204800, used:171454
16059 >>> # table: back_rdp, type: ip, size:204800, used:0
Willy Tarreau88bc4ec2010-08-01 07:58:48 +020016060
Simon Horman17bce342011-06-15 15:18:47 +090016061show table <name> [ data.<type> <operator> <value> ] | [ key <key> ]
Willy Tarreau88bc4ec2010-08-01 07:58:48 +020016062 Dump contents of stick-table <name>. In this mode, a first line of generic
16063 information about the table is reported as with "show table", then all
16064 entries are dumped. Since this can be quite heavy, it is possible to specify
Simon Horman17bce342011-06-15 15:18:47 +090016065 a filter in order to specify what entries to display.
16066
16067 When the "data." form is used the filter applies to the stored data (see
16068 "stick-table" in section 4.2). A stored data type must be specified
16069 in <type>, and this data type must be stored in the table otherwise an
16070 error is reported. The data is compared according to <operator> with the
16071 64-bit integer <value>. Operators are the same as with the ACLs :
16072
Willy Tarreau88bc4ec2010-08-01 07:58:48 +020016073 - eq : match entries whose data is equal to this value
16074 - ne : match entries whose data is not equal to this value
16075 - le : match entries whose data is less than or equal to this value
16076 - ge : match entries whose data is greater than or equal to this value
16077 - lt : match entries whose data is less than this value
16078 - gt : match entries whose data is greater than this value
16079
Simon Hormanc88b8872011-06-15 15:18:49 +090016080
16081 When the key form is used the entry <key> is shown. The key must be of the
Simon Horman619e3cc2011-06-15 15:18:52 +090016082 same type as the table, which currently is limited to IPv4, IPv6, integer,
16083 and string.
Simon Horman17bce342011-06-15 15:18:47 +090016084
Willy Tarreau88bc4ec2010-08-01 07:58:48 +020016085 Example :
Willy Tarreau62a36c42010-08-17 15:53:10 +020016086 $ echo "show table http_proxy" | socat stdio /tmp/sock1
Simon Horman64b28d02011-08-13 08:03:50 +090016087 >>> # table: http_proxy, type: ip, size:204800, used:2
Willy Tarreau62a36c42010-08-17 15:53:10 +020016088 >>> 0x80e6a4c: key=127.0.0.1 use=0 exp=3594729 gpc0=0 conn_rate(30000)=1 \
16089 bytes_out_rate(60000)=187
16090 >>> 0x80e6a80: key=127.0.0.2 use=0 exp=3594740 gpc0=1 conn_rate(30000)=10 \
16091 bytes_out_rate(60000)=191
Willy Tarreau88bc4ec2010-08-01 07:58:48 +020016092
Willy Tarreau62a36c42010-08-17 15:53:10 +020016093 $ echo "show table http_proxy data.gpc0 gt 0" | socat stdio /tmp/sock1
Simon Horman64b28d02011-08-13 08:03:50 +090016094 >>> # table: http_proxy, type: ip, size:204800, used:2
Willy Tarreau62a36c42010-08-17 15:53:10 +020016095 >>> 0x80e6a80: key=127.0.0.2 use=0 exp=3594740 gpc0=1 conn_rate(30000)=10 \
16096 bytes_out_rate(60000)=191
Willy Tarreau88bc4ec2010-08-01 07:58:48 +020016097
Willy Tarreau62a36c42010-08-17 15:53:10 +020016098 $ echo "show table http_proxy data.conn_rate gt 5" | \
16099 socat stdio /tmp/sock1
Simon Horman64b28d02011-08-13 08:03:50 +090016100 >>> # table: http_proxy, type: ip, size:204800, used:2
Willy Tarreau62a36c42010-08-17 15:53:10 +020016101 >>> 0x80e6a80: key=127.0.0.2 use=0 exp=3594740 gpc0=1 conn_rate(30000)=10 \
16102 bytes_out_rate(60000)=191
Willy Tarreau88bc4ec2010-08-01 07:58:48 +020016103
Simon Horman17bce342011-06-15 15:18:47 +090016104 $ echo "show table http_proxy key 127.0.0.2" | \
16105 socat stdio /tmp/sock1
Simon Horman64b28d02011-08-13 08:03:50 +090016106 >>> # table: http_proxy, type: ip, size:204800, used:2
Simon Horman17bce342011-06-15 15:18:47 +090016107 >>> 0x80e6a80: key=127.0.0.2 use=0 exp=3594740 gpc0=1 conn_rate(30000)=10 \
16108 bytes_out_rate(60000)=191
16109
Willy Tarreau88bc4ec2010-08-01 07:58:48 +020016110 When the data criterion applies to a dynamic value dependent on time such as
16111 a bytes rate, the value is dynamically computed during the evaluation of the
16112 entry in order to decide whether it has to be dumped or not. This means that
16113 such a filter could match for some time then not match anymore because as
16114 time goes, the average event rate drops.
16115
16116 It is possible to use this to extract lists of IP addresses abusing the
16117 service, in order to monitor them or even blacklist them in a firewall.
16118 Example :
Willy Tarreau62a36c42010-08-17 15:53:10 +020016119 $ echo "show table http_proxy data.gpc0 gt 0" \
16120 | socat stdio /tmp/sock1 \
Willy Tarreau88bc4ec2010-08-01 07:58:48 +020016121 | fgrep 'key=' | cut -d' ' -f2 | cut -d= -f2 > abusers-ip.txt
16122 ( or | awk '/key/{ print a[split($2,a,"=")]; }' )
Krzysztof Piotr Oledzki719e7262009-10-04 15:02:46 +020016123
Nenad Merdanovicc6985f02015-05-09 08:46:02 +020016124show tls-keys
16125 Dump all loaded TLS ticket keys. The TLS ticket key reference ID and the
16126 file from which the keys have been loaded is shown. Both of those can be
16127 used to update the TLS keys using "set ssl tls-key".
16128
Willy Tarreau532a4502011-09-07 22:37:44 +020016129shutdown frontend <frontend>
16130 Completely delete the specified frontend. All the ports it was bound to will
16131 be released. It will not be possible to enable the frontend anymore after
16132 this operation. This is intended to be used in environments where stopping a
16133 proxy is not even imaginable but a misconfigured proxy must be fixed. That
16134 way it's possible to release the port and bind it into another process to
16135 restore operations. The frontend will not appear at all on the stats page
16136 once it is terminated.
16137
16138 The frontend may be specified either by its name or by its numeric ID,
16139 prefixed with a sharp ('#').
16140
16141 This command is restricted and can only be issued on sockets configured for
16142 level "admin".
16143
Willy Tarreaua295edc2011-09-07 23:21:03 +020016144shutdown session <id>
16145 Immediately terminate the session matching the specified session identifier.
16146 This identifier is the first field at the beginning of the lines in the dumps
16147 of "show sess" (it corresponds to the session pointer). This can be used to
16148 terminate a long-running session without waiting for a timeout or when an
16149 endless transfer is ongoing. Such terminated sessions are reported with a 'K'
16150 flag in the logs.
16151
Cyril Bontée63a1eb2014-07-12 18:22:42 +020016152shutdown sessions server <backend>/<server>
Willy Tarreau52b2d222011-09-07 23:48:48 +020016153 Immediately terminate all the sessions attached to the specified server. This
16154 can be used to terminate long-running sessions after a server is put into
16155 maintenance mode, for instance. Such terminated sessions are reported with a
16156 'K' flag in the logs.
16157
Willy Tarreau0ba27502007-12-24 16:55:16 +010016158/*
16159 * Local variables:
16160 * fill-column: 79
16161 * End:
16162 */