blob: 3102516710789bf854394c7001a16947b358f884 [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
Cyril Bonté307ee1e2015-09-28 23:16:06 +0200533.6. Mailers
Willy Tarreauc57f0e22009-05-10 13:12:33 +020054
554. Proxies
564.1. Proxy keywords matrix
574.2. Alphabetically sorted keywords reference
58
Willy Tarreau086fbf52012-09-24 20:34:51 +0200595. Bind and Server options
605.1. Bind options
615.2. Server and default-server options
Baptiste Assmann1fa66662015-04-14 00:28:47 +0200625.3. Server DNS resolution
635.3.1. Global overview
645.3.2. The resolvers section
Willy Tarreauc57f0e22009-05-10 13:12:33 +020065
666. HTTP header manipulation
67
Willy Tarreau74ca5042013-06-11 23:12:07 +0200687. Using ACLs and fetching samples
697.1. ACL basics
707.1.1. Matching booleans
717.1.2. Matching integers
727.1.3. Matching strings
737.1.4. Matching regular expressions (regexes)
747.1.5. Matching arbitrary data blocks
757.1.6. Matching IPv4 and IPv6 addresses
767.2. Using ACLs to form conditions
777.3. Fetching samples
Thierry FOURNIER060762e2014-04-23 13:29:15 +0200787.3.1. Converters
797.3.2. Fetching samples from internal states
807.3.3. Fetching samples at Layer 4
817.3.4. Fetching samples at Layer 5
827.3.5. Fetching samples from buffer contents (Layer 6)
837.3.6. Fetching HTTP samples (Layer 7)
Willy Tarreau74ca5042013-06-11 23:12:07 +0200847.4. Pre-defined ACLs
Willy Tarreauc57f0e22009-05-10 13:12:33 +020085
868. Logging
878.1. Log levels
888.2. Log formats
898.2.1. Default log format
908.2.2. TCP log format
918.2.3. HTTP log format
William Lallemand48940402012-01-30 16:47:22 +0100928.2.4. Custom log format
Willy Tarreau5f51e1a2012-12-03 18:40:10 +0100938.2.5. Error log format
Willy Tarreauc57f0e22009-05-10 13:12:33 +0200948.3. Advanced logging options
958.3.1. Disabling logging of external tests
968.3.2. Logging before waiting for the session to terminate
978.3.3. Raising log level upon errors
988.3.4. Disabling logging of successful connections
998.4. Timing events
1008.5. Session state at disconnection
1018.6. Non-printable characters
1028.7. Capturing HTTP cookies
1038.8. Capturing HTTP headers
1048.9. Examples of logs
105
1069. Statistics and monitoring
1079.1. CSV format
1089.2. Unix Socket commands
109
110
1111. Quick reminder about HTTP
112----------------------------
113
114When haproxy is running in HTTP mode, both the request and the response are
115fully analyzed and indexed, thus it becomes possible to build matching criteria
116on almost anything found in the contents.
117
118However, it is important to understand how HTTP requests and responses are
119formed, and how HAProxy decomposes them. It will then become easier to write
120correct rules and to debug existing configurations.
121
122
1231.1. The HTTP transaction model
124-------------------------------
125
126The HTTP protocol is transaction-driven. This means that each request will lead
Krzysztof Piotr Oledzkif8645332009-12-13 21:55:50 +0100127to one and only one response. Traditionally, a TCP connection is established
Willy Tarreauc57f0e22009-05-10 13:12:33 +0200128from the client to the server, a request is sent by the client on the
129connection, the server responds and the connection is closed. A new request
130will involve a new connection :
131
132 [CON1] [REQ1] ... [RESP1] [CLO1] [CON2] [REQ2] ... [RESP2] [CLO2] ...
133
134In this mode, called the "HTTP close" mode, there are as many connection
135establishments as there are HTTP transactions. Since the connection is closed
136by the server after the response, the client does not need to know the content
137length.
138
139Due to the transactional nature of the protocol, it was possible to improve it
140to avoid closing a connection between two subsequent transactions. In this mode
141however, it is mandatory that the server indicates the content length for each
142response so that the client does not wait indefinitely. For this, a special
143header is used: "Content-length". This mode is called the "keep-alive" mode :
144
145 [CON] [REQ1] ... [RESP1] [REQ2] ... [RESP2] [CLO] ...
146
147Its advantages are a reduced latency between transactions, and less processing
148power required on the server side. It is generally better than the close mode,
149but not always because the clients often limit their concurrent connections to
Patrick Mezard9ec2ec42010-06-12 17:02:45 +0200150a smaller value.
Willy Tarreauc57f0e22009-05-10 13:12:33 +0200151
152A last improvement in the communications is the pipelining mode. It still uses
153keep-alive, but the client does not wait for the first response to send the
154second request. This is useful for fetching large number of images composing a
155page :
156
157 [CON] [REQ1] [REQ2] ... [RESP1] [RESP2] [CLO] ...
158
159This can obviously have a tremendous benefit on performance because the network
160latency is eliminated between subsequent requests. Many HTTP agents do not
161correctly support pipelining since there is no way to associate a response with
162the corresponding request in HTTP. For this reason, it is mandatory for the
Cyril Bonté78caf842010-03-10 22:41:43 +0100163server to reply in the exact same order as the requests were received.
Willy Tarreauc57f0e22009-05-10 13:12:33 +0200164
Willy Tarreau70dffda2014-01-30 03:07:23 +0100165By default HAProxy operates in keep-alive mode with regards to persistent
166connections: for each connection it processes each request and response, and
167leaves the connection idle on both sides between the end of a response and the
168start of a new request.
Patrick Mezard9ec2ec42010-06-12 17:02:45 +0200169
Willy Tarreau70dffda2014-01-30 03:07:23 +0100170HAProxy supports 5 connection modes :
171 - keep alive : all requests and responses are processed (default)
172 - tunnel : only the first request and response are processed,
173 everything else is forwarded with no analysis.
174 - passive close : tunnel with "Connection: close" added in both directions.
175 - server close : the server-facing connection is closed after the response.
176 - forced close : the connection is actively closed after end of response.
177
Willy Tarreauc57f0e22009-05-10 13:12:33 +0200178
1791.2. HTTP request
180-----------------
181
182First, let's consider this HTTP request :
183
184 Line Contents
Willy Tarreaud72758d2010-01-12 10:42:19 +0100185 number
Willy Tarreauc57f0e22009-05-10 13:12:33 +0200186 1 GET /serv/login.php?lang=en&profile=2 HTTP/1.1
187 2 Host: www.mydomain.com
188 3 User-agent: my small browser
189 4 Accept: image/jpeg, image/gif
190 5 Accept: image/png
191
192
1931.2.1. The Request line
194-----------------------
195
196Line 1 is the "request line". It is always composed of 3 fields :
197
198 - a METHOD : GET
199 - a URI : /serv/login.php?lang=en&profile=2
200 - a version tag : HTTP/1.1
201
202All of them are delimited by what the standard calls LWS (linear white spaces),
203which are commonly spaces, but can also be tabs or line feeds/carriage returns
204followed by spaces/tabs. The method itself cannot contain any colon (':') and
205is limited to alphabetic letters. All those various combinations make it
206desirable that HAProxy performs the splitting itself rather than leaving it to
207the user to write a complex or inaccurate regular expression.
208
209The URI itself can have several forms :
210
211 - A "relative URI" :
212
213 /serv/login.php?lang=en&profile=2
214
215 It is a complete URL without the host part. This is generally what is
216 received by servers, reverse proxies and transparent proxies.
217
218 - An "absolute URI", also called a "URL" :
219
220 http://192.168.0.12:8080/serv/login.php?lang=en&profile=2
221
222 It is composed of a "scheme" (the protocol name followed by '://'), a host
223 name or address, optionally a colon (':') followed by a port number, then
224 a relative URI beginning at the first slash ('/') after the address part.
225 This is generally what proxies receive, but a server supporting HTTP/1.1
226 must accept this form too.
227
228 - a star ('*') : this form is only accepted in association with the OPTIONS
229 method and is not relayable. It is used to inquiry a next hop's
230 capabilities.
Willy Tarreaud72758d2010-01-12 10:42:19 +0100231
Willy Tarreauc57f0e22009-05-10 13:12:33 +0200232 - an address:port combination : 192.168.0.12:80
233 This is used with the CONNECT method, which is used to establish TCP
234 tunnels through HTTP proxies, generally for HTTPS, but sometimes for
235 other protocols too.
236
237In a relative URI, two sub-parts are identified. The part before the question
238mark is called the "path". It is typically the relative path to static objects
239on the server. The part after the question mark is called the "query string".
240It is mostly used with GET requests sent to dynamic scripts and is very
241specific to the language, framework or application in use.
242
243
2441.2.2. The request headers
245--------------------------
246
247The headers start at the second line. They are composed of a name at the
248beginning of the line, immediately followed by a colon (':'). Traditionally,
249an LWS is added after the colon but that's not required. Then come the values.
250Multiple identical headers may be folded into one single line, delimiting the
251values with commas, provided that their order is respected. This is commonly
252encountered in the "Cookie:" field. A header may span over multiple lines if
253the subsequent lines begin with an LWS. In the example in 1.2, lines 4 and 5
254define a total of 3 values for the "Accept:" header.
255
256Contrary to a common mis-conception, header names are not case-sensitive, and
257their values are not either if they refer to other header names (such as the
258"Connection:" header).
259
260The end of the headers is indicated by the first empty line. People often say
261that it's a double line feed, which is not exact, even if a double line feed
262is one valid form of empty line.
263
264Fortunately, HAProxy takes care of all these complex combinations when indexing
265headers, checking values and counting them, so there is no reason to worry
266about the way they could be written, but it is important not to accuse an
267application of being buggy if it does unusual, valid things.
268
269Important note:
270 As suggested by RFC2616, HAProxy normalizes headers by replacing line breaks
271 in the middle of headers by LWS in order to join multi-line headers. This
272 is necessary for proper analysis and helps less capable HTTP parsers to work
273 correctly and not to be fooled by such complex constructs.
274
275
2761.3. HTTP response
277------------------
278
279An HTTP response looks very much like an HTTP request. Both are called HTTP
280messages. Let's consider this HTTP response :
281
282 Line Contents
Willy Tarreaud72758d2010-01-12 10:42:19 +0100283 number
Willy Tarreauc57f0e22009-05-10 13:12:33 +0200284 1 HTTP/1.1 200 OK
285 2 Content-length: 350
286 3 Content-Type: text/html
287
Willy Tarreau816b9792009-09-15 21:25:21 +0200288As a special case, HTTP supports so called "Informational responses" as status
289codes 1xx. These messages are special in that they don't convey any part of the
290response, they're just used as sort of a signaling message to ask a client to
Willy Tarreau5843d1a2010-02-01 15:13:32 +0100291continue to post its request for instance. In the case of a status 100 response
292the requested information will be carried by the next non-100 response message
293following the informational one. This implies that multiple responses may be
294sent to a single request, and that this only works when keep-alive is enabled
295(1xx messages are HTTP/1.1 only). HAProxy handles these messages and is able to
296correctly forward and skip them, and only process the next non-100 response. As
297such, these messages are neither logged nor transformed, unless explicitly
298state otherwise. Status 101 messages indicate that the protocol is changing
299over the same connection and that haproxy must switch to tunnel mode, just as
300if a CONNECT had occurred. Then the Upgrade header would contain additional
301information about the type of protocol the connection is switching to.
Willy Tarreau816b9792009-09-15 21:25:21 +0200302
Willy Tarreauc57f0e22009-05-10 13:12:33 +0200303
3041.3.1. The Response line
305------------------------
306
307Line 1 is the "response line". It is always composed of 3 fields :
308
309 - a version tag : HTTP/1.1
310 - a status code : 200
311 - a reason : OK
312
313The status code is always 3-digit. The first digit indicates a general status :
Willy Tarreau816b9792009-09-15 21:25:21 +0200314 - 1xx = informational message to be skipped (eg: 100, 101)
Willy Tarreauc57f0e22009-05-10 13:12:33 +0200315 - 2xx = OK, content is following (eg: 200, 206)
316 - 3xx = OK, no content following (eg: 302, 304)
317 - 4xx = error caused by the client (eg: 401, 403, 404)
318 - 5xx = error caused by the server (eg: 500, 502, 503)
319
320Please refer to RFC2616 for the detailed meaning of all such codes. The
Willy Tarreaud72758d2010-01-12 10:42:19 +0100321"reason" field is just a hint, but is not parsed by clients. Anything can be
Willy Tarreauc57f0e22009-05-10 13:12:33 +0200322found there, but it's a common practice to respect the well-established
323messages. It can be composed of one or multiple words, such as "OK", "Found",
324or "Authentication Required".
325
326Haproxy may emit the following status codes by itself :
327
328 Code When / reason
329 200 access to stats page, and when replying to monitoring requests
330 301 when performing a redirection, depending on the configured code
331 302 when performing a redirection, depending on the configured code
332 303 when performing a redirection, depending on the configured code
Willy Tarreaub67fdc42013-03-29 19:28:11 +0100333 307 when performing a redirection, depending on the configured code
334 308 when performing a redirection, depending on the configured code
Willy Tarreauc57f0e22009-05-10 13:12:33 +0200335 400 for an invalid or too large request
336 401 when an authentication is required to perform the action (when
337 accessing the stats page)
338 403 when a request is forbidden by a "block" ACL or "reqdeny" filter
339 408 when the request timeout strikes before the request is complete
340 500 when haproxy encounters an unrecoverable internal error, such as a
341 memory allocation failure, which should never happen
342 502 when the server returns an empty, invalid or incomplete response, or
343 when an "rspdeny" filter blocks the response.
344 503 when no server was available to handle the request, or in response to
345 monitoring requests which match the "monitor fail" condition
346 504 when the response timeout strikes before the server responds
347
348The error 4xx and 5xx codes above may be customized (see "errorloc" in section
3494.2).
350
351
3521.3.2. The response headers
353---------------------------
354
355Response headers work exactly like request headers, and as such, HAProxy uses
356the same parsing function for both. Please refer to paragraph 1.2.2 for more
357details.
358
359
3602. Configuring HAProxy
361----------------------
362
3632.1. Configuration file format
364------------------------------
Willy Tarreau6a06a402007-07-15 20:15:28 +0200365
366HAProxy's configuration process involves 3 major sources of parameters :
367
368 - the arguments from the command-line, which always take precedence
369 - the "global" section, which sets process-wide parameters
370 - the proxies sections which can take form of "defaults", "listen",
371 "frontend" and "backend".
372
Willy Tarreau0ba27502007-12-24 16:55:16 +0100373The configuration file syntax consists in lines beginning with a keyword
374referenced in this manual, optionally followed by one or several parameters
William Lallemandf9873ba2015-05-05 17:37:14 +0200375delimited by spaces.
Willy Tarreau0ba27502007-12-24 16:55:16 +0100376
Willy Tarreauc57f0e22009-05-10 13:12:33 +0200377
William Lallemandf9873ba2015-05-05 17:37:14 +02003782.2. Quoting and escaping
379-------------------------
380
381HAProxy's configuration introduces a quoting and escaping system similar to
382many programming languages. The configuration file supports 3 types: escaping
383with a backslash, weak quoting with double quotes, and strong quoting with
384single quotes.
385
386If spaces have to be entered in strings, then they must be escaped by preceding
387them by a backslash ('\') or by quoting them. Backslashes also have to be
388escaped by doubling or strong quoting them.
389
390Escaping is achieved by preceding a special character by a backslash ('\'):
391
392 \ to mark a space and differentiate it from a delimiter
393 \# to mark a hash and differentiate it from a comment
394 \\ to use a backslash
395 \' to use a single quote and differentiate it from strong quoting
396 \" to use a double quote and differentiate it from weak quoting
397
398Weak quoting is achieved by using double quotes (""). Weak quoting prevents
399the interpretation of:
400
401 space as a parameter separator
402 ' single quote as a strong quoting delimiter
403 # hash as a comment start
404
William Lallemandb2f07452015-05-12 14:27:13 +0200405Weak quoting permits the interpretation of variables, if you want to use a non
406-interpreted dollar within a double quoted string, you should escape it with a
407backslash ("\$"), it does not work outside weak quoting.
408
409Interpretation of escaping and special characters are not prevented by weak
William Lallemandf9873ba2015-05-05 17:37:14 +0200410quoting.
411
412Strong quoting is achieved by using single quotes (''). Inside single quotes,
413nothing is interpreted, it's the efficient way to quote regexes.
414
415Quoted and escaped strings are replaced in memory by their interpreted
416equivalent, it allows you to perform concatenation.
417
418 Example:
419 # those are equivalents:
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 log-format "%{+Q}o %t"' %s'\ %{-Q}r
425
426 # those are equivalents:
427 reqrep "^([^\ :]*)\ /static/(.*)" \1\ /\2
428 reqrep "^([^ :]*)\ /static/(.*)" '\1 /\2'
429 reqrep "^([^ :]*)\ /static/(.*)" "\1 /\2"
430 reqrep "^([^ :]*)\ /static/(.*)" "\1\ /\2"
431
432
William Lallemandb2f07452015-05-12 14:27:13 +02004332.3. Environment variables
434--------------------------
435
436HAProxy's configuration supports environment variables. Those variables are
437interpreted only within double quotes. Variables are expanded during the
438configuration parsing. Variable names must be preceded by a dollar ("$") and
439optionally enclosed with braces ("{}") similarly to what is done in Bourne
440shell. Variable names can contain alphanumerical characters or the character
441underscore ("_") but should not start with a digit.
442
443 Example:
444
445 bind "fd@${FD_APP1}"
446
447 log "${LOCAL_SYSLOG}:514" local0 notice # send to local server
448
449 user "$HAPROXY_USER"
450
451
4522.4. Time format
Willy Tarreauc57f0e22009-05-10 13:12:33 +0200453----------------
454
Krzysztof Piotr Oledzkif8645332009-12-13 21:55:50 +0100455Some parameters involve values representing time, such as timeouts. These
Willy Tarreau0ba27502007-12-24 16:55:16 +0100456values are generally expressed in milliseconds (unless explicitly stated
457otherwise) but may be expressed in any other unit by suffixing the unit to the
458numeric value. It is important to consider this because it will not be repeated
459for every keyword. Supported units are :
460
461 - us : microseconds. 1 microsecond = 1/1000000 second
462 - ms : milliseconds. 1 millisecond = 1/1000 second. This is the default.
463 - s : seconds. 1s = 1000ms
464 - m : minutes. 1m = 60s = 60000ms
465 - h : hours. 1h = 60m = 3600s = 3600000ms
466 - d : days. 1d = 24h = 1440m = 86400s = 86400000ms
467
468
William Lallemandf9873ba2015-05-05 17:37:14 +02004692.4. Examples
Patrick Mezard35da19c2010-06-12 17:02:47 +0200470-------------
471
472 # Simple configuration for an HTTP proxy listening on port 80 on all
473 # interfaces and forwarding requests to a single backend "servers" with a
474 # single server "server1" listening on 127.0.0.1:8000
475 global
476 daemon
477 maxconn 256
478
479 defaults
480 mode http
481 timeout connect 5000ms
482 timeout client 50000ms
483 timeout server 50000ms
484
485 frontend http-in
486 bind *:80
487 default_backend servers
488
489 backend servers
490 server server1 127.0.0.1:8000 maxconn 32
491
492
493 # The same configuration defined with a single listen block. Shorter but
494 # less expressive, especially in HTTP mode.
495 global
496 daemon
497 maxconn 256
498
499 defaults
500 mode http
501 timeout connect 5000ms
502 timeout client 50000ms
503 timeout server 50000ms
504
505 listen http-in
506 bind *:80
507 server server1 127.0.0.1:8000 maxconn 32
508
509
510Assuming haproxy is in $PATH, test these configurations in a shell with:
511
Willy Tarreauccb289d2010-12-11 20:19:38 +0100512 $ sudo haproxy -f configuration.conf -c
Patrick Mezard35da19c2010-06-12 17:02:47 +0200513
514
Willy Tarreauc57f0e22009-05-10 13:12:33 +02005153. Global parameters
Willy Tarreau6a06a402007-07-15 20:15:28 +0200516--------------------
517
518Parameters in the "global" section are process-wide and often OS-specific. They
519are generally set once for all and do not need being changed once correct. Some
520of them have command-line equivalents.
521
522The following keywords are supported in the "global" section :
523
524 * Process management and security
Emeric Brunc8e8d122012-10-02 18:42:10 +0200525 - ca-base
Willy Tarreau6a06a402007-07-15 20:15:28 +0200526 - chroot
Emeric Brunc8e8d122012-10-02 18:42:10 +0200527 - crt-base
Willy Tarreau6a06a402007-07-15 20:15:28 +0200528 - daemon
Simon Horman98637e52014-06-20 12:30:16 +0900529 - external-check
Willy Tarreau6a06a402007-07-15 20:15:28 +0200530 - gid
531 - group
532 - log
Joe Williamsdf5b38f2010-12-29 17:05:48 +0100533 - log-send-hostname
Willy Tarreau6a06a402007-07-15 20:15:28 +0200534 - nbproc
535 - pidfile
536 - uid
537 - ulimit-n
538 - user
Willy Tarreaufbee7132007-10-18 13:53:22 +0200539 - stats
Emeric Brun850efd52014-01-29 12:24:34 +0100540 - ssl-server-verify
Krzysztof Piotr Oledzki48cb2ae2009-10-02 22:51:14 +0200541 - node
542 - description
Willy Tarreauceb24bc2010-11-09 12:46:41 +0100543 - unix-bind
Thomas Holmesdb04f192015-05-18 13:21:39 +0100544 - 51degrees-data-file
545 - 51degrees-property-name-list
Dragan Dosen93b38d92015-06-29 16:43:25 +0200546 - 51degrees-property-separator
Dragan Dosenae6d39a2015-06-29 16:43:27 +0200547 - 51degrees-cache-size
Willy Tarreaud72758d2010-01-12 10:42:19 +0100548
Willy Tarreau6a06a402007-07-15 20:15:28 +0200549 * Performance tuning
Willy Tarreau1746eec2014-04-25 10:46:47 +0200550 - max-spread-checks
Willy Tarreau6a06a402007-07-15 20:15:28 +0200551 - maxconn
Willy Tarreau81c25d02011-09-07 15:17:21 +0200552 - maxconnrate
William Lallemandd85f9172012-11-09 17:05:39 +0100553 - maxcomprate
William Lallemand072a2bf2012-11-20 17:01:01 +0100554 - maxcompcpuusage
Willy Tarreauff4f82d2009-02-06 11:28:13 +0100555 - maxpipes
Willy Tarreau93e7c002013-10-07 18:51:07 +0200556 - maxsessrate
Willy Tarreau403edff2012-09-06 11:58:37 +0200557 - maxsslconn
Willy Tarreaue43d5322013-10-07 20:01:52 +0200558 - maxsslrate
Willy Tarreau6a06a402007-07-15 20:15:28 +0200559 - noepoll
560 - nokqueue
561 - nopoll
Willy Tarreauff4f82d2009-02-06 11:28:13 +0100562 - nosplice
Jarno Huuskonen0e82b922014-04-12 18:22:19 +0300563 - nogetaddrinfo
Willy Tarreaufe255b72007-10-14 23:09:26 +0200564 - spread-checks
Baptiste Assmann5626f482015-08-23 10:00:10 +0200565 - server-state-base
Baptiste Assmannef1f0fc2015-08-23 10:06:39 +0200566 - server-state-file
Willy Tarreau27a674e2009-08-17 07:23:33 +0200567 - tune.bufsize
Willy Tarreau43961d52010-10-04 20:39:20 +0200568 - tune.chksize
William Lallemandf3747832012-11-09 12:33:10 +0100569 - tune.comp.maxlevel
Willy Tarreau193b8c62012-11-22 00:17:38 +0100570 - tune.http.cookielen
Willy Tarreauac1932d2011-10-24 19:14:41 +0200571 - tune.http.maxhdr
Willy Tarreau7e312732014-02-12 16:35:14 +0100572 - tune.idletimer
Thierry FOURNIER90da1912015-03-05 11:17:06 +0100573 - tune.lua.forced-yield
Willy Tarreau32f61e22015-03-18 17:54:59 +0100574 - tune.lua.maxmem
Thierry FOURNIER90da1912015-03-05 11:17:06 +0100575 - tune.lua.session-timeout
576 - tune.lua.task-timeout
Willy Tarreaua0250ba2008-01-06 11:22:57 +0100577 - tune.maxaccept
578 - tune.maxpollevents
Willy Tarreau27a674e2009-08-17 07:23:33 +0200579 - tune.maxrewrite
Willy Tarreauf3045d22015-04-29 16:24:50 +0200580 - tune.pattern.cache-size
Willy Tarreaubd9a0a72011-10-23 21:14:29 +0200581 - tune.pipesize
Willy Tarreaue803de22010-01-21 17:43:04 +0100582 - tune.rcvbuf.client
583 - tune.rcvbuf.server
584 - tune.sndbuf.client
585 - tune.sndbuf.server
Willy Tarreau6ec58db2012-11-16 16:32:15 +0100586 - tune.ssl.cachesize
Willy Tarreaubfd59462013-02-21 07:46:09 +0100587 - tune.ssl.lifetime
Emeric Brun8dc60392014-05-09 13:52:00 +0200588 - tune.ssl.force-private-cache
Willy Tarreaubfd59462013-02-21 07:46:09 +0100589 - tune.ssl.maxrecord
Remi Gacognef46cd6e2014-06-12 14:58:40 +0200590 - tune.ssl.default-dh-param
Christopher Faulet31af49d2015-06-09 17:29:50 +0200591 - tune.ssl.ssl-ctx-cache-size
Thierry FOURNIER4834bc72015-06-06 19:29:07 +0200592 - tune.vars.global-max-size
593 - tune.vars.reqres-max-size
594 - tune.vars.sess-max-size
595 - tune.vars.txn-max-size
William Lallemanda509e4c2012-11-07 16:54:34 +0100596 - tune.zlib.memlevel
597 - tune.zlib.windowsize
Willy Tarreaud72758d2010-01-12 10:42:19 +0100598
Willy Tarreau6a06a402007-07-15 20:15:28 +0200599 * Debugging
600 - debug
601 - quiet
Willy Tarreau6a06a402007-07-15 20:15:28 +0200602
603
Willy Tarreauc57f0e22009-05-10 13:12:33 +02006043.1. Process management and security
Willy Tarreau6a06a402007-07-15 20:15:28 +0200605------------------------------------
606
Emeric Brunc8e8d122012-10-02 18:42:10 +0200607ca-base <dir>
608 Assigns a default directory to fetch SSL CA certificates and CRLs from when a
Emeric Brunfd33a262012-10-11 16:28:27 +0200609 relative path is used with "ca-file" or "crl-file" directives. Absolute
610 locations specified in "ca-file" and "crl-file" prevail and ignore "ca-base".
Emeric Brunc8e8d122012-10-02 18:42:10 +0200611
Willy Tarreau6a06a402007-07-15 20:15:28 +0200612chroot <jail dir>
613 Changes current directory to <jail dir> and performs a chroot() there before
614 dropping privileges. This increases the security level in case an unknown
615 vulnerability would be exploited, since it would make it very hard for the
616 attacker to exploit the system. This only works when the process is started
617 with superuser privileges. It is important to ensure that <jail_dir> is both
618 empty and unwritable to anyone.
Willy Tarreaud72758d2010-01-12 10:42:19 +0100619
Willy Tarreaufc6c0322012-11-16 16:12:27 +0100620cpu-map <"all"|"odd"|"even"|process_num> <cpu-set>...
621 On Linux 2.6 and above, it is possible to bind a process to a specific CPU
622 set. This means that the process will never run on other CPUs. The "cpu-map"
623 directive specifies CPU sets for process sets. The first argument is the
Willy Tarreaua9db57e2013-01-18 11:29:29 +0100624 process number to bind. This process must have a number between 1 and 32 or
625 64, depending on the machine's word size, and any process IDs above nbproc
626 are ignored. It is possible to specify all processes at once using "all",
627 only odd numbers using "odd" or even numbers using "even", just like with the
628 "bind-process" directive. The second and forthcoming arguments are CPU sets.
629 Each CPU set is either a unique number between 0 and 31 or 63 or a range with
630 two such numbers delimited by a dash ('-'). Multiple CPU numbers or ranges
631 may be specified, and the processes will be allowed to bind to all of them.
632 Obviously, multiple "cpu-map" directives may be specified. Each "cpu-map"
633 directive will replace the previous ones when they overlap.
Willy Tarreaufc6c0322012-11-16 16:12:27 +0100634
Emeric Brunc8e8d122012-10-02 18:42:10 +0200635crt-base <dir>
636 Assigns a default directory to fetch SSL certificates from when a relative
637 path is used with "crtfile" directives. Absolute locations specified after
638 "crtfile" prevail and ignore "crt-base".
639
Willy Tarreau6a06a402007-07-15 20:15:28 +0200640daemon
641 Makes the process fork into background. This is the recommended mode of
642 operation. It is equivalent to the command line "-D" argument. It can be
643 disabled by the command line "-db" argument.
644
David Carlier8167f302015-06-01 13:50:06 +0200645deviceatlas-json-file <path>
646 Sets the path of the DeviceAtlas JSON data file to be loaded by the API.
647 The path must be a valid JSON data file and accessible by Haproxy process.
648
649deviceatlas-log-level <value>
650 Sets the level of informations returned by the API. This directive is
651 optional and set to 0 by default if not set.
652
653deviceatlas-separator <char>
654 Sets the character separator for the API properties results. This directive
655 is optional and set to | by default if not set.
656
David Carlier29b3ca32015-09-25 14:09:21 +0100657devicatlas-properties-cookie <name>
Cyril Bonté307ee1e2015-09-28 23:16:06 +0200658 Sets the client cookie's name used for the detection if the DeviceAtlas
659 Client-side component was used during the request. This directive is optional
660 and set to DAPROPS by default if not set.
David Carlier29b3ca32015-09-25 14:09:21 +0100661
Simon Horman98637e52014-06-20 12:30:16 +0900662external-check
663 Allows the use of an external agent to perform health checks.
664 This is disabled by default as a security precaution.
665 See "option external-check".
666
Willy Tarreau6a06a402007-07-15 20:15:28 +0200667gid <number>
668 Changes the process' group ID to <number>. It is recommended that the group
669 ID is dedicated to HAProxy or to a small set of similar daemons. HAProxy must
670 be started with a user belonging to this group, or with superuser privileges.
Michael Schererab012dd2013-01-12 18:35:19 +0100671 Note that if haproxy is started from a user having supplementary groups, it
672 will only be able to drop these groups if started with superuser privileges.
Willy Tarreau6a06a402007-07-15 20:15:28 +0200673 See also "group" and "uid".
Willy Tarreaud72758d2010-01-12 10:42:19 +0100674
Willy Tarreau6a06a402007-07-15 20:15:28 +0200675group <group name>
676 Similar to "gid" but uses the GID of group name <group name> from /etc/group.
677 See also "gid" and "user".
Willy Tarreaud72758d2010-01-12 10:42:19 +0100678
Dragan Dosen7ad31542015-09-28 17:16:47 +0200679log <address> [len <length>] [format <format>] <facility> [max level [min level]]
Willy Tarreau6a06a402007-07-15 20:15:28 +0200680 Adds a global syslog server. Up to two global servers can be defined. They
681 will receive logs for startups and exits, as well as all logs from proxies
Robert Tsai81ae1952007-12-05 10:47:29 +0100682 configured with "log global".
683
684 <address> can be one of:
685
Willy Tarreau2769aa02007-12-27 18:26:09 +0100686 - An IPv4 address optionally followed by a colon and a UDP port. If
Robert Tsai81ae1952007-12-05 10:47:29 +0100687 no port is specified, 514 is used by default (the standard syslog
688 port).
689
David du Colombier24bb5f52011-03-17 10:40:23 +0100690 - An IPv6 address followed by a colon and optionally a UDP port. If
691 no port is specified, 514 is used by default (the standard syslog
692 port).
693
Robert Tsai81ae1952007-12-05 10:47:29 +0100694 - A filesystem path to a UNIX domain socket, keeping in mind
695 considerations for chroot (be sure the path is accessible inside
696 the chroot) and uid/gid (be sure the path is appropriately
697 writeable).
698
William Lallemandb2f07452015-05-12 14:27:13 +0200699 You may want to reference some environment variables in the address
700 parameter, see section 2.3 about environment variables.
Willy Tarreaudad36a32013-03-11 01:20:04 +0100701
Willy Tarreau18324f52014-06-27 18:10:07 +0200702 <length> is an optional maximum line length. Log lines larger than this value
703 will be truncated before being sent. The reason is that syslog
704 servers act differently on log line length. All servers support the
705 default value of 1024, but some servers simply drop larger lines
706 while others do log them. If a server supports long lines, it may
707 make sense to set this value here in order to avoid truncating long
708 lines. Similarly, if a server drops long lines, it is preferable to
709 truncate them before sending them. Accepted values are 80 to 65535
710 inclusive. The default value of 1024 is generally fine for all
711 standard usages. Some specific cases of long captures or
712 JSON-formated logs may require larger values.
713
Dragan Dosen7ad31542015-09-28 17:16:47 +0200714 <format> is the log format used when generating syslog messages. It may be
715 one of the following :
716
717 rfc3164 The RFC3164 syslog message format. This is the default.
718 (https://tools.ietf.org/html/rfc3164)
719
720 rfc5424 The RFC5424 syslog message format.
721 (https://tools.ietf.org/html/rfc5424)
722
Robert Tsai81ae1952007-12-05 10:47:29 +0100723 <facility> must be one of the 24 standard syslog facilities :
Willy Tarreau6a06a402007-07-15 20:15:28 +0200724
725 kern user mail daemon auth syslog lpr news
726 uucp cron auth2 ftp ntp audit alert cron2
727 local0 local1 local2 local3 local4 local5 local6 local7
728
729 An optional level can be specified to filter outgoing messages. By default,
Willy Tarreauf7edefa2009-05-10 17:20:05 +0200730 all messages are sent. If a maximum level is specified, only messages with a
731 severity at least as important as this level will be sent. An optional minimum
732 level can be specified. If it is set, logs emitted with a more severe level
733 than this one will be capped to this level. This is used to avoid sending
734 "emerg" messages on all terminals on some default syslog configurations.
735 Eight levels are known :
Willy Tarreau6a06a402007-07-15 20:15:28 +0200736
Cyril Bontédc4d9032012-04-08 21:57:39 +0200737 emerg alert crit err warning notice info debug
Willy Tarreau6a06a402007-07-15 20:15:28 +0200738
Joe Williamsdf5b38f2010-12-29 17:05:48 +0100739log-send-hostname [<string>]
740 Sets the hostname field in the syslog header. If optional "string" parameter
741 is set the header is set to the string contents, otherwise uses the hostname
742 of the system. Generally used if one is not relaying logs through an
743 intermediate syslog server or for simply customizing the hostname printed in
744 the logs.
745
Kevinm48936af2010-12-22 16:08:21 +0000746log-tag <string>
747 Sets the tag field in the syslog header to this string. It defaults to the
748 program name as launched from the command line, which usually is "haproxy".
749 Sometimes it can be useful to differentiate between multiple processes
Willy Tarreau094af4e2015-01-07 15:03:42 +0100750 running on the same host. See also the per-proxy "log-tag" directive.
Kevinm48936af2010-12-22 16:08:21 +0000751
Thierry FOURNIER90da1912015-03-05 11:17:06 +0100752lua-load <file>
753 This global directive loads and executes a Lua file. This directive can be
754 used multiple times.
755
Willy Tarreau6a06a402007-07-15 20:15:28 +0200756nbproc <number>
757 Creates <number> processes when going daemon. This requires the "daemon"
758 mode. By default, only one process is created, which is the recommended mode
759 of operation. For systems limited to small sets of file descriptors per
760 process, it may be needed to fork multiple daemons. USING MULTIPLE PROCESSES
761 IS HARDER TO DEBUG AND IS REALLY DISCOURAGED. See also "daemon".
762
763pidfile <pidfile>
764 Writes pids of all daemons into file <pidfile>. This option is equivalent to
765 the "-p" command line argument. The file must be accessible to the user
766 starting the process. See also "daemon".
767
Willy Tarreaua9db57e2013-01-18 11:29:29 +0100768stats bind-process [ all | odd | even | <number 1-64>[-<number 1-64>] ] ...
Willy Tarreau35b7b162012-10-22 23:17:18 +0200769 Limits the stats socket to a certain set of processes numbers. By default the
770 stats socket is bound to all processes, causing a warning to be emitted when
771 nbproc is greater than 1 because there is no way to select the target process
772 when connecting. However, by using this setting, it becomes possible to pin
773 the stats socket to a specific set of processes, typically the first one. The
774 warning will automatically be disabled when this setting is used, whatever
Willy Tarreaua9db57e2013-01-18 11:29:29 +0100775 the number of processes used. The maximum process ID depends on the machine's
Willy Tarreauae302532014-05-07 19:22:24 +0200776 word size (32 or 64). A better option consists in using the "process" setting
777 of the "stats socket" line to force the process on each line.
Willy Tarreau35b7b162012-10-22 23:17:18 +0200778
Baptiste Assmann5626f482015-08-23 10:00:10 +0200779server-state-base <directory>
780 Specifies the directory prefix to be prepended in front of all servers state
Baptiste Assmann01c6cc32015-08-23 11:45:29 +0200781 file names which do not start with a '/'. See also "server-state-file",
782 "load-server-state-from-file" and "server-state-file-name".
Baptiste Assmannef1f0fc2015-08-23 10:06:39 +0200783
784server-state-file <file>
785 Specifies the path to the file containing state of servers. If the path starts
786 with a slash ('/'), it is considered absolute, otherwise it is considered
787 relative to the directory specified using "server-state-base" (if set) or to
788 the current directory. Before reloading HAProxy, it is possible to save the
789 servers' current state using the stats command "show servers state". The
790 output of this command must be written in the file pointed by <file>. When
791 starting up, before handling traffic, HAProxy will read, load and apply state
792 for each server found in the file and available in its current running
Baptiste Assmann01c6cc32015-08-23 11:45:29 +0200793 configuration. See also "server-state-base" and "show servers state",
794 "load-server-state-from-file" and "server-state-file-name"
Baptiste Assmann5626f482015-08-23 10:00:10 +0200795
Willy Tarreau610f04b2014-02-13 11:36:41 +0100796ssl-default-bind-ciphers <ciphers>
797 This setting is only available when support for OpenSSL was built in. It sets
798 the default string describing the list of cipher algorithms ("cipher suite")
Jarno Huuskonen0e82b922014-04-12 18:22:19 +0300799 that are negotiated during the SSL/TLS handshake for all "bind" lines which
Willy Tarreau610f04b2014-02-13 11:36:41 +0100800 do not explicitly define theirs. The format of the string is defined in
801 "man 1 ciphers" from OpenSSL man pages, and can be for instance a string such
802 as "AES:ALL:!aNULL:!eNULL:+RC4:@STRENGTH" (without quotes). Please check the
803 "bind" keyword for more information.
804
Emeric Brun2c86cbf2014-10-30 15:56:50 +0100805ssl-default-bind-options [<option>]...
806 This setting is only available when support for OpenSSL was built in. It sets
807 default ssl-options to force on all "bind" lines. Please check the "bind"
808 keyword to see available options.
809
810 Example:
811 global
812 ssl-default-bind-options no-sslv3 no-tls-tickets
813
Willy Tarreau610f04b2014-02-13 11:36:41 +0100814ssl-default-server-ciphers <ciphers>
815 This setting is only available when support for OpenSSL was built in. It
816 sets the default string describing the list of cipher algorithms that are
Jarno Huuskonen0e82b922014-04-12 18:22:19 +0300817 negotiated during the SSL/TLS handshake with the server, for all "server"
Willy Tarreau610f04b2014-02-13 11:36:41 +0100818 lines which do not explicitly define theirs. The format of the string is
819 defined in "man 1 ciphers". Please check the "server" keyword for more
820 information.
821
Emeric Brun2c86cbf2014-10-30 15:56:50 +0100822ssl-default-server-options [<option>]...
823 This setting is only available when support for OpenSSL was built in. It sets
824 default ssl-options to force on all "server" lines. Please check the "server"
825 keyword to see available options.
826
Remi Gacogne47783ef2015-05-29 15:53:22 +0200827ssl-dh-param-file <file>
828 This setting is only available when support for OpenSSL was built in. It sets
829 the default DH parameters that are used during the SSL/TLS handshake when
830 ephemeral Diffie-Hellman (DHE) key exchange is used, for all "bind" lines
831 which do not explicitely define theirs. It will be overridden by custom DH
832 parameters found in a bind certificate file if any. If custom DH parameters
Cyril Bonté307ee1e2015-09-28 23:16:06 +0200833 are not specified either by using ssl-dh-param-file or by setting them
834 directly in the certificate file, pre-generated DH parameters of the size
835 specified by tune.ssl.default-dh-param will be used. Custom parameters are
836 known to be more secure and therefore their use is recommended.
Remi Gacogne47783ef2015-05-29 15:53:22 +0200837 Custom DH parameters may be generated by using the OpenSSL command
838 "openssl dhparam <size>", where size should be at least 2048, as 1024-bit DH
839 parameters should not be considered secure anymore.
840
Emeric Brun850efd52014-01-29 12:24:34 +0100841ssl-server-verify [none|required]
842 The default behavior for SSL verify on servers side. If specified to 'none',
843 servers certificates are not verified. The default is 'required' except if
844 forced using cmdline option '-dV'.
845
Willy Tarreauabb175f2012-09-24 12:43:26 +0200846stats socket [<address:port>|<path>] [param*]
847 Binds a UNIX socket to <path> or a TCPv4/v6 address to <address:port>.
848 Connections to this socket will return various statistics outputs and even
849 allow some commands to be issued to change some runtime settings. Please
850 consult section 9.2 "Unix Socket commands" for more details.
Willy Tarreau6162db22009-10-10 17:13:00 +0200851
Willy Tarreauabb175f2012-09-24 12:43:26 +0200852 All parameters supported by "bind" lines are supported, for instance to
853 restrict access to some users or their access rights. Please consult
854 section 5.1 for more information.
Willy Tarreaufbee7132007-10-18 13:53:22 +0200855
856stats timeout <timeout, in milliseconds>
857 The default timeout on the stats socket is set to 10 seconds. It is possible
858 to change this value with "stats timeout". The value must be passed in
Willy Tarreaubefdff12007-12-02 22:27:38 +0100859 milliseconds, or be suffixed by a time unit among { us, ms, s, m, h, d }.
Willy Tarreaufbee7132007-10-18 13:53:22 +0200860
861stats maxconn <connections>
862 By default, the stats socket is limited to 10 concurrent connections. It is
863 possible to change this value with "stats maxconn".
864
Willy Tarreau6a06a402007-07-15 20:15:28 +0200865uid <number>
866 Changes the process' user ID to <number>. It is recommended that the user ID
867 is dedicated to HAProxy or to a small set of similar daemons. HAProxy must
868 be started with superuser privileges in order to be able to switch to another
869 one. See also "gid" and "user".
870
871ulimit-n <number>
872 Sets the maximum number of per-process file-descriptors to <number>. By
873 default, it is automatically computed, so it is recommended not to use this
874 option.
875
Willy Tarreauceb24bc2010-11-09 12:46:41 +0100876unix-bind [ prefix <prefix> ] [ mode <mode> ] [ user <user> ] [ uid <uid> ]
877 [ group <group> ] [ gid <gid> ]
878
879 Fixes common settings to UNIX listening sockets declared in "bind" statements.
880 This is mainly used to simplify declaration of those UNIX sockets and reduce
881 the risk of errors, since those settings are most commonly required but are
882 also process-specific. The <prefix> setting can be used to force all socket
883 path to be relative to that directory. This might be needed to access another
884 component's chroot. Note that those paths are resolved before haproxy chroots
885 itself, so they are absolute. The <mode>, <user>, <uid>, <group> and <gid>
886 all have the same meaning as their homonyms used by the "bind" statement. If
887 both are specified, the "bind" statement has priority, meaning that the
888 "unix-bind" settings may be seen as process-wide default settings.
889
Willy Tarreau6a06a402007-07-15 20:15:28 +0200890user <user name>
891 Similar to "uid" but uses the UID of user name <user name> from /etc/passwd.
892 See also "uid" and "group".
893
Krzysztof Piotr Oledzki48cb2ae2009-10-02 22:51:14 +0200894node <name>
895 Only letters, digits, hyphen and underscore are allowed, like in DNS names.
896
897 This statement is useful in HA configurations where two or more processes or
898 servers share the same IP address. By setting a different node-name on all
899 nodes, it becomes easy to immediately spot what server is handling the
900 traffic.
901
902description <text>
903 Add a text that describes the instance.
904
905 Please note that it is required to escape certain characters (# for example)
906 and this text is inserted into a html page so you should avoid using
907 "<" and ">" characters.
908
Thomas Holmesdb04f192015-05-18 13:21:39 +010090951degrees-data-file <file path>
910 The path of the 51Degrees data file to provide device detection services. The
911 file should be unzipped and accessible by HAProxy with relevavnt permissions.
912
Dragan Dosenae6d39a2015-06-29 16:43:27 +0200913 Please note that this option is only available when haproxy has been
Thomas Holmesdb04f192015-05-18 13:21:39 +0100914 compiled with USE_51DEGREES.
915
91651degrees-property-name-list [<string>]
917 A list of 51Degrees property names to be load from the dataset. A full list
918 of names is available on the 51Degrees website:
919 https://51degrees.com/resources/property-dictionary
920
Dragan Dosenae6d39a2015-06-29 16:43:27 +0200921 Please note that this option is only available when haproxy has been
Thomas Holmesdb04f192015-05-18 13:21:39 +0100922 compiled with USE_51DEGREES.
923
Dragan Dosen93b38d92015-06-29 16:43:25 +020092451degrees-property-separator <char>
Thomas Holmesdb04f192015-05-18 13:21:39 +0100925 A char that will be appended to every property value in a response header
926 containing 51Degrees results. If not set that will be set as ','.
927
Dragan Dosenae6d39a2015-06-29 16:43:27 +0200928 Please note that this option is only available when haproxy has been
929 compiled with USE_51DEGREES.
930
93151degrees-cache-size <number>
932 Sets the size of the 51Degrees converter cache to <number> entries. This
933 is an LRU cache which reminds previous device detections and their results.
934 By default, this cache is disabled.
935
936 Please note that this option is only available when haproxy has been
Thomas Holmesdb04f192015-05-18 13:21:39 +0100937 compiled with USE_51DEGREES.
938
Willy Tarreau6a06a402007-07-15 20:15:28 +0200939
Willy Tarreauc57f0e22009-05-10 13:12:33 +02009403.2. Performance tuning
Willy Tarreau6a06a402007-07-15 20:15:28 +0200941-----------------------
942
Willy Tarreau1746eec2014-04-25 10:46:47 +0200943max-spread-checks <delay in milliseconds>
944 By default, haproxy tries to spread the start of health checks across the
945 smallest health check interval of all the servers in a farm. The principle is
946 to avoid hammering services running on the same server. But when using large
947 check intervals (10 seconds or more), the last servers in the farm take some
948 time before starting to be tested, which can be a problem. This parameter is
949 used to enforce an upper bound on delay between the first and the last check,
950 even if the servers' check intervals are larger. When servers run with
951 shorter intervals, their intervals will be respected though.
952
Willy Tarreau6a06a402007-07-15 20:15:28 +0200953maxconn <number>
954 Sets the maximum per-process number of concurrent connections to <number>. It
955 is equivalent to the command-line argument "-n". Proxies will stop accepting
956 connections when this limit is reached. The "ulimit-n" parameter is
Willy Tarreau8274e102014-06-19 15:31:25 +0200957 automatically adjusted according to this value. See also "ulimit-n". Note:
958 the "select" poller cannot reliably use more than 1024 file descriptors on
959 some platforms. If your platform only supports select and reports "select
960 FAILED" on startup, you need to reduce maxconn until it works (slightly
Willy Tarreaud0256482015-01-15 21:45:22 +0100961 below 500 in general). If this value is not set, it will default to the value
962 set in DEFAULT_MAXCONN at build time (reported in haproxy -vv) if no memory
963 limit is enforced, or will be computed based on the memory limit, the buffer
964 size, memory allocated to compression, SSL cache size, and use or not of SSL
965 and the associated maxsslconn (which can also be automatic).
Willy Tarreau6a06a402007-07-15 20:15:28 +0200966
Willy Tarreau81c25d02011-09-07 15:17:21 +0200967maxconnrate <number>
968 Sets the maximum per-process number of connections per second to <number>.
969 Proxies will stop accepting connections when this limit is reached. It can be
970 used to limit the global capacity regardless of each frontend capacity. It is
971 important to note that this can only be used as a service protection measure,
972 as there will not necessarily be a fair share between frontends when the
973 limit is reached, so it's a good idea to also limit each frontend to some
974 value close to its expected share. Also, lowering tune.maxaccept can improve
975 fairness.
976
William Lallemandd85f9172012-11-09 17:05:39 +0100977maxcomprate <number>
978 Sets the maximum per-process input compression rate to <number> kilobytes
Jarno Huuskonen0e82b922014-04-12 18:22:19 +0300979 per second. For each session, if the maximum is reached, the compression
William Lallemandd85f9172012-11-09 17:05:39 +0100980 level will be decreased during the session. If the maximum is reached at the
981 beginning of a session, the session will not compress at all. If the maximum
982 is not reached, the compression level will be increased up to
983 tune.comp.maxlevel. A value of zero means there is no limit, this is the
984 default value.
985
William Lallemand072a2bf2012-11-20 17:01:01 +0100986maxcompcpuusage <number>
987 Sets the maximum CPU usage HAProxy can reach before stopping the compression
988 for new requests or decreasing the compression level of current requests.
989 It works like 'maxcomprate' but measures CPU usage instead of incoming data
990 bandwidth. The value is expressed in percent of the CPU used by haproxy. In
991 case of multiple processes (nbproc > 1), each process manages its individual
992 usage. A value of 100 disable the limit. The default value is 100. Setting
993 a lower value will prevent the compression work from slowing the whole
994 process down and from introducing high latencies.
995
Willy Tarreauff4f82d2009-02-06 11:28:13 +0100996maxpipes <number>
997 Sets the maximum per-process number of pipes to <number>. Currently, pipes
998 are only used by kernel-based tcp splicing. Since a pipe contains two file
999 descriptors, the "ulimit-n" value will be increased accordingly. The default
1000 value is maxconn/4, which seems to be more than enough for most heavy usages.
1001 The splice code dynamically allocates and releases pipes, and can fall back
1002 to standard copy, so setting this value too low may only impact performance.
1003
Willy Tarreau93e7c002013-10-07 18:51:07 +02001004maxsessrate <number>
1005 Sets the maximum per-process number of sessions per second to <number>.
1006 Proxies will stop accepting connections when this limit is reached. It can be
1007 used to limit the global capacity regardless of each frontend capacity. It is
1008 important to note that this can only be used as a service protection measure,
1009 as there will not necessarily be a fair share between frontends when the
1010 limit is reached, so it's a good idea to also limit each frontend to some
1011 value close to its expected share. Also, lowering tune.maxaccept can improve
1012 fairness.
1013
Willy Tarreau403edff2012-09-06 11:58:37 +02001014maxsslconn <number>
1015 Sets the maximum per-process number of concurrent SSL connections to
1016 <number>. By default there is no SSL-specific limit, which means that the
1017 global maxconn setting will apply to all connections. Setting this limit
1018 avoids having openssl use too much memory and crash when malloc returns NULL
1019 (since it unfortunately does not reliably check for such conditions). Note
1020 that the limit applies both to incoming and outgoing connections, so one
1021 connection which is deciphered then ciphered accounts for 2 SSL connections.
Willy Tarreaud0256482015-01-15 21:45:22 +01001022 If this value is not set, but a memory limit is enforced, this value will be
1023 automatically computed based on the memory limit, maxconn, the buffer size,
1024 memory allocated to compression, SSL cache size, and use of SSL in either
1025 frontends, backends or both. If neither maxconn nor maxsslconn are specified
1026 when there is a memory limit, haproxy will automatically adjust these values
1027 so that 100% of the connections can be made over SSL with no risk, and will
1028 consider the sides where it is enabled (frontend, backend, both).
Willy Tarreau403edff2012-09-06 11:58:37 +02001029
Willy Tarreaue43d5322013-10-07 20:01:52 +02001030maxsslrate <number>
1031 Sets the maximum per-process number of SSL sessions per second to <number>.
1032 SSL listeners will stop accepting connections when this limit is reached. It
1033 can be used to limit the global SSL CPU usage regardless of each frontend
1034 capacity. It is important to note that this can only be used as a service
1035 protection measure, as there will not necessarily be a fair share between
1036 frontends when the limit is reached, so it's a good idea to also limit each
1037 frontend to some value close to its expected share. It is also important to
1038 note that the sessions are accounted before they enter the SSL stack and not
1039 after, which also protects the stack against bad handshakes. Also, lowering
1040 tune.maxaccept can improve fairness.
1041
William Lallemand9d5f5482012-11-07 16:12:57 +01001042maxzlibmem <number>
1043 Sets the maximum amount of RAM in megabytes per process usable by the zlib.
1044 When the maximum amount is reached, future sessions will not compress as long
1045 as RAM is unavailable. When sets to 0, there is no limit.
William Lallemande3a7d992012-11-20 11:25:20 +01001046 The default value is 0. The value is available in bytes on the UNIX socket
1047 with "show info" on the line "MaxZlibMemUsage", the memory used by zlib is
1048 "ZlibMemUsage" in bytes.
1049
Willy Tarreau6a06a402007-07-15 20:15:28 +02001050noepoll
1051 Disables the use of the "epoll" event polling system on Linux. It is
1052 equivalent to the command-line argument "-de". The next polling system
Willy Tarreaue9f49e72012-11-11 17:42:00 +01001053 used will generally be "poll". See also "nopoll".
Willy Tarreau6a06a402007-07-15 20:15:28 +02001054
1055nokqueue
1056 Disables the use of the "kqueue" event polling system on BSD. It is
1057 equivalent to the command-line argument "-dk". The next polling system
1058 used will generally be "poll". See also "nopoll".
1059
1060nopoll
1061 Disables the use of the "poll" event polling system. It is equivalent to the
1062 command-line argument "-dp". The next polling system used will be "select".
Willy Tarreau0ba27502007-12-24 16:55:16 +01001063 It should never be needed to disable "poll" since it's available on all
Willy Tarreaue9f49e72012-11-11 17:42:00 +01001064 platforms supported by HAProxy. See also "nokqueue" and "noepoll".
Willy Tarreau6a06a402007-07-15 20:15:28 +02001065
Willy Tarreauff4f82d2009-02-06 11:28:13 +01001066nosplice
1067 Disables the use of kernel tcp splicing between sockets on Linux. It is
1068 equivalent to the command line argument "-dS". Data will then be copied
1069 using conventional and more portable recv/send calls. Kernel tcp splicing is
Krzysztof Piotr Oledzkif8645332009-12-13 21:55:50 +01001070 limited to some very recent instances of kernel 2.6. Most versions between
Willy Tarreauff4f82d2009-02-06 11:28:13 +01001071 2.6.25 and 2.6.28 are buggy and will forward corrupted data, so they must not
1072 be used. This option makes it easier to globally disable kernel splicing in
1073 case of doubt. See also "option splice-auto", "option splice-request" and
1074 "option splice-response".
1075
Jarno Huuskonen0e82b922014-04-12 18:22:19 +03001076nogetaddrinfo
1077 Disables the use of getaddrinfo(3) for name resolving. It is equivalent to
1078 the command line argument "-dG". Deprecated gethostbyname(3) will be used.
1079
Willy Tarreaufe255b72007-10-14 23:09:26 +02001080spread-checks <0..50, in percent>
Simon Hormand60d6912013-11-25 10:46:36 +09001081 Sometimes it is desirable to avoid sending agent and health checks to
1082 servers at exact intervals, for instance when many logical servers are
1083 located on the same physical server. With the help of this parameter, it
1084 becomes possible to add some randomness in the check interval between 0
1085 and +/- 50%. A value between 2 and 5 seems to show good results. The
1086 default value remains at 0.
Willy Tarreaufe255b72007-10-14 23:09:26 +02001087
Willy Tarreau33cb0652014-12-23 22:52:37 +01001088tune.buffers.limit <number>
1089 Sets a hard limit on the number of buffers which may be allocated per process.
1090 The default value is zero which means unlimited. The minimum non-zero value
1091 will always be greater than "tune.buffers.reserve" and should ideally always
1092 be about twice as large. Forcing this value can be particularly useful to
1093 limit the amount of memory a process may take, while retaining a sane
1094 behaviour. When this limit is reached, sessions which need a buffer wait for
1095 another one to be released by another session. Since buffers are dynamically
1096 allocated and released, the waiting time is very short and not perceptible
1097 provided that limits remain reasonable. In fact sometimes reducing the limit
1098 may even increase performance by increasing the CPU cache's efficiency. Tests
1099 have shown good results on average HTTP traffic with a limit to 1/10 of the
1100 expected global maxconn setting, which also significantly reduces memory
1101 usage. The memory savings come from the fact that a number of connections
1102 will not allocate 2*tune.bufsize. It is best not to touch this value unless
1103 advised to do so by an haproxy core developer.
1104
Willy Tarreau1058ae72014-12-23 22:40:40 +01001105tune.buffers.reserve <number>
1106 Sets the number of buffers which are pre-allocated and reserved for use only
1107 during memory shortage conditions resulting in failed memory allocations. The
1108 minimum value is 2 and is also the default. There is no reason a user would
1109 want to change this value, it's mostly aimed at haproxy core developers.
1110
Willy Tarreau27a674e2009-08-17 07:23:33 +02001111tune.bufsize <number>
1112 Sets the buffer size to this size (in bytes). Lower values allow more
1113 sessions to coexist in the same amount of RAM, and higher values allow some
1114 applications with very large cookies to work. The default value is 16384 and
1115 can be changed at build time. It is strongly recommended not to change this
1116 from the default value, as very low values will break some services such as
1117 statistics, and values larger than default size will increase memory usage,
1118 possibly causing the system to run out of memory. At least the global maxconn
1119 parameter should be decreased by the same factor as this one is increased.
Dmitry Sivachenkof6f4f7b2012-10-21 18:10:25 +04001120 If HTTP request is larger than (tune.bufsize - tune.maxrewrite), haproxy will
1121 return HTTP 400 (Bad Request) error. Similarly if an HTTP response is larger
1122 than this size, haproxy will return HTTP 502 (Bad Gateway).
Willy Tarreau27a674e2009-08-17 07:23:33 +02001123
Willy Tarreau43961d52010-10-04 20:39:20 +02001124tune.chksize <number>
1125 Sets the check buffer size to this size (in bytes). Higher values may help
1126 find string or regex patterns in very large pages, though doing so may imply
1127 more memory and CPU usage. The default value is 16384 and can be changed at
1128 build time. It is not recommended to change this value, but to use better
1129 checks whenever possible.
1130
William Lallemandf3747832012-11-09 12:33:10 +01001131tune.comp.maxlevel <number>
1132 Sets the maximum compression level. The compression level affects CPU
1133 usage during compression. This value affects CPU usage during compression.
1134 Each session using compression initializes the compression algorithm with
1135 this value. The default value is 1.
1136
Willy Tarreau193b8c62012-11-22 00:17:38 +01001137tune.http.cookielen <number>
1138 Sets the maximum length of captured cookies. This is the maximum value that
1139 the "capture cookie xxx len yyy" will be allowed to take, and any upper value
1140 will automatically be truncated to this one. It is important not to set too
1141 high a value because all cookie captures still allocate this size whatever
1142 their configured value (they share a same pool). This value is per request
1143 per response, so the memory allocated is twice this value per connection.
1144 When not specified, the limit is set to 63 characters. It is recommended not
1145 to change this value.
1146
Willy Tarreauac1932d2011-10-24 19:14:41 +02001147tune.http.maxhdr <number>
1148 Sets the maximum number of headers in a request. When a request comes with a
1149 number of headers greater than this value (including the first line), it is
1150 rejected with a "400 Bad Request" status code. Similarly, too large responses
1151 are blocked with "502 Bad Gateway". The default value is 101, which is enough
1152 for all usages, considering that the widely deployed Apache server uses the
1153 same limit. It can be useful to push this limit further to temporarily allow
1154 a buggy application to work by the time it gets fixed. Keep in mind that each
1155 new header consumes 32bits of memory for each session, so don't push this
1156 limit too high.
1157
Willy Tarreau7e312732014-02-12 16:35:14 +01001158tune.idletimer <timeout>
1159 Sets the duration after which haproxy will consider that an empty buffer is
1160 probably associated with an idle stream. This is used to optimally adjust
1161 some packet sizes while forwarding large and small data alternatively. The
1162 decision to use splice() or to send large buffers in SSL is modulated by this
1163 parameter. The value is in milliseconds between 0 and 65535. A value of zero
1164 means that haproxy will not try to detect idle streams. The default is 1000,
1165 which seems to correctly detect end user pauses (eg: read a page before
1166 clicking). There should be not reason for changing this value. Please check
1167 tune.ssl.maxrecord below.
1168
Thierry FOURNIER90da1912015-03-05 11:17:06 +01001169tune.lua.forced-yield <number>
1170 This directive forces the Lua engine to execute a yield each <number> of
1171 instructions executed. This permits interruptng a long script and allows the
1172 HAProxy scheduler to process other tasks like accepting connections or
1173 forwarding traffic. The default value is 10000 instructions. If HAProxy often
1174 executes some Lua code but more reactivity is required, this value can be
1175 lowered. If the Lua code is quite long and its result is absolutely required
1176 to process the data, the <number> can be increased.
1177
Willy Tarreau32f61e22015-03-18 17:54:59 +01001178tune.lua.maxmem
1179 Sets the maximum amount of RAM in megabytes per process usable by Lua. By
1180 default it is zero which means unlimited. It is important to set a limit to
1181 ensure that a bug in a script will not result in the system running out of
1182 memory.
1183
Thierry FOURNIER90da1912015-03-05 11:17:06 +01001184tune.lua.session-timeout <timeout>
1185 This is the execution timeout for the Lua sessions. This is useful for
1186 preventing infinite loops or spending too much time in Lua. This timeout has a
1187 priority over other timeouts. For example, if this timeout is set to 4s and
1188 you run a 5s sleep, the code will be interrupted with an error after waiting
1189 4s.
1190
1191tune.lua.task-timeout <timeout>
1192 Purpose is the same as "tune.lua.session-timeout", but this timeout is
1193 dedicated to the tasks. By default, this timeout isn't set because a task may
1194 remain alive during of the lifetime of HAProxy. For example, a task used to
1195 check servers.
1196
Willy Tarreaua0250ba2008-01-06 11:22:57 +01001197tune.maxaccept <number>
Willy Tarreau16a21472012-11-19 12:39:59 +01001198 Sets the maximum number of consecutive connections a process may accept in a
1199 row before switching to other work. In single process mode, higher numbers
1200 give better performance at high connection rates. However in multi-process
1201 modes, keeping a bit of fairness between processes generally is better to
1202 increase performance. This value applies individually to each listener, so
1203 that the number of processes a listener is bound to is taken into account.
1204 This value defaults to 64. In multi-process mode, it is divided by twice
1205 the number of processes the listener is bound to. Setting this value to -1
1206 completely disables the limitation. It should normally not be needed to tweak
1207 this value.
Willy Tarreaua0250ba2008-01-06 11:22:57 +01001208
1209tune.maxpollevents <number>
1210 Sets the maximum amount of events that can be processed at once in a call to
1211 the polling system. The default value is adapted to the operating system. It
1212 has been noticed that reducing it below 200 tends to slightly decrease
1213 latency at the expense of network bandwidth, and increasing it above 200
1214 tends to trade latency for slightly increased bandwidth.
1215
Willy Tarreau27a674e2009-08-17 07:23:33 +02001216tune.maxrewrite <number>
1217 Sets the reserved buffer space to this size in bytes. The reserved space is
1218 used for header rewriting or appending. The first reads on sockets will never
1219 fill more than bufsize-maxrewrite. Historically it has defaulted to half of
1220 bufsize, though that does not make much sense since there are rarely large
1221 numbers of headers to add. Setting it too high prevents processing of large
1222 requests or responses. Setting it too low prevents addition of new headers
1223 to already large requests or to POST requests. It is generally wise to set it
1224 to about 1024. It is automatically readjusted to half of bufsize if it is
1225 larger than that. This means you don't have to worry about it when changing
1226 bufsize.
1227
Willy Tarreauf3045d22015-04-29 16:24:50 +02001228tune.pattern.cache-size <number>
1229 Sets the size of the pattern lookup cache to <number> entries. This is an LRU
1230 cache which reminds previous lookups and their results. It is used by ACLs
1231 and maps on slow pattern lookups, namely the ones using the "sub", "reg",
1232 "dir", "dom", "end", "bin" match methods as well as the case-insensitive
1233 strings. It applies to pattern expressions which means that it will be able
1234 to memorize the result of a lookup among all the patterns specified on a
1235 configuration line (including all those loaded from files). It automatically
1236 invalidates entries which are updated using HTTP actions or on the CLI. The
1237 default cache size is set to 10000 entries, which limits its footprint to
1238 about 5 MB on 32-bit systems and 8 MB on 64-bit systems. There is a very low
1239 risk of collision in this cache, which is in the order of the size of the
1240 cache divided by 2^64. Typically, at 10000 requests per second with the
1241 default cache size of 10000 entries, there's 1% chance that a brute force
1242 attack could cause a single collision after 60 years, or 0.1% after 6 years.
1243 This is considered much lower than the risk of a memory corruption caused by
1244 aging components. If this is not acceptable, the cache can be disabled by
1245 setting this parameter to 0.
1246
Willy Tarreaubd9a0a72011-10-23 21:14:29 +02001247tune.pipesize <number>
1248 Sets the kernel pipe buffer size to this size (in bytes). By default, pipes
1249 are the default size for the system. But sometimes when using TCP splicing,
1250 it can improve performance to increase pipe sizes, especially if it is
1251 suspected that pipes are not filled and that many calls to splice() are
1252 performed. This has an impact on the kernel's memory footprint, so this must
1253 not be changed if impacts are not understood.
1254
Willy Tarreaue803de22010-01-21 17:43:04 +01001255tune.rcvbuf.client <number>
1256tune.rcvbuf.server <number>
1257 Forces the kernel socket receive buffer size on the client or the server side
1258 to the specified value in bytes. This value applies to all TCP/HTTP frontends
1259 and backends. It should normally never be set, and the default size (0) lets
1260 the kernel autotune this value depending on the amount of available memory.
1261 However it can sometimes help to set it to very low values (eg: 4096) in
1262 order to save kernel memory by preventing it from buffering too large amounts
1263 of received data. Lower values will significantly increase CPU usage though.
1264
1265tune.sndbuf.client <number>
1266tune.sndbuf.server <number>
1267 Forces the kernel socket send buffer size on the client or the server side to
1268 the specified value in bytes. This value applies to all TCP/HTTP frontends
1269 and backends. It should normally never be set, and the default size (0) lets
1270 the kernel autotune this value depending on the amount of available memory.
1271 However it can sometimes help to set it to very low values (eg: 4096) in
1272 order to save kernel memory by preventing it from buffering too large amounts
1273 of received data. Lower values will significantly increase CPU usage though.
1274 Another use case is to prevent write timeouts with extremely slow clients due
1275 to the kernel waiting for a large part of the buffer to be read before
1276 notifying haproxy again.
1277
Willy Tarreau6ec58db2012-11-16 16:32:15 +01001278tune.ssl.cachesize <number>
Emeric Brunaf9619d2012-11-28 18:47:52 +01001279 Sets the size of the global SSL session cache, in a number of blocks. A block
1280 is large enough to contain an encoded session without peer certificate.
1281 An encoded session with peer certificate is stored in multiple blocks
Jarno Huuskonen0e82b922014-04-12 18:22:19 +03001282 depending on the size of the peer certificate. A block uses approximately
Emeric Brunaf9619d2012-11-28 18:47:52 +01001283 200 bytes of memory. The default value may be forced at build time, otherwise
1284 defaults to 20000. When the cache is full, the most idle entries are purged
1285 and reassigned. Higher values reduce the occurrence of such a purge, hence
1286 the number of CPU-intensive SSL handshakes by ensuring that all users keep
1287 their session as long as possible. All entries are pre-allocated upon startup
Emeric Brun22890a12012-12-28 14:41:32 +01001288 and are shared between all processes if "nbproc" is greater than 1. Setting
1289 this value to 0 disables the SSL session cache.
Willy Tarreau6ec58db2012-11-16 16:32:15 +01001290
Emeric Brun8dc60392014-05-09 13:52:00 +02001291tune.ssl.force-private-cache
1292 This boolean disables SSL session cache sharing between all processes. It
1293 should normally not be used since it will force many renegotiations due to
1294 clients hitting a random process. But it may be required on some operating
1295 systems where none of the SSL cache synchronization method may be used. In
1296 this case, adding a first layer of hash-based load balancing before the SSL
1297 layer might limit the impact of the lack of session sharing.
1298
Emeric Brun4f65bff2012-11-16 15:11:00 +01001299tune.ssl.lifetime <timeout>
1300 Sets how long a cached SSL session may remain valid. This time is expressed
Jarno Huuskonen0e82b922014-04-12 18:22:19 +03001301 in seconds and defaults to 300 (5 min). It is important to understand that it
Emeric Brun4f65bff2012-11-16 15:11:00 +01001302 does not guarantee that sessions will last that long, because if the cache is
1303 full, the longest idle sessions will be purged despite their configured
1304 lifetime. The real usefulness of this setting is to prevent sessions from
1305 being used for too long.
1306
Willy Tarreaubfd59462013-02-21 07:46:09 +01001307tune.ssl.maxrecord <number>
1308 Sets the maximum amount of bytes passed to SSL_write() at a time. Default
1309 value 0 means there is no limit. Over SSL/TLS, the client can decipher the
1310 data only once it has received a full record. With large records, it means
1311 that clients might have to download up to 16kB of data before starting to
1312 process them. Limiting the value can improve page load times on browsers
1313 located over high latency or low bandwidth networks. It is suggested to find
1314 optimal values which fit into 1 or 2 TCP segments (generally 1448 bytes over
1315 Ethernet with TCP timestamps enabled, or 1460 when timestamps are disabled),
1316 keeping in mind that SSL/TLS add some overhead. Typical values of 1419 and
1317 2859 gave good results during tests. Use "strace -e trace=write" to find the
Willy Tarreau7e312732014-02-12 16:35:14 +01001318 best value. Haproxy will automatically switch to this setting after an idle
1319 stream has been detected (see tune.idletimer above).
Willy Tarreaubfd59462013-02-21 07:46:09 +01001320
Remi Gacognef46cd6e2014-06-12 14:58:40 +02001321tune.ssl.default-dh-param <number>
1322 Sets the maximum size of the Diffie-Hellman parameters used for generating
1323 the ephemeral/temporary Diffie-Hellman key in case of DHE key exchange. The
1324 final size will try to match the size of the server's RSA (or DSA) key (e.g,
1325 a 2048 bits temporary DH key for a 2048 bits RSA key), but will not exceed
1326 this maximum value. Default value if 1024. Only 1024 or higher values are
1327 allowed. Higher values will increase the CPU load, and values greater than
1328 1024 bits are not supported by Java 7 and earlier clients. This value is not
Remi Gacogne47783ef2015-05-29 15:53:22 +02001329 used if static Diffie-Hellman parameters are supplied either directly
1330 in the certificate file or by using the ssl-dh-param-file parameter.
Remi Gacognef46cd6e2014-06-12 14:58:40 +02001331
Christopher Faulet31af49d2015-06-09 17:29:50 +02001332tune.ssl.ssl-ctx-cache-size <number>
1333 Sets the size of the cache used to store generated certificates to <number>
1334 entries. This is a LRU cache. Because generating a SSL certificate
1335 dynamically is expensive, they are cached. The default cache size is set to
1336 1000 entries.
1337
Thierry FOURNIER4834bc72015-06-06 19:29:07 +02001338tune.vars.global-max-size <size>
1339tune.vars.reqres-max-size <size>
1340tune.vars.sess-max-size <size>
1341tune.vars.txn-max-size <size>
1342 These four tunes helps to manage the allowed amount of memory used by the
1343 variables system. "global" limits the memory for all the systems. "sess" limit
1344 the memory by session, "txn" limits the memory by transaction and "reqres"
1345 limits the memory for each request or response processing. during the
1346 accounting, "sess" embbed "txn" and "txn" embed "reqres".
1347
1348 By example, we considers that "tune.vars.sess-max-size" is fixed to 100,
1349 "tune.vars.txn-max-size" is fixed to 100, "tune.vars.reqres-max-size" is
1350 also fixed to 100. If we create a variable "txn.var" that contains 100 bytes,
1351 we cannot create any more variable in the other contexts.
1352
William Lallemanda509e4c2012-11-07 16:54:34 +01001353tune.zlib.memlevel <number>
1354 Sets the memLevel parameter in zlib initialization for each session. It
Jarno Huuskonen0e82b922014-04-12 18:22:19 +03001355 defines how much memory should be allocated for the internal compression
William Lallemanda509e4c2012-11-07 16:54:34 +01001356 state. A value of 1 uses minimum memory but is slow and reduces compression
1357 ratio, a value of 9 uses maximum memory for optimal speed. Can be a value
1358 between 1 and 9. The default value is 8.
1359
1360tune.zlib.windowsize <number>
1361 Sets the window size (the size of the history buffer) as a parameter of the
1362 zlib initialization for each session. Larger values of this parameter result
1363 in better compression at the expense of memory usage. Can be a value between
1364 8 and 15. The default value is 15.
Willy Tarreau6a06a402007-07-15 20:15:28 +02001365
Willy Tarreauc57f0e22009-05-10 13:12:33 +020013663.3. Debugging
1367--------------
Willy Tarreau6a06a402007-07-15 20:15:28 +02001368
1369debug
1370 Enables debug mode which dumps to stdout all exchanges, and disables forking
1371 into background. It is the equivalent of the command-line argument "-d". It
1372 should never be used in a production configuration since it may prevent full
1373 system startup.
1374
1375quiet
1376 Do not display any message during startup. It is equivalent to the command-
1377 line argument "-q".
1378
Emeric Brunf099e792010-09-27 12:05:28 +02001379
Krzysztof Piotr Oledzki6b35ce12010-02-01 23:35:44 +010013803.4. Userlists
1381--------------
1382It is possible to control access to frontend/backend/listen sections or to
1383http stats by allowing only authenticated and authorized users. To do this,
1384it is required to create at least one userlist and to define users.
1385
1386userlist <listname>
Cyril Bonté78caf842010-03-10 22:41:43 +01001387 Creates new userlist with name <listname>. Many independent userlists can be
Krzysztof Piotr Oledzki6b35ce12010-02-01 23:35:44 +01001388 used to store authentication & authorization data for independent customers.
1389
1390group <groupname> [users <user>,<user>,(...)]
Cyril Bonté78caf842010-03-10 22:41:43 +01001391 Adds group <groupname> to the current userlist. It is also possible to
Krzysztof Piotr Oledzki6b35ce12010-02-01 23:35:44 +01001392 attach users to this group by using a comma separated list of names
1393 proceeded by "users" keyword.
1394
Cyril Bontéf0c60612010-02-06 14:44:47 +01001395user <username> [password|insecure-password <password>]
1396 [groups <group>,<group>,(...)]
Krzysztof Piotr Oledzki6b35ce12010-02-01 23:35:44 +01001397 Adds user <username> to the current userlist. Both secure (encrypted) and
1398 insecure (unencrypted) passwords can be used. Encrypted passwords are
Cyril Bonté78caf842010-03-10 22:41:43 +01001399 evaluated using the crypt(3) function so depending of the system's
1400 capabilities, different algorithms are supported. For example modern Glibc
Krzysztof Piotr Oledzki6b35ce12010-02-01 23:35:44 +01001401 based Linux system supports MD5, SHA-256, SHA-512 and of course classic,
Jarno Huuskonen0e82b922014-04-12 18:22:19 +03001402 DES-based method of encrypting passwords.
Krzysztof Piotr Oledzki6b35ce12010-02-01 23:35:44 +01001403
1404
1405 Example:
Cyril Bontéf0c60612010-02-06 14:44:47 +01001406 userlist L1
1407 group G1 users tiger,scott
1408 group G2 users xdb,scott
Krzysztof Piotr Oledzki6b35ce12010-02-01 23:35:44 +01001409
Cyril Bontéf0c60612010-02-06 14:44:47 +01001410 user tiger password $6$k6y3o.eP$JlKBx9za9667qe4(...)xHSwRv6J.C0/D7cV91
1411 user scott insecure-password elgato
1412 user xdb insecure-password hello
Krzysztof Piotr Oledzki6b35ce12010-02-01 23:35:44 +01001413
Cyril Bontéf0c60612010-02-06 14:44:47 +01001414 userlist L2
1415 group G1
1416 group G2
Krzysztof Piotr Oledzki6b35ce12010-02-01 23:35:44 +01001417
Cyril Bontéf0c60612010-02-06 14:44:47 +01001418 user tiger password $6$k6y3o.eP$JlKBx(...)xHSwRv6J.C0/D7cV91 groups G1
1419 user scott insecure-password elgato groups G1,G2
1420 user xdb insecure-password hello groups G2
Krzysztof Piotr Oledzki6b35ce12010-02-01 23:35:44 +01001421
1422 Please note that both lists are functionally identical.
Willy Tarreau6a06a402007-07-15 20:15:28 +02001423
Emeric Brunf099e792010-09-27 12:05:28 +02001424
14253.5. Peers
Cyril Bontédc4d9032012-04-08 21:57:39 +02001426----------
Emeric Brun94900952015-06-11 18:25:54 +02001427It is possible to propagate entries of any data-types in stick-tables between
1428several haproxy instances over TCP connections in a multi-master fashion. Each
1429instance pushes its local updates and insertions to remote peers. The pushed
1430values overwrite remote ones without aggregation. Interrupted exchanges are
1431automatically detected and recovered from the last known point.
1432In addition, during a soft restart, the old process connects to the new one
1433using such a TCP connection to push all its entries before the new process
1434tries to connect to other peers. That ensures very fast replication during a
1435reload, it typically takes a fraction of a second even for large tables.
1436Note that Server IDs are used to identify servers remotely, so it is important
1437that configurations look similar or at least that the same IDs are forced on
1438each server on all participants.
Emeric Brunf099e792010-09-27 12:05:28 +02001439
1440peers <peersect>
Jamie Gloudon801a0a32012-08-25 00:18:33 -04001441 Creates a new peer list with name <peersect>. It is an independent section,
Emeric Brunf099e792010-09-27 12:05:28 +02001442 which is referenced by one or more stick-tables.
1443
Willy Tarreau77e4bd12015-05-01 20:02:17 +02001444disabled
1445 Disables a peers section. It disables both listening and any synchronization
1446 related to this section. This is provided to disable synchronization of stick
1447 tables without having to comment out all "peers" references.
1448
1449enable
1450 This re-enables a disabled peers section which was previously disabled.
1451
Emeric Brunf099e792010-09-27 12:05:28 +02001452peer <peername> <ip>:<port>
1453 Defines a peer inside a peers section.
1454 If <peername> is set to the local peer name (by default hostname, or forced
1455 using "-L" command line option), haproxy will listen for incoming remote peer
1456 connection on <ip>:<port>. Otherwise, <ip>:<port> defines where to connect to
1457 to join the remote peer, and <peername> is used at the protocol level to
1458 identify and validate the remote peer on the server side.
1459
1460 During a soft restart, local peer <ip>:<port> is used by the old instance to
1461 connect the new one and initiate a complete replication (teaching process).
1462
1463 It is strongly recommended to have the exact same peers declaration on all
1464 peers and to only rely on the "-L" command line argument to change the local
1465 peer name. This makes it easier to maintain coherent configuration files
1466 across all peers.
1467
William Lallemandb2f07452015-05-12 14:27:13 +02001468 You may want to reference some environment variables in the address
1469 parameter, see section 2.3 about environment variables.
Willy Tarreaudad36a32013-03-11 01:20:04 +01001470
Cyril Bontédc4d9032012-04-08 21:57:39 +02001471 Example:
Emeric Brunf099e792010-09-27 12:05:28 +02001472 peers mypeers
Willy Tarreauf7b30a92010-12-06 22:59:17 +01001473 peer haproxy1 192.168.0.1:1024
1474 peer haproxy2 192.168.0.2:1024
1475 peer haproxy3 10.2.0.1:1024
Emeric Brunf099e792010-09-27 12:05:28 +02001476
1477 backend mybackend
1478 mode tcp
1479 balance roundrobin
1480 stick-table type ip size 20k peers mypeers
1481 stick on src
1482
Willy Tarreauf7b30a92010-12-06 22:59:17 +01001483 server srv1 192.168.0.30:80
1484 server srv2 192.168.0.31:80
Emeric Brunf099e792010-09-27 12:05:28 +02001485
1486
Simon Horman51a1cf62015-02-03 13:00:44 +090014873.6. Mailers
1488------------
1489It is possible to send email alerts when the state of servers changes.
1490If configured email alerts are sent to each mailer that is configured
1491in a mailers section. Email is sent to mailers using SMTP.
1492
Pieter Baauw386a1272015-08-16 15:26:24 +02001493mailers <mailersect>
Simon Horman51a1cf62015-02-03 13:00:44 +09001494 Creates a new mailer list with the name <mailersect>. It is an
1495 independent section which is referenced by one or more proxies.
1496
1497mailer <mailername> <ip>:<port>
1498 Defines a mailer inside a mailers section.
1499
1500 Example:
1501 mailers mymailers
1502 mailer smtp1 192.168.0.1:587
1503 mailer smtp2 192.168.0.2:587
1504
1505 backend mybackend
1506 mode tcp
1507 balance roundrobin
1508
1509 email-alert mailers mymailers
1510 email-alert from test1@horms.org
1511 email-alert to test2@horms.org
1512
1513 server srv1 192.168.0.30:80
1514 server srv2 192.168.0.31:80
1515
1516
Willy Tarreauc57f0e22009-05-10 13:12:33 +020015174. Proxies
Willy Tarreau6a06a402007-07-15 20:15:28 +02001518----------
Willy Tarreau0ba27502007-12-24 16:55:16 +01001519
Willy Tarreau6a06a402007-07-15 20:15:28 +02001520Proxy configuration can be located in a set of sections :
William Lallemand6e62fb62015-04-28 16:55:23 +02001521 - defaults [<name>]
Willy Tarreau6a06a402007-07-15 20:15:28 +02001522 - frontend <name>
1523 - backend <name>
1524 - listen <name>
1525
1526A "defaults" section sets default parameters for all other sections following
1527its declaration. Those default parameters are reset by the next "defaults"
1528section. See below for the list of parameters which can be set in a "defaults"
Willy Tarreau0ba27502007-12-24 16:55:16 +01001529section. The name is optional but its use is encouraged for better readability.
Willy Tarreau6a06a402007-07-15 20:15:28 +02001530
1531A "frontend" section describes a set of listening sockets accepting client
1532connections.
1533
1534A "backend" section describes a set of servers to which the proxy will connect
1535to forward incoming connections.
1536
1537A "listen" section defines a complete proxy with its frontend and backend
1538parts combined in one section. It is generally useful for TCP-only traffic.
1539
Willy Tarreau0ba27502007-12-24 16:55:16 +01001540All proxy names must be formed from upper and lower case letters, digits,
1541'-' (dash), '_' (underscore) , '.' (dot) and ':' (colon). ACL names are
1542case-sensitive, which means that "www" and "WWW" are two different proxies.
1543
1544Historically, all proxy names could overlap, it just caused troubles in the
1545logs. Since the introduction of content switching, it is mandatory that two
1546proxies with overlapping capabilities (frontend/backend) have different names.
1547However, it is still permitted that a frontend and a backend share the same
1548name, as this configuration seems to be commonly encountered.
1549
1550Right now, two major proxy modes are supported : "tcp", also known as layer 4,
1551and "http", also known as layer 7. In layer 4 mode, HAProxy simply forwards
Krzysztof Piotr Oledzkif8645332009-12-13 21:55:50 +01001552bidirectional traffic between two sides. In layer 7 mode, HAProxy analyzes the
Willy Tarreau0ba27502007-12-24 16:55:16 +01001553protocol, and can interact with it by allowing, blocking, switching, adding,
1554modifying, or removing arbitrary contents in requests or responses, based on
1555arbitrary criteria.
1556
Willy Tarreau70dffda2014-01-30 03:07:23 +01001557In HTTP mode, the processing applied to requests and responses flowing over
1558a connection depends in the combination of the frontend's HTTP options and
1559the backend's. HAProxy supports 5 connection modes :
1560
1561 - KAL : keep alive ("option http-keep-alive") which is the default mode : all
1562 requests and responses are processed, and connections remain open but idle
1563 between responses and new requests.
1564
1565 - TUN: tunnel ("option http-tunnel") : this was the default mode for versions
1566 1.0 to 1.5-dev21 : only the first request and response are processed, and
1567 everything else is forwarded with no analysis at all. This mode should not
1568 be used as it creates lots of trouble with logging and HTTP processing.
1569
1570 - PCL: passive close ("option httpclose") : exactly the same as tunnel mode,
1571 but with "Connection: close" appended in both directions to try to make
1572 both ends close after the first request/response exchange.
1573
1574 - SCL: server close ("option http-server-close") : the server-facing
1575 connection is closed after the end of the response is received, but the
1576 client-facing connection remains open.
1577
1578 - FCL: forced close ("option forceclose") : the connection is actively closed
1579 after the end of the response.
1580
1581The effective mode that will be applied to a connection passing through a
1582frontend and a backend can be determined by both proxy modes according to the
1583following matrix, but in short, the modes are symmetric, keep-alive is the
1584weakest option and force close is the strongest.
1585
1586 Backend mode
1587
1588 | KAL | TUN | PCL | SCL | FCL
1589 ----+-----+-----+-----+-----+----
1590 KAL | KAL | TUN | PCL | SCL | FCL
1591 ----+-----+-----+-----+-----+----
1592 TUN | TUN | TUN | PCL | SCL | FCL
1593 Frontend ----+-----+-----+-----+-----+----
1594 mode PCL | PCL | PCL | PCL | FCL | FCL
1595 ----+-----+-----+-----+-----+----
1596 SCL | SCL | SCL | FCL | SCL | FCL
1597 ----+-----+-----+-----+-----+----
1598 FCL | FCL | FCL | FCL | FCL | FCL
1599
Willy Tarreau0ba27502007-12-24 16:55:16 +01001600
Willy Tarreau70dffda2014-01-30 03:07:23 +01001601
Willy Tarreauc57f0e22009-05-10 13:12:33 +020016024.1. Proxy keywords matrix
1603--------------------------
Willy Tarreau0ba27502007-12-24 16:55:16 +01001604
Willy Tarreauc57f0e22009-05-10 13:12:33 +02001605The following list of keywords is supported. Most of them may only be used in a
1606limited set of section types. Some of them are marked as "deprecated" because
1607they are inherited from an old syntax which may be confusing or functionally
1608limited, and there are new recommended keywords to replace them. Keywords
Willy Tarreau5c6f7b32010-02-26 13:34:29 +01001609marked with "(*)" can be optionally inverted using the "no" prefix, eg. "no
Willy Tarreauc57f0e22009-05-10 13:12:33 +02001610option contstats". This makes sense when the option has been enabled by default
Willy Tarreau3842f002009-06-14 11:39:52 +02001611and must be disabled for a specific instance. Such options may also be prefixed
1612with "default" in order to restore default settings regardless of what has been
1613specified in a previous "defaults" section.
Willy Tarreau0ba27502007-12-24 16:55:16 +01001614
Willy Tarreau6a06a402007-07-15 20:15:28 +02001615
Willy Tarreau5c6f7b32010-02-26 13:34:29 +01001616 keyword defaults frontend listen backend
1617------------------------------------+----------+----------+---------+---------
1618acl - X X X
Willy Tarreau294d0f02015-08-10 19:40:12 +02001619appsession - - - -
Willy Tarreau5c6f7b32010-02-26 13:34:29 +01001620backlog X X X -
1621balance X - X X
1622bind - X X -
1623bind-process X X X X
1624block - X X X
1625capture cookie - X X -
1626capture request header - X X -
1627capture response header - X X -
1628clitimeout (deprecated) X X X -
William Lallemand82fe75c2012-10-23 10:25:10 +02001629compression X X X X
Willy Tarreau5c6f7b32010-02-26 13:34:29 +01001630contimeout (deprecated) X - X X
1631cookie X - X X
Thierry FOURNIERa0a1b752015-05-26 17:44:32 +02001632declare capture - X X -
Willy Tarreau5c6f7b32010-02-26 13:34:29 +01001633default-server X - X X
1634default_backend X X X -
1635description - X X X
1636disabled X X X X
1637dispatch - - X X
Simon Horman51a1cf62015-02-03 13:00:44 +09001638email-alert from X X X X
Simon Horman64e34162015-02-06 11:11:57 +09001639email-alert level X X X X
Simon Horman51a1cf62015-02-03 13:00:44 +09001640email-alert mailers X X X X
1641email-alert myhostname X X X X
1642email-alert to X X X X
Willy Tarreau5c6f7b32010-02-26 13:34:29 +01001643enabled X X X X
1644errorfile X X X X
1645errorloc X X X X
1646errorloc302 X X X X
1647-- keyword -------------------------- defaults - frontend - listen -- backend -
1648errorloc303 X X X X
Cyril Bonté0d4bf012010-04-25 23:21:46 +02001649force-persist - X X X
Willy Tarreau5c6f7b32010-02-26 13:34:29 +01001650fullconn X - X X
1651grace X X X X
1652hash-type X - X X
1653http-check disable-on-404 X - X X
Willy Tarreaubd741542010-03-16 18:46:54 +01001654http-check expect - - X X
Willy Tarreau7ab6aff2010-10-12 06:30:16 +02001655http-check send-state X - X X
Willy Tarreau5c6f7b32010-02-26 13:34:29 +01001656http-request - X X X
Willy Tarreaue365c0b2013-06-11 16:06:12 +02001657http-response - X X X
Willy Tarreau30631952015-08-06 15:05:24 +02001658http-reuse X - X X
Baptiste Assmann2c42ef52013-10-09 21:57:02 +02001659http-send-name-header - - X X
Willy Tarreau5c6f7b32010-02-26 13:34:29 +01001660id - X X X
Cyril Bonté0d4bf012010-04-25 23:21:46 +02001661ignore-persist - X X X
Baptiste Assmann01c6cc32015-08-23 11:45:29 +02001662load-server-state-from-file X - X X
William Lallemand0f99e342011-10-12 17:50:54 +02001663log (*) X X X X
Willy Tarreaufb4e7ea2015-01-07 14:55:17 +01001664log-format X X X -
Dragan Dosen7ad31542015-09-28 17:16:47 +02001665log-format-sd X X X -
Willy Tarreau094af4e2015-01-07 15:03:42 +01001666log-tag X X X X
Willy Tarreauc35362a2014-04-25 13:58:37 +02001667max-keep-alive-queue X - X X
Willy Tarreau5c6f7b32010-02-26 13:34:29 +01001668maxconn X X X -
1669mode X X X X
1670monitor fail - X X -
1671monitor-net X X X -
1672monitor-uri X X X -
1673option abortonclose (*) X - X X
1674option accept-invalid-http-request (*) X X X -
1675option accept-invalid-http-response (*) X - X X
1676option allbackups (*) X - X X
1677option checkcache (*) X - X X
1678option clitcpka (*) X X X -
1679option contstats (*) X X X -
1680option dontlog-normal (*) X X X -
1681option dontlognull (*) X X X -
1682option forceclose (*) X X X X
1683-- keyword -------------------------- defaults - frontend - listen -- backend -
1684option forwardfor X X X X
Willy Tarreau9fbe18e2015-05-01 22:42:08 +02001685option http-buffer-request (*) X X X X
Willy Tarreau82649f92015-05-01 22:40:51 +02001686option http-ignore-probes (*) X X X -
Willy Tarreau16bfb022010-01-16 19:48:41 +01001687option http-keep-alive (*) X X X X
Willy Tarreau96e31212011-05-30 18:10:30 +02001688option http-no-delay (*) X X X X
Willy Tarreau8a8e1d92010-04-05 16:15:16 +02001689option http-pretend-keepalive (*) X X X X
Willy Tarreau5c6f7b32010-02-26 13:34:29 +01001690option http-server-close (*) X X X X
Willy Tarreau02bce8b2014-01-30 00:15:28 +01001691option http-tunnel (*) X X X X
Willy Tarreau5c6f7b32010-02-26 13:34:29 +01001692option http-use-proxy-header (*) X X X -
1693option httpchk X - X X
1694option httpclose (*) X X X X
1695option httplog X X X X
1696option http_proxy (*) X X X X
Jamie Gloudon801a0a32012-08-25 00:18:33 -04001697option independent-streams (*) X X X X
Gabor Lekenyb4c81e42010-09-29 18:17:05 +02001698option ldap-check X - X X
Simon Horman98637e52014-06-20 12:30:16 +09001699option external-check X - X X
Willy Tarreau5c6f7b32010-02-26 13:34:29 +01001700option log-health-checks (*) X - X X
1701option log-separate-errors (*) X X X -
1702option logasap (*) X X X -
1703option mysql-check X - X X
Rauf Kuliyev38b41562011-01-04 15:14:13 +01001704option pgsql-check X - X X
Willy Tarreau5c6f7b32010-02-26 13:34:29 +01001705option nolinger (*) X X X X
1706option originalto X X X X
1707option persist (*) X - X X
1708option redispatch (*) X - X X
Hervé COMMOWICKec032d62011-08-05 16:23:48 +02001709option redis-check X - X X
Willy Tarreau5c6f7b32010-02-26 13:34:29 +01001710option smtpchk X - X X
1711option socket-stats (*) X X X -
1712option splice-auto (*) X X X X
1713option splice-request (*) X X X X
1714option splice-response (*) X X X X
1715option srvtcpka (*) X - X X
1716option ssl-hello-chk X - X X
1717-- keyword -------------------------- defaults - frontend - listen -- backend -
Willy Tarreaued179852013-12-16 01:07:00 +01001718option tcp-check X - X X
Willy Tarreau5c6f7b32010-02-26 13:34:29 +01001719option tcp-smart-accept (*) X X X -
1720option tcp-smart-connect (*) X - X X
1721option tcpka X X X X
1722option tcplog X X X X
1723option transparent (*) X - X X
Simon Horman98637e52014-06-20 12:30:16 +09001724external-check command X - X X
1725external-check path X - X X
Willy Tarreau5c6f7b32010-02-26 13:34:29 +01001726persist rdp-cookie X - X X
1727rate-limit sessions X X X -
1728redirect - X X X
1729redisp (deprecated) X - X X
1730redispatch (deprecated) X - X X
1731reqadd - X X X
1732reqallow - X X X
1733reqdel - X X X
1734reqdeny - X X X
1735reqiallow - X X X
1736reqidel - X X X
1737reqideny - X X X
1738reqipass - X X X
1739reqirep - X X X
Willy Tarreau5c6f7b32010-02-26 13:34:29 +01001740reqitarpit - X X X
1741reqpass - X X X
1742reqrep - X X X
1743-- keyword -------------------------- defaults - frontend - listen -- backend -
Willy Tarreau5c6f7b32010-02-26 13:34:29 +01001744reqtarpit - X X X
1745retries X - X X
1746rspadd - X X X
1747rspdel - X X X
1748rspdeny - X X X
1749rspidel - X X X
1750rspideny - X X X
1751rspirep - X X X
1752rsprep - X X X
1753server - - X X
Baptiste Assmann01c6cc32015-08-23 11:45:29 +02001754server-state-file-name X - X X
Willy Tarreau5c6f7b32010-02-26 13:34:29 +01001755source X - X X
1756srvtimeout (deprecated) X - X X
Cyril Bonté66c327d2010-10-12 00:14:37 +02001757stats admin - - X X
Willy Tarreau5c6f7b32010-02-26 13:34:29 +01001758stats auth X - X X
1759stats enable X - X X
1760stats hide-version X - X X
Cyril Bonté2be1b3f2010-09-30 23:46:30 +02001761stats http-request - - X X
Willy Tarreau5c6f7b32010-02-26 13:34:29 +01001762stats realm X - X X
1763stats refresh X - X X
1764stats scope X - X X
1765stats show-desc X - X X
1766stats show-legends X - X X
1767stats show-node X - X X
1768stats uri X - X X
1769-- keyword -------------------------- defaults - frontend - listen -- backend -
1770stick match - - X X
1771stick on - - X X
1772stick store-request - - X X
Willy Tarreaud8dc99f2011-07-01 11:33:25 +02001773stick store-response - - X X
Willy Tarreau5c6f7b32010-02-26 13:34:29 +01001774stick-table - - X X
Willy Tarreau938c7fe2014-04-25 14:21:39 +02001775tcp-check connect - - X X
1776tcp-check expect - - X X
1777tcp-check send - - X X
1778tcp-check send-binary - - X X
Willy Tarreaue9656522010-08-17 15:40:09 +02001779tcp-request connection - X X -
1780tcp-request content - X X X
Willy Tarreaua56235c2010-09-14 11:31:36 +02001781tcp-request inspect-delay - X X X
Emeric Brun0a3b67f2010-09-24 15:34:53 +02001782tcp-response content - - X X
1783tcp-response inspect-delay - - X X
Willy Tarreau5c6f7b32010-02-26 13:34:29 +01001784timeout check X - X X
1785timeout client X X X -
Willy Tarreau05cdd962014-05-10 14:30:07 +02001786timeout client-fin X X X -
Willy Tarreau5c6f7b32010-02-26 13:34:29 +01001787timeout clitimeout (deprecated) X X X -
1788timeout connect X - X X
1789timeout contimeout (deprecated) X - X X
1790timeout http-keep-alive X X X X
1791timeout http-request X X X X
1792timeout queue X - X X
1793timeout server X - X X
Willy Tarreau05cdd962014-05-10 14:30:07 +02001794timeout server-fin X - X X
Willy Tarreau5c6f7b32010-02-26 13:34:29 +01001795timeout srvtimeout (deprecated) X - X X
1796timeout tarpit X X X X
Willy Tarreauce887fd2012-05-12 12:50:00 +02001797timeout tunnel X - X X
Willy Tarreau5c6f7b32010-02-26 13:34:29 +01001798transparent (deprecated) X - X X
William Lallemanda73203e2012-03-12 12:48:57 +01001799unique-id-format X X X -
1800unique-id-header X X X -
Willy Tarreau5c6f7b32010-02-26 13:34:29 +01001801use_backend - X X -
Willy Tarreau4a5cade2012-04-05 21:09:48 +02001802use-server - - X X
Willy Tarreau5c6f7b32010-02-26 13:34:29 +01001803------------------------------------+----------+----------+---------+---------
1804 keyword defaults frontend listen backend
Willy Tarreau6a06a402007-07-15 20:15:28 +02001805
Willy Tarreau0ba27502007-12-24 16:55:16 +01001806
Willy Tarreauc57f0e22009-05-10 13:12:33 +020018074.2. Alphabetically sorted keywords reference
1808---------------------------------------------
Willy Tarreau0ba27502007-12-24 16:55:16 +01001809
1810This section provides a description of each keyword and its usage.
1811
1812
1813acl <aclname> <criterion> [flags] [operator] <value> ...
1814 Declare or complete an access list.
1815 May be used in sections : defaults | frontend | listen | backend
1816 no | yes | yes | yes
1817 Example:
1818 acl invalid_src src 0.0.0.0/7 224.0.0.0/3
1819 acl invalid_src src_port 0:1023
1820 acl local_dst hdr(host) -i localhost
1821
Willy Tarreauc57f0e22009-05-10 13:12:33 +02001822 See section 7 about ACL usage.
Willy Tarreau0ba27502007-12-24 16:55:16 +01001823
1824
Cyril Bontéb21570a2009-11-29 20:04:48 +01001825appsession <cookie> len <length> timeout <holdtime>
1826 [request-learn] [prefix] [mode <path-parameters|query-string>]
Willy Tarreau0ba27502007-12-24 16:55:16 +01001827 Define session stickiness on an existing application cookie.
1828 May be used in sections : defaults | frontend | listen | backend
1829 no | no | yes | yes
1830 Arguments :
1831 <cookie> this is the name of the cookie used by the application and which
1832 HAProxy will have to learn for each new session.
1833
Cyril Bontéb21570a2009-11-29 20:04:48 +01001834 <length> this is the max number of characters that will be memorized and
Willy Tarreau0ba27502007-12-24 16:55:16 +01001835 checked in each cookie value.
1836
1837 <holdtime> this is the time after which the cookie will be removed from
1838 memory if unused. If no unit is specified, this time is in
1839 milliseconds.
1840
Cyril Bontébf47aeb2009-10-15 00:15:40 +02001841 request-learn
1842 If this option is specified, then haproxy will be able to learn
1843 the cookie found in the request in case the server does not
1844 specify any in response. This is typically what happens with
1845 PHPSESSID cookies, or when haproxy's session expires before
1846 the application's session and the correct server is selected.
1847 It is recommended to specify this option to improve reliability.
1848
Cyril Bontéb21570a2009-11-29 20:04:48 +01001849 prefix When this option is specified, haproxy will match on the cookie
1850 prefix (or URL parameter prefix). The appsession value is the
1851 data following this prefix.
1852
1853 Example :
1854 appsession ASPSESSIONID len 64 timeout 3h prefix
1855
1856 This will match the cookie ASPSESSIONIDXXXX=XXXXX,
1857 the appsession value will be XXXX=XXXXX.
1858
1859 mode This option allows to change the URL parser mode.
1860 2 modes are currently supported :
1861 - path-parameters :
1862 The parser looks for the appsession in the path parameters
1863 part (each parameter is separated by a semi-colon), which is
1864 convenient for JSESSIONID for example.
1865 This is the default mode if the option is not set.
1866 - query-string :
1867 In this mode, the parser will look for the appsession in the
1868 query string.
1869
Willy Tarreau294d0f02015-08-10 19:40:12 +02001870 As of version 1.6, appsessions was removed. It is more flexible and more
1871 convenient to use stick-tables instead, and stick-tables support multi-master
1872 replication and data conservation across reloads, which appsessions did not.
Willy Tarreau0ba27502007-12-24 16:55:16 +01001873
Cyril Bonté02ff8ef2010-12-14 22:48:49 +01001874 See also : "cookie", "capture cookie", "balance", "stick", "stick-table",
1875 "ignore-persist", "nbproc" and "bind-process".
Willy Tarreau0ba27502007-12-24 16:55:16 +01001876
1877
Willy Tarreauc73ce2b2008-01-06 10:55:10 +01001878backlog <conns>
1879 Give hints to the system about the approximate listen backlog desired size
1880 May be used in sections : defaults | frontend | listen | backend
1881 yes | yes | yes | no
1882 Arguments :
1883 <conns> is the number of pending connections. Depending on the operating
1884 system, it may represent the number of already acknowledged
Cyril Bontédc4d9032012-04-08 21:57:39 +02001885 connections, of non-acknowledged ones, or both.
Willy Tarreauc73ce2b2008-01-06 10:55:10 +01001886
1887 In order to protect against SYN flood attacks, one solution is to increase
1888 the system's SYN backlog size. Depending on the system, sometimes it is just
1889 tunable via a system parameter, sometimes it is not adjustable at all, and
1890 sometimes the system relies on hints given by the application at the time of
1891 the listen() syscall. By default, HAProxy passes the frontend's maxconn value
1892 to the listen() syscall. On systems which can make use of this value, it can
1893 sometimes be useful to be able to specify a different value, hence this
1894 backlog parameter.
1895
1896 On Linux 2.4, the parameter is ignored by the system. On Linux 2.6, it is
1897 used as a hint and the system accepts up to the smallest greater power of
1898 two, and never more than some limits (usually 32768).
1899
1900 See also : "maxconn" and the target operating system's tuning guide.
1901
1902
Willy Tarreau0ba27502007-12-24 16:55:16 +01001903balance <algorithm> [ <arguments> ]
Willy Tarreau226071e2014-04-10 11:55:45 +02001904balance url_param <param> [check_post]
Willy Tarreau0ba27502007-12-24 16:55:16 +01001905 Define the load balancing algorithm to be used in a backend.
1906 May be used in sections : defaults | frontend | listen | backend
1907 yes | no | yes | yes
1908 Arguments :
1909 <algorithm> is the algorithm used to select a server when doing load
1910 balancing. This only applies when no persistence information
1911 is available, or when a connection is redispatched to another
1912 server. <algorithm> may be one of the following :
1913
1914 roundrobin Each server is used in turns, according to their weights.
1915 This is the smoothest and fairest algorithm when the server's
1916 processing time remains equally distributed. This algorithm
1917 is dynamic, which means that server weights may be adjusted
Willy Tarreau9757a382009-10-03 12:56:50 +02001918 on the fly for slow starts for instance. It is limited by
Godbacha34bdc02013-07-22 07:44:53 +08001919 design to 4095 active servers per backend. Note that in some
Willy Tarreau9757a382009-10-03 12:56:50 +02001920 large farms, when a server becomes up after having been down
1921 for a very short time, it may sometimes take a few hundreds
1922 requests for it to be re-integrated into the farm and start
1923 receiving traffic. This is normal, though very rare. It is
1924 indicated here in case you would have the chance to observe
1925 it, so that you don't worry.
1926
1927 static-rr Each server is used in turns, according to their weights.
1928 This algorithm is as similar to roundrobin except that it is
1929 static, which means that changing a server's weight on the
1930 fly will have no effect. On the other hand, it has no design
1931 limitation on the number of servers, and when a server goes
1932 up, it is always immediately reintroduced into the farm, once
1933 the full map is recomputed. It also uses slightly less CPU to
1934 run (around -1%).
Willy Tarreau0ba27502007-12-24 16:55:16 +01001935
Willy Tarreau2d2a7f82008-03-17 12:07:56 +01001936 leastconn The server with the lowest number of connections receives the
1937 connection. Round-robin is performed within groups of servers
1938 of the same load to ensure that all servers will be used. Use
1939 of this algorithm is recommended where very long sessions are
1940 expected, such as LDAP, SQL, TSE, etc... but is not very well
1941 suited for protocols using short sessions such as HTTP. This
1942 algorithm is dynamic, which means that server weights may be
1943 adjusted on the fly for slow starts for instance.
1944
Willy Tarreauf09c6602012-02-13 17:12:08 +01001945 first The first server with available connection slots receives the
Jarno Huuskonen0e82b922014-04-12 18:22:19 +03001946 connection. The servers are chosen from the lowest numeric
Willy Tarreauf09c6602012-02-13 17:12:08 +01001947 identifier to the highest (see server parameter "id"), which
1948 defaults to the server's position in the farm. Once a server
Willy Tarreau64559c52012-04-07 09:08:45 +02001949 reaches its maxconn value, the next server is used. It does
Willy Tarreauf09c6602012-02-13 17:12:08 +01001950 not make sense to use this algorithm without setting maxconn.
1951 The purpose of this algorithm is to always use the smallest
1952 number of servers so that extra servers can be powered off
1953 during non-intensive hours. This algorithm ignores the server
1954 weight, and brings more benefit to long session such as RDP
Willy Tarreau64559c52012-04-07 09:08:45 +02001955 or IMAP than HTTP, though it can be useful there too. In
1956 order to use this algorithm efficiently, it is recommended
1957 that a cloud controller regularly checks server usage to turn
1958 them off when unused, and regularly checks backend queue to
1959 turn new servers on when the queue inflates. Alternatively,
1960 using "http-check send-state" may inform servers on the load.
Willy Tarreauf09c6602012-02-13 17:12:08 +01001961
Willy Tarreau0ba27502007-12-24 16:55:16 +01001962 source The source IP address is hashed and divided by the total
1963 weight of the running servers to designate which server will
1964 receive the request. This ensures that the same client IP
1965 address will always reach the same server as long as no
1966 server goes down or up. If the hash result changes due to the
1967 number of running servers changing, many clients will be
1968 directed to a different server. This algorithm is generally
1969 used in TCP mode where no cookie may be inserted. It may also
Krzysztof Piotr Oledzkif8645332009-12-13 21:55:50 +01001970 be used on the Internet to provide a best-effort stickiness
Willy Tarreau0ba27502007-12-24 16:55:16 +01001971 to clients which refuse session cookies. This algorithm is
Willy Tarreau6b2e11b2009-10-01 07:52:15 +02001972 static by default, which means that changing a server's
1973 weight on the fly will have no effect, but this can be
1974 changed using "hash-type".
Willy Tarreau0ba27502007-12-24 16:55:16 +01001975
Oskar Stolc8dc41842012-05-19 10:19:54 +01001976 uri This algorithm hashes either the left part of the URI (before
1977 the question mark) or the whole URI (if the "whole" parameter
1978 is present) and divides the hash value by the total weight of
1979 the running servers. The result designates which server will
1980 receive the request. This ensures that the same URI will
1981 always be directed to the same server as long as no server
1982 goes up or down. This is used with proxy caches and
1983 anti-virus proxies in order to maximize the cache hit rate.
1984 Note that this algorithm may only be used in an HTTP backend.
1985 This algorithm is static by default, which means that
1986 changing a server's weight on the fly will have no effect,
1987 but this can be changed using "hash-type".
Willy Tarreau0ba27502007-12-24 16:55:16 +01001988
Oskar Stolc8dc41842012-05-19 10:19:54 +01001989 This algorithm supports two optional parameters "len" and
Marek Majkowski9c30fc12008-04-27 23:25:55 +02001990 "depth", both followed by a positive integer number. These
1991 options may be helpful when it is needed to balance servers
1992 based on the beginning of the URI only. The "len" parameter
1993 indicates that the algorithm should only consider that many
1994 characters at the beginning of the URI to compute the hash.
1995 Note that having "len" set to 1 rarely makes sense since most
1996 URIs start with a leading "/".
1997
1998 The "depth" parameter indicates the maximum directory depth
1999 to be used to compute the hash. One level is counted for each
2000 slash in the request. If both parameters are specified, the
2001 evaluation stops when either is reached.
2002
Willy Tarreau0ba27502007-12-24 16:55:16 +01002003 url_param The URL parameter specified in argument will be looked up in
matt.farnsworth@nokia.com1c2ab962008-04-14 20:47:37 +02002004 the query string of each HTTP GET request.
2005
2006 If the modifier "check_post" is used, then an HTTP POST
Cyril Bontédc4d9032012-04-08 21:57:39 +02002007 request entity will be searched for the parameter argument,
2008 when it is not found in a query string after a question mark
Willy Tarreau226071e2014-04-10 11:55:45 +02002009 ('?') in the URL. The message body will only start to be
2010 analyzed once either the advertised amount of data has been
2011 received or the request buffer is full. In the unlikely event
2012 that chunked encoding is used, only the first chunk is
Cyril Bontédc4d9032012-04-08 21:57:39 +02002013 scanned. Parameter values separated by a chunk boundary, may
Willy Tarreau226071e2014-04-10 11:55:45 +02002014 be randomly balanced if at all. This keyword used to support
2015 an optional <max_wait> parameter which is now ignored.
matt.farnsworth@nokia.com1c2ab962008-04-14 20:47:37 +02002016
2017 If the parameter is found followed by an equal sign ('=') and
2018 a value, then the value is hashed and divided by the total
2019 weight of the running servers. The result designates which
2020 server will receive the request.
2021
2022 This is used to track user identifiers in requests and ensure
2023 that a same user ID will always be sent to the same server as
2024 long as no server goes up or down. If no value is found or if
2025 the parameter is not found, then a round robin algorithm is
2026 applied. Note that this algorithm may only be used in an HTTP
Willy Tarreau6b2e11b2009-10-01 07:52:15 +02002027 backend. This algorithm is static by default, which means
2028 that changing a server's weight on the fly will have no
2029 effect, but this can be changed using "hash-type".
Willy Tarreau0ba27502007-12-24 16:55:16 +01002030
Cyril Bontédc4d9032012-04-08 21:57:39 +02002031 hdr(<name>) The HTTP header <name> will be looked up in each HTTP
2032 request. Just as with the equivalent ACL 'hdr()' function,
2033 the header name in parenthesis is not case sensitive. If the
2034 header is absent or if it does not contain any value, the
2035 roundrobin algorithm is applied instead.
Benoitaffb4812009-03-25 13:02:10 +01002036
Krzysztof Piotr Oledzkif8645332009-12-13 21:55:50 +01002037 An optional 'use_domain_only' parameter is available, for
Benoitaffb4812009-03-25 13:02:10 +01002038 reducing the hash algorithm to the main domain part with some
2039 specific headers such as 'Host'. For instance, in the Host
2040 value "haproxy.1wt.eu", only "1wt" will be considered.
2041
Willy Tarreau6b2e11b2009-10-01 07:52:15 +02002042 This algorithm is static by default, which means that
2043 changing a server's weight on the fly will have no effect,
2044 but this can be changed using "hash-type".
2045
Emeric Brun736aa232009-06-30 17:56:00 +02002046 rdp-cookie
Hervé COMMOWICKa3eb39c2011-08-05 18:48:51 +02002047 rdp-cookie(<name>)
Emeric Brun736aa232009-06-30 17:56:00 +02002048 The RDP cookie <name> (or "mstshash" if omitted) will be
2049 looked up and hashed for each incoming TCP request. Just as
2050 with the equivalent ACL 'req_rdp_cookie()' function, the name
2051 is not case-sensitive. This mechanism is useful as a degraded
2052 persistence mode, as it makes it possible to always send the
2053 same user (or the same session ID) to the same server. If the
Krzysztof Piotr Oledzkif8645332009-12-13 21:55:50 +01002054 cookie is not found, the normal roundrobin algorithm is
Emeric Brun736aa232009-06-30 17:56:00 +02002055 used instead.
2056
2057 Note that for this to work, the frontend must ensure that an
2058 RDP cookie is already present in the request buffer. For this
2059 you must use 'tcp-request content accept' rule combined with
2060 a 'req_rdp_cookie_cnt' ACL.
2061
Willy Tarreau6b2e11b2009-10-01 07:52:15 +02002062 This algorithm is static by default, which means that
2063 changing a server's weight on the fly will have no effect,
2064 but this can be changed using "hash-type".
2065
Cyril Bontédc4d9032012-04-08 21:57:39 +02002066 See also the rdp_cookie pattern fetch function.
Simon Hormanab814e02011-06-24 14:50:20 +09002067
Willy Tarreau0ba27502007-12-24 16:55:16 +01002068 <arguments> is an optional list of arguments which may be needed by some
Marek Majkowski9c30fc12008-04-27 23:25:55 +02002069 algorithms. Right now, only "url_param" and "uri" support an
2070 optional argument.
matt.farnsworth@nokia.com1c2ab962008-04-14 20:47:37 +02002071
Willy Tarreau3cd9af22009-03-15 14:06:41 +01002072 The load balancing algorithm of a backend is set to roundrobin when no other
2073 algorithm, mode nor option have been set. The algorithm may only be set once
2074 for each backend.
Willy Tarreau0ba27502007-12-24 16:55:16 +01002075
2076 Examples :
2077 balance roundrobin
2078 balance url_param userid
matt.farnsworth@nokia.com1c2ab962008-04-14 20:47:37 +02002079 balance url_param session_id check_post 64
Benoitaffb4812009-03-25 13:02:10 +01002080 balance hdr(User-Agent)
2081 balance hdr(host)
2082 balance hdr(Host) use_domain_only
matt.farnsworth@nokia.com1c2ab962008-04-14 20:47:37 +02002083
2084 Note: the following caveats and limitations on using the "check_post"
2085 extension with "url_param" must be considered :
2086
Krzysztof Piotr Oledzkif8645332009-12-13 21:55:50 +01002087 - all POST requests are eligible for consideration, because there is no way
matt.farnsworth@nokia.com1c2ab962008-04-14 20:47:37 +02002088 to determine if the parameters will be found in the body or entity which
2089 may contain binary data. Therefore another method may be required to
2090 restrict consideration of POST requests that have no URL parameters in
2091 the body. (see acl reqideny http_end)
2092
2093 - using a <max_wait> value larger than the request buffer size does not
2094 make sense and is useless. The buffer size is set at build time, and
2095 defaults to 16 kB.
2096
2097 - Content-Encoding is not supported, the parameter search will probably
2098 fail; and load balancing will fall back to Round Robin.
2099
2100 - Expect: 100-continue is not supported, load balancing will fall back to
2101 Round Robin.
2102
2103 - Transfer-Encoding (RFC2616 3.6.1) is only supported in the first chunk.
2104 If the entire parameter value is not present in the first chunk, the
2105 selection of server is undefined (actually, defined by how little
2106 actually appeared in the first chunk).
2107
2108 - This feature does not support generation of a 100, 411 or 501 response.
2109
2110 - In some cases, requesting "check_post" MAY attempt to scan the entire
Krzysztof Piotr Oledzkif8645332009-12-13 21:55:50 +01002111 contents of a message body. Scanning normally terminates when linear
matt.farnsworth@nokia.com1c2ab962008-04-14 20:47:37 +02002112 white space or control characters are found, indicating the end of what
2113 might be a URL parameter list. This is probably not a concern with SGML
2114 type message bodies.
Willy Tarreau0ba27502007-12-24 16:55:16 +01002115
Willy Tarreau294d0f02015-08-10 19:40:12 +02002116 See also : "dispatch", "cookie", "transparent", "hash-type" and "http_proxy".
Willy Tarreau0ba27502007-12-24 16:55:16 +01002117
2118
Willy Tarreaub6205fd2012-09-24 12:27:33 +02002119bind [<address>]:<port_range> [, ...] [param*]
2120bind /<path> [, ...] [param*]
Willy Tarreau0ba27502007-12-24 16:55:16 +01002121 Define one or several listening addresses and/or ports in a frontend.
2122 May be used in sections : defaults | frontend | listen | backend
2123 no | yes | yes | no
2124 Arguments :
Willy Tarreaub1e52e82008-01-13 14:49:51 +01002125 <address> is optional and can be a host name, an IPv4 address, an IPv6
2126 address, or '*'. It designates the address the frontend will
2127 listen on. If unset, all IPv4 addresses of the system will be
2128 listened on. The same will apply for '*' or the system's
David du Colombier9c938da2011-03-17 10:40:27 +01002129 special address "0.0.0.0". The IPv6 equivalent is '::'.
Willy Tarreau24709282013-03-10 21:32:12 +01002130 Optionally, an address family prefix may be used before the
2131 address to force the family regardless of the address format,
2132 which can be useful to specify a path to a unix socket with
2133 no slash ('/'). Currently supported prefixes are :
2134 - 'ipv4@' -> address is always IPv4
2135 - 'ipv6@' -> address is always IPv6
2136 - 'unix@' -> address is a path to a local unix socket
Willy Tarreau70f72e02014-07-08 00:37:50 +02002137 - 'abns@' -> address is in abstract namespace (Linux only).
2138 Note: since abstract sockets are not "rebindable", they
2139 do not cope well with multi-process mode during
2140 soft-restart, so it is better to avoid them if
2141 nbproc is greater than 1. The effect is that if the
2142 new process fails to start, only one of the old ones
2143 will be able to rebind to the socket.
Willy Tarreau40aa0702013-03-10 23:51:38 +01002144 - 'fd@<n>' -> use file descriptor <n> inherited from the
2145 parent. The fd must be bound and may or may not already
2146 be listening.
William Lallemandb2f07452015-05-12 14:27:13 +02002147 You may want to reference some environment variables in the
2148 address parameter, see section 2.3 about environment
2149 variables.
Willy Tarreaub1e52e82008-01-13 14:49:51 +01002150
Willy Tarreauc5011ca2010-03-22 11:53:56 +01002151 <port_range> is either a unique TCP port, or a port range for which the
2152 proxy will accept connections for the IP address specified
Willy Tarreauceb24bc2010-11-09 12:46:41 +01002153 above. The port is mandatory for TCP listeners. Note that in
2154 the case of an IPv6 address, the port is always the number
2155 after the last colon (':'). A range can either be :
Willy Tarreauc5011ca2010-03-22 11:53:56 +01002156 - a numerical port (ex: '80')
2157 - a dash-delimited ports range explicitly stating the lower
2158 and upper bounds (ex: '2000-2100') which are included in
2159 the range.
2160
2161 Particular care must be taken against port ranges, because
2162 every <address:port> couple consumes one socket (= a file
2163 descriptor), so it's easy to consume lots of descriptors
2164 with a simple range, and to run out of sockets. Also, each
2165 <address:port> couple must be used only once among all
2166 instances running on a same system. Please note that binding
2167 to ports lower than 1024 generally require particular
Jamie Gloudon801a0a32012-08-25 00:18:33 -04002168 privileges to start the program, which are independent of
Willy Tarreauc5011ca2010-03-22 11:53:56 +01002169 the 'uid' parameter.
Willy Tarreau0ba27502007-12-24 16:55:16 +01002170
Willy Tarreauceb24bc2010-11-09 12:46:41 +01002171 <path> is a UNIX socket path beginning with a slash ('/'). This is
2172 alternative to the TCP listening port. Haproxy will then
2173 receive UNIX connections on the socket located at this place.
2174 The path must begin with a slash and by default is absolute.
2175 It can be relative to the prefix defined by "unix-bind" in
2176 the global section. Note that the total length of the prefix
2177 followed by the socket path cannot exceed some system limits
2178 for UNIX sockets, which commonly are set to 107 characters.
2179
Willy Tarreaub6205fd2012-09-24 12:27:33 +02002180 <param*> is a list of parameters common to all sockets declared on the
2181 same line. These numerous parameters depend on OS and build
2182 options and have a complete section dedicated to them. Please
2183 refer to section 5 to for more details.
Willy Tarreaua0ee1d02012-09-10 09:01:23 +02002184
Willy Tarreau0ba27502007-12-24 16:55:16 +01002185 It is possible to specify a list of address:port combinations delimited by
2186 commas. The frontend will then listen on all of these addresses. There is no
2187 fixed limit to the number of addresses and ports which can be listened on in
2188 a frontend, as well as there is no limit to the number of "bind" statements
2189 in a frontend.
2190
2191 Example :
2192 listen http_proxy
2193 bind :80,:443
2194 bind 10.0.0.1:10080,10.0.0.1:10443
Willy Tarreauceb24bc2010-11-09 12:46:41 +01002195 bind /var/run/ssl-frontend.sock user root mode 600 accept-proxy
Willy Tarreau0ba27502007-12-24 16:55:16 +01002196
Willy Tarreaua0ee1d02012-09-10 09:01:23 +02002197 listen http_https_proxy
2198 bind :80
Cyril Bonté0d44fc62012-10-09 22:45:33 +02002199 bind :443 ssl crt /etc/haproxy/site.pem
Willy Tarreaua0ee1d02012-09-10 09:01:23 +02002200
Willy Tarreau24709282013-03-10 21:32:12 +01002201 listen http_https_proxy_explicit
2202 bind ipv6@:80
2203 bind ipv4@public_ssl:443 ssl crt /etc/haproxy/site.pem
2204 bind unix@ssl-frontend.sock user root mode 600 accept-proxy
2205
Willy Tarreaudad36a32013-03-11 01:20:04 +01002206 listen external_bind_app1
William Lallemandb2f07452015-05-12 14:27:13 +02002207 bind "fd@${FD_APP1}"
Willy Tarreaudad36a32013-03-11 01:20:04 +01002208
Willy Tarreau55dcaf62015-09-27 15:03:15 +02002209 Note: regarding Linux's abstract namespace sockets, HAProxy uses the whole
2210 sun_path length is used for the address length. Some other programs
2211 such as socat use the string length only by default. Pass the option
2212 ",unix-tightsocklen=0" to any abstract socket definition in socat to
2213 make it compatible with HAProxy's.
2214
Willy Tarreauceb24bc2010-11-09 12:46:41 +01002215 See also : "source", "option forwardfor", "unix-bind" and the PROXY protocol
Willy Tarreaub6205fd2012-09-24 12:27:33 +02002216 documentation, and section 5 about bind options.
Willy Tarreau0ba27502007-12-24 16:55:16 +01002217
2218
Willy Tarreaua9db57e2013-01-18 11:29:29 +01002219bind-process [ all | odd | even | <number 1-64>[-<number 1-64>] ] ...
Willy Tarreau0b9c02c2009-02-04 22:05:05 +01002220 Limit visibility of an instance to a certain set of processes numbers.
2221 May be used in sections : defaults | frontend | listen | backend
2222 yes | yes | yes | yes
2223 Arguments :
2224 all All process will see this instance. This is the default. It
2225 may be used to override a default value.
2226
Willy Tarreaua9db57e2013-01-18 11:29:29 +01002227 odd This instance will be enabled on processes 1,3,5,...63. This
Willy Tarreau0b9c02c2009-02-04 22:05:05 +01002228 option may be combined with other numbers.
2229
Willy Tarreaua9db57e2013-01-18 11:29:29 +01002230 even This instance will be enabled on processes 2,4,6,...64. This
Willy Tarreau0b9c02c2009-02-04 22:05:05 +01002231 option may be combined with other numbers. Do not use it
2232 with less than 2 processes otherwise some instances might be
2233 missing from all processes.
2234
Willy Tarreau110ecc12012-11-15 17:50:01 +01002235 number The instance will be enabled on this process number or range,
Willy Tarreaua9db57e2013-01-18 11:29:29 +01002236 whose values must all be between 1 and 32 or 64 depending on
Willy Tarreau102df612014-05-07 23:56:38 +02002237 the machine's word size. If a proxy is bound to process
2238 numbers greater than the configured global.nbproc, it will
2239 either be forced to process #1 if a single process was
2240 specified, or to all processes otherwise.
Willy Tarreau0b9c02c2009-02-04 22:05:05 +01002241
2242 This keyword limits binding of certain instances to certain processes. This
2243 is useful in order not to have too many processes listening to the same
2244 ports. For instance, on a dual-core machine, it might make sense to set
2245 'nbproc 2' in the global section, then distributes the listeners among 'odd'
2246 and 'even' instances.
2247
Willy Tarreaua9db57e2013-01-18 11:29:29 +01002248 At the moment, it is not possible to reference more than 32 or 64 processes
2249 using this keyword, but this should be more than enough for most setups.
2250 Please note that 'all' really means all processes regardless of the machine's
2251 word size, and is not limited to the first 32 or 64.
Willy Tarreau0b9c02c2009-02-04 22:05:05 +01002252
Willy Tarreau6ae1ba62014-05-07 19:01:58 +02002253 Each "bind" line may further be limited to a subset of the proxy's processes,
2254 please consult the "process" bind keyword in section 5.1.
2255
Willy Tarreaub369a042014-09-16 13:21:03 +02002256 When a frontend has no explicit "bind-process" line, it tries to bind to all
2257 the processes referenced by its "bind" lines. That means that frontends can
2258 easily adapt to their listeners' processes.
2259
Willy Tarreau0b9c02c2009-02-04 22:05:05 +01002260 If some backends are referenced by frontends bound to other processes, the
2261 backend automatically inherits the frontend's processes.
2262
2263 Example :
2264 listen app_ip1
2265 bind 10.0.0.1:80
Willy Tarreaubfcd3112010-10-23 11:22:08 +02002266 bind-process odd
Willy Tarreau0b9c02c2009-02-04 22:05:05 +01002267
2268 listen app_ip2
2269 bind 10.0.0.2:80
Willy Tarreaubfcd3112010-10-23 11:22:08 +02002270 bind-process even
Willy Tarreau0b9c02c2009-02-04 22:05:05 +01002271
2272 listen management
2273 bind 10.0.0.3:80
Willy Tarreaubfcd3112010-10-23 11:22:08 +02002274 bind-process 1 2 3 4
Willy Tarreau0b9c02c2009-02-04 22:05:05 +01002275
Willy Tarreau110ecc12012-11-15 17:50:01 +01002276 listen management
2277 bind 10.0.0.4:80
2278 bind-process 1-4
2279
Willy Tarreau6ae1ba62014-05-07 19:01:58 +02002280 See also : "nbproc" in global section, and "process" in section 5.1.
Willy Tarreau0b9c02c2009-02-04 22:05:05 +01002281
2282
Willy Tarreau0ba27502007-12-24 16:55:16 +01002283block { if | unless } <condition>
2284 Block a layer 7 request if/unless a condition is matched
2285 May be used in sections : defaults | frontend | listen | backend
2286 no | yes | yes | yes
2287
2288 The HTTP request will be blocked very early in the layer 7 processing
2289 if/unless <condition> is matched. A 403 error will be returned if the request
Willy Tarreauc57f0e22009-05-10 13:12:33 +02002290 is blocked. The condition has to reference ACLs (see section 7). This is
Willy Tarreau3c92c5f2011-08-28 09:45:47 +02002291 typically used to deny access to certain sensitive resources if some
Willy Tarreau0ba27502007-12-24 16:55:16 +01002292 conditions are met or not met. There is no fixed limit to the number of
2293 "block" statements per instance.
2294
2295 Example:
2296 acl invalid_src src 0.0.0.0/7 224.0.0.0/3
2297 acl invalid_src src_port 0:1023
2298 acl local_dst hdr(host) -i localhost
2299 block if invalid_src || local_dst
2300
Willy Tarreauc57f0e22009-05-10 13:12:33 +02002301 See section 7 about ACL usage.
Willy Tarreau0ba27502007-12-24 16:55:16 +01002302
2303
2304capture cookie <name> len <length>
2305 Capture and log a cookie in the request and in the response.
2306 May be used in sections : defaults | frontend | listen | backend
2307 no | yes | yes | no
2308 Arguments :
2309 <name> is the beginning of the name of the cookie to capture. In order
2310 to match the exact name, simply suffix the name with an equal
2311 sign ('='). The full name will appear in the logs, which is
2312 useful with application servers which adjust both the cookie name
2313 and value (eg: ASPSESSIONXXXXX).
2314
2315 <length> is the maximum number of characters to report in the logs, which
2316 include the cookie name, the equal sign and the value, all in the
2317 standard "name=value" form. The string will be truncated on the
2318 right if it exceeds <length>.
2319
2320 Only the first cookie is captured. Both the "cookie" request headers and the
2321 "set-cookie" response headers are monitored. This is particularly useful to
2322 check for application bugs causing session crossing or stealing between
2323 users, because generally the user's cookies can only change on a login page.
2324
2325 When the cookie was not presented by the client, the associated log column
2326 will report "-". When a request does not cause a cookie to be assigned by the
2327 server, a "-" is reported in the response column.
2328
2329 The capture is performed in the frontend only because it is necessary that
2330 the log format does not change for a given frontend depending on the
2331 backends. This may change in the future. Note that there can be only one
Willy Tarreau193b8c62012-11-22 00:17:38 +01002332 "capture cookie" statement in a frontend. The maximum capture length is set
2333 by the global "tune.http.cookielen" setting and defaults to 63 characters. It
2334 is not possible to specify a capture in a "defaults" section.
Willy Tarreau0ba27502007-12-24 16:55:16 +01002335
2336 Example:
2337 capture cookie ASPSESSION len 32
2338
2339 See also : "capture request header", "capture response header" as well as
Willy Tarreauc57f0e22009-05-10 13:12:33 +02002340 section 8 about logging.
Willy Tarreau0ba27502007-12-24 16:55:16 +01002341
2342
2343capture request header <name> len <length>
Willy Tarreau4460d032012-11-21 23:37:37 +01002344 Capture and log the last occurrence of the specified request header.
Willy Tarreau0ba27502007-12-24 16:55:16 +01002345 May be used in sections : defaults | frontend | listen | backend
2346 no | yes | yes | no
2347 Arguments :
2348 <name> is the name of the header to capture. The header names are not
Willy Tarreaud2a4aa22008-01-31 15:28:22 +01002349 case-sensitive, but it is a common practice to write them as they
Willy Tarreau0ba27502007-12-24 16:55:16 +01002350 appear in the requests, with the first letter of each word in
2351 upper case. The header name will not appear in the logs, only the
2352 value is reported, but the position in the logs is respected.
2353
2354 <length> is the maximum number of characters to extract from the value and
2355 report in the logs. The string will be truncated on the right if
2356 it exceeds <length>.
2357
Willy Tarreau4460d032012-11-21 23:37:37 +01002358 The complete value of the last occurrence of the header is captured. The
Willy Tarreau0ba27502007-12-24 16:55:16 +01002359 value will be added to the logs between braces ('{}'). If multiple headers
2360 are captured, they will be delimited by a vertical bar ('|') and will appear
Willy Tarreaucc6c8912009-02-22 10:53:55 +01002361 in the same order they were declared in the configuration. Non-existent
2362 headers will be logged just as an empty string. Common uses for request
2363 header captures include the "Host" field in virtual hosting environments, the
2364 "Content-length" when uploads are supported, "User-agent" to quickly
Krzysztof Piotr Oledzkif8645332009-12-13 21:55:50 +01002365 differentiate between real users and robots, and "X-Forwarded-For" in proxied
Willy Tarreaucc6c8912009-02-22 10:53:55 +01002366 environments to find where the request came from.
2367
2368 Note that when capturing headers such as "User-agent", some spaces may be
2369 logged, making the log analysis more difficult. Thus be careful about what
2370 you log if you know your log parser is not smart enough to rely on the
2371 braces.
Willy Tarreau0ba27502007-12-24 16:55:16 +01002372
Willy Tarreau0900abb2012-11-22 00:21:46 +01002373 There is no limit to the number of captured request headers nor to their
2374 length, though it is wise to keep them low to limit memory usage per session.
2375 In order to keep log format consistent for a same frontend, header captures
2376 can only be declared in a frontend. It is not possible to specify a capture
2377 in a "defaults" section.
Willy Tarreau0ba27502007-12-24 16:55:16 +01002378
2379 Example:
2380 capture request header Host len 15
2381 capture request header X-Forwarded-For len 15
2382 capture request header Referrer len 15
2383
Willy Tarreauc57f0e22009-05-10 13:12:33 +02002384 See also : "capture cookie", "capture response header" as well as section 8
Willy Tarreau0ba27502007-12-24 16:55:16 +01002385 about logging.
2386
2387
2388capture response header <name> len <length>
Willy Tarreau4460d032012-11-21 23:37:37 +01002389 Capture and log the last occurrence of the specified response header.
Willy Tarreau0ba27502007-12-24 16:55:16 +01002390 May be used in sections : defaults | frontend | listen | backend
2391 no | yes | yes | no
2392 Arguments :
2393 <name> is the name of the header to capture. The header names are not
Willy Tarreaud2a4aa22008-01-31 15:28:22 +01002394 case-sensitive, but it is a common practice to write them as they
Willy Tarreau0ba27502007-12-24 16:55:16 +01002395 appear in the response, with the first letter of each word in
2396 upper case. The header name will not appear in the logs, only the
2397 value is reported, but the position in the logs is respected.
2398
2399 <length> is the maximum number of characters to extract from the value and
2400 report in the logs. The string will be truncated on the right if
2401 it exceeds <length>.
2402
Willy Tarreau4460d032012-11-21 23:37:37 +01002403 The complete value of the last occurrence of the header is captured. The
Willy Tarreau0ba27502007-12-24 16:55:16 +01002404 result will be added to the logs between braces ('{}') after the captured
2405 request headers. If multiple headers are captured, they will be delimited by
2406 a vertical bar ('|') and will appear in the same order they were declared in
Willy Tarreaucc6c8912009-02-22 10:53:55 +01002407 the configuration. Non-existent headers will be logged just as an empty
2408 string. Common uses for response header captures include the "Content-length"
2409 header which indicates how many bytes are expected to be returned, the
2410 "Location" header to track redirections.
Willy Tarreau0ba27502007-12-24 16:55:16 +01002411
Willy Tarreau0900abb2012-11-22 00:21:46 +01002412 There is no limit to the number of captured response headers nor to their
2413 length, though it is wise to keep them low to limit memory usage per session.
2414 In order to keep log format consistent for a same frontend, header captures
2415 can only be declared in a frontend. It is not possible to specify a capture
2416 in a "defaults" section.
Willy Tarreau0ba27502007-12-24 16:55:16 +01002417
2418 Example:
2419 capture response header Content-length len 9
2420 capture response header Location len 15
2421
Willy Tarreauc57f0e22009-05-10 13:12:33 +02002422 See also : "capture cookie", "capture request header" as well as section 8
Willy Tarreau0ba27502007-12-24 16:55:16 +01002423 about logging.
2424
2425
Cyril Bontéf0c60612010-02-06 14:44:47 +01002426clitimeout <timeout> (deprecated)
Willy Tarreau0ba27502007-12-24 16:55:16 +01002427 Set the maximum inactivity time on the client side.
2428 May be used in sections : defaults | frontend | listen | backend
2429 yes | yes | yes | no
2430 Arguments :
2431 <timeout> is the timeout value is specified in milliseconds by default, but
2432 can be in any other unit if the number is suffixed by the unit,
2433 as explained at the top of this document.
2434
2435 The inactivity timeout applies when the client is expected to acknowledge or
2436 send data. In HTTP mode, this timeout is particularly important to consider
2437 during the first phase, when the client sends the request, and during the
2438 response while it is reading data sent by the server. The value is specified
2439 in milliseconds by default, but can be in any other unit if the number is
2440 suffixed by the unit, as specified at the top of this document. In TCP mode
2441 (and to a lesser extent, in HTTP mode), it is highly recommended that the
2442 client timeout remains equal to the server timeout in order to avoid complex
Willy Tarreaud2a4aa22008-01-31 15:28:22 +01002443 situations to debug. It is a good practice to cover one or several TCP packet
Willy Tarreau0ba27502007-12-24 16:55:16 +01002444 losses by specifying timeouts that are slightly above multiples of 3 seconds
2445 (eg: 4 or 5 seconds).
2446
2447 This parameter is specific to frontends, but can be specified once for all in
2448 "defaults" sections. This is in fact one of the easiest solutions not to
2449 forget about it. An unspecified timeout results in an infinite timeout, which
2450 is not recommended. Such a usage is accepted and works but reports a warning
2451 during startup because it may results in accumulation of expired sessions in
2452 the system if the system's timeouts are not configured either.
2453
2454 This parameter is provided for compatibility but is currently deprecated.
2455 Please use "timeout client" instead.
2456
Willy Tarreau036fae02008-01-06 13:24:40 +01002457 See also : "timeout client", "timeout http-request", "timeout server", and
2458 "srvtimeout".
Willy Tarreau0ba27502007-12-24 16:55:16 +01002459
Cyril Bonté316a8cf2012-11-11 13:38:27 +01002460compression algo <algorithm> ...
2461compression type <mime type> ...
Willy Tarreau70737d12012-10-27 00:34:28 +02002462compression offload
William Lallemand82fe75c2012-10-23 10:25:10 +02002463 Enable HTTP compression.
2464 May be used in sections : defaults | frontend | listen | backend
2465 yes | yes | yes | yes
2466 Arguments :
Cyril Bonté316a8cf2012-11-11 13:38:27 +01002467 algo is followed by the list of supported compression algorithms.
2468 type is followed by the list of MIME types that will be compressed.
2469 offload makes haproxy work as a compression offloader only (see notes).
2470
2471 The currently supported algorithms are :
Willy Tarreauc91840a2015-03-28 17:00:39 +01002472 identity this is mostly for debugging, and it was useful for developing
2473 the compression feature. Identity does not apply any change on
2474 data.
Cyril Bonté316a8cf2012-11-11 13:38:27 +01002475
Willy Tarreauc91840a2015-03-28 17:00:39 +01002476 gzip applies gzip compression. This setting is only available when
2477 support for zlib was built in.
2478
2479 deflate same as "gzip", but with deflate algorithm and zlib format.
2480 Note that this algorithm has ambiguous support on many
2481 browsers and no support at all from recent ones. It is
2482 strongly recommended not to use it for anything else than
2483 experimentation. This setting is only available when support
2484 for zlib was built in.
Cyril Bonté316a8cf2012-11-11 13:38:27 +01002485
Willy Tarreauc91840a2015-03-28 17:00:39 +01002486 raw-deflate same as "deflate" without the zlib wrapper, and used as an
2487 alternative when the browser wants "deflate". All major
2488 browsers understand it and despite violating the standards,
2489 it is known to work better than "deflate", at least on MSIE
2490 and some versions of Safari. Do not use it in conjunction
2491 with "deflate", use either one or the other since both react
2492 to the same Accept-Encoding token. This setting is only
2493 available when support for zlib was built in.
Cyril Bonté316a8cf2012-11-11 13:38:27 +01002494
Dmitry Sivachenko87c208b2012-11-22 20:03:26 +04002495 Compression will be activated depending on the Accept-Encoding request
Cyril Bonté316a8cf2012-11-11 13:38:27 +01002496 header. With identity, it does not take care of that header.
Dmitry Sivachenkoc9f3b452012-11-28 17:47:11 +04002497 If backend servers support HTTP compression, these directives
2498 will be no-op: haproxy will see the compressed response and will not
2499 compress again. If backend servers do not support HTTP compression and
2500 there is Accept-Encoding header in request, haproxy will compress the
2501 matching response.
Willy Tarreau70737d12012-10-27 00:34:28 +02002502
2503 The "offload" setting makes haproxy remove the Accept-Encoding header to
2504 prevent backend servers from compressing responses. It is strongly
2505 recommended not to do this because this means that all the compression work
2506 will be done on the single point where haproxy is located. However in some
2507 deployment scenarios, haproxy may be installed in front of a buggy gateway
Dmitry Sivachenkoc9f3b452012-11-28 17:47:11 +04002508 with broken HTTP compression implementation which can't be turned off.
2509 In that case haproxy can be used to prevent that gateway from emitting
2510 invalid payloads. In this case, simply removing the header in the
2511 configuration does not work because it applies before the header is parsed,
2512 so that prevents haproxy from compressing. The "offload" setting should
Willy Tarreauffea9fd2014-07-12 16:37:02 +02002513 then be used for such scenarios. Note: for now, the "offload" setting is
2514 ignored when set in a defaults section.
William Lallemand82fe75c2012-10-23 10:25:10 +02002515
William Lallemand05097442012-11-20 12:14:28 +01002516 Compression is disabled when:
Baptiste Assmann650d53d2013-01-05 15:44:44 +01002517 * the request does not advertise a supported compression algorithm in the
2518 "Accept-Encoding" header
2519 * the response message is not HTTP/1.1
William Lallemandd3002612012-11-26 14:34:47 +01002520 * HTTP status code is not 200
William Lallemand8bb4e342013-12-10 17:28:48 +01002521 * response header "Transfer-Encoding" contains "chunked" (Temporary
2522 Workaround)
Baptiste Assmann650d53d2013-01-05 15:44:44 +01002523 * response contain neither a "Content-Length" header nor a
2524 "Transfer-Encoding" whose last value is "chunked"
2525 * response contains a "Content-Type" header whose first value starts with
2526 "multipart"
2527 * the response contains the "no-transform" value in the "Cache-control"
2528 header
2529 * User-Agent matches "Mozilla/4" unless it is MSIE 6 with XP SP2, or MSIE 7
2530 and later
2531 * The response contains a "Content-Encoding" header, indicating that the
2532 response is already compressed (see compression offload)
William Lallemand05097442012-11-20 12:14:28 +01002533
Baptiste Assmann650d53d2013-01-05 15:44:44 +01002534 Note: The compression does not rewrite Etag headers, and does not emit the
2535 Warning header.
William Lallemand05097442012-11-20 12:14:28 +01002536
William Lallemand82fe75c2012-10-23 10:25:10 +02002537 Examples :
2538 compression algo gzip
2539 compression type text/html text/plain
Willy Tarreau0ba27502007-12-24 16:55:16 +01002540
Cyril Bontéf0c60612010-02-06 14:44:47 +01002541contimeout <timeout> (deprecated)
Willy Tarreau0ba27502007-12-24 16:55:16 +01002542 Set the maximum time to wait for a connection attempt to a server to succeed.
2543 May be used in sections : defaults | frontend | listen | backend
2544 yes | no | yes | yes
2545 Arguments :
2546 <timeout> is the timeout value is specified in milliseconds by default, but
2547 can be in any other unit if the number is suffixed by the unit,
2548 as explained at the top of this document.
2549
2550 If the server is located on the same LAN as haproxy, the connection should be
Willy Tarreaud2a4aa22008-01-31 15:28:22 +01002551 immediate (less than a few milliseconds). Anyway, it is a good practice to
Willy Tarreaud72758d2010-01-12 10:42:19 +01002552 cover one or several TCP packet losses by specifying timeouts that are
Willy Tarreau0ba27502007-12-24 16:55:16 +01002553 slightly above multiples of 3 seconds (eg: 4 or 5 seconds). By default, the
2554 connect timeout also presets the queue timeout to the same value if this one
2555 has not been specified. Historically, the contimeout was also used to set the
2556 tarpit timeout in a listen section, which is not possible in a pure frontend.
2557
2558 This parameter is specific to backends, but can be specified once for all in
2559 "defaults" sections. This is in fact one of the easiest solutions not to
2560 forget about it. An unspecified timeout results in an infinite timeout, which
2561 is not recommended. Such a usage is accepted and works but reports a warning
2562 during startup because it may results in accumulation of failed sessions in
2563 the system if the system's timeouts are not configured either.
2564
2565 This parameter is provided for backwards compatibility but is currently
2566 deprecated. Please use "timeout connect", "timeout queue" or "timeout tarpit"
2567 instead.
2568
2569 See also : "timeout connect", "timeout queue", "timeout tarpit",
2570 "timeout server", "contimeout".
2571
2572
Willy Tarreau55165fe2009-05-10 12:02:55 +02002573cookie <name> [ rewrite | insert | prefix ] [ indirect ] [ nocache ]
Willy Tarreau4992dd22012-05-31 21:02:17 +02002574 [ postonly ] [ preserve ] [ httponly ] [ secure ]
2575 [ domain <domain> ]* [ maxidle <idle> ] [ maxlife <life> ]
Willy Tarreau0ba27502007-12-24 16:55:16 +01002576 Enable cookie-based persistence in a backend.
2577 May be used in sections : defaults | frontend | listen | backend
2578 yes | no | yes | yes
2579 Arguments :
2580 <name> is the name of the cookie which will be monitored, modified or
2581 inserted in order to bring persistence. This cookie is sent to
2582 the client via a "Set-Cookie" header in the response, and is
2583 brought back by the client in a "Cookie" header in all requests.
2584 Special care should be taken to choose a name which does not
2585 conflict with any likely application cookie. Also, if the same
2586 backends are subject to be used by the same clients (eg:
2587 HTTP/HTTPS), care should be taken to use different cookie names
2588 between all backends if persistence between them is not desired.
2589
2590 rewrite This keyword indicates that the cookie will be provided by the
2591 server and that haproxy will have to modify its value to set the
2592 server's identifier in it. This mode is handy when the management
2593 of complex combinations of "Set-cookie" and "Cache-control"
2594 headers is left to the application. The application can then
2595 decide whether or not it is appropriate to emit a persistence
2596 cookie. Since all responses should be monitored, this mode only
2597 works in HTTP close mode. Unless the application behaviour is
2598 very complex and/or broken, it is advised not to start with this
2599 mode for new deployments. This keyword is incompatible with
2600 "insert" and "prefix".
2601
2602 insert This keyword indicates that the persistence cookie will have to
Willy Tarreaua79094d2010-08-31 22:54:15 +02002603 be inserted by haproxy in server responses if the client did not
Willy Tarreauba4c5be2010-10-23 12:46:42 +02002604
Willy Tarreaua79094d2010-08-31 22:54:15 +02002605 already have a cookie that would have permitted it to access this
Willy Tarreauba4c5be2010-10-23 12:46:42 +02002606 server. When used without the "preserve" option, if the server
2607 emits a cookie with the same name, it will be remove before
2608 processing. For this reason, this mode can be used to upgrade
2609 existing configurations running in the "rewrite" mode. The cookie
2610 will only be a session cookie and will not be stored on the
2611 client's disk. By default, unless the "indirect" option is added,
2612 the server will see the cookies emitted by the client. Due to
2613 caching effects, it is generally wise to add the "nocache" or
2614 "postonly" keywords (see below). The "insert" keyword is not
2615 compatible with "rewrite" and "prefix".
Willy Tarreau0ba27502007-12-24 16:55:16 +01002616
2617 prefix This keyword indicates that instead of relying on a dedicated
2618 cookie for the persistence, an existing one will be completed.
2619 This may be needed in some specific environments where the client
2620 does not support more than one single cookie and the application
2621 already needs it. In this case, whenever the server sets a cookie
2622 named <name>, it will be prefixed with the server's identifier
2623 and a delimiter. The prefix will be removed from all client
2624 requests so that the server still finds the cookie it emitted.
2625 Since all requests and responses are subject to being modified,
2626 this mode requires the HTTP close mode. The "prefix" keyword is
Willy Tarreau37229df2011-10-17 12:24:55 +02002627 not compatible with "rewrite" and "insert". Note: it is highly
2628 recommended not to use "indirect" with "prefix", otherwise server
2629 cookie updates would not be sent to clients.
Willy Tarreau0ba27502007-12-24 16:55:16 +01002630
Willy Tarreaua79094d2010-08-31 22:54:15 +02002631 indirect When this option is specified, no cookie will be emitted to a
2632 client which already has a valid one for the server which has
2633 processed the request. If the server sets such a cookie itself,
Willy Tarreauba4c5be2010-10-23 12:46:42 +02002634 it will be removed, unless the "preserve" option is also set. In
2635 "insert" mode, this will additionally remove cookies from the
2636 requests transmitted to the server, making the persistence
2637 mechanism totally transparent from an application point of view.
Willy Tarreau37229df2011-10-17 12:24:55 +02002638 Note: it is highly recommended not to use "indirect" with
2639 "prefix", otherwise server cookie updates would not be sent to
2640 clients.
Willy Tarreau0ba27502007-12-24 16:55:16 +01002641
2642 nocache This option is recommended in conjunction with the insert mode
2643 when there is a cache between the client and HAProxy, as it
2644 ensures that a cacheable response will be tagged non-cacheable if
2645 a cookie needs to be inserted. This is important because if all
2646 persistence cookies are added on a cacheable home page for
2647 instance, then all customers will then fetch the page from an
2648 outer cache and will all share the same persistence cookie,
2649 leading to one server receiving much more traffic than others.
2650 See also the "insert" and "postonly" options.
2651
2652 postonly This option ensures that cookie insertion will only be performed
2653 on responses to POST requests. It is an alternative to the
2654 "nocache" option, because POST responses are not cacheable, so
2655 this ensures that the persistence cookie will never get cached.
2656 Since most sites do not need any sort of persistence before the
2657 first POST which generally is a login request, this is a very
2658 efficient method to optimize caching without risking to find a
2659 persistence cookie in the cache.
2660 See also the "insert" and "nocache" options.
2661
Willy Tarreauba4c5be2010-10-23 12:46:42 +02002662 preserve This option may only be used with "insert" and/or "indirect". It
2663 allows the server to emit the persistence cookie itself. In this
2664 case, if a cookie is found in the response, haproxy will leave it
2665 untouched. This is useful in order to end persistence after a
2666 logout request for instance. For this, the server just has to
2667 emit a cookie with an invalid value (eg: empty) or with a date in
2668 the past. By combining this mechanism with the "disable-on-404"
2669 check option, it is possible to perform a completely graceful
2670 shutdown because users will definitely leave the server after
2671 they logout.
2672
Willy Tarreau4992dd22012-05-31 21:02:17 +02002673 httponly This option tells haproxy to add an "HttpOnly" cookie attribute
2674 when a cookie is inserted. This attribute is used so that a
2675 user agent doesn't share the cookie with non-HTTP components.
2676 Please check RFC6265 for more information on this attribute.
2677
2678 secure This option tells haproxy to add a "Secure" cookie attribute when
2679 a cookie is inserted. This attribute is used so that a user agent
2680 never emits this cookie over non-secure channels, which means
2681 that a cookie learned with this flag will be presented only over
2682 SSL/TLS connections. Please check RFC6265 for more information on
2683 this attribute.
2684
Krzysztof Piotr Oledzkiefe3b6f2008-05-23 23:49:32 +02002685 domain This option allows to specify the domain at which a cookie is
Krzysztof Piotr Oledzkif8645332009-12-13 21:55:50 +01002686 inserted. It requires exactly one parameter: a valid domain
Willy Tarreau68a897b2009-12-03 23:28:34 +01002687 name. If the domain begins with a dot, the browser is allowed to
2688 use it for any host ending with that name. It is also possible to
2689 specify several domain names by invoking this option multiple
2690 times. Some browsers might have small limits on the number of
2691 domains, so be careful when doing that. For the record, sending
2692 10 domains to MSIE 6 or Firefox 2 works as expected.
Krzysztof Piotr Oledzkiefe3b6f2008-05-23 23:49:32 +02002693
Willy Tarreau996a92c2010-10-13 19:30:47 +02002694 maxidle This option allows inserted cookies to be ignored after some idle
2695 time. It only works with insert-mode cookies. When a cookie is
2696 sent to the client, the date this cookie was emitted is sent too.
2697 Upon further presentations of this cookie, if the date is older
2698 than the delay indicated by the parameter (in seconds), it will
2699 be ignored. Otherwise, it will be refreshed if needed when the
2700 response is sent to the client. This is particularly useful to
2701 prevent users who never close their browsers from remaining for
2702 too long on the same server (eg: after a farm size change). When
2703 this option is set and a cookie has no date, it is always
2704 accepted, but gets refreshed in the response. This maintains the
2705 ability for admins to access their sites. Cookies that have a
2706 date in the future further than 24 hours are ignored. Doing so
2707 lets admins fix timezone issues without risking kicking users off
2708 the site.
2709
2710 maxlife This option allows inserted cookies to be ignored after some life
2711 time, whether they're in use or not. It only works with insert
2712 mode cookies. When a cookie is first sent to the client, the date
2713 this cookie was emitted is sent too. Upon further presentations
2714 of this cookie, if the date is older than the delay indicated by
2715 the parameter (in seconds), it will be ignored. If the cookie in
2716 the request has no date, it is accepted and a date will be set.
2717 Cookies that have a date in the future further than 24 hours are
2718 ignored. Doing so lets admins fix timezone issues without risking
2719 kicking users off the site. Contrary to maxidle, this value is
2720 not refreshed, only the first visit date counts. Both maxidle and
2721 maxlife may be used at the time. This is particularly useful to
2722 prevent users who never close their browsers from remaining for
2723 too long on the same server (eg: after a farm size change). This
2724 is stronger than the maxidle method in that it forces a
2725 redispatch after some absolute delay.
2726
Willy Tarreau0ba27502007-12-24 16:55:16 +01002727 There can be only one persistence cookie per HTTP backend, and it can be
2728 declared in a defaults section. The value of the cookie will be the value
2729 indicated after the "cookie" keyword in a "server" statement. If no cookie
2730 is declared for a given server, the cookie is not set.
Willy Tarreau6a06a402007-07-15 20:15:28 +02002731
Willy Tarreau0ba27502007-12-24 16:55:16 +01002732 Examples :
2733 cookie JSESSIONID prefix
2734 cookie SRV insert indirect nocache
2735 cookie SRV insert postonly indirect
Willy Tarreau996a92c2010-10-13 19:30:47 +02002736 cookie SRV insert indirect nocache maxidle 30m maxlife 8h
Willy Tarreau0ba27502007-12-24 16:55:16 +01002737
Willy Tarreau294d0f02015-08-10 19:40:12 +02002738 See also : "balance source", "capture cookie", "server" and "ignore-persist".
Willy Tarreau0ba27502007-12-24 16:55:16 +01002739
Willy Tarreau983e01e2010-01-11 18:42:06 +01002740
Thierry FOURNIERa0a1b752015-05-26 17:44:32 +02002741declare capture [ request | response ] len <length>
2742 Declares a capture slot.
2743 May be used in sections : defaults | frontend | listen | backend
2744 no | yes | yes | no
2745 Arguments:
2746 <length> is the length allowed for the capture.
2747
2748 This declaration is only available in the frontend or listen section, but the
2749 reserved slot can be used in the backends. The "request" keyword allocates a
2750 capture slot for use in the request, and "response" allocates a capture slot
2751 for use in the response.
2752
2753 See also: "capture-req", "capture-res" (sample converters),
2754 "http-request capture" and "http-response capture".
2755
2756
Krzysztof Piotr Oledzkic6df0662010-01-05 16:38:49 +01002757default-server [param*]
2758 Change default options for a server in a backend
2759 May be used in sections : defaults | frontend | listen | backend
2760 yes | no | yes | yes
2761 Arguments:
Willy Tarreau983e01e2010-01-11 18:42:06 +01002762 <param*> is a list of parameters for this server. The "default-server"
2763 keyword accepts an important number of options and has a complete
2764 section dedicated to it. Please refer to section 5 for more
2765 details.
Krzysztof Piotr Oledzkic6df0662010-01-05 16:38:49 +01002766
Willy Tarreau983e01e2010-01-11 18:42:06 +01002767 Example :
Krzysztof Piotr Oledzkic6df0662010-01-05 16:38:49 +01002768 default-server inter 1000 weight 13
2769
2770 See also: "server" and section 5 about server options
Willy Tarreau0ba27502007-12-24 16:55:16 +01002771
Willy Tarreau983e01e2010-01-11 18:42:06 +01002772
Willy Tarreau0ba27502007-12-24 16:55:16 +01002773default_backend <backend>
2774 Specify the backend to use when no "use_backend" rule has been matched.
2775 May be used in sections : defaults | frontend | listen | backend
2776 yes | yes | yes | no
2777 Arguments :
2778 <backend> is the name of the backend to use.
2779
2780 When doing content-switching between frontend and backends using the
2781 "use_backend" keyword, it is often useful to indicate which backend will be
2782 used when no rule has matched. It generally is the dynamic backend which
2783 will catch all undetermined requests.
2784
Willy Tarreau0ba27502007-12-24 16:55:16 +01002785 Example :
2786
2787 use_backend dynamic if url_dyn
2788 use_backend static if url_css url_img extension_img
2789 default_backend dynamic
2790
Willy Tarreau98d04852015-05-26 12:18:29 +02002791 See also : "use_backend"
Willy Tarreau2769aa02007-12-27 18:26:09 +01002792
Willy Tarreau0ba27502007-12-24 16:55:16 +01002793
Baptiste Assmann27f51342013-10-09 06:51:49 +02002794description <string>
2795 Describe a listen, frontend or backend.
2796 May be used in sections : defaults | frontend | listen | backend
2797 no | yes | yes | yes
2798 Arguments : string
2799
2800 Allows to add a sentence to describe the related object in the HAProxy HTML
2801 stats page. The description will be printed on the right of the object name
2802 it describes.
2803 No need to backslash spaces in the <string> arguments.
2804
2805
Willy Tarreau0ba27502007-12-24 16:55:16 +01002806disabled
2807 Disable a proxy, frontend or backend.
2808 May be used in sections : defaults | frontend | listen | backend
2809 yes | yes | yes | yes
2810 Arguments : none
2811
2812 The "disabled" keyword is used to disable an instance, mainly in order to
2813 liberate a listening port or to temporarily disable a service. The instance
2814 will still be created and its configuration will be checked, but it will be
2815 created in the "stopped" state and will appear as such in the statistics. It
2816 will not receive any traffic nor will it send any health-checks or logs. It
2817 is possible to disable many instances at once by adding the "disabled"
2818 keyword in a "defaults" section.
2819
2820 See also : "enabled"
2821
2822
Willy Tarreau5ce94572010-06-07 14:35:41 +02002823dispatch <address>:<port>
2824 Set a default server address
2825 May be used in sections : defaults | frontend | listen | backend
2826 no | no | yes | yes
Cyril Bonté108cf6e2012-04-21 23:30:29 +02002827 Arguments :
Willy Tarreau5ce94572010-06-07 14:35:41 +02002828
2829 <address> is the IPv4 address of the default server. Alternatively, a
2830 resolvable hostname is supported, but this name will be resolved
2831 during start-up.
2832
2833 <ports> is a mandatory port specification. All connections will be sent
2834 to this port, and it is not permitted to use port offsets as is
2835 possible with normal servers.
2836
Willy Tarreau787aed52011-04-15 06:45:37 +02002837 The "dispatch" keyword designates a default server for use when no other
Willy Tarreau5ce94572010-06-07 14:35:41 +02002838 server can take the connection. In the past it was used to forward non
2839 persistent connections to an auxiliary load balancer. Due to its simple
2840 syntax, it has also been used for simple TCP relays. It is recommended not to
2841 use it for more clarity, and to use the "server" directive instead.
2842
2843 See also : "server"
2844
2845
Willy Tarreau0ba27502007-12-24 16:55:16 +01002846enabled
2847 Enable a proxy, frontend or backend.
2848 May be used in sections : defaults | frontend | listen | backend
2849 yes | yes | yes | yes
2850 Arguments : none
2851
2852 The "enabled" keyword is used to explicitly enable an instance, when the
2853 defaults has been set to "disabled". This is very rarely used.
2854
2855 See also : "disabled"
2856
2857
2858errorfile <code> <file>
2859 Return a file contents instead of errors generated by HAProxy
2860 May be used in sections : defaults | frontend | listen | backend
2861 yes | yes | yes | yes
2862 Arguments :
2863 <code> is the HTTP status code. Currently, HAProxy is capable of
CJ Ess108b1dd2015-04-07 12:03:37 -04002864 generating codes 200, 400, 403, 405, 408, 429, 500, 502, 503, and
2865 504.
Willy Tarreau0ba27502007-12-24 16:55:16 +01002866
2867 <file> designates a file containing the full HTTP response. It is
Willy Tarreaud2a4aa22008-01-31 15:28:22 +01002868 recommended to follow the common practice of appending ".http" to
Willy Tarreau0ba27502007-12-24 16:55:16 +01002869 the filename so that people do not confuse the response with HTML
Willy Tarreau59140a22009-02-22 12:02:30 +01002870 error pages, and to use absolute paths, since files are read
2871 before any chroot is performed.
Willy Tarreau0ba27502007-12-24 16:55:16 +01002872
2873 It is important to understand that this keyword is not meant to rewrite
2874 errors returned by the server, but errors detected and returned by HAProxy.
2875 This is why the list of supported errors is limited to a small set.
2876
Willy Tarreauae94d4d2011-05-11 16:28:49 +02002877 Code 200 is emitted in response to requests matching a "monitor-uri" rule.
2878
Willy Tarreau0ba27502007-12-24 16:55:16 +01002879 The files are returned verbatim on the TCP socket. This allows any trick such
2880 as redirections to another URL or site, as well as tricks to clean cookies,
2881 force enable or disable caching, etc... The package provides default error
2882 files returning the same contents as default errors.
2883
Willy Tarreau59140a22009-02-22 12:02:30 +01002884 The files should not exceed the configured buffer size (BUFSIZE), which
2885 generally is 8 or 16 kB, otherwise they will be truncated. It is also wise
2886 not to put any reference to local contents (eg: images) in order to avoid
2887 loops between the client and HAProxy when all servers are down, causing an
2888 error to be returned instead of an image. For better HTTP compliance, it is
2889 recommended that all header lines end with CR-LF and not LF alone.
2890
Willy Tarreau0ba27502007-12-24 16:55:16 +01002891 The files are read at the same time as the configuration and kept in memory.
2892 For this reason, the errors continue to be returned even when the process is
2893 chrooted, and no file change is considered while the process is running. A
Willy Tarreauc27debf2008-01-06 08:57:02 +01002894 simple method for developing those files consists in associating them to the
Willy Tarreau0ba27502007-12-24 16:55:16 +01002895 403 status code and interrogating a blocked URL.
2896
2897 See also : "errorloc", "errorloc302", "errorloc303"
2898
Willy Tarreau59140a22009-02-22 12:02:30 +01002899 Example :
2900 errorfile 400 /etc/haproxy/errorfiles/400badreq.http
Willy Tarreau2705a612014-05-23 17:38:34 +02002901 errorfile 408 /dev/null # workaround Chrome pre-connect bug
Willy Tarreau59140a22009-02-22 12:02:30 +01002902 errorfile 403 /etc/haproxy/errorfiles/403forbid.http
2903 errorfile 503 /etc/haproxy/errorfiles/503sorry.http
2904
Willy Tarreau2769aa02007-12-27 18:26:09 +01002905
2906errorloc <code> <url>
2907errorloc302 <code> <url>
2908 Return an HTTP redirection to a URL instead of errors generated by HAProxy
2909 May be used in sections : defaults | frontend | listen | backend
2910 yes | yes | yes | yes
2911 Arguments :
2912 <code> is the HTTP status code. Currently, HAProxy is capable of
Willy Tarreauae94d4d2011-05-11 16:28:49 +02002913 generating codes 200, 400, 403, 408, 500, 502, 503, and 504.
Willy Tarreau2769aa02007-12-27 18:26:09 +01002914
2915 <url> it is the exact contents of the "Location" header. It may contain
2916 either a relative URI to an error page hosted on the same site,
2917 or an absolute URI designating an error page on another site.
2918 Special care should be given to relative URIs to avoid redirect
2919 loops if the URI itself may generate the same error (eg: 500).
2920
2921 It is important to understand that this keyword is not meant to rewrite
2922 errors returned by the server, but errors detected and returned by HAProxy.
2923 This is why the list of supported errors is limited to a small set.
2924
Willy Tarreauae94d4d2011-05-11 16:28:49 +02002925 Code 200 is emitted in response to requests matching a "monitor-uri" rule.
2926
Willy Tarreau2769aa02007-12-27 18:26:09 +01002927 Note that both keyword return the HTTP 302 status code, which tells the
2928 client to fetch the designated URL using the same HTTP method. This can be
2929 quite problematic in case of non-GET methods such as POST, because the URL
2930 sent to the client might not be allowed for something other than GET. To
2931 workaround this problem, please use "errorloc303" which send the HTTP 303
2932 status code, indicating to the client that the URL must be fetched with a GET
2933 request.
2934
2935 See also : "errorfile", "errorloc303"
2936
2937
2938errorloc303 <code> <url>
2939 Return an HTTP redirection to a URL instead of errors generated by HAProxy
2940 May be used in sections : defaults | frontend | listen | backend
2941 yes | yes | yes | yes
2942 Arguments :
2943 <code> is the HTTP status code. Currently, HAProxy is capable of
2944 generating codes 400, 403, 408, 500, 502, 503, and 504.
2945
2946 <url> it is the exact contents of the "Location" header. It may contain
2947 either a relative URI to an error page hosted on the same site,
2948 or an absolute URI designating an error page on another site.
2949 Special care should be given to relative URIs to avoid redirect
2950 loops if the URI itself may generate the same error (eg: 500).
2951
2952 It is important to understand that this keyword is not meant to rewrite
2953 errors returned by the server, but errors detected and returned by HAProxy.
2954 This is why the list of supported errors is limited to a small set.
2955
Willy Tarreauae94d4d2011-05-11 16:28:49 +02002956 Code 200 is emitted in response to requests matching a "monitor-uri" rule.
2957
Willy Tarreau2769aa02007-12-27 18:26:09 +01002958 Note that both keyword return the HTTP 303 status code, which tells the
2959 client to fetch the designated URL using the same HTTP GET method. This
2960 solves the usual problems associated with "errorloc" and the 302 code. It is
2961 possible that some very old browsers designed before HTTP/1.1 do not support
Willy Tarreaud2a4aa22008-01-31 15:28:22 +01002962 it, but no such problem has been reported till now.
Willy Tarreau2769aa02007-12-27 18:26:09 +01002963
2964 See also : "errorfile", "errorloc", "errorloc302"
2965
2966
Simon Horman51a1cf62015-02-03 13:00:44 +09002967email-alert from <emailaddr>
2968 Declare the from email address to be used in both the envelope and header
2969 of email alerts. This is the address that email alerts are sent from.
2970 May be used in sections: defaults | frontend | listen | backend
2971 yes | yes | yes | yes
2972
2973 Arguments :
2974
2975 <emailaddr> is the from email address to use when sending email alerts
2976
2977 Also requires "email-alert mailers" and "email-alert to" to be set
2978 and if so sending email alerts is enabled for the proxy.
2979
Simon Horman64e34162015-02-06 11:11:57 +09002980 See also : "email-alert level", "email-alert mailers",
Cyril Bonté307ee1e2015-09-28 23:16:06 +02002981 "email-alert myhostname", "email-alert to", section 3.6 about
2982 mailers.
Simon Horman64e34162015-02-06 11:11:57 +09002983
2984
2985email-alert level <level>
2986 Declare the maximum log level of messages for which email alerts will be
2987 sent. This acts as a filter on the sending of email alerts.
2988 May be used in sections: defaults | frontend | listen | backend
2989 yes | yes | yes | yes
2990
2991 Arguments :
2992
2993 <level> One of the 8 syslog levels:
2994 emerg alert crit err warning notice info debug
2995 The above syslog levels are ordered from lowest to highest.
2996
2997 By default level is alert
2998
2999 Also requires "email-alert from", "email-alert mailers" and
3000 "email-alert to" to be set and if so sending email alerts is enabled
3001 for the proxy.
3002
Simon Horman1421e212015-04-30 13:10:35 +09003003 Alerts are sent when :
3004
3005 * An un-paused server is marked as down and <level> is alert or lower
3006 * A paused server is marked as down and <level> is notice or lower
3007 * A server is marked as up or enters the drain state and <level>
3008 is notice or lower
3009 * "option log-health-checks" is enabled, <level> is info or lower,
3010 and a health check status update occurs
3011
Simon Horman64e34162015-02-06 11:11:57 +09003012 See also : "email-alert from", "email-alert mailers",
3013 "email-alert myhostname", "email-alert to",
Simon Horman51a1cf62015-02-03 13:00:44 +09003014 section 3.6 about mailers.
3015
3016
3017email-alert mailers <mailersect>
3018 Declare the mailers to be used when sending email alerts
3019 May be used in sections: defaults | frontend | listen | backend
3020 yes | yes | yes | yes
3021
3022 Arguments :
3023
3024 <mailersect> is the name of the mailers section to send email alerts.
3025
3026 Also requires "email-alert from" and "email-alert to" to be set
3027 and if so sending email alerts is enabled for the proxy.
3028
Simon Horman64e34162015-02-06 11:11:57 +09003029 See also : "email-alert from", "email-alert level", "email-alert myhostname",
3030 "email-alert to", section 3.6 about mailers.
Simon Horman51a1cf62015-02-03 13:00:44 +09003031
3032
3033email-alert myhostname <hostname>
3034 Declare the to hostname address to be used when communicating with
3035 mailers.
3036 May be used in sections: defaults | frontend | listen | backend
3037 yes | yes | yes | yes
3038
3039 Arguments :
3040
3041 <emailaddr> is the to email address to use when sending email alerts
3042
3043 By default the systems hostname is used.
3044
3045 Also requires "email-alert from", "email-alert mailers" and
3046 "email-alert to" to be set and if so sending email alerts is enabled
3047 for the proxy.
3048
Simon Horman64e34162015-02-06 11:11:57 +09003049 See also : "email-alert from", "email-alert level", "email-alert mailers",
3050 "email-alert to", section 3.6 about mailers.
Simon Horman51a1cf62015-02-03 13:00:44 +09003051
3052
3053email-alert to <emailaddr>
3054 Declare both the recipent address in the envelope and to address in the
3055 header of email alerts. This is the address that email alerts are sent to.
3056 May be used in sections: defaults | frontend | listen | backend
3057 yes | yes | yes | yes
3058
3059 Arguments :
3060
3061 <emailaddr> is the to email address to use when sending email alerts
3062
3063 Also requires "email-alert mailers" and "email-alert to" to be set
3064 and if so sending email alerts is enabled for the proxy.
3065
Simon Horman64e34162015-02-06 11:11:57 +09003066 See also : "email-alert from", "email-alert level", "email-alert mailers",
Simon Horman51a1cf62015-02-03 13:00:44 +09003067 "email-alert myhostname", section 3.6 about mailers.
3068
3069
Willy Tarreau4de91492010-01-22 19:10:05 +01003070force-persist { if | unless } <condition>
3071 Declare a condition to force persistence on down servers
3072 May be used in sections: defaults | frontend | listen | backend
3073 no | yes | yes | yes
3074
3075 By default, requests are not dispatched to down servers. It is possible to
3076 force this using "option persist", but it is unconditional and redispatches
3077 to a valid server if "option redispatch" is set. That leaves with very little
3078 possibilities to force some requests to reach a server which is artificially
3079 marked down for maintenance operations.
3080
3081 The "force-persist" statement allows one to declare various ACL-based
3082 conditions which, when met, will cause a request to ignore the down status of
3083 a server and still try to connect to it. That makes it possible to start a
3084 server, still replying an error to the health checks, and run a specially
3085 configured browser to test the service. Among the handy methods, one could
3086 use a specific source IP address, or a specific cookie. The cookie also has
3087 the advantage that it can easily be added/removed on the browser from a test
3088 page. Once the service is validated, it is then possible to open the service
3089 to the world by returning a valid response to health checks.
3090
3091 The forced persistence is enabled when an "if" condition is met, or unless an
3092 "unless" condition is met. The final redispatch is always disabled when this
3093 is used.
3094
Cyril Bonté0d4bf012010-04-25 23:21:46 +02003095 See also : "option redispatch", "ignore-persist", "persist",
Cyril Bontéa8e7bbc2010-04-25 22:29:29 +02003096 and section 7 about ACL usage.
Willy Tarreau4de91492010-01-22 19:10:05 +01003097
3098
Willy Tarreau2769aa02007-12-27 18:26:09 +01003099fullconn <conns>
3100 Specify at what backend load the servers will reach their maxconn
3101 May be used in sections : defaults | frontend | listen | backend
3102 yes | no | yes | yes
3103 Arguments :
3104 <conns> is the number of connections on the backend which will make the
3105 servers use the maximal number of connections.
3106
Willy Tarreau198a7442008-01-17 12:05:32 +01003107 When a server has a "maxconn" parameter specified, it means that its number
Willy Tarreau2769aa02007-12-27 18:26:09 +01003108 of concurrent connections will never go higher. Additionally, if it has a
Willy Tarreau198a7442008-01-17 12:05:32 +01003109 "minconn" parameter, it indicates a dynamic limit following the backend's
Willy Tarreau2769aa02007-12-27 18:26:09 +01003110 load. The server will then always accept at least <minconn> connections,
3111 never more than <maxconn>, and the limit will be on the ramp between both
3112 values when the backend has less than <conns> concurrent connections. This
3113 makes it possible to limit the load on the servers during normal loads, but
3114 push it further for important loads without overloading the servers during
Krzysztof Piotr Oledzkif8645332009-12-13 21:55:50 +01003115 exceptional loads.
Willy Tarreau2769aa02007-12-27 18:26:09 +01003116
Willy Tarreaufbb78422011-06-05 15:38:35 +02003117 Since it's hard to get this value right, haproxy automatically sets it to
3118 10% of the sum of the maxconns of all frontends that may branch to this
Bertrand Jacquin702d44f2013-11-19 11:43:06 +01003119 backend (based on "use_backend" and "default_backend" rules). That way it's
3120 safe to leave it unset. However, "use_backend" involving dynamic names are
3121 not counted since there is no way to know if they could match or not.
Willy Tarreaufbb78422011-06-05 15:38:35 +02003122
Willy Tarreau2769aa02007-12-27 18:26:09 +01003123 Example :
3124 # The servers will accept between 100 and 1000 concurrent connections each
3125 # and the maximum of 1000 will be reached when the backend reaches 10000
3126 # connections.
3127 backend dynamic
3128 fullconn 10000
3129 server srv1 dyn1:80 minconn 100 maxconn 1000
3130 server srv2 dyn2:80 minconn 100 maxconn 1000
3131
3132 See also : "maxconn", "server"
3133
3134
3135grace <time>
3136 Maintain a proxy operational for some time after a soft stop
3137 May be used in sections : defaults | frontend | listen | backend
Cyril Bonté99ed3272010-01-24 23:29:44 +01003138 yes | yes | yes | yes
Willy Tarreau2769aa02007-12-27 18:26:09 +01003139 Arguments :
3140 <time> is the time (by default in milliseconds) for which the instance
3141 will remain operational with the frontend sockets still listening
3142 when a soft-stop is received via the SIGUSR1 signal.
3143
3144 This may be used to ensure that the services disappear in a certain order.
3145 This was designed so that frontends which are dedicated to monitoring by an
Krzysztof Piotr Oledzkif8645332009-12-13 21:55:50 +01003146 external equipment fail immediately while other ones remain up for the time
Willy Tarreau2769aa02007-12-27 18:26:09 +01003147 needed by the equipment to detect the failure.
3148
3149 Note that currently, there is very little benefit in using this parameter,
3150 and it may in fact complicate the soft-reconfiguration process more than
3151 simplify it.
3152
Willy Tarreau0ba27502007-12-24 16:55:16 +01003153
Bhaskar Maddalab6c0ac92013-11-05 11:54:02 -05003154hash-type <method> <function> <modifier>
Willy Tarreau6b2e11b2009-10-01 07:52:15 +02003155 Specify a method to use for mapping hashes to servers
3156 May be used in sections : defaults | frontend | listen | backend
3157 yes | no | yes | yes
3158 Arguments :
Bhaskar98634f02013-10-29 23:30:51 -04003159 <method> is the method used to select a server from the hash computed by
3160 the <function> :
Willy Tarreau6b2e11b2009-10-01 07:52:15 +02003161
Bhaskar98634f02013-10-29 23:30:51 -04003162 map-based the hash table is a static array containing all alive servers.
3163 The hashes will be very smooth, will consider weights, but
3164 will be static in that weight changes while a server is up
3165 will be ignored. This means that there will be no slow start.
3166 Also, since a server is selected by its position in the array,
3167 most mappings are changed when the server count changes. This
3168 means that when a server goes up or down, or when a server is
3169 added to a farm, most connections will be redistributed to
3170 different servers. This can be inconvenient with caches for
3171 instance.
Willy Tarreau798a39c2010-11-24 15:04:29 +01003172
Bhaskar98634f02013-10-29 23:30:51 -04003173 consistent the hash table is a tree filled with many occurrences of each
3174 server. The hash key is looked up in the tree and the closest
3175 server is chosen. This hash is dynamic, it supports changing
3176 weights while the servers are up, so it is compatible with the
3177 slow start feature. It has the advantage that when a server
3178 goes up or down, only its associations are moved. When a
3179 server is added to the farm, only a few part of the mappings
3180 are redistributed, making it an ideal method for caches.
3181 However, due to its principle, the distribution will never be
3182 very smooth and it may sometimes be necessary to adjust a
3183 server's weight or its ID to get a more balanced distribution.
3184 In order to get the same distribution on multiple load
3185 balancers, it is important that all servers have the exact
Bhaskar Maddalab6c0ac92013-11-05 11:54:02 -05003186 same IDs. Note: consistent hash uses sdbm and avalanche if no
3187 hash function is specified.
Bhaskar98634f02013-10-29 23:30:51 -04003188
3189 <function> is the hash function to be used :
3190
Jarno Huuskonen0e82b922014-04-12 18:22:19 +03003191 sdbm this function was created initially for sdbm (a public-domain
Bhaskar98634f02013-10-29 23:30:51 -04003192 reimplementation of ndbm) database library. It was found to do
3193 well in scrambling bits, causing better distribution of the keys
3194 and fewer splits. It also happens to be a good general hashing
Bhaskar Maddalab6c0ac92013-11-05 11:54:02 -05003195 function with good distribution, unless the total server weight
3196 is a multiple of 64, in which case applying the avalanche
3197 modifier may help.
Bhaskar98634f02013-10-29 23:30:51 -04003198
3199 djb2 this function was first proposed by Dan Bernstein many years ago
3200 on comp.lang.c. Studies have shown that for certain workload this
Bhaskar Maddalab6c0ac92013-11-05 11:54:02 -05003201 function provides a better distribution than sdbm. It generally
3202 works well with text-based inputs though it can perform extremely
3203 poorly with numeric-only input or when the total server weight is
3204 a multiple of 33, unless the avalanche modifier is also used.
3205
Willy Tarreaua0f42712013-11-14 14:30:35 +01003206 wt6 this function was designed for haproxy while testing other
3207 functions in the past. It is not as smooth as the other ones, but
3208 is much less sensible to the input data set or to the number of
3209 servers. It can make sense as an alternative to sdbm+avalanche or
3210 djb2+avalanche for consistent hashing or when hashing on numeric
3211 data such as a source IP address or a visitor identifier in a URL
3212 parameter.
3213
Willy Tarreau324f07f2015-01-20 19:44:50 +01003214 crc32 this is the most common CRC32 implementation as used in Ethernet,
3215 gzip, PNG, etc. It is slower than the other ones but may provide
3216 a better distribution or less predictable results especially when
3217 used on strings.
3218
Bhaskar Maddalab6c0ac92013-11-05 11:54:02 -05003219 <modifier> indicates an optional method applied after hashing the key :
3220
3221 avalanche This directive indicates that the result from the hash
3222 function above should not be used in its raw form but that
3223 a 4-byte full avalanche hash must be applied first. The
3224 purpose of this step is to mix the resulting bits from the
3225 previous hash in order to avoid any undesired effect when
3226 the input contains some limited values or when the number of
3227 servers is a multiple of one of the hash's components (64
3228 for SDBM, 33 for DJB2). Enabling avalanche tends to make the
3229 result less predictable, but it's also not as smooth as when
3230 using the original function. Some testing might be needed
3231 with some workloads. This hash is one of the many proposed
3232 by Bob Jenkins.
Willy Tarreau6b2e11b2009-10-01 07:52:15 +02003233
Bhaskar98634f02013-10-29 23:30:51 -04003234 The default hash type is "map-based" and is recommended for most usages. The
3235 default function is "sdbm", the selection of a function should be based on
3236 the range of the values being hashed.
Willy Tarreau6b2e11b2009-10-01 07:52:15 +02003237
3238 See also : "balance", "server"
3239
3240
Willy Tarreau0ba27502007-12-24 16:55:16 +01003241http-check disable-on-404
3242 Enable a maintenance mode upon HTTP/404 response to health-checks
3243 May be used in sections : defaults | frontend | listen | backend
Willy Tarreau2769aa02007-12-27 18:26:09 +01003244 yes | no | yes | yes
Willy Tarreau0ba27502007-12-24 16:55:16 +01003245 Arguments : none
3246
3247 When this option is set, a server which returns an HTTP code 404 will be
3248 excluded from further load-balancing, but will still receive persistent
3249 connections. This provides a very convenient method for Web administrators
3250 to perform a graceful shutdown of their servers. It is also important to note
3251 that a server which is detected as failed while it was in this mode will not
3252 generate an alert, just a notice. If the server responds 2xx or 3xx again, it
3253 will immediately be reinserted into the farm. The status on the stats page
3254 reports "NOLB" for a server in this mode. It is important to note that this
Willy Tarreaubd741542010-03-16 18:46:54 +01003255 option only works in conjunction with the "httpchk" option. If this option
3256 is used with "http-check expect", then it has precedence over it so that 404
3257 responses will still be considered as soft-stop.
3258
3259 See also : "option httpchk", "http-check expect"
3260
3261
3262http-check expect [!] <match> <pattern>
Jamie Gloudonaaa21002012-08-25 00:18:33 -04003263 Make HTTP health checks consider response contents or specific status codes
Willy Tarreaubd741542010-03-16 18:46:54 +01003264 May be used in sections : defaults | frontend | listen | backend
Willy Tarreau1ee51a62011-08-19 20:04:17 +02003265 yes | no | yes | yes
Willy Tarreaubd741542010-03-16 18:46:54 +01003266 Arguments :
3267 <match> is a keyword indicating how to look for a specific pattern in the
3268 response. The keyword may be one of "status", "rstatus",
Jamie Gloudonaaa21002012-08-25 00:18:33 -04003269 "string", or "rstring". The keyword may be preceded by an
Willy Tarreaubd741542010-03-16 18:46:54 +01003270 exclamation mark ("!") to negate the match. Spaces are allowed
3271 between the exclamation mark and the keyword. See below for more
3272 details on the supported keywords.
3273
3274 <pattern> is the pattern to look for. It may be a string or a regular
3275 expression. If the pattern contains spaces, they must be escaped
3276 with the usual backslash ('\').
3277
3278 By default, "option httpchk" considers that response statuses 2xx and 3xx
3279 are valid, and that others are invalid. When "http-check expect" is used,
3280 it defines what is considered valid or invalid. Only one "http-check"
3281 statement is supported in a backend. If a server fails to respond or times
3282 out, the check obviously fails. The available matches are :
3283
3284 status <string> : test the exact string match for the HTTP status code.
Jamie Gloudonaaa21002012-08-25 00:18:33 -04003285 A health check response will be considered valid if the
Willy Tarreaubd741542010-03-16 18:46:54 +01003286 response's status code is exactly this string. If the
3287 "status" keyword is prefixed with "!", then the response
3288 will be considered invalid if the status code matches.
3289
3290 rstatus <regex> : test a regular expression for the HTTP status code.
Jamie Gloudonaaa21002012-08-25 00:18:33 -04003291 A health check response will be considered valid if the
Willy Tarreaubd741542010-03-16 18:46:54 +01003292 response's status code matches the expression. If the
3293 "rstatus" keyword is prefixed with "!", then the response
3294 will be considered invalid if the status code matches.
3295 This is mostly used to check for multiple codes.
3296
3297 string <string> : test the exact string match in the HTTP response body.
Jamie Gloudonaaa21002012-08-25 00:18:33 -04003298 A health check response will be considered valid if the
Willy Tarreaubd741542010-03-16 18:46:54 +01003299 response's body contains this exact string. If the
3300 "string" keyword is prefixed with "!", then the response
3301 will be considered invalid if the body contains this
3302 string. This can be used to look for a mandatory word at
3303 the end of a dynamic page, or to detect a failure when a
3304 specific error appears on the check page (eg: a stack
3305 trace).
3306
3307 rstring <regex> : test a regular expression on the HTTP response body.
Jamie Gloudonaaa21002012-08-25 00:18:33 -04003308 A health check response will be considered valid if the
Willy Tarreaubd741542010-03-16 18:46:54 +01003309 response's body matches this expression. If the "rstring"
3310 keyword is prefixed with "!", then the response will be
3311 considered invalid if the body matches the expression.
3312 This can be used to look for a mandatory word at the end
3313 of a dynamic page, or to detect a failure when a specific
3314 error appears on the check page (eg: a stack trace).
3315
3316 It is important to note that the responses will be limited to a certain size
3317 defined by the global "tune.chksize" option, which defaults to 16384 bytes.
3318 Thus, too large responses may not contain the mandatory pattern when using
3319 "string" or "rstring". If a large response is absolutely required, it is
3320 possible to change the default max size by setting the global variable.
3321 However, it is worth keeping in mind that parsing very large responses can
3322 waste some CPU cycles, especially when regular expressions are used, and that
3323 it is always better to focus the checks on smaller resources.
3324
Cyril Bonté32602d22015-01-30 00:07:07 +01003325 Also "http-check expect" doesn't support HTTP keep-alive. Keep in mind that it
3326 will automatically append a "Connection: close" header, meaning that this
3327 header should not be present in the request provided by "option httpchk".
3328
Willy Tarreaubd741542010-03-16 18:46:54 +01003329 Last, if "http-check expect" is combined with "http-check disable-on-404",
3330 then this last one has precedence when the server responds with 404.
3331
3332 Examples :
3333 # only accept status 200 as valid
Willy Tarreau8f2a1e72011-01-06 16:36:10 +01003334 http-check expect status 200
Willy Tarreaubd741542010-03-16 18:46:54 +01003335
3336 # consider SQL errors as errors
Willy Tarreau8f2a1e72011-01-06 16:36:10 +01003337 http-check expect ! string SQL\ Error
Willy Tarreaubd741542010-03-16 18:46:54 +01003338
3339 # consider status 5xx only as errors
Willy Tarreau8f2a1e72011-01-06 16:36:10 +01003340 http-check expect ! rstatus ^5
Willy Tarreaubd741542010-03-16 18:46:54 +01003341
3342 # check that we have a correct hexadecimal tag before /html
Willy Tarreau8f2a1e72011-01-06 16:36:10 +01003343 http-check expect rstring <!--tag:[0-9a-f]*</html>
Willy Tarreau0ba27502007-12-24 16:55:16 +01003344
Willy Tarreaubd741542010-03-16 18:46:54 +01003345 See also : "option httpchk", "http-check disable-on-404"
Willy Tarreau2769aa02007-12-27 18:26:09 +01003346
3347
Willy Tarreauef781042010-01-27 11:53:01 +01003348http-check send-state
3349 Enable emission of a state header with HTTP health checks
3350 May be used in sections : defaults | frontend | listen | backend
3351 yes | no | yes | yes
3352 Arguments : none
3353
3354 When this option is set, haproxy will systematically send a special header
3355 "X-Haproxy-Server-State" with a list of parameters indicating to each server
3356 how they are seen by haproxy. This can be used for instance when a server is
3357 manipulated without access to haproxy and the operator needs to know whether
3358 haproxy still sees it up or not, or if the server is the last one in a farm.
3359
3360 The header is composed of fields delimited by semi-colons, the first of which
3361 is a word ("UP", "DOWN", "NOLB"), possibly followed by a number of valid
3362 checks on the total number before transition, just as appears in the stats
3363 interface. Next headers are in the form "<variable>=<value>", indicating in
3364 no specific order some values available in the stats interface :
Joseph Lynch514061c2015-01-15 17:52:59 -08003365 - a variable "address", containing the address of the backend server.
3366 This corresponds to the <address> field in the server declaration. For
3367 unix domain sockets, it will read "unix".
3368
3369 - a variable "port", containing the port of the backend server. This
3370 corresponds to the <port> field in the server declaration. For unix
3371 domain sockets, it will read "unix".
3372
Willy Tarreauef781042010-01-27 11:53:01 +01003373 - a variable "name", containing the name of the backend followed by a slash
3374 ("/") then the name of the server. This can be used when a server is
3375 checked in multiple backends.
3376
3377 - a variable "node" containing the name of the haproxy node, as set in the
3378 global "node" variable, otherwise the system's hostname if unspecified.
3379
3380 - a variable "weight" indicating the weight of the server, a slash ("/")
3381 and the total weight of the farm (just counting usable servers). This
3382 helps to know if other servers are available to handle the load when this
3383 one fails.
3384
3385 - a variable "scur" indicating the current number of concurrent connections
3386 on the server, followed by a slash ("/") then the total number of
3387 connections on all servers of the same backend.
3388
3389 - a variable "qcur" indicating the current number of requests in the
3390 server's queue.
3391
3392 Example of a header received by the application server :
3393 >>> X-Haproxy-Server-State: UP 2/3; name=bck/srv2; node=lb1; weight=1/2; \
3394 scur=13/22; qcur=0
3395
3396 See also : "option httpchk", "http-check disable-on-404"
3397
Willy Tarreauccbcc372012-12-27 12:37:57 +01003398http-request { allow | deny | tarpit | auth [realm <realm>] | redirect <rule> |
Willy Tarreauf4c43c12013-06-11 17:01:13 +02003399 add-header <name> <fmt> | set-header <name> <fmt> |
Thierry FOURNIER82bf70d2015-05-26 17:58:29 +02003400 capture <sample> [ len <length> | id <id> ] |
Thierry FOURNIERdad3d1d2014-04-22 18:07:25 +02003401 del-header <name> | set-nice <nice> | set-log-level <level> |
Sasha Pachev218f0642014-06-16 12:05:59 -06003402 replace-header <name> <match-regex> <replace-fmt> |
3403 replace-value <name> <match-regex> <replace-fmt> |
Willy Tarreaua0dc23f2015-01-22 20:46:11 +01003404 set-method <fmt> | set-path <fmt> | set-query <fmt> |
3405 set-uri <fmt> | set-tos <tos> | set-mark <mark> |
Baptiste Assmannfabcbe02014-04-24 22:16:59 +02003406 add-acl(<file name>) <key fmt> |
3407 del-acl(<file name>) <key fmt> |
3408 del-map(<file name>) <key fmt> |
Baptiste Assmannbb7e86a2014-09-03 18:29:47 +02003409 set-map(<file name>) <key fmt> <value fmt> |
Thierry FOURNIER4834bc72015-06-06 19:29:07 +02003410 set-var(<var name>) <expr> |
Thierry FOURNIER90da1912015-03-05 11:17:06 +01003411 { track-sc0 | track-sc1 | track-sc2 } <key> [table <table>] |
Thierry FOURNIERe0627bd2015-08-04 08:20:33 +02003412 sc-inc-gpc0(<sc-id>) |
Thierry FOURNIER236657b2015-08-19 08:25:14 +02003413 sc-set-gpt0(<sc-id>) <int> |
Willy Tarreau2d392c22015-08-24 01:43:45 +02003414 silent-drop |
Thierry FOURNIER90da1912015-03-05 11:17:06 +01003415 lua <function name>
Baptiste Assmannfabcbe02014-04-24 22:16:59 +02003416 }
Cyril Bontéf0c60612010-02-06 14:44:47 +01003417 [ { if | unless } <condition> ]
Krzysztof Piotr Oledzki6b35ce12010-02-01 23:35:44 +01003418 Access control for Layer 7 requests
3419
3420 May be used in sections: defaults | frontend | listen | backend
3421 no | yes | yes | yes
3422
Willy Tarreau20b0de52012-12-24 15:45:22 +01003423 The http-request statement defines a set of rules which apply to layer 7
3424 processing. The rules are evaluated in their declaration order when they are
3425 met in a frontend, listen or backend section. Any rule may optionally be
3426 followed by an ACL-based condition, in which case it will only be evaluated
3427 if the condition is true.
Krzysztof Piotr Oledzki6b35ce12010-02-01 23:35:44 +01003428
Willy Tarreau20b0de52012-12-24 15:45:22 +01003429 The first keyword is the rule's action. Currently supported actions include :
3430 - "allow" : this stops the evaluation of the rules and lets the request
3431 pass the check. No further "http-request" rules are evaluated.
3432
3433 - "deny" : this stops the evaluation of the rules and immediately rejects
3434 the request and emits an HTTP 403 error. No further "http-request" rules
3435 are evaluated.
3436
Willy Tarreauccbcc372012-12-27 12:37:57 +01003437 - "tarpit" : this stops the evaluation of the rules and immediately blocks
3438 the request without responding for a delay specified by "timeout tarpit"
3439 or "timeout connect" if the former is not set. After that delay, if the
3440 client is still connected, an HTTP error 500 is returned so that the
3441 client does not suspect it has been tarpitted. Logs will report the flags
3442 "PT". The goal of the tarpit rule is to slow down robots during an attack
3443 when they're limited on the number of concurrent requests. It can be very
3444 efficient against very dumb robots, and will significantly reduce the
3445 load on firewalls compared to a "deny" rule. But when facing "correctly"
Jarno Huuskonen0e82b922014-04-12 18:22:19 +03003446 developed robots, it can make things worse by forcing haproxy and the
Willy Tarreau2d392c22015-08-24 01:43:45 +02003447 front firewall to support insane number of concurrent connections. See
3448 also the "silent-drop" action below.
Willy Tarreauccbcc372012-12-27 12:37:57 +01003449
Willy Tarreau20b0de52012-12-24 15:45:22 +01003450 - "auth" : this stops the evaluation of the rules and immediately responds
3451 with an HTTP 401 or 407 error code to invite the user to present a valid
3452 user name and password. No further "http-request" rules are evaluated. An
3453 optional "realm" parameter is supported, it sets the authentication realm
3454 that is returned with the response (typically the application's name).
3455
Willy Tarreau81499eb2012-12-27 12:19:02 +01003456 - "redirect" : this performs an HTTP redirection based on a redirect rule.
3457 This is exactly the same as the "redirect" statement except that it
3458 inserts a redirect rule which can be processed in the middle of other
Thierry FOURNIERd18cd0f2013-11-29 12:15:45 +01003459 "http-request" rules and that these rules use the "log-format" strings.
3460 See the "redirect" keyword for the rule's syntax.
Willy Tarreau81499eb2012-12-27 12:19:02 +01003461
Willy Tarreau20b0de52012-12-24 15:45:22 +01003462 - "add-header" appends an HTTP header field whose name is specified in
3463 <name> and whose value is defined by <fmt> which follows the log-format
3464 rules (see Custom Log Format in section 8.2.4). This is particularly
3465 useful to pass connection-specific information to the server (eg: the
3466 client's SSL certificate), or to combine several headers into one. This
3467 rule is not final, so it is possible to add other similar rules. Note
3468 that header addition is performed immediately, so one rule might reuse
3469 the resulting header from a previous rule.
3470
3471 - "set-header" does the same as "add-header" except that the header name
3472 is first removed if it existed. This is useful when passing security
3473 information to the server, where the header must not be manipulated by
Willy Tarreau85603282015-01-21 20:39:27 +01003474 external users. Note that the new value is computed before the removal so
3475 it is possible to concatenate a value to an existing header.
Willy Tarreau20b0de52012-12-24 15:45:22 +01003476
Thierry FOURNIERdad3d1d2014-04-22 18:07:25 +02003477 - "del-header" removes all HTTP header fields whose name is specified in
3478 <name>.
3479
Sasha Pachev218f0642014-06-16 12:05:59 -06003480 - "replace-header" matches the regular expression in all occurrences of
3481 header field <name> according to <match-regex>, and replaces them with
3482 the <replace-fmt> argument. Format characters are allowed in replace-fmt
3483 and work like in <fmt> arguments in "add-header". The match is only
3484 case-sensitive. It is important to understand that this action only
3485 considers whole header lines, regardless of the number of values they
3486 may contain. This usage is suited to headers naturally containing commas
3487 in their value, such as If-Modified-Since and so on.
3488
3489 Example:
3490
3491 http-request replace-header Cookie foo=([^;]*);(.*) foo=\1;ip=%bi;\2
3492
3493 applied to:
3494
3495 Cookie: foo=foobar; expires=Tue, 14-Jun-2016 01:40:45 GMT;
3496
3497 outputs:
3498
3499 Cookie: foo=foobar;ip=192.168.1.20; expires=Tue, 14-Jun-2016 01:40:45 GMT;
3500
3501 assuming the backend IP is 192.168.1.20
3502
3503 - "replace-value" works like "replace-header" except that it matches the
3504 regex against every comma-delimited value of the header field <name>
3505 instead of the entire header. This is suited for all headers which are
3506 allowed to carry more than one value. An example could be the Accept
3507 header.
3508
3509 Example:
3510
3511 http-request replace-value X-Forwarded-For ^192\.168\.(.*)$ 172.16.\1
3512
3513 applied to:
3514
3515 X-Forwarded-For: 192.168.10.1, 192.168.13.24, 10.0.0.37
3516
3517 outputs:
3518
3519 X-Forwarded-For: 172.16.10.1, 172.16.13.24, 10.0.0.37
3520
Willy Tarreaua0dc23f2015-01-22 20:46:11 +01003521 - "set-method" rewrites the request method with the result of the
3522 evaluation of format string <fmt>. There should be very few valid reasons
3523 for having to do so as this is more likely to break something than to fix
3524 it.
3525
3526 - "set-path" rewrites the request path with the result of the evaluation of
3527 format string <fmt>. The query string, if any, is left intact. If a
3528 scheme and authority is found before the path, they are left intact as
3529 well. If the request doesn't have a path ("*"), this one is replaced with
3530 the format. This can be used to prepend a directory component in front of
3531 a path for example. See also "set-query" and "set-uri".
3532
3533 Example :
3534 # prepend the host name before the path
3535 http-request set-path /%[hdr(host)]%[path]
3536
3537 - "set-query" rewrites the request's query string which appears after the
3538 first question mark ("?") with the result of the evaluation of format
3539 string <fmt>. The part prior to the question mark is left intact. If the
3540 request doesn't contain a question mark and the new value is not empty,
3541 then one is added at the end of the URI, followed by the new value. If
3542 a question mark was present, it will never be removed even if the value
3543 is empty. This can be used to add or remove parameters from the query
3544 string. See also "set-query" and "set-uri".
3545
3546 Example :
3547 # replace "%3D" with "=" in the query string
3548 http-request set-query %[query,regsub(%3D,=,g)]
3549
3550 - "set-uri" rewrites the request URI with the result of the evaluation of
3551 format string <fmt>. The scheme, authority, path and query string are all
3552 replaced at once. This can be used to rewrite hosts in front of proxies,
3553 or to perform complex modifications to the URI such as moving parts
3554 between the path and the query string. See also "set-path" and
3555 "set-query".
3556
Willy Tarreauf4c43c12013-06-11 17:01:13 +02003557 - "set-nice" sets the "nice" factor of the current request being processed.
3558 It only has effect against the other requests being processed at the same
3559 time. The default value is 0, unless altered by the "nice" setting on the
3560 "bind" line. The accepted range is -1024..1024. The higher the value, the
3561 nicest the request will be. Lower values will make the request more
3562 important than other ones. This can be useful to improve the speed of
3563 some requests, or lower the priority of non-important requests. Using
3564 this setting without prior experimentation can cause some major slowdown.
3565
Willy Tarreau9a355ec2013-06-11 17:45:46 +02003566 - "set-log-level" is used to change the log level of the current request
3567 when a certain condition is met. Valid levels are the 8 syslog levels
3568 (see the "log" keyword) plus the special level "silent" which disables
3569 logging for this request. This rule is not final so the last matching
3570 rule wins. This rule can be useful to disable health checks coming from
3571 another equipment.
3572
Willy Tarreau42cf39e2013-06-11 18:51:32 +02003573 - "set-tos" is used to set the TOS or DSCP field value of packets sent to
3574 the client to the value passed in <tos> on platforms which support this.
3575 This value represents the whole 8 bits of the IP TOS field, and can be
3576 expressed both in decimal or hexadecimal format (prefixed by "0x"). Note
3577 that only the 6 higher bits are used in DSCP or TOS, and the two lower
3578 bits are always 0. This can be used to adjust some routing behaviour on
3579 border routers based on some information from the request. See RFC 2474,
3580 2597, 3260 and 4594 for more information.
3581
Willy Tarreau51347ed2013-06-11 19:34:13 +02003582 - "set-mark" is used to set the Netfilter MARK on all packets sent to the
3583 client to the value passed in <mark> on platforms which support it. This
3584 value is an unsigned 32 bit value which can be matched by netfilter and
3585 by the routing table. It can be expressed both in decimal or hexadecimal
3586 format (prefixed by "0x"). This can be useful to force certain packets to
3587 take a different route (for example a cheaper network path for bulk
3588 downloads). This works on Linux kernels 2.6.32 and above and requires
3589 admin privileges.
3590
Baptiste Assmannfabcbe02014-04-24 22:16:59 +02003591 - "add-acl" is used to add a new entry into an ACL. The ACL must be loaded
3592 from a file (even a dummy empty file). The file name of the ACL to be
3593 updated is passed between parentheses. It takes one argument: <key fmt>,
3594 which follows log-format rules, to collect content of the new entry. It
3595 performs a lookup in the ACL before insertion, to avoid duplicated (or
3596 more) values. This lookup is done by a linear search and can be expensive
3597 with large lists! It is the equivalent of the "add acl" command from the
3598 stats socket, but can be triggered by an HTTP request.
3599
3600 - "del-acl" is used to delete an entry from an ACL. The ACL must be loaded
3601 from a file (even a dummy empty file). The file name of the ACL to be
3602 updated is passed between parentheses. It takes one argument: <key fmt>,
3603 which follows log-format rules, to collect content of the entry to delete.
3604 It is the equivalent of the "del acl" command from the stats socket, but
3605 can be triggered by an HTTP request.
3606
3607 - "del-map" is used to delete an entry from a MAP. The MAP must be loaded
3608 from a file (even a dummy empty file). The file name of the MAP to be
3609 updated is passed between parentheses. It takes one argument: <key fmt>,
3610 which follows log-format rules, to collect content of the entry to delete.
3611 It takes one argument: "file name" It is the equivalent of the "del map"
3612 command from the stats socket, but can be triggered by an HTTP request.
3613
3614 - "set-map" is used to add a new entry into a MAP. The MAP must be loaded
3615 from a file (even a dummy empty file). The file name of the MAP to be
3616 updated is passed between parentheses. It takes 2 arguments: <key fmt>,
3617 which follows log-format rules, used to collect MAP key, and <value fmt>,
3618 which follows log-format rules, used to collect content for the new entry.
3619 It performs a lookup in the MAP before insertion, to avoid duplicated (or
3620 more) values. This lookup is done by a linear search and can be expensive
3621 with large lists! It is the equivalent of the "set map" command from the
3622 stats socket, but can be triggered by an HTTP request.
3623
Thierry FOURNIER82bf70d2015-05-26 17:58:29 +02003624 - capture <sample> [ len <length> | id <id> ] :
Willy Tarreaua9083d02015-05-08 15:27:59 +02003625 captures sample expression <sample> from the request buffer, and converts
3626 it to a string of at most <len> characters. The resulting string is
3627 stored into the next request "capture" slot, so it will possibly appear
3628 next to some captured HTTP headers. It will then automatically appear in
3629 the logs, and it will be possible to extract it using sample fetch rules
3630 to feed it into headers or anything. The length should be limited given
3631 that this size will be allocated for each capture during the whole
3632 session life. Please check section 7.3 (Fetching samples) and "capture
3633 request header" for more information.
3634
Thierry FOURNIER82bf70d2015-05-26 17:58:29 +02003635 If the keyword "id" is used instead of "len", the action tries to store
3636 the captured string in a previously declared capture slot. This is useful
3637 to run captures in backends. The slot id can be declared by a previous
3638 directive "http-request capture" or with the "declare capture" keyword.
3639
Willy Tarreau09448f72014-06-25 18:12:15 +02003640 - { track-sc0 | track-sc1 | track-sc2 } <key> [table <table>] :
3641 enables tracking of sticky counters from current request. These rules
3642 do not stop evaluation and do not change default action. Three sets of
3643 counters may be simultaneously tracked by the same connection. The first
3644 "track-sc0" rule executed enables tracking of the counters of the
3645 specified table as the first set. The first "track-sc1" rule executed
3646 enables tracking of the counters of the specified table as the second
3647 set. The first "track-sc2" rule executed enables tracking of the
3648 counters of the specified table as the third set. It is a recommended
3649 practice to use the first set of counters for the per-frontend counters
3650 and the second set for the per-backend ones. But this is just a
3651 guideline, all may be used everywhere.
3652
3653 These actions take one or two arguments :
3654 <key> is mandatory, and is a sample expression rule as described
3655 in section 7.3. It describes what elements of the incoming
3656 request or connection will be analysed, extracted, combined,
3657 and used to select which table entry to update the counters.
3658
3659 <table> is an optional table to be used instead of the default one,
3660 which is the stick-table declared in the current proxy. All
3661 the counters for the matches and updates for the key will
3662 then be performed in that table until the session ends.
3663
3664 Once a "track-sc*" rule is executed, the key is looked up in the table
3665 and if it is not found, an entry is allocated for it. Then a pointer to
3666 that entry is kept during all the session's life, and this entry's
3667 counters are updated as often as possible, every time the session's
3668 counters are updated, and also systematically when the session ends.
3669 Counters are only updated for events that happen after the tracking has
3670 been started. As an exception, connection counters and request counters
3671 are systematically updated so that they reflect useful information.
3672
3673 If the entry tracks concurrent connection counters, one connection is
3674 counted for as long as the entry is tracked, and the entry will not
3675 expire during that time. Tracking counters also provides a performance
3676 advantage over just checking the keys, because only one table lookup is
3677 performed for all ACL checks that make use of it.
3678
Thierry FOURNIER236657b2015-08-19 08:25:14 +02003679 - sc-set-gpt0(<sc-id>) <int> :
3680 This action sets the GPT0 tag according to the sticky counter designated
3681 by <sc-id> and the value of <int>. The expected result is a boolean. If
3682 an error occurs, this action silently fails and the actions evaluation
3683 continues.
3684
Thierry FOURNIERe0627bd2015-08-04 08:20:33 +02003685 - sc-inc-gpc0(<sc-id>):
3686 This action increments the GPC0 counter according with the sticky counter
3687 designated by <sc-id>. If an error occurs, this action silently fails and
3688 the actions evaluation continues.
3689
Thierry FOURNIER90da1912015-03-05 11:17:06 +01003690 - "lua" is used to run a Lua function if the action is executed. The single
3691 parameter is the name of the function to run. The prototype of the
3692 function is documented in the API documentation.
3693
Thierry FOURNIER4834bc72015-06-06 19:29:07 +02003694 - set-var(<var-name>) <expr> :
3695 Is used to set the contents of a variable. The variable is declared
3696 inline.
3697
3698 <var-name> The name of the variable starts by an indication about its
3699 scope. The allowed scopes are:
3700 "sess" : the variable is shared with all the session,
3701 "txn" : the variable is shared with all the transaction
3702 (request and response)
3703 "req" : the variable is shared only during the request
3704 processing
3705 "res" : the variable is shared only during the response
3706 processing.
3707 This prefix is followed by a name. The separator is a '.'.
3708 The name may only contain characters 'a-z', 'A-Z', '0-9',
3709 and '_'.
3710
3711 <expr> Is a standard HAProxy expression formed by a sample-fetch
3712 followed by some converters.
3713
3714 Example:
3715
3716 http-request set-var(req.my_var) req.fhdr(user-agent),lower
3717
Adis Nezirovic2fbcafc2015-07-06 15:44:30 +02003718 - set-src <expr> :
3719 Is used to set the source IP address to the value of specified
3720 expression. Useful when a proxy in front of HAProxy rewrites source IP,
3721 but provides the correct IP in a HTTP header; or you want to mask
3722 source IP for privacy.
3723
3724 <expr> Is a standard HAProxy expression formed by a sample-fetch
3725 followed by some converters.
3726
3727 Example:
3728
3729 http-request set-src hdr(x-forwarded-for)
3730 http-request set-src src,ipmask(24)
3731
3732 When set-src is successful, the source port is set to 0.
3733
Willy Tarreau2d392c22015-08-24 01:43:45 +02003734 - "silent-drop" : this stops the evaluation of the rules and makes the
3735 client-facing connection suddenly disappear using a system-dependant way
3736 that tries to prevent the client from being notified. The effect it then
3737 that the client still sees an established connection while there's none
3738 on HAProxy. The purpose is to achieve a comparable effect to "tarpit"
3739 except that it doesn't use any local resource at all on the machine
3740 running HAProxy. It can resist much higher loads than "tarpit", and slow
3741 down stronger attackers. It is important to undestand the impact of using
3742 this mechanism. All stateful equipments placed between the client and
3743 HAProxy (firewalls, proxies, load balancers) will also keep the
3744 established connection for a long time and may suffer from this action.
3745 On modern Linux systems running with enough privileges, the TCP_REPAIR
3746 socket option is used to block the emission of a TCP reset. On other
3747 systems, the socket's TTL is reduced to 1 so that the TCP reset doesn't
3748 pass the first router, though it's still delivered to local networks. Do
3749 not use it unless you fully understand how it works.
3750
Willy Tarreau20b0de52012-12-24 15:45:22 +01003751 There is no limit to the number of http-request statements per instance.
3752
3753 It is important to know that http-request rules are processed very early in
3754 the HTTP processing, just after "block" rules and before "reqdel" or "reqrep"
3755 rules. That way, headers added by "add-header"/"set-header" are visible by
3756 almost all further ACL rules.
Krzysztof Piotr Oledzki6b35ce12010-02-01 23:35:44 +01003757
3758 Example:
Cyril Bonté78caf842010-03-10 22:41:43 +01003759 acl nagios src 192.168.129.3
3760 acl local_net src 192.168.0.0/16
3761 acl auth_ok http_auth(L1)
Krzysztof Piotr Oledzki6b35ce12010-02-01 23:35:44 +01003762
Cyril Bonté78caf842010-03-10 22:41:43 +01003763 http-request allow if nagios
3764 http-request allow if local_net auth_ok
3765 http-request auth realm Gimme if local_net auth_ok
3766 http-request deny
Krzysztof Piotr Oledzki6b35ce12010-02-01 23:35:44 +01003767
Cyril Bonté78caf842010-03-10 22:41:43 +01003768 Example:
3769 acl auth_ok http_auth_group(L1) G1
Cyril Bonté78caf842010-03-10 22:41:43 +01003770 http-request auth unless auth_ok
Krzysztof Piotr Oledzki6b35ce12010-02-01 23:35:44 +01003771
Willy Tarreau20b0de52012-12-24 15:45:22 +01003772 Example:
3773 http-request set-header X-Haproxy-Current-Date %T
3774 http-request set-header X-SSL %[ssl_fc]
Willy Tarreaufca42612015-08-27 17:15:05 +02003775 http-request set-header X-SSL-Session_ID %[ssl_fc_session_id,hex]
Willy Tarreau20b0de52012-12-24 15:45:22 +01003776 http-request set-header X-SSL-Client-Verify %[ssl_c_verify]
3777 http-request set-header X-SSL-Client-DN %{+Q}[ssl_c_s_dn]
3778 http-request set-header X-SSL-Client-CN %{+Q}[ssl_c_s_dn(cn)]
3779 http-request set-header X-SSL-Issuer %{+Q}[ssl_c_i_dn]
3780 http-request set-header X-SSL-Client-NotBefore %{+Q}[ssl_c_notbefore]
3781 http-request set-header X-SSL-Client-NotAfter %{+Q}[ssl_c_notafter]
3782
Baptiste Assmannfabcbe02014-04-24 22:16:59 +02003783 Example:
3784 acl key req.hdr(X-Add-Acl-Key) -m found
3785 acl add path /addacl
3786 acl del path /delacl
3787
3788 acl myhost hdr(Host) -f myhost.lst
3789
3790 http-request add-acl(myhost.lst) %[req.hdr(X-Add-Acl-Key)] if key add
3791 http-request del-acl(myhost.lst) %[req.hdr(X-Add-Acl-Key)] if key del
3792
3793 Example:
3794 acl value req.hdr(X-Value) -m found
3795 acl setmap path /setmap
3796 acl delmap path /delmap
3797
3798 use_backend bk_appli if { hdr(Host),map_str(map.lst) -m found }
3799
3800 http-request set-map(map.lst) %[src] %[req.hdr(X-Value)] if setmap value
3801 http-request del-map(map.lst) %[src] if delmap
3802
Cyril Bonté2be1b3f2010-09-30 23:46:30 +02003803 See also : "stats http-request", section 3.4 about userlists and section 7
3804 about ACL usage.
Willy Tarreauef781042010-01-27 11:53:01 +01003805
Willy Tarreauf4c43c12013-06-11 17:01:13 +02003806http-response { allow | deny | add-header <name> <fmt> | set-nice <nice> |
Willy Tarreau51d861a2015-05-22 17:30:48 +02003807 capture <sample> id <id> | redirect <rule> |
Thierry FOURNIERdad3d1d2014-04-22 18:07:25 +02003808 set-header <name> <fmt> | del-header <name> |
Sasha Pachev218f0642014-06-16 12:05:59 -06003809 replace-header <name> <regex-match> <replace-fmt> |
3810 replace-value <name> <regex-match> <replace-fmt> |
Thierry FOURNIER35d70ef2015-08-26 16:21:56 +02003811 set-status <status> |
Baptiste Assmannfabcbe02014-04-24 22:16:59 +02003812 set-log-level <level> | set-mark <mark> | set-tos <tos> |
3813 add-acl(<file name>) <key fmt> |
3814 del-acl(<file name>) <key fmt> |
3815 del-map(<file name>) <key fmt> |
Thierry FOURNIER90da1912015-03-05 11:17:06 +01003816 set-map(<file name>) <key fmt> <value fmt> |
Thierry FOURNIER4834bc72015-06-06 19:29:07 +02003817 set-var(<var-name>) <expr> |
Thierry FOURNIERe0627bd2015-08-04 08:20:33 +02003818 sc-inc-gpc0(<sc-id>) |
Thierry FOURNIER236657b2015-08-19 08:25:14 +02003819 sc-set-gpt0(<sc-id>) <int> |
Willy Tarreau2d392c22015-08-24 01:43:45 +02003820 silent-drop |
Thierry FOURNIER90da1912015-03-05 11:17:06 +01003821 lua <function name>
Baptiste Assmannfabcbe02014-04-24 22:16:59 +02003822 }
Lukas Tribus2dd1d1a2013-06-19 23:34:41 +02003823 [ { if | unless } <condition> ]
Willy Tarreaue365c0b2013-06-11 16:06:12 +02003824 Access control for Layer 7 responses
3825
3826 May be used in sections: defaults | frontend | listen | backend
3827 no | yes | yes | yes
3828
3829 The http-response statement defines a set of rules which apply to layer 7
3830 processing. The rules are evaluated in their declaration order when they are
3831 met in a frontend, listen or backend section. Any rule may optionally be
3832 followed by an ACL-based condition, in which case it will only be evaluated
3833 if the condition is true. Since these rules apply on responses, the backend
3834 rules are applied first, followed by the frontend's rules.
3835
3836 The first keyword is the rule's action. Currently supported actions include :
3837 - "allow" : this stops the evaluation of the rules and lets the response
3838 pass the check. No further "http-response" rules are evaluated for the
3839 current section.
3840
3841 - "deny" : this stops the evaluation of the rules and immediately rejects
3842 the response and emits an HTTP 502 error. No further "http-response"
3843 rules are evaluated.
3844
3845 - "add-header" appends an HTTP header field whose name is specified in
3846 <name> and whose value is defined by <fmt> which follows the log-format
3847 rules (see Custom Log Format in section 8.2.4). This may be used to send
3848 a cookie to a client for example, or to pass some internal information.
3849 This rule is not final, so it is possible to add other similar rules.
3850 Note that header addition is performed immediately, so one rule might
3851 reuse the resulting header from a previous rule.
3852
3853 - "set-header" does the same as "add-header" except that the header name
3854 is first removed if it existed. This is useful when passing security
3855 information to the server, where the header must not be manipulated by
3856 external users.
3857
Thierry FOURNIERdad3d1d2014-04-22 18:07:25 +02003858 - "del-header" removes all HTTP header fields whose name is specified in
3859 <name>.
3860
Sasha Pachev218f0642014-06-16 12:05:59 -06003861 - "replace-header" matches the regular expression in all occurrences of
3862 header field <name> according to <match-regex>, and replaces them with
3863 the <replace-fmt> argument. Format characters are allowed in replace-fmt
3864 and work like in <fmt> arguments in "add-header". The match is only
3865 case-sensitive. It is important to understand that this action only
3866 considers whole header lines, regardless of the number of values they
3867 may contain. This usage is suited to headers naturally containing commas
3868 in their value, such as Set-Cookie, Expires and so on.
3869
3870 Example:
3871
3872 http-response replace-header Set-Cookie (C=[^;]*);(.*) \1;ip=%bi;\2
3873
3874 applied to:
3875
3876 Set-Cookie: C=1; expires=Tue, 14-Jun-2016 01:40:45 GMT
3877
3878 outputs:
3879
3880 Set-Cookie: C=1;ip=192.168.1.20; expires=Tue, 14-Jun-2016 01:40:45 GMT
3881
3882 assuming the backend IP is 192.168.1.20.
3883
3884 - "replace-value" works like "replace-header" except that it matches the
3885 regex against every comma-delimited value of the header field <name>
3886 instead of the entire header. This is suited for all headers which are
3887 allowed to carry more than one value. An example could be the Accept
3888 header.
3889
3890 Example:
3891
3892 http-response replace-value Cache-control ^public$ private
3893
3894 applied to:
3895
3896 Cache-Control: max-age=3600, public
3897
3898 outputs:
3899
3900 Cache-Control: max-age=3600, private
3901
Thierry FOURNIER35d70ef2015-08-26 16:21:56 +02003902 - "set-status" replaces the response status code with <status> which must
3903 be an integer between 100 and 999. Note that the reason is automatically
3904 adapted to the new code.
3905
3906 Example:
3907
3908 # return "431 Request Header Fields Too Large"
3909 http-response set-status 431
3910
Willy Tarreauf4c43c12013-06-11 17:01:13 +02003911 - "set-nice" sets the "nice" factor of the current request being processed.
3912 It only has effect against the other requests being processed at the same
3913 time. The default value is 0, unless altered by the "nice" setting on the
3914 "bind" line. The accepted range is -1024..1024. The higher the value, the
3915 nicest the request will be. Lower values will make the request more
3916 important than other ones. This can be useful to improve the speed of
3917 some requests, or lower the priority of non-important requests. Using
3918 this setting without prior experimentation can cause some major slowdown.
3919
Willy Tarreau9a355ec2013-06-11 17:45:46 +02003920 - "set-log-level" is used to change the log level of the current request
3921 when a certain condition is met. Valid levels are the 8 syslog levels
3922 (see the "log" keyword) plus the special level "silent" which disables
3923 logging for this request. This rule is not final so the last matching
3924 rule wins. This rule can be useful to disable health checks coming from
3925 another equipment.
3926
Willy Tarreau42cf39e2013-06-11 18:51:32 +02003927 - "set-tos" is used to set the TOS or DSCP field value of packets sent to
3928 the client to the value passed in <tos> on platforms which support this.
3929 This value represents the whole 8 bits of the IP TOS field, and can be
3930 expressed both in decimal or hexadecimal format (prefixed by "0x"). Note
3931 that only the 6 higher bits are used in DSCP or TOS, and the two lower
3932 bits are always 0. This can be used to adjust some routing behaviour on
3933 border routers based on some information from the request. See RFC 2474,
3934 2597, 3260 and 4594 for more information.
3935
Willy Tarreau51347ed2013-06-11 19:34:13 +02003936 - "set-mark" is used to set the Netfilter MARK on all packets sent to the
3937 client to the value passed in <mark> on platforms which support it. This
3938 value is an unsigned 32 bit value which can be matched by netfilter and
3939 by the routing table. It can be expressed both in decimal or hexadecimal
3940 format (prefixed by "0x"). This can be useful to force certain packets to
3941 take a different route (for example a cheaper network path for bulk
3942 downloads). This works on Linux kernels 2.6.32 and above and requires
3943 admin privileges.
3944
Baptiste Assmannfabcbe02014-04-24 22:16:59 +02003945 - "add-acl" is used to add a new entry into an ACL. The ACL must be loaded
3946 from a file (even a dummy empty file). The file name of the ACL to be
3947 updated is passed between parentheses. It takes one argument: <key fmt>,
3948 which follows log-format rules, to collect content of the new entry. It
3949 performs a lookup in the ACL before insertion, to avoid duplicated (or
3950 more) values. This lookup is done by a linear search and can be expensive
3951 with large lists! It is the equivalent of the "add acl" command from the
3952 stats socket, but can be triggered by an HTTP response.
3953
3954 - "del-acl" is used to delete an entry from an ACL. The ACL must be loaded
3955 from a file (even a dummy empty file). The file name of the ACL to be
3956 updated is passed between parentheses. It takes one argument: <key fmt>,
3957 which follows log-format rules, to collect content of the entry to delete.
3958 It is the equivalent of the "del acl" command from the stats socket, but
3959 can be triggered by an HTTP response.
3960
3961 - "del-map" is used to delete an entry from a MAP. The MAP must be loaded
3962 from a file (even a dummy empty file). The file name of the MAP to be
3963 updated is passed between parentheses. It takes one argument: <key fmt>,
3964 which follows log-format rules, to collect content of the entry to delete.
3965 It takes one argument: "file name" It is the equivalent of the "del map"
3966 command from the stats socket, but can be triggered by an HTTP response.
3967
3968 - "set-map" is used to add a new entry into a MAP. The MAP must be loaded
3969 from a file (even a dummy empty file). The file name of the MAP to be
3970 updated is passed between parentheses. It takes 2 arguments: <key fmt>,
3971 which follows log-format rules, used to collect MAP key, and <value fmt>,
3972 which follows log-format rules, used to collect content for the new entry.
3973 It performs a lookup in the MAP before insertion, to avoid duplicated (or
3974 more) values. This lookup is done by a linear search and can be expensive
3975 with large lists! It is the equivalent of the "set map" command from the
3976 stats socket, but can be triggered by an HTTP response.
3977
Thierry FOURNIER90da1912015-03-05 11:17:06 +01003978 - "lua" is used to run a Lua function if the action is executed. The single
3979 parameter is the name of the function to run. The prototype of the
3980 function is documented in the API documentation.
3981
Thierry FOURNIERe80fada2015-05-26 18:06:31 +02003982 - capture <sample> id <id> :
3983 captures sample expression <sample> from the response buffer, and converts
3984 it to a string. The resulting string is stored into the next request
3985 "capture" slot, so it will possibly appear next to some captured HTTP
3986 headers. It will then automatically appear in the logs, and it will be
3987 possible to extract it using sample fetch rules to feed it into headers or
3988 anything. Please check section 7.3 (Fetching samples) and "capture
3989 response header" for more information.
3990
3991 The keyword "id" is the id of the capture slot which is used for storing
3992 the string. The capture slot must be defined in an associated frontend.
3993 This is useful to run captures in backends. The slot id can be declared by
3994 a previous directive "http-response capture" or with the "declare capture"
3995 keyword.
3996
Willy Tarreau51d861a2015-05-22 17:30:48 +02003997 - "redirect" : this performs an HTTP redirection based on a redirect rule.
3998 This supports a format string similarly to "http-request redirect" rules,
3999 with the exception that only the "location" type of redirect is possible
4000 on the response. See the "redirect" keyword for the rule's syntax. When
4001 a redirect rule is applied during a response, connections to the server
4002 are closed so that no data can be forwarded from the server to the client.
4003
Thierry FOURNIER4834bc72015-06-06 19:29:07 +02004004 - set-var(<var-name>) expr:
4005 Is used to set the contents of a variable. The variable is declared
4006 inline.
4007
4008 <var-name> The name of the variable starts by an indication about its
4009 scope. The allowed scopes are:
4010 "sess" : the variable is shared with all the session,
4011 "txn" : the variable is shared with all the transaction
4012 (request and response)
4013 "req" : the variable is shared only during the request
4014 processing
4015 "res" : the variable is shared only during the response
4016 processing.
4017 This prefix is followed by a name. The separator is a '.'.
4018 The name may only contain characters 'a-z', 'A-Z', '0-9',
4019 and '_'.
4020
4021 <expr> Is a standard HAProxy expression formed by a sample-fetch
4022 followed by some converters.
4023
4024 Example:
4025
4026 http-response set-var(sess.last_redir) res.hdr(location)
4027
Thierry FOURNIER236657b2015-08-19 08:25:14 +02004028 - sc-set-gpt0(<sc-id>) <int> :
4029 This action sets the GPT0 tag according to the sticky counter designated
4030 by <sc-id> and the value of <int>. The expected result is a boolean. If
4031 an error occurs, this action silently fails and the actions evaluation
4032 continues.
4033
Thierry FOURNIERe0627bd2015-08-04 08:20:33 +02004034 - sc-inc-gpc0(<sc-id>):
4035 This action increments the GPC0 counter according with the sticky counter
4036 designated by <sc-id>. If an error occurs, this action silently fails and
4037 the actions evaluation continues.
4038
Willy Tarreau2d392c22015-08-24 01:43:45 +02004039 - "silent-drop" : this stops the evaluation of the rules and makes the
4040 client-facing connection suddenly disappear using a system-dependant way
4041 that tries to prevent the client from being notified. The effect it then
4042 that the client still sees an established connection while there's none
4043 on HAProxy. The purpose is to achieve a comparable effect to "tarpit"
4044 except that it doesn't use any local resource at all on the machine
4045 running HAProxy. It can resist much higher loads than "tarpit", and slow
4046 down stronger attackers. It is important to undestand the impact of using
4047 this mechanism. All stateful equipments placed between the client and
4048 HAProxy (firewalls, proxies, load balancers) will also keep the
4049 established connection for a long time and may suffer from this action.
4050 On modern Linux systems running with enough privileges, the TCP_REPAIR
4051 socket option is used to block the emission of a TCP reset. On other
4052 systems, the socket's TTL is reduced to 1 so that the TCP reset doesn't
4053 pass the first router, though it's still delivered to local networks. Do
4054 not use it unless you fully understand how it works.
4055
Willy Tarreaue365c0b2013-06-11 16:06:12 +02004056 There is no limit to the number of http-response statements per instance.
4057
Godbach09250262013-07-02 01:19:15 +08004058 It is important to know that http-response rules are processed very early in
Willy Tarreaue365c0b2013-06-11 16:06:12 +02004059 the HTTP processing, before "reqdel" or "reqrep" rules. That way, headers
4060 added by "add-header"/"set-header" are visible by almost all further ACL
4061 rules.
4062
Baptiste Assmannfabcbe02014-04-24 22:16:59 +02004063 Example:
4064 acl key_acl res.hdr(X-Acl-Key) -m found
4065
4066 acl myhost hdr(Host) -f myhost.lst
4067
4068 http-response add-acl(myhost.lst) %[res.hdr(X-Acl-Key)] if key_acl
4069 http-response del-acl(myhost.lst) %[res.hdr(X-Acl-Key)] if key_acl
4070
4071 Example:
4072 acl value res.hdr(X-Value) -m found
4073
4074 use_backend bk_appli if { hdr(Host),map_str(map.lst) -m found }
4075
4076 http-response set-map(map.lst) %[src] %[res.hdr(X-Value)] if value
4077 http-response del-map(map.lst) %[src] if ! value
4078
Willy Tarreaue365c0b2013-06-11 16:06:12 +02004079 See also : "http-request", section 3.4 about userlists and section 7 about
4080 ACL usage.
4081
Baptiste Assmann5ecb77f2013-10-06 23:24:13 +02004082
Willy Tarreau30631952015-08-06 15:05:24 +02004083http-reuse { never | safe | aggressive | always }
4084 Declare how idle HTTP connections may be shared between requests
4085
4086 May be used in sections: defaults | frontend | listen | backend
4087 yes | no | yes | yes
4088
4089 By default, a connection established between haproxy and the backend server
4090 belongs to the session that initiated it. The downside is that between the
4091 response and the next request, the connection remains idle and is not used.
4092 In many cases for performance reasons it is desirable to make it possible to
4093 reuse these idle connections to serve other requests from different sessions.
4094 This directive allows to tune this behaviour.
4095
4096 The argument indicates the desired connection reuse strategy :
4097
4098 - "never" : idle connections are never shared between sessions. This is
4099 the default choice. It may be enforced to cancel a different
4100 strategy inherited from a defaults section or for
4101 troubleshooting. For example, if an old bogus application
4102 considers that multiple requests over the same connection come
4103 from the same client and it is not possible to fix the
4104 application, it may be desirable to disable connection sharing
4105 in a single backend. An example of such an application could
4106 be an old haproxy using cookie insertion in tunnel mode and
4107 not checking any request past the first one.
4108
4109 - "safe" : this is the recommended strategy. The first request of a
4110 session is always sent over its own connection, and only
4111 subsequent requests may be dispatched over other existing
4112 connections. This ensures that in case the server closes the
4113 connection when the request is being sent, the browser can
4114 decide to silently retry it. Since it is exactly equivalent to
4115 regular keep-alive, there should be no side effects.
4116
4117 - "aggressive" : this mode may be useful in webservices environments where
4118 all servers are not necessarily known and where it would be
4119 appreciable to deliver most first requests over existing
4120 connections. In this case, first requests are only delivered
4121 over existing connections that have been reused at least once,
4122 proving that the server correctly supports connection reuse.
4123 It should only be used when it's sure that the client can
4124 retry a failed request once in a while and where the benefit
4125 of aggressive connection reuse significantly outweights the
4126 downsides of rare connection failures.
4127
4128 - "always" : this mode is only recommended when the path to the server is
4129 known for never breaking existing connections quickly after
4130 releasing them. It allows the first request of a session to be
4131 sent to an existing connection. This can provide a significant
4132 performance increase over the "safe" strategy when the backend
4133 is a cache farm, since such components tend to show a
4134 consistent behaviour and will benefit from the connection
4135 sharing. It is recommended that the "http-keep-alive" timeout
4136 remains low in this mode so that no dead connections remain
4137 usable. In most cases, this will lead to the same performance
4138 gains as "aggressive" but with more risks. It should only be
4139 used when it improves the situation over "aggressive".
4140
4141 When http connection sharing is enabled, a great care is taken to respect the
4142 connection properties and compatiblities. Specifically :
4143 - connections made with "usesrc" followed by a client-dependant value
4144 ("client", "clientip", "hdr_ip") are marked private and never shared ;
4145
4146 - connections sent to a server with a TLS SNI extension are marked private
4147 and are never shared ;
4148
4149 - connections receiving a status code 401 or 407 expect some authentication
4150 to be sent in return. Due to certain bogus authentication schemes (such
4151 as NTLM) relying on the connection, these connections are marked private
4152 and are never shared ;
4153
4154 No connection pool is involved, once a session dies, the last idle connection
4155 it was attached to is deleted at the same time. This ensures that connections
4156 may not last after all sessions are closed.
4157
4158 Note: connection reuse improves the accuracy of the "server maxconn" setting,
4159 because almost no new connection will be established while idle connections
4160 remain available. This is particularly true with the "always" strategy.
4161
4162 See also : "option http-keep-alive", "server maxconn"
4163
4164
Mark Lamourinec2247f02012-01-04 13:02:01 -05004165http-send-name-header [<header>]
4166 Add the server name to a request. Use the header string given by <header>
4167
4168 May be used in sections: defaults | frontend | listen | backend
4169 yes | no | yes | yes
4170
4171 Arguments :
4172
4173 <header> The header string to use to send the server name
4174
4175 The "http-send-name-header" statement causes the name of the target
4176 server to be added to the headers of an HTTP request. The name
4177 is added with the header string proved.
4178
4179 See also : "server"
4180
Krzysztof Piotr Oledzkif58a9622008-02-23 01:19:10 +01004181id <value>
Willy Tarreau53fb4ae2009-10-04 23:04:08 +02004182 Set a persistent ID to a proxy.
4183 May be used in sections : defaults | frontend | listen | backend
4184 no | yes | yes | yes
4185 Arguments : none
4186
4187 Set a persistent ID for the proxy. This ID must be unique and positive.
4188 An unused ID will automatically be assigned if unset. The first assigned
4189 value will be 1. This ID is currently only returned in statistics.
Krzysztof Piotr Oledzkif58a9622008-02-23 01:19:10 +01004190
4191
Cyril Bonté0d4bf012010-04-25 23:21:46 +02004192ignore-persist { if | unless } <condition>
4193 Declare a condition to ignore persistence
4194 May be used in sections: defaults | frontend | listen | backend
4195 no | yes | yes | yes
4196
4197 By default, when cookie persistence is enabled, every requests containing
4198 the cookie are unconditionally persistent (assuming the target server is up
4199 and running).
4200
4201 The "ignore-persist" statement allows one to declare various ACL-based
4202 conditions which, when met, will cause a request to ignore persistence.
4203 This is sometimes useful to load balance requests for static files, which
Jarno Huuskonen0e82b922014-04-12 18:22:19 +03004204 often don't require persistence. This can also be used to fully disable
Cyril Bonté0d4bf012010-04-25 23:21:46 +02004205 persistence for a specific User-Agent (for example, some web crawler bots).
4206
Cyril Bonté0d4bf012010-04-25 23:21:46 +02004207 The persistence is ignored when an "if" condition is met, or unless an
4208 "unless" condition is met.
4209
4210 See also : "force-persist", "cookie", and section 7 about ACL usage.
4211
Baptiste Assmann01c6cc32015-08-23 11:45:29 +02004212load-server-state-from-file { global | local | none }
4213 Allow seamless reload of HAProxy
4214 May be used in sections: defaults | frontend | listen | backend
4215 yes | no | yes | yes
4216
4217 This directive points HAProxy to a file where server state from previous
4218 running process has been saved. That way, when starting up, before handling
4219 traffic, the new process can apply old states to servers exactly has if no
4220 reload occured. The purpose of the "load-server-state-from-file" directive is
4221 to tell haproxy which file to use. For now, only 2 arguments to either prevent
4222 loading state or load states from a file containing all backends and servers.
4223 The state file can be generated by running the command "show servers state"
4224 over the stats socket and redirect output.
4225
4226 The format of the file is versionned and is very specific. To understand it,
4227 please read the documentation of the "show servers state" command (chapter
4228 9.2).
4229
4230 Arguments:
4231 global load the content of the file pointed by the global directive
4232 named "server-state-file".
4233
4234 local load the content of the file pointed by the directive
4235 "server-state-file-name" if set. If not set, then the backend
4236 name is used as a file name.
4237
4238 none don't load any stat for this backend
4239
4240 Notes:
4241 - server's IP address is not updated unless DNS resolution is enabled on
4242 the server. It means that if a server IP address has been changed using
4243 the stat socket, this information won't be re-applied after reloading.
4244
4245 - server's weight is applied from previous running process unless it has
4246 has changed between previous and new configuration files.
4247
4248 Example 1:
4249
4250 Minimal configuration:
4251
4252 global
4253 stats socket /tmp/socket
4254 server-state-file /tmp/server_state
4255
4256 defaults
4257 load-server-state-from-file global
4258
4259 backend bk
4260 server s1 127.0.0.1:22 check weight 11
4261 server s2 127.0.0.1:22 check weight 12
4262
4263 Then one can run :
4264
4265 socat /tmp/socket - <<< "show servers state" > /tmp/server_state
4266
4267 Content of the file /tmp/server_state would be like this:
4268
4269 1
4270 # <field names skipped for the doc example>
4271 1 bk 1 s1 127.0.0.1 2 0 11 11 4 6 3 4 6 0 0
4272 1 bk 2 s2 127.0.0.1 2 0 12 12 4 6 3 4 6 0 0
4273
4274 Example 2:
4275
4276 Minimal configuration:
4277
4278 global
4279 stats socket /tmp/socket
4280 server-state-base /etc/haproxy/states
4281
4282 defaults
4283 load-server-state-from-file local
4284
4285 backend bk
4286 server s1 127.0.0.1:22 check weight 11
4287 server s2 127.0.0.1:22 check weight 12
4288
4289 Then one can run :
4290
4291 socat /tmp/socket - <<< "show servers state bk" > /etc/haproxy/states/bk
4292
4293 Content of the file /etc/haproxy/states/bk would be like this:
4294
4295 1
4296 # <field names skipped for the doc example>
4297 1 bk 1 s1 127.0.0.1 2 0 11 11 4 6 3 4 6 0 0
4298 1 bk 2 s2 127.0.0.1 2 0 12 12 4 6 3 4 6 0 0
4299
4300 See also: "server-state-file", "server-state-file-name", and
4301 "show servers state"
4302
Cyril Bonté0d4bf012010-04-25 23:21:46 +02004303
Willy Tarreau2769aa02007-12-27 18:26:09 +01004304log global
Willy Tarreau18324f52014-06-27 18:10:07 +02004305log <address> [len <length>] <facility> [<level> [<minlevel>]]
William Lallemand0f99e342011-10-12 17:50:54 +02004306no log
Willy Tarreau2769aa02007-12-27 18:26:09 +01004307 Enable per-instance logging of events and traffic.
4308 May be used in sections : defaults | frontend | listen | backend
4309 yes | yes | yes | yes
William Lallemand0f99e342011-10-12 17:50:54 +02004310
4311 Prefix :
4312 no should be used when the logger list must be flushed. For example,
4313 if you don't want to inherit from the default logger list. This
4314 prefix does not allow arguments.
4315
Willy Tarreau2769aa02007-12-27 18:26:09 +01004316 Arguments :
4317 global should be used when the instance's logging parameters are the
4318 same as the global ones. This is the most common usage. "global"
4319 replaces <address>, <facility> and <level> with those of the log
4320 entries found in the "global" section. Only one "log global"
4321 statement may be used per instance, and this form takes no other
4322 parameter.
4323
4324 <address> indicates where to send the logs. It takes the same format as
4325 for the "global" section's logs, and can be one of :
4326
4327 - An IPv4 address optionally followed by a colon (':') and a UDP
4328 port. If no port is specified, 514 is used by default (the
4329 standard syslog port).
4330
David du Colombier24bb5f52011-03-17 10:40:23 +01004331 - An IPv6 address followed by a colon (':') and optionally a UDP
4332 port. If no port is specified, 514 is used by default (the
4333 standard syslog port).
4334
Willy Tarreau2769aa02007-12-27 18:26:09 +01004335 - A filesystem path to a UNIX domain socket, keeping in mind
4336 considerations for chroot (be sure the path is accessible
4337 inside the chroot) and uid/gid (be sure the path is
4338 appropriately writeable).
4339
William Lallemandb2f07452015-05-12 14:27:13 +02004340 You may want to reference some environment variables in the
4341 address parameter, see section 2.3 about environment variables.
Willy Tarreaudad36a32013-03-11 01:20:04 +01004342
Willy Tarreau18324f52014-06-27 18:10:07 +02004343 <length> is an optional maximum line length. Log lines larger than this
4344 value will be truncated before being sent. The reason is that
4345 syslog servers act differently on log line length. All servers
4346 support the default value of 1024, but some servers simply drop
4347 larger lines while others do log them. If a server supports long
4348 lines, it may make sense to set this value here in order to avoid
4349 truncating long lines. Similarly, if a server drops long lines,
4350 it is preferable to truncate them before sending them. Accepted
4351 values are 80 to 65535 inclusive. The default value of 1024 is
4352 generally fine for all standard usages. Some specific cases of
4353 long captures or JSON-formated logs may require larger values.
4354
Willy Tarreau2769aa02007-12-27 18:26:09 +01004355 <facility> must be one of the 24 standard syslog facilities :
4356
4357 kern user mail daemon auth syslog lpr news
4358 uucp cron auth2 ftp ntp audit alert cron2
4359 local0 local1 local2 local3 local4 local5 local6 local7
4360
4361 <level> is optional and can be specified to filter outgoing messages. By
4362 default, all messages are sent. If a level is specified, only
4363 messages with a severity at least as important as this level
Willy Tarreauf7edefa2009-05-10 17:20:05 +02004364 will be sent. An optional minimum level can be specified. If it
4365 is set, logs emitted with a more severe level than this one will
4366 be capped to this level. This is used to avoid sending "emerg"
4367 messages on all terminals on some default syslog configurations.
4368 Eight levels are known :
Willy Tarreau2769aa02007-12-27 18:26:09 +01004369
4370 emerg alert crit err warning notice info debug
4371
William Lallemand0f99e342011-10-12 17:50:54 +02004372 It is important to keep in mind that it is the frontend which decides what to
4373 log from a connection, and that in case of content switching, the log entries
4374 from the backend will be ignored. Connections are logged at level "info".
Willy Tarreaucc6c8912009-02-22 10:53:55 +01004375
4376 However, backend log declaration define how and where servers status changes
4377 will be logged. Level "notice" will be used to indicate a server going up,
4378 "warning" will be used for termination signals and definitive service
4379 termination, and "alert" will be used for when a server goes down.
4380
4381 Note : According to RFC3164, messages are truncated to 1024 bytes before
4382 being emitted.
Willy Tarreau2769aa02007-12-27 18:26:09 +01004383
4384 Example :
4385 log global
Willy Tarreauf7edefa2009-05-10 17:20:05 +02004386 log 127.0.0.1:514 local0 notice # only send important events
4387 log 127.0.0.1:514 local0 notice notice # same but limit output level
William Lallemandb2f07452015-05-12 14:27:13 +02004388 log "${LOCAL_SYSLOG}:514" local0 notice # send to local server
Willy Tarreaudad36a32013-03-11 01:20:04 +01004389
Willy Tarreau2769aa02007-12-27 18:26:09 +01004390
William Lallemand48940402012-01-30 16:47:22 +01004391log-format <string>
Willy Tarreaufb4e7ea2015-01-07 14:55:17 +01004392 Specifies the log format string to use for traffic logs
4393 May be used in sections: defaults | frontend | listen | backend
4394 yes | yes | yes | no
William Lallemand48940402012-01-30 16:47:22 +01004395
Willy Tarreaufb4e7ea2015-01-07 14:55:17 +01004396 This directive specifies the log format string that will be used for all logs
4397 resulting from traffic passing through the frontend using this line. If the
4398 directive is used in a defaults section, all subsequent frontends will use
4399 the same log format. Please see section 8.2.4 which covers the log format
4400 string in depth.
William Lallemand48940402012-01-30 16:47:22 +01004401
Dragan Dosen7ad31542015-09-28 17:16:47 +02004402log-format-sd <string>
4403 Specifies the RFC5424 structured-data log format string
4404 May be used in sections: defaults | frontend | listen | backend
4405 yes | yes | yes | no
4406
4407 This directive specifies the RFC5424 structured-data log format string that
4408 will be used for all logs resulting from traffic passing through the frontend
4409 using this line. If the directive is used in a defaults section, all
4410 subsequent frontends will use the same log format. Please see section 8.2.4
4411 which covers the log format string in depth.
4412
4413 See https://tools.ietf.org/html/rfc5424#section-6.3 for more information
4414 about the RFC5424 structured-data part.
4415
4416 Note : This log format string will be used only for loggers that have set
4417 log format to "rfc5424".
4418
4419 Example :
4420 log-format-sd [exampleSDID@1234\ bytes=\"%B\"\ status=\"%ST\"]
4421
4422
Willy Tarreau094af4e2015-01-07 15:03:42 +01004423log-tag <string>
4424 Specifies the log tag to use for all outgoing logs
4425 May be used in sections: defaults | frontend | listen | backend
4426 yes | yes | yes | yes
4427
4428 Sets the tag field in the syslog header to this string. It defaults to the
4429 log-tag set in the global section, otherwise the program name as launched
4430 from the command line, which usually is "haproxy". Sometimes it can be useful
4431 to differentiate between multiple processes running on the same host, or to
4432 differentiate customer instances running in the same process. In the backend,
4433 logs about servers up/down will use this tag. As a hint, it can be convenient
4434 to set a log-tag related to a hosted customer in a defaults section then put
4435 all the frontends and backends for that customer, then start another customer
4436 in a new defaults section. See also the global "log-tag" directive.
Willy Tarreau2769aa02007-12-27 18:26:09 +01004437
Willy Tarreauc35362a2014-04-25 13:58:37 +02004438max-keep-alive-queue <value>
4439 Set the maximum server queue size for maintaining keep-alive connections
4440 May be used in sections: defaults | frontend | listen | backend
4441 yes | no | yes | yes
4442
4443 HTTP keep-alive tries to reuse the same server connection whenever possible,
4444 but sometimes it can be counter-productive, for example if a server has a lot
4445 of connections while other ones are idle. This is especially true for static
4446 servers.
4447
4448 The purpose of this setting is to set a threshold on the number of queued
4449 connections at which haproxy stops trying to reuse the same server and prefers
4450 to find another one. The default value, -1, means there is no limit. A value
4451 of zero means that keep-alive requests will never be queued. For very close
4452 servers which can be reached with a low latency and which are not sensible to
4453 breaking keep-alive, a low value is recommended (eg: local static server can
4454 use a value of 10 or less). For remote servers suffering from a high latency,
4455 higher values might be needed to cover for the latency and/or the cost of
4456 picking a different server.
4457
4458 Note that this has no impact on responses which are maintained to the same
4459 server consecutively to a 401 response. They will still go to the same server
4460 even if they have to be queued.
4461
4462 See also : "option http-server-close", "option prefer-last-server", server
4463 "maxconn" and cookie persistence.
4464
4465
Willy Tarreau2769aa02007-12-27 18:26:09 +01004466maxconn <conns>
4467 Fix the maximum number of concurrent connections on a frontend
4468 May be used in sections : defaults | frontend | listen | backend
4469 yes | yes | yes | no
4470 Arguments :
4471 <conns> is the maximum number of concurrent connections the frontend will
4472 accept to serve. Excess connections will be queued by the system
4473 in the socket's listen queue and will be served once a connection
4474 closes.
4475
4476 If the system supports it, it can be useful on big sites to raise this limit
4477 very high so that haproxy manages connection queues, instead of leaving the
4478 clients with unanswered connection attempts. This value should not exceed the
4479 global maxconn. Also, keep in mind that a connection contains two buffers
4480 of 8kB each, as well as some other data resulting in about 17 kB of RAM being
4481 consumed per established connection. That means that a medium system equipped
4482 with 1GB of RAM can withstand around 40000-50000 concurrent connections if
4483 properly tuned.
4484
4485 Also, when <conns> is set to large values, it is possible that the servers
4486 are not sized to accept such loads, and for this reason it is generally wise
4487 to assign them some reasonable connection limits.
4488
Vincent Bernat6341be52012-06-27 17:18:30 +02004489 By default, this value is set to 2000.
4490
Willy Tarreau2769aa02007-12-27 18:26:09 +01004491 See also : "server", global section's "maxconn", "fullconn"
4492
4493
4494mode { tcp|http|health }
4495 Set the running mode or protocol of the instance
4496 May be used in sections : defaults | frontend | listen | backend
4497 yes | yes | yes | yes
4498 Arguments :
4499 tcp The instance will work in pure TCP mode. A full-duplex connection
4500 will be established between clients and servers, and no layer 7
4501 examination will be performed. This is the default mode. It
4502 should be used for SSL, SSH, SMTP, ...
4503
4504 http The instance will work in HTTP mode. The client request will be
4505 analyzed in depth before connecting to any server. Any request
4506 which is not RFC-compliant will be rejected. Layer 7 filtering,
4507 processing and switching will be possible. This is the mode which
4508 brings HAProxy most of its value.
4509
4510 health The instance will work in "health" mode. It will just reply "OK"
Willy Tarreau82569f92012-09-27 23:48:56 +02004511 to incoming connections and close the connection. Alternatively,
4512 If the "httpchk" option is set, "HTTP/1.0 200 OK" will be sent
4513 instead. Nothing will be logged in either case. This mode is used
4514 to reply to external components health checks. This mode is
4515 deprecated and should not be used anymore as it is possible to do
4516 the same and even better by combining TCP or HTTP modes with the
4517 "monitor" keyword.
Willy Tarreau2769aa02007-12-27 18:26:09 +01004518
Cyril Bonté108cf6e2012-04-21 23:30:29 +02004519 When doing content switching, it is mandatory that the frontend and the
4520 backend are in the same mode (generally HTTP), otherwise the configuration
4521 will be refused.
Willy Tarreau2769aa02007-12-27 18:26:09 +01004522
Cyril Bonté108cf6e2012-04-21 23:30:29 +02004523 Example :
Willy Tarreau2769aa02007-12-27 18:26:09 +01004524 defaults http_instances
4525 mode http
4526
Cyril Bonté108cf6e2012-04-21 23:30:29 +02004527 See also : "monitor", "monitor-net"
Willy Tarreau2769aa02007-12-27 18:26:09 +01004528
Willy Tarreau0ba27502007-12-24 16:55:16 +01004529
Cyril Bontéf0c60612010-02-06 14:44:47 +01004530monitor fail { if | unless } <condition>
Willy Tarreau2769aa02007-12-27 18:26:09 +01004531 Add a condition to report a failure to a monitor HTTP request.
Willy Tarreau0ba27502007-12-24 16:55:16 +01004532 May be used in sections : defaults | frontend | listen | backend
4533 no | yes | yes | no
Willy Tarreau0ba27502007-12-24 16:55:16 +01004534 Arguments :
4535 if <cond> the monitor request will fail if the condition is satisfied,
4536 and will succeed otherwise. The condition should describe a
Krzysztof Piotr Oledzkif8645332009-12-13 21:55:50 +01004537 combined test which must induce a failure if all conditions
Willy Tarreau0ba27502007-12-24 16:55:16 +01004538 are met, for instance a low number of servers both in a
4539 backend and its backup.
4540
4541 unless <cond> the monitor request will succeed only if the condition is
4542 satisfied, and will fail otherwise. Such a condition may be
4543 based on a test on the presence of a minimum number of active
4544 servers in a list of backends.
4545
4546 This statement adds a condition which can force the response to a monitor
4547 request to report a failure. By default, when an external component queries
4548 the URI dedicated to monitoring, a 200 response is returned. When one of the
4549 conditions above is met, haproxy will return 503 instead of 200. This is
4550 very useful to report a site failure to an external component which may base
4551 routing advertisements between multiple sites on the availability reported by
4552 haproxy. In this case, one would rely on an ACL involving the "nbsrv"
Willy Tarreauae94d4d2011-05-11 16:28:49 +02004553 criterion. Note that "monitor fail" only works in HTTP mode. Both status
4554 messages may be tweaked using "errorfile" or "errorloc" if needed.
Willy Tarreau0ba27502007-12-24 16:55:16 +01004555
4556 Example:
4557 frontend www
Willy Tarreau2769aa02007-12-27 18:26:09 +01004558 mode http
Willy Tarreau0ba27502007-12-24 16:55:16 +01004559 acl site_dead nbsrv(dynamic) lt 2
4560 acl site_dead nbsrv(static) lt 2
4561 monitor-uri /site_alive
4562 monitor fail if site_dead
4563
Willy Tarreauae94d4d2011-05-11 16:28:49 +02004564 See also : "monitor-net", "monitor-uri", "errorfile", "errorloc"
Willy Tarreau2769aa02007-12-27 18:26:09 +01004565
4566
4567monitor-net <source>
4568 Declare a source network which is limited to monitor requests
4569 May be used in sections : defaults | frontend | listen | backend
4570 yes | yes | yes | no
4571 Arguments :
4572 <source> is the source IPv4 address or network which will only be able to
4573 get monitor responses to any request. It can be either an IPv4
4574 address, a host name, or an address followed by a slash ('/')
4575 followed by a mask.
4576
4577 In TCP mode, any connection coming from a source matching <source> will cause
4578 the connection to be immediately closed without any log. This allows another
Krzysztof Piotr Oledzkif8645332009-12-13 21:55:50 +01004579 equipment to probe the port and verify that it is still listening, without
Willy Tarreau2769aa02007-12-27 18:26:09 +01004580 forwarding the connection to a remote server.
4581
4582 In HTTP mode, a connection coming from a source matching <source> will be
4583 accepted, the following response will be sent without waiting for a request,
4584 then the connection will be closed : "HTTP/1.0 200 OK". This is normally
4585 enough for any front-end HTTP probe to detect that the service is UP and
Willy Tarreau82569f92012-09-27 23:48:56 +02004586 running without forwarding the request to a backend server. Note that this
4587 response is sent in raw format, without any transformation. This is important
4588 as it means that it will not be SSL-encrypted on SSL listeners.
Willy Tarreau2769aa02007-12-27 18:26:09 +01004589
Willy Tarreau82569f92012-09-27 23:48:56 +02004590 Monitor requests are processed very early, just after tcp-request connection
4591 ACLs which are the only ones able to block them. These connections are short
4592 lived and never wait for any data from the client. They cannot be logged, and
4593 it is the intended purpose. They are only used to report HAProxy's health to
4594 an upper component, nothing more. Please note that "monitor fail" rules do
4595 not apply to connections intercepted by "monitor-net".
Willy Tarreau2769aa02007-12-27 18:26:09 +01004596
Willy Tarreau95cd2832010-03-04 23:36:33 +01004597 Last, please note that only one "monitor-net" statement can be specified in
4598 a frontend. If more than one is found, only the last one will be considered.
Cyril Bonté108cf6e2012-04-21 23:30:29 +02004599
Willy Tarreau2769aa02007-12-27 18:26:09 +01004600 Example :
4601 # addresses .252 and .253 are just probing us.
4602 frontend www
4603 monitor-net 192.168.0.252/31
4604
4605 See also : "monitor fail", "monitor-uri"
4606
4607
4608monitor-uri <uri>
4609 Intercept a URI used by external components' monitor requests
4610 May be used in sections : defaults | frontend | listen | backend
4611 yes | yes | yes | no
4612 Arguments :
4613 <uri> is the exact URI which we want to intercept to return HAProxy's
4614 health status instead of forwarding the request.
4615
4616 When an HTTP request referencing <uri> will be received on a frontend,
4617 HAProxy will not forward it nor log it, but instead will return either
4618 "HTTP/1.0 200 OK" or "HTTP/1.0 503 Service unavailable", depending on failure
4619 conditions defined with "monitor fail". This is normally enough for any
4620 front-end HTTP probe to detect that the service is UP and running without
4621 forwarding the request to a backend server. Note that the HTTP method, the
4622 version and all headers are ignored, but the request must at least be valid
4623 at the HTTP level. This keyword may only be used with an HTTP-mode frontend.
4624
4625 Monitor requests are processed very early. It is not possible to block nor
4626 divert them using ACLs. They cannot be logged either, and it is the intended
4627 purpose. They are only used to report HAProxy's health to an upper component,
4628 nothing more. However, it is possible to add any number of conditions using
4629 "monitor fail" and ACLs so that the result can be adjusted to whatever check
4630 can be imagined (most often the number of available servers in a backend).
4631
4632 Example :
4633 # Use /haproxy_test to report haproxy's status
4634 frontend www
4635 mode http
4636 monitor-uri /haproxy_test
4637
4638 See also : "monitor fail", "monitor-net"
4639
Willy Tarreau0ba27502007-12-24 16:55:16 +01004640
Willy Tarreaubf1f8162007-12-28 17:42:56 +01004641option abortonclose
4642no option abortonclose
4643 Enable or disable early dropping of aborted requests pending in queues.
4644 May be used in sections : defaults | frontend | listen | backend
4645 yes | no | yes | yes
4646 Arguments : none
4647
4648 In presence of very high loads, the servers will take some time to respond.
4649 The per-instance connection queue will inflate, and the response time will
4650 increase respective to the size of the queue times the average per-session
4651 response time. When clients will wait for more than a few seconds, they will
Willy Tarreau198a7442008-01-17 12:05:32 +01004652 often hit the "STOP" button on their browser, leaving a useless request in
Willy Tarreaubf1f8162007-12-28 17:42:56 +01004653 the queue, and slowing down other users, and the servers as well, because the
4654 request will eventually be served, then aborted at the first error
4655 encountered while delivering the response.
4656
4657 As there is no way to distinguish between a full STOP and a simple output
4658 close on the client side, HTTP agents should be conservative and consider
4659 that the client might only have closed its output channel while waiting for
4660 the response. However, this introduces risks of congestion when lots of users
4661 do the same, and is completely useless nowadays because probably no client at
4662 all will close the session while waiting for the response. Some HTTP agents
Willy Tarreaud72758d2010-01-12 10:42:19 +01004663 support this behaviour (Squid, Apache, HAProxy), and others do not (TUX, most
Willy Tarreaubf1f8162007-12-28 17:42:56 +01004664 hardware-based load balancers). So the probability for a closed input channel
Willy Tarreau198a7442008-01-17 12:05:32 +01004665 to represent a user hitting the "STOP" button is close to 100%, and the risk
Willy Tarreaubf1f8162007-12-28 17:42:56 +01004666 of being the single component to break rare but valid traffic is extremely
4667 low, which adds to the temptation to be able to abort a session early while
4668 still not served and not pollute the servers.
4669
4670 In HAProxy, the user can choose the desired behaviour using the option
4671 "abortonclose". By default (without the option) the behaviour is HTTP
4672 compliant and aborted requests will be served. But when the option is
4673 specified, a session with an incoming channel closed will be aborted while
4674 it is still possible, either pending in the queue for a connection slot, or
4675 during the connection establishment if the server has not yet acknowledged
4676 the connection request. This considerably reduces the queue size and the load
4677 on saturated servers when users are tempted to click on STOP, which in turn
Willy Tarreaud72758d2010-01-12 10:42:19 +01004678 reduces the response time for other users.
Willy Tarreaubf1f8162007-12-28 17:42:56 +01004679
4680 If this option has been enabled in a "defaults" section, it can be disabled
4681 in a specific instance by prepending the "no" keyword before it.
4682
4683 See also : "timeout queue" and server's "maxconn" and "maxqueue" parameters
4684
4685
Willy Tarreau4076a152009-04-02 15:18:36 +02004686option accept-invalid-http-request
4687no option accept-invalid-http-request
4688 Enable or disable relaxing of HTTP request parsing
4689 May be used in sections : defaults | frontend | listen | backend
4690 yes | yes | yes | no
4691 Arguments : none
4692
Willy Tarreau91852eb2015-05-01 13:26:00 +02004693 By default, HAProxy complies with RFC7230 in terms of message parsing. This
Willy Tarreau4076a152009-04-02 15:18:36 +02004694 means that invalid characters in header names are not permitted and cause an
4695 error to be returned to the client. This is the desired behaviour as such
4696 forbidden characters are essentially used to build attacks exploiting server
4697 weaknesses, and bypass security filtering. Sometimes, a buggy browser or
4698 server will emit invalid header names for whatever reason (configuration,
4699 implementation) and the issue will not be immediately fixed. In such a case,
4700 it is possible to relax HAProxy's header name parser to accept any character
Willy Tarreau422246e2012-01-07 23:54:13 +01004701 even if that does not make sense, by specifying this option. Similarly, the
4702 list of characters allowed to appear in a URI is well defined by RFC3986, and
4703 chars 0-31, 32 (space), 34 ('"'), 60 ('<'), 62 ('>'), 92 ('\'), 94 ('^'), 96
4704 ('`'), 123 ('{'), 124 ('|'), 125 ('}'), 127 (delete) and anything above are
4705 not allowed at all. Haproxy always blocks a number of them (0..32, 127). The
Willy Tarreau91852eb2015-05-01 13:26:00 +02004706 remaining ones are blocked by default unless this option is enabled. This
Willy Tarreau13317662015-05-01 13:47:08 +02004707 option also relaxes the test on the HTTP version, it allows HTTP/0.9 requests
4708 to pass through (no version specified) and multiple digits for both the major
4709 and the minor version.
Willy Tarreau4076a152009-04-02 15:18:36 +02004710
4711 This option should never be enabled by default as it hides application bugs
4712 and open security breaches. It should only be deployed after a problem has
4713 been confirmed.
4714
4715 When this option is enabled, erroneous header names will still be accepted in
4716 requests, but the complete request will be captured in order to permit later
Willy Tarreau422246e2012-01-07 23:54:13 +01004717 analysis using the "show errors" request on the UNIX stats socket. Similarly,
4718 requests containing invalid chars in the URI part will be logged. Doing this
Willy Tarreau4076a152009-04-02 15:18:36 +02004719 also helps confirming that the issue has been solved.
4720
4721 If this option has been enabled in a "defaults" section, it can be disabled
4722 in a specific instance by prepending the "no" keyword before it.
4723
4724 See also : "option accept-invalid-http-response" and "show errors" on the
4725 stats socket.
4726
4727
4728option accept-invalid-http-response
4729no option accept-invalid-http-response
4730 Enable or disable relaxing of HTTP response parsing
4731 May be used in sections : defaults | frontend | listen | backend
4732 yes | no | yes | yes
4733 Arguments : none
4734
Willy Tarreau91852eb2015-05-01 13:26:00 +02004735 By default, HAProxy complies with RFC7230 in terms of message parsing. This
Willy Tarreau4076a152009-04-02 15:18:36 +02004736 means that invalid characters in header names are not permitted and cause an
4737 error to be returned to the client. This is the desired behaviour as such
4738 forbidden characters are essentially used to build attacks exploiting server
4739 weaknesses, and bypass security filtering. Sometimes, a buggy browser or
4740 server will emit invalid header names for whatever reason (configuration,
4741 implementation) and the issue will not be immediately fixed. In such a case,
4742 it is possible to relax HAProxy's header name parser to accept any character
Willy Tarreau91852eb2015-05-01 13:26:00 +02004743 even if that does not make sense, by specifying this option. This option also
4744 relaxes the test on the HTTP version format, it allows multiple digits for
4745 both the major and the minor version.
Willy Tarreau4076a152009-04-02 15:18:36 +02004746
4747 This option should never be enabled by default as it hides application bugs
4748 and open security breaches. It should only be deployed after a problem has
4749 been confirmed.
4750
4751 When this option is enabled, erroneous header names will still be accepted in
4752 responses, but the complete response will be captured in order to permit
4753 later analysis using the "show errors" request on the UNIX stats socket.
4754 Doing this also helps confirming that the issue has been solved.
4755
4756 If this option has been enabled in a "defaults" section, it can be disabled
4757 in a specific instance by prepending the "no" keyword before it.
4758
4759 See also : "option accept-invalid-http-request" and "show errors" on the
4760 stats socket.
4761
4762
Willy Tarreaubf1f8162007-12-28 17:42:56 +01004763option allbackups
4764no option allbackups
4765 Use either all backup servers at a time or only the first one
4766 May be used in sections : defaults | frontend | listen | backend
4767 yes | no | yes | yes
4768 Arguments : none
4769
4770 By default, the first operational backup server gets all traffic when normal
4771 servers are all down. Sometimes, it may be preferred to use multiple backups
4772 at once, because one will not be enough. When "option allbackups" is enabled,
4773 the load balancing will be performed among all backup servers when all normal
4774 ones are unavailable. The same load balancing algorithm will be used and the
4775 servers' weights will be respected. Thus, there will not be any priority
4776 order between the backup servers anymore.
4777
4778 This option is mostly used with static server farms dedicated to return a
4779 "sorry" page when an application is completely offline.
4780
4781 If this option has been enabled in a "defaults" section, it can be disabled
4782 in a specific instance by prepending the "no" keyword before it.
4783
4784
4785option checkcache
4786no option checkcache
Godbach7056a352013-12-11 20:01:07 +08004787 Analyze all server responses and block responses with cacheable cookies
Willy Tarreaubf1f8162007-12-28 17:42:56 +01004788 May be used in sections : defaults | frontend | listen | backend
4789 yes | no | yes | yes
4790 Arguments : none
4791
4792 Some high-level frameworks set application cookies everywhere and do not
4793 always let enough control to the developer to manage how the responses should
Krzysztof Piotr Oledzkif8645332009-12-13 21:55:50 +01004794 be cached. When a session cookie is returned on a cacheable object, there is a
Willy Tarreaubf1f8162007-12-28 17:42:56 +01004795 high risk of session crossing or stealing between users traversing the same
4796 caches. In some situations, it is better to block the response than to let
Willy Tarreau3c92c5f2011-08-28 09:45:47 +02004797 some sensitive session information go in the wild.
Willy Tarreaubf1f8162007-12-28 17:42:56 +01004798
4799 The option "checkcache" enables deep inspection of all server responses for
Krzysztof Piotr Oledzkif8645332009-12-13 21:55:50 +01004800 strict compliance with HTTP specification in terms of cacheability. It
Willy Tarreau198a7442008-01-17 12:05:32 +01004801 carefully checks "Cache-control", "Pragma" and "Set-cookie" headers in server
Willy Tarreaubf1f8162007-12-28 17:42:56 +01004802 response to check if there's a risk of caching a cookie on a client-side
4803 proxy. When this option is enabled, the only responses which can be delivered
Willy Tarreau198a7442008-01-17 12:05:32 +01004804 to the client are :
4805 - all those without "Set-Cookie" header ;
Willy Tarreaubf1f8162007-12-28 17:42:56 +01004806 - all those with a return code other than 200, 203, 206, 300, 301, 410,
Willy Tarreau198a7442008-01-17 12:05:32 +01004807 provided that the server has not set a "Cache-control: public" header ;
Willy Tarreaubf1f8162007-12-28 17:42:56 +01004808 - all those that come from a POST request, provided that the server has not
4809 set a 'Cache-Control: public' header ;
4810 - those with a 'Pragma: no-cache' header
4811 - those with a 'Cache-control: private' header
4812 - those with a 'Cache-control: no-store' header
4813 - those with a 'Cache-control: max-age=0' header
4814 - those with a 'Cache-control: s-maxage=0' header
4815 - those with a 'Cache-control: no-cache' header
4816 - those with a 'Cache-control: no-cache="set-cookie"' header
4817 - those with a 'Cache-control: no-cache="set-cookie,' header
4818 (allowing other fields after set-cookie)
4819
4820 If a response doesn't respect these requirements, then it will be blocked
Willy Tarreau198a7442008-01-17 12:05:32 +01004821 just as if it was from an "rspdeny" filter, with an "HTTP 502 bad gateway".
Willy Tarreaubf1f8162007-12-28 17:42:56 +01004822 The session state shows "PH--" meaning that the proxy blocked the response
Krzysztof Piotr Oledzkif8645332009-12-13 21:55:50 +01004823 during headers processing. Additionally, an alert will be sent in the logs so
Willy Tarreaubf1f8162007-12-28 17:42:56 +01004824 that admins are informed that there's something to be fixed.
4825
4826 Due to the high impact on the application, the application should be tested
4827 in depth with the option enabled before going to production. It is also a
Willy Tarreaud2a4aa22008-01-31 15:28:22 +01004828 good practice to always activate it during tests, even if it is not used in
Willy Tarreaubf1f8162007-12-28 17:42:56 +01004829 production, as it will report potentially dangerous application behaviours.
4830
4831 If this option has been enabled in a "defaults" section, it can be disabled
4832 in a specific instance by prepending the "no" keyword before it.
4833
4834
4835option clitcpka
4836no option clitcpka
4837 Enable or disable the sending of TCP keepalive packets on the client side
4838 May be used in sections : defaults | frontend | listen | backend
4839 yes | yes | yes | no
4840 Arguments : none
4841
4842 When there is a firewall or any session-aware component between a client and
4843 a server, and when the protocol involves very long sessions with long idle
4844 periods (eg: remote desktops), there is a risk that one of the intermediate
4845 components decides to expire a session which has remained idle for too long.
4846
4847 Enabling socket-level TCP keep-alives makes the system regularly send packets
4848 to the other end of the connection, leaving it active. The delay between
4849 keep-alive probes is controlled by the system only and depends both on the
4850 operating system and its tuning parameters.
4851
4852 It is important to understand that keep-alive packets are neither emitted nor
4853 received at the application level. It is only the network stacks which sees
4854 them. For this reason, even if one side of the proxy already uses keep-alives
4855 to maintain its connection alive, those keep-alive packets will not be
4856 forwarded to the other side of the proxy.
4857
4858 Please note that this has nothing to do with HTTP keep-alive.
4859
4860 Using option "clitcpka" enables the emission of TCP keep-alive probes on the
4861 client side of a connection, which should help when session expirations are
4862 noticed between HAProxy and a client.
4863
4864 If this option has been enabled in a "defaults" section, it can be disabled
4865 in a specific instance by prepending the "no" keyword before it.
4866
4867 See also : "option srvtcpka", "option tcpka"
4868
4869
Willy Tarreau0ba27502007-12-24 16:55:16 +01004870option contstats
4871 Enable continuous traffic statistics updates
4872 May be used in sections : defaults | frontend | listen | backend
4873 yes | yes | yes | no
4874 Arguments : none
4875
4876 By default, counters used for statistics calculation are incremented
4877 only when a session finishes. It works quite well when serving small
4878 objects, but with big ones (for example large images or archives) or
4879 with A/V streaming, a graph generated from haproxy counters looks like
4880 a hedgehog. With this option enabled counters get incremented continuously,
4881 during a whole session. Recounting touches a hotpath directly so
4882 it is not enabled by default, as it has small performance impact (~0.5%).
4883
4884
Willy Tarreauc9bd0cc2009-05-10 11:57:02 +02004885option dontlog-normal
4886no option dontlog-normal
4887 Enable or disable logging of normal, successful connections
4888 May be used in sections : defaults | frontend | listen | backend
4889 yes | yes | yes | no
4890 Arguments : none
4891
4892 There are large sites dealing with several thousand connections per second
4893 and for which logging is a major pain. Some of them are even forced to turn
4894 logs off and cannot debug production issues. Setting this option ensures that
4895 normal connections, those which experience no error, no timeout, no retry nor
4896 redispatch, will not be logged. This leaves disk space for anomalies. In HTTP
4897 mode, the response status code is checked and return codes 5xx will still be
4898 logged.
4899
4900 It is strongly discouraged to use this option as most of the time, the key to
4901 complex issues is in the normal logs which will not be logged here. If you
4902 need to separate logs, see the "log-separate-errors" option instead.
4903
Willy Tarreauc57f0e22009-05-10 13:12:33 +02004904 See also : "log", "dontlognull", "log-separate-errors" and section 8 about
Willy Tarreauc9bd0cc2009-05-10 11:57:02 +02004905 logging.
4906
4907
Willy Tarreaubf1f8162007-12-28 17:42:56 +01004908option dontlognull
4909no option dontlognull
4910 Enable or disable logging of null connections
4911 May be used in sections : defaults | frontend | listen | backend
4912 yes | yes | yes | no
4913 Arguments : none
4914
4915 In certain environments, there are components which will regularly connect to
4916 various systems to ensure that they are still alive. It can be the case from
4917 another load balancer as well as from monitoring systems. By default, even a
4918 simple port probe or scan will produce a log. If those connections pollute
4919 the logs too much, it is possible to enable option "dontlognull" to indicate
4920 that a connection on which no data has been transferred will not be logged,
Willy Tarreau0f228a02015-05-01 15:37:53 +02004921 which typically corresponds to those probes. Note that errors will still be
4922 returned to the client and accounted for in the stats. If this is not what is
4923 desired, option http-ignore-probes can be used instead.
Willy Tarreaubf1f8162007-12-28 17:42:56 +01004924
4925 It is generally recommended not to use this option in uncontrolled
4926 environments (eg: internet), otherwise scans and other malicious activities
4927 would not be logged.
4928
4929 If this option has been enabled in a "defaults" section, it can be disabled
4930 in a specific instance by prepending the "no" keyword before it.
4931
Willy Tarreau0f228a02015-05-01 15:37:53 +02004932 See also : "log", "http-ignore-probes", "monitor-net", "monitor-uri", and
4933 section 8 about logging.
Willy Tarreaubf1f8162007-12-28 17:42:56 +01004934
4935
4936option forceclose
4937no option forceclose
4938 Enable or disable active connection closing after response is transferred.
4939 May be used in sections : defaults | frontend | listen | backend
Willy Tarreaua31e5df2009-12-30 01:10:35 +01004940 yes | yes | yes | yes
Willy Tarreaubf1f8162007-12-28 17:42:56 +01004941 Arguments : none
4942
4943 Some HTTP servers do not necessarily close the connections when they receive
4944 the "Connection: close" set by "option httpclose", and if the client does not
4945 close either, then the connection remains open till the timeout expires. This
4946 causes high number of simultaneous connections on the servers and shows high
4947 global session times in the logs.
4948
4949 When this happens, it is possible to use "option forceclose". It will
Willy Tarreau82eeaf22009-12-29 12:09:05 +01004950 actively close the outgoing server channel as soon as the server has finished
Cyril Bonté653dcd62014-02-20 00:13:15 +01004951 to respond and release some resources earlier than with "option httpclose".
Willy Tarreaubf1f8162007-12-28 17:42:56 +01004952
Willy Tarreau8a8e1d92010-04-05 16:15:16 +02004953 This option may also be combined with "option http-pretend-keepalive", which
4954 will disable sending of the "Connection: close" header, but will still cause
4955 the connection to be closed once the whole response is received.
4956
Cyril Bonté653dcd62014-02-20 00:13:15 +01004957 This option disables and replaces any previous "option httpclose", "option
4958 http-server-close", "option http-keep-alive", or "option http-tunnel".
Willy Tarreau02bce8b2014-01-30 00:15:28 +01004959
Willy Tarreaubf1f8162007-12-28 17:42:56 +01004960 If this option has been enabled in a "defaults" section, it can be disabled
4961 in a specific instance by prepending the "no" keyword before it.
4962
Willy Tarreau8a8e1d92010-04-05 16:15:16 +02004963 See also : "option httpclose" and "option http-pretend-keepalive"
Willy Tarreaubf1f8162007-12-28 17:42:56 +01004964
4965
Willy Tarreau87cf5142011-08-19 22:57:24 +02004966option forwardfor [ except <network> ] [ header <name> ] [ if-none ]
Willy Tarreauc27debf2008-01-06 08:57:02 +01004967 Enable insertion of the X-Forwarded-For header to requests sent to servers
4968 May be used in sections : defaults | frontend | listen | backend
4969 yes | yes | yes | yes
4970 Arguments :
4971 <network> is an optional argument used to disable this option for sources
4972 matching <network>
Ross Westaf72a1d2008-08-03 10:51:45 +02004973 <name> an optional argument to specify a different "X-Forwarded-For"
Willy Tarreaud72758d2010-01-12 10:42:19 +01004974 header name.
Willy Tarreauc27debf2008-01-06 08:57:02 +01004975
4976 Since HAProxy works in reverse-proxy mode, the servers see its IP address as
4977 their client address. This is sometimes annoying when the client's IP address
4978 is expected in server logs. To solve this problem, the well-known HTTP header
4979 "X-Forwarded-For" may be added by HAProxy to all requests sent to the server.
4980 This header contains a value representing the client's IP address. Since this
4981 header is always appended at the end of the existing header list, the server
4982 must be configured to always use the last occurrence of this header only. See
Ross Westaf72a1d2008-08-03 10:51:45 +02004983 the server's manual to find how to enable use of this standard header. Note
4984 that only the last occurrence of the header must be used, since it is really
4985 possible that the client has already brought one.
4986
Willy Tarreaud72758d2010-01-12 10:42:19 +01004987 The keyword "header" may be used to supply a different header name to replace
Ross Westaf72a1d2008-08-03 10:51:45 +02004988 the default "X-Forwarded-For". This can be useful where you might already
Willy Tarreaud72758d2010-01-12 10:42:19 +01004989 have a "X-Forwarded-For" header from a different application (eg: stunnel),
4990 and you need preserve it. Also if your backend server doesn't use the
Ross Westaf72a1d2008-08-03 10:51:45 +02004991 "X-Forwarded-For" header and requires different one (eg: Zeus Web Servers
4992 require "X-Cluster-Client-IP").
Willy Tarreauc27debf2008-01-06 08:57:02 +01004993
4994 Sometimes, a same HAProxy instance may be shared between a direct client
4995 access and a reverse-proxy access (for instance when an SSL reverse-proxy is
4996 used to decrypt HTTPS traffic). It is possible to disable the addition of the
4997 header for a known source address or network by adding the "except" keyword
4998 followed by the network address. In this case, any source IP matching the
4999 network will not cause an addition of this header. Most common uses are with
5000 private networks or 127.0.0.1.
5001
Willy Tarreau87cf5142011-08-19 22:57:24 +02005002 Alternatively, the keyword "if-none" states that the header will only be
5003 added if it is not present. This should only be used in perfectly trusted
5004 environment, as this might cause a security issue if headers reaching haproxy
5005 are under the control of the end-user.
5006
Willy Tarreauc27debf2008-01-06 08:57:02 +01005007 This option may be specified either in the frontend or in the backend. If at
Ross Westaf72a1d2008-08-03 10:51:45 +02005008 least one of them uses it, the header will be added. Note that the backend's
5009 setting of the header subargument takes precedence over the frontend's if
Willy Tarreau87cf5142011-08-19 22:57:24 +02005010 both are defined. In the case of the "if-none" argument, if at least one of
5011 the frontend or the backend does not specify it, it wants the addition to be
5012 mandatory, so it wins.
Willy Tarreauc27debf2008-01-06 08:57:02 +01005013
Ross Westaf72a1d2008-08-03 10:51:45 +02005014 Examples :
Willy Tarreauc27debf2008-01-06 08:57:02 +01005015 # Public HTTP address also used by stunnel on the same machine
5016 frontend www
5017 mode http
5018 option forwardfor except 127.0.0.1 # stunnel already adds the header
5019
Ross Westaf72a1d2008-08-03 10:51:45 +02005020 # Those servers want the IP Address in X-Client
5021 backend www
5022 mode http
5023 option forwardfor header X-Client
5024
Willy Tarreau87cf5142011-08-19 22:57:24 +02005025 See also : "option httpclose", "option http-server-close",
Willy Tarreau70dffda2014-01-30 03:07:23 +01005026 "option forceclose", "option http-keep-alive"
Willy Tarreauc27debf2008-01-06 08:57:02 +01005027
Willy Tarreau8a8e1d92010-04-05 16:15:16 +02005028
Willy Tarreau9fbe18e2015-05-01 22:42:08 +02005029option http-buffer-request
5030no option http-buffer-request
5031 Enable or disable waiting for whole HTTP request body before proceeding
5032 May be used in sections : defaults | frontend | listen | backend
5033 yes | yes | yes | yes
5034 Arguments : none
5035
5036 It is sometimes desirable to wait for the body of an HTTP request before
5037 taking a decision. This is what is being done by "balance url_param" for
5038 example. The first use case is to buffer requests from slow clients before
5039 connecting to the server. Another use case consists in taking the routing
5040 decision based on the request body's contents. This option placed in a
5041 frontend or backend forces the HTTP processing to wait until either the whole
5042 body is received, or the request buffer is full, or the first chunk is
5043 complete in case of chunked encoding. It can have undesired side effects with
5044 some applications abusing HTTP by expecting unbufferred transmissions between
5045 the frontend and the backend, so this should definitely not be used by
5046 default.
5047
5048 See also : "option http-no-delay"
5049
5050
Willy Tarreau0f228a02015-05-01 15:37:53 +02005051option http-ignore-probes
5052no option http-ignore-probes
5053 Enable or disable logging of null connections and request timeouts
5054 May be used in sections : defaults | frontend | listen | backend
5055 yes | yes | yes | no
5056 Arguments : none
5057
5058 Recently some browsers started to implement a "pre-connect" feature
5059 consisting in speculatively connecting to some recently visited web sites
5060 just in case the user would like to visit them. This results in many
5061 connections being established to web sites, which end up in 408 Request
5062 Timeout if the timeout strikes first, or 400 Bad Request when the browser
5063 decides to close them first. These ones pollute the log and feed the error
5064 counters. There was already "option dontlognull" but it's insufficient in
5065 this case. Instead, this option does the following things :
5066 - prevent any 400/408 message from being sent to the client if nothing
5067 was received over a connection before it was closed ;
5068 - prevent any log from being emitted in this situation ;
5069 - prevent any error counter from being incremented
5070
5071 That way the empty connection is silently ignored. Note that it is better
5072 not to use this unless it is clear that it is needed, because it will hide
5073 real problems. The most common reason for not receiving a request and seeing
5074 a 408 is due to an MTU inconsistency between the client and an intermediary
5075 element such as a VPN, which blocks too large packets. These issues are
5076 generally seen with POST requests as well as GET with large cookies. The logs
5077 are often the only way to detect them.
5078
5079 If this option has been enabled in a "defaults" section, it can be disabled
5080 in a specific instance by prepending the "no" keyword before it.
5081
5082 See also : "log", "dontlognull", "errorfile", and section 8 about logging.
5083
5084
Willy Tarreau16bfb022010-01-16 19:48:41 +01005085option http-keep-alive
5086no option http-keep-alive
5087 Enable or disable HTTP keep-alive from client to server
5088 May be used in sections : defaults | frontend | listen | backend
5089 yes | yes | yes | yes
5090 Arguments : none
5091
Willy Tarreau70dffda2014-01-30 03:07:23 +01005092 By default HAProxy operates in keep-alive mode with regards to persistent
5093 connections: for each connection it processes each request and response, and
5094 leaves the connection idle on both sides between the end of a response and the
5095 start of a new request. This mode may be changed by several options such as
5096 "option http-server-close", "option forceclose", "option httpclose" or
5097 "option http-tunnel". This option allows to set back the keep-alive mode,
5098 which can be useful when another mode was used in a defaults section.
5099
5100 Setting "option http-keep-alive" enables HTTP keep-alive mode on the client-
5101 and server- sides. This provides the lowest latency on the client side (slow
Willy Tarreau16bfb022010-01-16 19:48:41 +01005102 network) and the fastest session reuse on the server side at the expense
5103 of maintaining idle connections to the servers. In general, it is possible
5104 with this option to achieve approximately twice the request rate that the
5105 "http-server-close" option achieves on small objects. There are mainly two
5106 situations where this option may be useful :
5107
5108 - when the server is non-HTTP compliant and authenticates the connection
5109 instead of requests (eg: NTLM authentication)
5110
5111 - when the cost of establishing the connection to the server is significant
5112 compared to the cost of retrieving the associated object from the server.
5113
5114 This last case can happen when the server is a fast static server of cache.
5115 In this case, the server will need to be properly tuned to support high enough
5116 connection counts because connections will last until the client sends another
5117 request.
5118
5119 If the client request has to go to another backend or another server due to
5120 content switching or the load balancing algorithm, the idle connection will
Willy Tarreau9420b122013-12-15 18:58:25 +01005121 immediately be closed and a new one re-opened. Option "prefer-last-server" is
5122 available to try optimize server selection so that if the server currently
5123 attached to an idle connection is usable, it will be used.
Willy Tarreau16bfb022010-01-16 19:48:41 +01005124
5125 In general it is preferred to use "option http-server-close" with application
5126 servers, and some static servers might benefit from "option http-keep-alive".
5127
5128 At the moment, logs will not indicate whether requests came from the same
5129 session or not. The accept date reported in the logs corresponds to the end
5130 of the previous request, and the request time corresponds to the time spent
5131 waiting for a new request. The keep-alive request time is still bound to the
5132 timeout defined by "timeout http-keep-alive" or "timeout http-request" if
5133 not set.
5134
Cyril Bonté653dcd62014-02-20 00:13:15 +01005135 This option disables and replaces any previous "option httpclose", "option
5136 http-server-close", "option forceclose" or "option http-tunnel". When backend
Willy Tarreau70dffda2014-01-30 03:07:23 +01005137 and frontend options differ, all of these 4 options have precedence over
Cyril Bonté653dcd62014-02-20 00:13:15 +01005138 "option http-keep-alive".
Willy Tarreau16bfb022010-01-16 19:48:41 +01005139
5140 See also : "option forceclose", "option http-server-close",
Willy Tarreau9420b122013-12-15 18:58:25 +01005141 "option prefer-last-server", "option http-pretend-keepalive",
5142 "option httpclose", and "1.1. The HTTP transaction model".
Willy Tarreau16bfb022010-01-16 19:48:41 +01005143
5144
Willy Tarreau96e31212011-05-30 18:10:30 +02005145option http-no-delay
5146no option http-no-delay
5147 Instruct the system to favor low interactive delays over performance in HTTP
5148 May be used in sections : defaults | frontend | listen | backend
5149 yes | yes | yes | yes
5150 Arguments : none
5151
5152 In HTTP, each payload is unidirectional and has no notion of interactivity.
5153 Any agent is expected to queue data somewhat for a reasonably low delay.
5154 There are some very rare server-to-server applications that abuse the HTTP
5155 protocol and expect the payload phase to be highly interactive, with many
5156 interleaved data chunks in both directions within a single request. This is
5157 absolutely not supported by the HTTP specification and will not work across
5158 most proxies or servers. When such applications attempt to do this through
5159 haproxy, it works but they will experience high delays due to the network
5160 optimizations which favor performance by instructing the system to wait for
5161 enough data to be available in order to only send full packets. Typical
5162 delays are around 200 ms per round trip. Note that this only happens with
5163 abnormal uses. Normal uses such as CONNECT requests nor WebSockets are not
5164 affected.
5165
5166 When "option http-no-delay" is present in either the frontend or the backend
5167 used by a connection, all such optimizations will be disabled in order to
5168 make the exchanges as fast as possible. Of course this offers no guarantee on
5169 the functionality, as it may break at any other place. But if it works via
5170 HAProxy, it will work as fast as possible. This option should never be used
5171 by default, and should never be used at all unless such a buggy application
5172 is discovered. The impact of using this option is an increase of bandwidth
5173 usage and CPU usage, which may significantly lower performance in high
5174 latency environments.
5175
Willy Tarreau9fbe18e2015-05-01 22:42:08 +02005176 See also : "option http-buffer-request"
5177
Willy Tarreau96e31212011-05-30 18:10:30 +02005178
Willy Tarreau8a8e1d92010-04-05 16:15:16 +02005179option http-pretend-keepalive
5180no option http-pretend-keepalive
5181 Define whether haproxy will announce keepalive to the server or not
5182 May be used in sections : defaults | frontend | listen | backend
5183 yes | yes | yes | yes
5184 Arguments : none
5185
5186 When running with "option http-server-close" or "option forceclose", haproxy
5187 adds a "Connection: close" header to the request forwarded to the server.
5188 Unfortunately, when some servers see this header, they automatically refrain
5189 from using the chunked encoding for responses of unknown length, while this
5190 is totally unrelated. The immediate effect is that this prevents haproxy from
5191 maintaining the client connection alive. A second effect is that a client or
5192 a cache could receive an incomplete response without being aware of it, and
5193 consider the response complete.
5194
5195 By setting "option http-pretend-keepalive", haproxy will make the server
5196 believe it will keep the connection alive. The server will then not fall back
5197 to the abnormal undesired above. When haproxy gets the whole response, it
5198 will close the connection with the server just as it would do with the
5199 "forceclose" option. That way the client gets a normal response and the
5200 connection is correctly closed on the server side.
5201
5202 It is recommended not to enable this option by default, because most servers
5203 will more efficiently close the connection themselves after the last packet,
5204 and release its buffers slightly earlier. Also, the added packet on the
5205 network could slightly reduce the overall peak performance. However it is
5206 worth noting that when this option is enabled, haproxy will have slightly
5207 less work to do. So if haproxy is the bottleneck on the whole architecture,
5208 enabling this option might save a few CPU cycles.
5209
5210 This option may be set both in a frontend and in a backend. It is enabled if
5211 at least one of the frontend or backend holding a connection has it enabled.
Jamie Gloudonaaa21002012-08-25 00:18:33 -04005212 This option may be combined with "option httpclose", which will cause
Willy Tarreau22a95342010-09-29 14:31:41 +02005213 keepalive to be announced to the server and close to be announced to the
5214 client. This practice is discouraged though.
Willy Tarreau8a8e1d92010-04-05 16:15:16 +02005215
5216 If this option has been enabled in a "defaults" section, it can be disabled
5217 in a specific instance by prepending the "no" keyword before it.
5218
Willy Tarreau16bfb022010-01-16 19:48:41 +01005219 See also : "option forceclose", "option http-server-close", and
5220 "option http-keep-alive"
Willy Tarreau8a8e1d92010-04-05 16:15:16 +02005221
Willy Tarreauc27debf2008-01-06 08:57:02 +01005222
Willy Tarreaub608feb2010-01-02 22:47:18 +01005223option http-server-close
5224no option http-server-close
5225 Enable or disable HTTP connection closing on the server side
5226 May be used in sections : defaults | frontend | listen | backend
5227 yes | yes | yes | yes
5228 Arguments : none
5229
Willy Tarreau70dffda2014-01-30 03:07:23 +01005230 By default HAProxy operates in keep-alive mode with regards to persistent
5231 connections: for each connection it processes each request and response, and
5232 leaves the connection idle on both sides between the end of a response and
5233 the start of a new request. This mode may be changed by several options such
5234 as "option http-server-close", "option forceclose", "option httpclose" or
5235 "option http-tunnel". Setting "option http-server-close" enables HTTP
5236 connection-close mode on the server side while keeping the ability to support
5237 HTTP keep-alive and pipelining on the client side. This provides the lowest
5238 latency on the client side (slow network) and the fastest session reuse on
5239 the server side to save server resources, similarly to "option forceclose".
5240 It also permits non-keepalive capable servers to be served in keep-alive mode
5241 to the clients if they conform to the requirements of RFC2616. Please note
5242 that some servers do not always conform to those requirements when they see
5243 "Connection: close" in the request. The effect will be that keep-alive will
5244 never be used. A workaround consists in enabling "option
5245 http-pretend-keepalive".
Willy Tarreaub608feb2010-01-02 22:47:18 +01005246
5247 At the moment, logs will not indicate whether requests came from the same
5248 session or not. The accept date reported in the logs corresponds to the end
5249 of the previous request, and the request time corresponds to the time spent
5250 waiting for a new request. The keep-alive request time is still bound to the
Willy Tarreaub16a5742010-01-10 14:46:16 +01005251 timeout defined by "timeout http-keep-alive" or "timeout http-request" if
5252 not set.
Willy Tarreaub608feb2010-01-02 22:47:18 +01005253
5254 This option may be set both in a frontend and in a backend. It is enabled if
5255 at least one of the frontend or backend holding a connection has it enabled.
Cyril Bonté653dcd62014-02-20 00:13:15 +01005256 It disables and replaces any previous "option httpclose", "option forceclose",
5257 "option http-tunnel" or "option http-keep-alive". Please check section 4
Willy Tarreau70dffda2014-01-30 03:07:23 +01005258 ("Proxies") to see how this option combines with others when frontend and
5259 backend options differ.
Willy Tarreaub608feb2010-01-02 22:47:18 +01005260
5261 If this option has been enabled in a "defaults" section, it can be disabled
5262 in a specific instance by prepending the "no" keyword before it.
5263
Patrick Mezard9ec2ec42010-06-12 17:02:45 +02005264 See also : "option forceclose", "option http-pretend-keepalive",
Willy Tarreau16bfb022010-01-16 19:48:41 +01005265 "option httpclose", "option http-keep-alive", and
5266 "1.1. The HTTP transaction model".
Willy Tarreaub608feb2010-01-02 22:47:18 +01005267
5268
Willy Tarreau02bce8b2014-01-30 00:15:28 +01005269option http-tunnel
5270no option http-tunnel
5271 Disable or enable HTTP connection processing after first transaction
5272 May be used in sections : defaults | frontend | listen | backend
5273 yes | yes | yes | yes
5274 Arguments : none
5275
Willy Tarreau70dffda2014-01-30 03:07:23 +01005276 By default HAProxy operates in keep-alive mode with regards to persistent
5277 connections: for each connection it processes each request and response, and
5278 leaves the connection idle on both sides between the end of a response and
5279 the start of a new request. This mode may be changed by several options such
5280 as "option http-server-close", "option forceclose", "option httpclose" or
5281 "option http-tunnel".
5282
5283 Option "http-tunnel" disables any HTTP processing past the first request and
Jarno Huuskonen0e82b922014-04-12 18:22:19 +03005284 the first response. This is the mode which was used by default in versions
Willy Tarreau70dffda2014-01-30 03:07:23 +01005285 1.0 to 1.5-dev21. It is the mode with the lowest processing overhead, which
5286 is normally not needed anymore unless in very specific cases such as when
5287 using an in-house protocol that looks like HTTP but is not compatible, or
5288 just to log one request per client in order to reduce log size. Note that
5289 everything which works at the HTTP level, including header parsing/addition,
5290 cookie processing or content switching will only work for the first request
5291 and will be ignored after the first response.
Willy Tarreau02bce8b2014-01-30 00:15:28 +01005292
5293 If this option has been enabled in a "defaults" section, it can be disabled
5294 in a specific instance by prepending the "no" keyword before it.
5295
5296 See also : "option forceclose", "option http-server-close",
5297 "option httpclose", "option http-keep-alive", and
5298 "1.1. The HTTP transaction model".
5299
5300
Willy Tarreau88d349d2010-01-25 12:15:43 +01005301option http-use-proxy-header
Cyril Bontéf0c60612010-02-06 14:44:47 +01005302no option http-use-proxy-header
Willy Tarreau88d349d2010-01-25 12:15:43 +01005303 Make use of non-standard Proxy-Connection header instead of Connection
5304 May be used in sections : defaults | frontend | listen | backend
5305 yes | yes | yes | no
5306 Arguments : none
5307
5308 While RFC2616 explicitly states that HTTP/1.1 agents must use the
5309 Connection header to indicate their wish of persistent or non-persistent
5310 connections, both browsers and proxies ignore this header for proxied
5311 connections and make use of the undocumented, non-standard Proxy-Connection
5312 header instead. The issue begins when trying to put a load balancer between
5313 browsers and such proxies, because there will be a difference between what
5314 haproxy understands and what the client and the proxy agree on.
5315
5316 By setting this option in a frontend, haproxy can automatically switch to use
5317 that non-standard header if it sees proxied requests. A proxied request is
5318 defined here as one where the URI begins with neither a '/' nor a '*'. The
5319 choice of header only affects requests passing through proxies making use of
5320 one of the "httpclose", "forceclose" and "http-server-close" options. Note
5321 that this option can only be specified in a frontend and will affect the
5322 request along its whole life.
5323
Willy Tarreau844a7e72010-01-31 21:46:18 +01005324 Also, when this option is set, a request which requires authentication will
5325 automatically switch to use proxy authentication headers if it is itself a
5326 proxied request. That makes it possible to check or enforce authentication in
5327 front of an existing proxy.
5328
Willy Tarreau88d349d2010-01-25 12:15:43 +01005329 This option should normally never be used, except in front of a proxy.
5330
5331 See also : "option httpclose", "option forceclose" and "option
5332 http-server-close".
5333
5334
Willy Tarreaud63335a2010-02-26 12:56:52 +01005335option httpchk
5336option httpchk <uri>
5337option httpchk <method> <uri>
5338option httpchk <method> <uri> <version>
5339 Enable HTTP protocol to check on the servers health
5340 May be used in sections : defaults | frontend | listen | backend
5341 yes | no | yes | yes
5342 Arguments :
5343 <method> is the optional HTTP method used with the requests. When not set,
5344 the "OPTIONS" method is used, as it generally requires low server
5345 processing and is easy to filter out from the logs. Any method
5346 may be used, though it is not recommended to invent non-standard
5347 ones.
5348
5349 <uri> is the URI referenced in the HTTP requests. It defaults to " / "
5350 which is accessible by default on almost any server, but may be
5351 changed to any other URI. Query strings are permitted.
5352
5353 <version> is the optional HTTP version string. It defaults to "HTTP/1.0"
5354 but some servers might behave incorrectly in HTTP 1.0, so turning
5355 it to HTTP/1.1 may sometimes help. Note that the Host field is
5356 mandatory in HTTP/1.1, and as a trick, it is possible to pass it
5357 after "\r\n" following the version string.
5358
5359 By default, server health checks only consist in trying to establish a TCP
5360 connection. When "option httpchk" is specified, a complete HTTP request is
5361 sent once the TCP connection is established, and responses 2xx and 3xx are
5362 considered valid, while all other ones indicate a server failure, including
5363 the lack of any response.
5364
5365 The port and interval are specified in the server configuration.
5366
5367 This option does not necessarily require an HTTP backend, it also works with
5368 plain TCP backends. This is particularly useful to check simple scripts bound
5369 to some dedicated ports using the inetd daemon.
5370
5371 Examples :
5372 # Relay HTTPS traffic to Apache instance and check service availability
5373 # using HTTP request "OPTIONS * HTTP/1.1" on port 80.
5374 backend https_relay
5375 mode tcp
5376 option httpchk OPTIONS * HTTP/1.1\r\nHost:\ www
5377 server apache1 192.168.1.1:443 check port 80
5378
Simon Hormanafc47ee2013-11-25 10:46:35 +09005379 See also : "option ssl-hello-chk", "option smtpchk", "option mysql-check",
5380 "option pgsql-check", "http-check" and the "check", "port" and
5381 "inter" server options.
Willy Tarreaud63335a2010-02-26 12:56:52 +01005382
5383
Willy Tarreauc27debf2008-01-06 08:57:02 +01005384option httpclose
5385no option httpclose
5386 Enable or disable passive HTTP connection closing
5387 May be used in sections : defaults | frontend | listen | backend
5388 yes | yes | yes | yes
5389 Arguments : none
5390
Willy Tarreau70dffda2014-01-30 03:07:23 +01005391 By default HAProxy operates in keep-alive mode with regards to persistent
5392 connections: for each connection it processes each request and response, and
5393 leaves the connection idle on both sides between the end of a response and
5394 the start of a new request. This mode may be changed by several options such
Cyril Bonté653dcd62014-02-20 00:13:15 +01005395 as "option http-server-close", "option forceclose", "option httpclose" or
Willy Tarreau70dffda2014-01-30 03:07:23 +01005396 "option http-tunnel".
5397
5398 If "option httpclose" is set, HAProxy will work in HTTP tunnel mode and check
5399 if a "Connection: close" header is already set in each direction, and will
5400 add one if missing. Each end should react to this by actively closing the TCP
5401 connection after each transfer, thus resulting in a switch to the HTTP close
5402 mode. Any "Connection" header different from "close" will also be removed.
5403 Note that this option is deprecated since what it does is very cheap but not
5404 reliable. Using "option http-server-close" or "option forceclose" is strongly
5405 recommended instead.
Willy Tarreauc27debf2008-01-06 08:57:02 +01005406
5407 It seldom happens that some servers incorrectly ignore this header and do not
Jamie Gloudonaaa21002012-08-25 00:18:33 -04005408 close the connection even though they reply "Connection: close". For this
Willy Tarreau0dfdf192010-01-05 11:33:11 +01005409 reason, they are not compatible with older HTTP 1.0 browsers. If this happens
5410 it is possible to use the "option forceclose" which actively closes the
5411 request connection once the server responds. Option "forceclose" also
5412 releases the server connection earlier because it does not have to wait for
5413 the client to acknowledge it.
Willy Tarreauc27debf2008-01-06 08:57:02 +01005414
5415 This option may be set both in a frontend and in a backend. It is enabled if
5416 at least one of the frontend or backend holding a connection has it enabled.
Cyril Bonté653dcd62014-02-20 00:13:15 +01005417 It disables and replaces any previous "option http-server-close",
5418 "option forceclose", "option http-keep-alive" or "option http-tunnel". Please
Willy Tarreau70dffda2014-01-30 03:07:23 +01005419 check section 4 ("Proxies") to see how this option combines with others when
5420 frontend and backend options differ.
Willy Tarreauc27debf2008-01-06 08:57:02 +01005421
5422 If this option has been enabled in a "defaults" section, it can be disabled
5423 in a specific instance by prepending the "no" keyword before it.
5424
Patrick Mezard9ec2ec42010-06-12 17:02:45 +02005425 See also : "option forceclose", "option http-server-close" and
5426 "1.1. The HTTP transaction model".
Willy Tarreauc27debf2008-01-06 08:57:02 +01005427
5428
Emeric Brun3a058f32009-06-30 18:26:00 +02005429option httplog [ clf ]
Willy Tarreauc27debf2008-01-06 08:57:02 +01005430 Enable logging of HTTP request, session state and timers
5431 May be used in sections : defaults | frontend | listen | backend
5432 yes | yes | yes | yes
Emeric Brun3a058f32009-06-30 18:26:00 +02005433 Arguments :
5434 clf if the "clf" argument is added, then the output format will be
5435 the CLF format instead of HAProxy's default HTTP format. You can
5436 use this when you need to feed HAProxy's logs through a specific
5437 log analyser which only support the CLF format and which is not
5438 extensible.
Willy Tarreauc27debf2008-01-06 08:57:02 +01005439
5440 By default, the log output format is very poor, as it only contains the
5441 source and destination addresses, and the instance name. By specifying
5442 "option httplog", each log line turns into a much richer format including,
5443 but not limited to, the HTTP request, the connection timers, the session
5444 status, the connections numbers, the captured headers and cookies, the
5445 frontend, backend and server name, and of course the source address and
5446 ports.
5447
5448 This option may be set either in the frontend or the backend.
5449
PiBa-NLbd556bf2014-12-11 21:31:54 +01005450 Specifying only "option httplog" will automatically clear the 'clf' mode
5451 if it was set by default.
Emeric Brun3a058f32009-06-30 18:26:00 +02005452
Willy Tarreauc57f0e22009-05-10 13:12:33 +02005453 See also : section 8 about logging.
Willy Tarreauc27debf2008-01-06 08:57:02 +01005454
Willy Tarreau55165fe2009-05-10 12:02:55 +02005455
5456option http_proxy
5457no option http_proxy
5458 Enable or disable plain HTTP proxy mode
5459 May be used in sections : defaults | frontend | listen | backend
5460 yes | yes | yes | yes
5461 Arguments : none
5462
5463 It sometimes happens that people need a pure HTTP proxy which understands
5464 basic proxy requests without caching nor any fancy feature. In this case,
5465 it may be worth setting up an HAProxy instance with the "option http_proxy"
5466 set. In this mode, no server is declared, and the connection is forwarded to
5467 the IP address and port found in the URL after the "http://" scheme.
5468
5469 No host address resolution is performed, so this only works when pure IP
5470 addresses are passed. Since this option's usage perimeter is rather limited,
5471 it will probably be used only by experts who know they need exactly it. Last,
5472 if the clients are susceptible of sending keep-alive requests, it will be
Cyril Bonté2409e682010-12-14 22:47:51 +01005473 needed to add "option httpclose" to ensure that all requests will correctly
Willy Tarreau55165fe2009-05-10 12:02:55 +02005474 be analyzed.
5475
5476 If this option has been enabled in a "defaults" section, it can be disabled
5477 in a specific instance by prepending the "no" keyword before it.
5478
5479 Example :
5480 # this backend understands HTTP proxy requests and forwards them directly.
5481 backend direct_forward
5482 option httpclose
5483 option http_proxy
5484
5485 See also : "option httpclose"
5486
Willy Tarreau211ad242009-10-03 21:45:07 +02005487
Jamie Gloudon801a0a32012-08-25 00:18:33 -04005488option independent-streams
5489no option independent-streams
5490 Enable or disable independent timeout processing for both directions
Willy Tarreauf27b5ea2009-10-03 22:01:18 +02005491 May be used in sections : defaults | frontend | listen | backend
5492 yes | yes | yes | yes
5493 Arguments : none
5494
5495 By default, when data is sent over a socket, both the write timeout and the
5496 read timeout for that socket are refreshed, because we consider that there is
5497 activity on that socket, and we have no other means of guessing if we should
5498 receive data or not.
5499
5500 While this default behaviour is desirable for almost all applications, there
5501 exists a situation where it is desirable to disable it, and only refresh the
5502 read timeout if there are incoming data. This happens on sessions with large
5503 timeouts and low amounts of exchanged data such as telnet session. If the
5504 server suddenly disappears, the output data accumulates in the system's
5505 socket buffers, both timeouts are correctly refreshed, and there is no way
5506 to know the server does not receive them, so we don't timeout. However, when
5507 the underlying protocol always echoes sent data, it would be enough by itself
5508 to detect the issue using the read timeout. Note that this problem does not
5509 happen with more verbose protocols because data won't accumulate long in the
5510 socket buffers.
5511
5512 When this option is set on the frontend, it will disable read timeout updates
5513 on data sent to the client. There probably is little use of this case. When
5514 the option is set on the backend, it will disable read timeout updates on
5515 data sent to the server. Doing so will typically break large HTTP posts from
5516 slow lines, so use it with caution.
5517
Jarno Huuskonen0e82b922014-04-12 18:22:19 +03005518 Note: older versions used to call this setting "option independent-streams"
Jamie Gloudon801a0a32012-08-25 00:18:33 -04005519 with a spelling mistake. This spelling is still supported but
5520 deprecated.
5521
Willy Tarreauce887fd2012-05-12 12:50:00 +02005522 See also : "timeout client", "timeout server" and "timeout tunnel"
Willy Tarreauf27b5ea2009-10-03 22:01:18 +02005523
5524
Gabor Lekenyb4c81e42010-09-29 18:17:05 +02005525option ldap-check
5526 Use LDAPv3 health checks for server testing
5527 May be used in sections : defaults | frontend | listen | backend
5528 yes | no | yes | yes
5529 Arguments : none
5530
5531 It is possible to test that the server correctly talks LDAPv3 instead of just
5532 testing that it accepts the TCP connection. When this option is set, an
5533 LDAPv3 anonymous simple bind message is sent to the server, and the response
5534 is analyzed to find an LDAPv3 bind response message.
5535
5536 The server is considered valid only when the LDAP response contains success
5537 resultCode (http://tools.ietf.org/html/rfc4511#section-4.1.9).
5538
5539 Logging of bind requests is server dependent see your documentation how to
5540 configure it.
5541
5542 Example :
5543 option ldap-check
5544
5545 See also : "option httpchk"
5546
5547
Simon Horman98637e52014-06-20 12:30:16 +09005548option external-check
5549 Use external processes for server health checks
5550 May be used in sections : defaults | frontend | listen | backend
5551 yes | no | yes | yes
5552
5553 It is possible to test the health of a server using an external command.
5554 This is achieved by running the executable set using "external-check
5555 command".
5556
5557 Requires the "external-check" global to be set.
5558
5559 See also : "external-check", "external-check command", "external-check path"
5560
5561
Willy Tarreau211ad242009-10-03 21:45:07 +02005562option log-health-checks
5563no option log-health-checks
Willy Tarreaubef1b322014-05-13 21:01:39 +02005564 Enable or disable logging of health checks status updates
Willy Tarreau211ad242009-10-03 21:45:07 +02005565 May be used in sections : defaults | frontend | listen | backend
5566 yes | no | yes | yes
5567 Arguments : none
5568
Willy Tarreaubef1b322014-05-13 21:01:39 +02005569 By default, failed health check are logged if server is UP and successful
5570 health checks are logged if server is DOWN, so the amount of additional
5571 information is limited.
Willy Tarreau211ad242009-10-03 21:45:07 +02005572
Willy Tarreaubef1b322014-05-13 21:01:39 +02005573 When this option is enabled, any change of the health check status or to
5574 the server's health will be logged, so that it becomes possible to know
5575 that a server was failing occasional checks before crashing, or exactly when
5576 it failed to respond a valid HTTP status, then when the port started to
5577 reject connections, then when the server stopped responding at all.
5578
5579 Note that status changes not caused by health checks (eg: enable/disable on
5580 the CLI) are intentionally not logged by this option.
Willy Tarreau211ad242009-10-03 21:45:07 +02005581
Willy Tarreaubef1b322014-05-13 21:01:39 +02005582 See also: "option httpchk", "option ldap-check", "option mysql-check",
5583 "option pgsql-check", "option redis-check", "option smtpchk",
5584 "option tcp-check", "log" and section 8 about logging.
Willy Tarreau211ad242009-10-03 21:45:07 +02005585
Willy Tarreauc9bd0cc2009-05-10 11:57:02 +02005586
5587option log-separate-errors
5588no option log-separate-errors
5589 Change log level for non-completely successful connections
5590 May be used in sections : defaults | frontend | listen | backend
5591 yes | yes | yes | no
5592 Arguments : none
5593
5594 Sometimes looking for errors in logs is not easy. This option makes haproxy
5595 raise the level of logs containing potentially interesting information such
5596 as errors, timeouts, retries, redispatches, or HTTP status codes 5xx. The
5597 level changes from "info" to "err". This makes it possible to log them
5598 separately to a different file with most syslog daemons. Be careful not to
5599 remove them from the original file, otherwise you would lose ordering which
5600 provides very important information.
5601
5602 Using this option, large sites dealing with several thousand connections per
5603 second may log normal traffic to a rotating buffer and only archive smaller
5604 error logs.
5605
Willy Tarreauc57f0e22009-05-10 13:12:33 +02005606 See also : "log", "dontlognull", "dontlog-normal" and section 8 about
Willy Tarreauc9bd0cc2009-05-10 11:57:02 +02005607 logging.
5608
Willy Tarreauc27debf2008-01-06 08:57:02 +01005609
5610option logasap
5611no option logasap
5612 Enable or disable early logging of HTTP requests
5613 May be used in sections : defaults | frontend | listen | backend
5614 yes | yes | yes | no
5615 Arguments : none
5616
5617 By default, HTTP requests are logged upon termination so that the total
5618 transfer time and the number of bytes appear in the logs. When large objects
5619 are being transferred, it may take a while before the request appears in the
5620 logs. Using "option logasap", the request gets logged as soon as the server
5621 sends the complete headers. The only missing information in the logs will be
5622 the total number of bytes which will indicate everything except the amount
5623 of data transferred, and the total time which will not take the transfer
Willy Tarreaud2a4aa22008-01-31 15:28:22 +01005624 time into account. In such a situation, it's a good practice to capture the
Willy Tarreauc27debf2008-01-06 08:57:02 +01005625 "Content-Length" response header so that the logs at least indicate how many
5626 bytes are expected to be transferred.
5627
Willy Tarreaucc6c8912009-02-22 10:53:55 +01005628 Examples :
5629 listen http_proxy 0.0.0.0:80
5630 mode http
5631 option httplog
5632 option logasap
5633 log 192.168.2.200 local3
5634
5635 >>> Feb 6 12:14:14 localhost \
5636 haproxy[14389]: 10.0.1.2:33317 [06/Feb/2009:12:14:14.655] http-in \
5637 static/srv1 9/10/7/14/+30 200 +243 - - ---- 3/1/1/1/0 1/0 \
5638 "GET /image.iso HTTP/1.0"
5639
Willy Tarreauc57f0e22009-05-10 13:12:33 +02005640 See also : "option httplog", "capture response header", and section 8 about
Willy Tarreauc27debf2008-01-06 08:57:02 +01005641 logging.
5642
5643
Nenad Merdanovic6639a7c2014-05-30 14:26:32 +02005644option mysql-check [ user <username> [ post-41 ] ]
Hervé COMMOWICK8776f1b2010-10-18 15:58:36 +02005645 Use MySQL health checks for server testing
Hervé COMMOWICK698ae002010-01-12 09:25:13 +01005646 May be used in sections : defaults | frontend | listen | backend
5647 yes | no | yes | yes
Hervé COMMOWICK8776f1b2010-10-18 15:58:36 +02005648 Arguments :
Cyril Bonté108cf6e2012-04-21 23:30:29 +02005649 <username> This is the username which will be used when connecting to MySQL
5650 server.
Nenad Merdanovic6639a7c2014-05-30 14:26:32 +02005651 post-41 Send post v4.1 client compatible checks
Hervé COMMOWICK8776f1b2010-10-18 15:58:36 +02005652
5653 If you specify a username, the check consists of sending two MySQL packet,
5654 one Client Authentication packet, and one QUIT packet, to correctly close
5655 MySQL session. We then parse the MySQL Handshake Initialisation packet and/or
5656 Error packet. It is a basic but useful test which does not produce error nor
5657 aborted connect on the server. However, it requires adding an authorization
5658 in the MySQL table, like this :
5659
5660 USE mysql;
5661 INSERT INTO user (Host,User) values ('<ip_of_haproxy>','<username>');
5662 FLUSH PRIVILEGES;
5663
5664 If you don't specify a username (it is deprecated and not recommended), the
5665 check only consists in parsing the Mysql Handshake Initialisation packet or
5666 Error packet, we don't send anything in this mode. It was reported that it
5667 can generate lockout if check is too frequent and/or if there is not enough
5668 traffic. In fact, you need in this case to check MySQL "max_connect_errors"
5669 value as if a connection is established successfully within fewer than MySQL
5670 "max_connect_errors" attempts after a previous connection was interrupted,
5671 the error count for the host is cleared to zero. If HAProxy's server get
5672 blocked, the "FLUSH HOSTS" statement is the only way to unblock it.
5673
5674 Remember that this does not check database presence nor database consistency.
5675 To do this, you can use an external check with xinetd for example.
Hervé COMMOWICK698ae002010-01-12 09:25:13 +01005676
Hervé COMMOWICK212f7782011-06-10 14:05:59 +02005677 The check requires MySQL >=3.22, for older version, please use TCP check.
Hervé COMMOWICK698ae002010-01-12 09:25:13 +01005678
5679 Most often, an incoming MySQL server needs to see the client's IP address for
5680 various purposes, including IP privilege matching and connection logging.
5681 When possible, it is often wise to masquerade the client's IP address when
5682 connecting to the server using the "usesrc" argument of the "source" keyword,
Willy Tarreau29fbe512015-08-20 19:35:14 +02005683 which requires the transparent proxy feature to be compiled in, and the MySQL
5684 server to route the client via the machine hosting haproxy.
Hervé COMMOWICK698ae002010-01-12 09:25:13 +01005685
5686 See also: "option httpchk"
5687
5688
Willy Tarreaua453bdd2008-01-08 19:50:52 +01005689option nolinger
5690no option nolinger
Krzysztof Piotr Oledzkif8645332009-12-13 21:55:50 +01005691 Enable or disable immediate session resource cleaning after close
Willy Tarreaua453bdd2008-01-08 19:50:52 +01005692 May be used in sections: defaults | frontend | listen | backend
5693 yes | yes | yes | yes
Willy Tarreaueabeafa2008-01-16 16:17:06 +01005694 Arguments : none
Willy Tarreaua453bdd2008-01-08 19:50:52 +01005695
5696 When clients or servers abort connections in a dirty way (eg: they are
5697 physically disconnected), the session timeouts triggers and the session is
5698 closed. But it will remain in FIN_WAIT1 state for some time in the system,
5699 using some resources and possibly limiting the ability to establish newer
5700 connections.
5701
5702 When this happens, it is possible to activate "option nolinger" which forces
5703 the system to immediately remove any socket's pending data on close. Thus,
5704 the session is instantly purged from the system's tables. This usually has
5705 side effects such as increased number of TCP resets due to old retransmits
5706 getting immediately rejected. Some firewalls may sometimes complain about
5707 this too.
5708
5709 For this reason, it is not recommended to use this option when not absolutely
5710 needed. You know that you need it when you have thousands of FIN_WAIT1
5711 sessions on your system (TIME_WAIT ones do not count).
5712
5713 This option may be used both on frontends and backends, depending on the side
5714 where it is required. Use it on the frontend for clients, and on the backend
5715 for servers.
5716
5717 If this option has been enabled in a "defaults" section, it can be disabled
5718 in a specific instance by prepending the "no" keyword before it.
5719
5720
Willy Tarreau55165fe2009-05-10 12:02:55 +02005721option originalto [ except <network> ] [ header <name> ]
5722 Enable insertion of the X-Original-To header to requests sent to servers
5723 May be used in sections : defaults | frontend | listen | backend
5724 yes | yes | yes | yes
5725 Arguments :
5726 <network> is an optional argument used to disable this option for sources
5727 matching <network>
5728 <name> an optional argument to specify a different "X-Original-To"
5729 header name.
5730
5731 Since HAProxy can work in transparent mode, every request from a client can
5732 be redirected to the proxy and HAProxy itself can proxy every request to a
5733 complex SQUID environment and the destination host from SO_ORIGINAL_DST will
5734 be lost. This is annoying when you want access rules based on destination ip
5735 addresses. To solve this problem, a new HTTP header "X-Original-To" may be
5736 added by HAProxy to all requests sent to the server. This header contains a
5737 value representing the original destination IP address. Since this must be
5738 configured to always use the last occurrence of this header only. Note that
5739 only the last occurrence of the header must be used, since it is really
5740 possible that the client has already brought one.
5741
5742 The keyword "header" may be used to supply a different header name to replace
5743 the default "X-Original-To". This can be useful where you might already
5744 have a "X-Original-To" header from a different application, and you need
5745 preserve it. Also if your backend server doesn't use the "X-Original-To"
5746 header and requires different one.
5747
5748 Sometimes, a same HAProxy instance may be shared between a direct client
5749 access and a reverse-proxy access (for instance when an SSL reverse-proxy is
5750 used to decrypt HTTPS traffic). It is possible to disable the addition of the
5751 header for a known source address or network by adding the "except" keyword
5752 followed by the network address. In this case, any source IP matching the
5753 network will not cause an addition of this header. Most common uses are with
5754 private networks or 127.0.0.1.
5755
5756 This option may be specified either in the frontend or in the backend. If at
5757 least one of them uses it, the header will be added. Note that the backend's
5758 setting of the header subargument takes precedence over the frontend's if
5759 both are defined.
5760
Willy Tarreau55165fe2009-05-10 12:02:55 +02005761 Examples :
5762 # Original Destination address
5763 frontend www
5764 mode http
5765 option originalto except 127.0.0.1
5766
5767 # Those servers want the IP Address in X-Client-Dst
5768 backend www
5769 mode http
5770 option originalto header X-Client-Dst
5771
Willy Tarreau87cf5142011-08-19 22:57:24 +02005772 See also : "option httpclose", "option http-server-close",
5773 "option forceclose"
Willy Tarreau55165fe2009-05-10 12:02:55 +02005774
5775
Willy Tarreaua453bdd2008-01-08 19:50:52 +01005776option persist
5777no option persist
5778 Enable or disable forced persistence on down servers
5779 May be used in sections: defaults | frontend | listen | backend
5780 yes | no | yes | yes
Willy Tarreaueabeafa2008-01-16 16:17:06 +01005781 Arguments : none
Willy Tarreaua453bdd2008-01-08 19:50:52 +01005782
5783 When an HTTP request reaches a backend with a cookie which references a dead
5784 server, by default it is redispatched to another server. It is possible to
5785 force the request to be sent to the dead server first using "option persist"
5786 if absolutely needed. A common use case is when servers are under extreme
5787 load and spend their time flapping. In this case, the users would still be
5788 directed to the server they opened the session on, in the hope they would be
5789 correctly served. It is recommended to use "option redispatch" in conjunction
5790 with this option so that in the event it would not be possible to connect to
5791 the server at all (server definitely dead), the client would finally be
5792 redirected to another valid server.
5793
5794 If this option has been enabled in a "defaults" section, it can be disabled
5795 in a specific instance by prepending the "no" keyword before it.
5796
Willy Tarreau4de91492010-01-22 19:10:05 +01005797 See also : "option redispatch", "retries", "force-persist"
Willy Tarreaua453bdd2008-01-08 19:50:52 +01005798
5799
Willy Tarreau0c122822013-12-15 18:49:01 +01005800option pgsql-check [ user <username> ]
5801 Use PostgreSQL health checks for server testing
5802 May be used in sections : defaults | frontend | listen | backend
5803 yes | no | yes | yes
5804 Arguments :
5805 <username> This is the username which will be used when connecting to
5806 PostgreSQL server.
5807
5808 The check sends a PostgreSQL StartupMessage and waits for either
5809 Authentication request or ErrorResponse message. It is a basic but useful
5810 test which does not produce error nor aborted connect on the server.
5811 This check is identical with the "mysql-check".
5812
5813 See also: "option httpchk"
5814
5815
Willy Tarreau9420b122013-12-15 18:58:25 +01005816option prefer-last-server
5817no option prefer-last-server
5818 Allow multiple load balanced requests to remain on the same server
5819 May be used in sections: defaults | frontend | listen | backend
5820 yes | no | yes | yes
5821 Arguments : none
5822
5823 When the load balancing algorithm in use is not deterministic, and a previous
5824 request was sent to a server to which haproxy still holds a connection, it is
5825 sometimes desirable that subsequent requests on a same session go to the same
5826 server as much as possible. Note that this is different from persistence, as
5827 we only indicate a preference which haproxy tries to apply without any form
5828 of warranty. The real use is for keep-alive connections sent to servers. When
5829 this option is used, haproxy will try to reuse the same connection that is
5830 attached to the server instead of rebalancing to another server, causing a
5831 close of the connection. This can make sense for static file servers. It does
Willy Tarreau068621e2013-12-23 15:11:25 +01005832 not make much sense to use this in combination with hashing algorithms. Note,
5833 haproxy already automatically tries to stick to a server which sends a 401 or
5834 to a proxy which sends a 407 (authentication required). This is mandatory for
5835 use with the broken NTLM authentication challenge, and significantly helps in
5836 troubleshooting some faulty applications. Option prefer-last-server might be
5837 desirable in these environments as well, to avoid redistributing the traffic
5838 after every other response.
Willy Tarreau9420b122013-12-15 18:58:25 +01005839
5840 If this option has been enabled in a "defaults" section, it can be disabled
5841 in a specific instance by prepending the "no" keyword before it.
5842
5843 See also: "option http-keep-alive"
5844
5845
Krzysztof Piotr Oledzki25b501a2008-01-06 16:36:16 +01005846option redispatch
Joseph Lynch726ab712015-05-11 23:25:34 -07005847option redispatch <interval>
Krzysztof Piotr Oledzki25b501a2008-01-06 16:36:16 +01005848no option redispatch
5849 Enable or disable session redistribution in case of connection failure
5850 May be used in sections: defaults | frontend | listen | backend
5851 yes | no | yes | yes
Joseph Lynch726ab712015-05-11 23:25:34 -07005852 Arguments :
5853 <interval> The optional integer value that controls how often redispatches
5854 occur when retrying connections. Positive value P indicates a
5855 redispatch is desired on every Pth retry, and negative value
5856 N indicate a redispath is desired on the Nth retry prior to the
5857 last retry. For example, the default of -1 preserves the
5858 historical behaviour of redispatching on the last retry, a
5859 positive value of 1 would indicate a redispatch on every retry,
5860 and a positive value of 3 would indicate a redispatch on every
5861 third retry. You can disable redispatches with a value of 0.
5862
Krzysztof Piotr Oledzki25b501a2008-01-06 16:36:16 +01005863
5864 In HTTP mode, if a server designated by a cookie is down, clients may
5865 definitely stick to it because they cannot flush the cookie, so they will not
5866 be able to access the service anymore.
5867
5868 Specifying "option redispatch" will allow the proxy to break their
5869 persistence and redistribute them to a working server.
5870
Joseph Lynch726ab712015-05-11 23:25:34 -07005871 It also allows to retry connections to another server in case of multiple
Krzysztof Piotr Oledzki25b501a2008-01-06 16:36:16 +01005872 connection failures. Of course, it requires having "retries" set to a nonzero
5873 value.
Willy Tarreaud72758d2010-01-12 10:42:19 +01005874
Krzysztof Piotr Oledzki25b501a2008-01-06 16:36:16 +01005875 This form is the preferred form, which replaces both the "redispatch" and
5876 "redisp" keywords.
5877
5878 If this option has been enabled in a "defaults" section, it can be disabled
5879 in a specific instance by prepending the "no" keyword before it.
5880
Willy Tarreau4de91492010-01-22 19:10:05 +01005881 See also : "redispatch", "retries", "force-persist"
Krzysztof Piotr Oledzki25b501a2008-01-06 16:36:16 +01005882
Willy Tarreaua453bdd2008-01-08 19:50:52 +01005883
Hervé COMMOWICKec032d62011-08-05 16:23:48 +02005884option redis-check
5885 Use redis health checks for server testing
5886 May be used in sections : defaults | frontend | listen | backend
5887 yes | no | yes | yes
5888 Arguments : none
5889
5890 It is possible to test that the server correctly talks REDIS protocol instead
5891 of just testing that it accepts the TCP connection. When this option is set,
5892 a PING redis command is sent to the server, and the response is analyzed to
5893 find the "+PONG" response message.
5894
5895 Example :
5896 option redis-check
5897
5898 See also : "option httpchk"
5899
5900
Willy Tarreaua453bdd2008-01-08 19:50:52 +01005901option smtpchk
5902option smtpchk <hello> <domain>
5903 Use SMTP health checks for server testing
5904 May be used in sections : defaults | frontend | listen | backend
5905 yes | no | yes | yes
Willy Tarreaud72758d2010-01-12 10:42:19 +01005906 Arguments :
Willy Tarreaua453bdd2008-01-08 19:50:52 +01005907 <hello> is an optional argument. It is the "hello" command to use. It can
5908 be either "HELO" (for SMTP) or "EHLO" (for ESTMP). All other
5909 values will be turned into the default command ("HELO").
5910
5911 <domain> is the domain name to present to the server. It may only be
5912 specified (and is mandatory) if the hello command has been
5913 specified. By default, "localhost" is used.
5914
5915 When "option smtpchk" is set, the health checks will consist in TCP
5916 connections followed by an SMTP command. By default, this command is
5917 "HELO localhost". The server's return code is analyzed and only return codes
5918 starting with a "2" will be considered as valid. All other responses,
5919 including a lack of response will constitute an error and will indicate a
5920 dead server.
5921
5922 This test is meant to be used with SMTP servers or relays. Depending on the
5923 request, it is possible that some servers do not log each connection attempt,
5924 so you may want to experiment to improve the behaviour. Using telnet on port
5925 25 is often easier than adjusting the configuration.
5926
5927 Most often, an incoming SMTP server needs to see the client's IP address for
5928 various purposes, including spam filtering, anti-spoofing and logging. When
5929 possible, it is often wise to masquerade the client's IP address when
5930 connecting to the server using the "usesrc" argument of the "source" keyword,
Willy Tarreau29fbe512015-08-20 19:35:14 +02005931 which requires the transparent proxy feature to be compiled in.
Willy Tarreaua453bdd2008-01-08 19:50:52 +01005932
5933 Example :
5934 option smtpchk HELO mydomain.org
5935
5936 See also : "option httpchk", "source"
5937
Krzysztof Piotr Oledzki25b501a2008-01-06 16:36:16 +01005938
Krzysztof Piotr Oledzkiaeebf9b2009-10-04 15:43:17 +02005939option socket-stats
5940no option socket-stats
5941
5942 Enable or disable collecting & providing separate statistics for each socket.
5943 May be used in sections : defaults | frontend | listen | backend
5944 yes | yes | yes | no
5945
5946 Arguments : none
5947
5948
Willy Tarreauff4f82d2009-02-06 11:28:13 +01005949option splice-auto
5950no option splice-auto
5951 Enable or disable automatic kernel acceleration on sockets in both directions
5952 May be used in sections : defaults | frontend | listen | backend
5953 yes | yes | yes | yes
5954 Arguments : none
5955
5956 When this option is enabled either on a frontend or on a backend, haproxy
5957 will automatically evaluate the opportunity to use kernel tcp splicing to
5958 forward data between the client and the server, in either direction. Haproxy
5959 uses heuristics to estimate if kernel splicing might improve performance or
Krzysztof Piotr Oledzkif8645332009-12-13 21:55:50 +01005960 not. Both directions are handled independently. Note that the heuristics used
Willy Tarreauff4f82d2009-02-06 11:28:13 +01005961 are not much aggressive in order to limit excessive use of splicing. This
5962 option requires splicing to be enabled at compile time, and may be globally
5963 disabled with the global option "nosplice". Since splice uses pipes, using it
5964 requires that there are enough spare pipes.
5965
5966 Important note: kernel-based TCP splicing is a Linux-specific feature which
5967 first appeared in kernel 2.6.25. It offers kernel-based acceleration to
5968 transfer data between sockets without copying these data to user-space, thus
5969 providing noticeable performance gains and CPU cycles savings. Since many
5970 early implementations are buggy, corrupt data and/or are inefficient, this
5971 feature is not enabled by default, and it should be used with extreme care.
5972 While it is not possible to detect the correctness of an implementation,
5973 2.6.29 is the first version offering a properly working implementation. In
5974 case of doubt, splicing may be globally disabled using the global "nosplice"
5975 keyword.
5976
5977 Example :
5978 option splice-auto
5979
5980 If this option has been enabled in a "defaults" section, it can be disabled
5981 in a specific instance by prepending the "no" keyword before it.
5982
5983 See also : "option splice-request", "option splice-response", and global
5984 options "nosplice" and "maxpipes"
5985
5986
5987option splice-request
5988no option splice-request
5989 Enable or disable automatic kernel acceleration on sockets for requests
5990 May be used in sections : defaults | frontend | listen | backend
5991 yes | yes | yes | yes
5992 Arguments : none
5993
5994 When this option is enabled either on a frontend or on a backend, haproxy
Jamie Gloudonaaa21002012-08-25 00:18:33 -04005995 will use kernel tcp splicing whenever possible to forward data going from
Willy Tarreauff4f82d2009-02-06 11:28:13 +01005996 the client to the server. It might still use the recv/send scheme if there
5997 are no spare pipes left. This option requires splicing to be enabled at
5998 compile time, and may be globally disabled with the global option "nosplice".
5999 Since splice uses pipes, using it requires that there are enough spare pipes.
6000
6001 Important note: see "option splice-auto" for usage limitations.
6002
6003 Example :
6004 option splice-request
6005
6006 If this option has been enabled in a "defaults" section, it can be disabled
6007 in a specific instance by prepending the "no" keyword before it.
6008
6009 See also : "option splice-auto", "option splice-response", and global options
6010 "nosplice" and "maxpipes"
6011
6012
6013option splice-response
6014no option splice-response
6015 Enable or disable automatic kernel acceleration on sockets for responses
6016 May be used in sections : defaults | frontend | listen | backend
6017 yes | yes | yes | yes
6018 Arguments : none
6019
6020 When this option is enabled either on a frontend or on a backend, haproxy
Jamie Gloudonaaa21002012-08-25 00:18:33 -04006021 will use kernel tcp splicing whenever possible to forward data going from
Willy Tarreauff4f82d2009-02-06 11:28:13 +01006022 the server to the client. It might still use the recv/send scheme if there
6023 are no spare pipes left. This option requires splicing to be enabled at
6024 compile time, and may be globally disabled with the global option "nosplice".
6025 Since splice uses pipes, using it requires that there are enough spare pipes.
6026
6027 Important note: see "option splice-auto" for usage limitations.
6028
6029 Example :
6030 option splice-response
6031
6032 If this option has been enabled in a "defaults" section, it can be disabled
6033 in a specific instance by prepending the "no" keyword before it.
6034
6035 See also : "option splice-auto", "option splice-request", and global options
6036 "nosplice" and "maxpipes"
6037
6038
Willy Tarreaubf1f8162007-12-28 17:42:56 +01006039option srvtcpka
6040no option srvtcpka
6041 Enable or disable the sending of TCP keepalive packets on the server side
6042 May be used in sections : defaults | frontend | listen | backend
6043 yes | no | yes | yes
6044 Arguments : none
6045
6046 When there is a firewall or any session-aware component between a client and
6047 a server, and when the protocol involves very long sessions with long idle
6048 periods (eg: remote desktops), there is a risk that one of the intermediate
6049 components decides to expire a session which has remained idle for too long.
6050
6051 Enabling socket-level TCP keep-alives makes the system regularly send packets
6052 to the other end of the connection, leaving it active. The delay between
6053 keep-alive probes is controlled by the system only and depends both on the
6054 operating system and its tuning parameters.
6055
6056 It is important to understand that keep-alive packets are neither emitted nor
6057 received at the application level. It is only the network stacks which sees
6058 them. For this reason, even if one side of the proxy already uses keep-alives
6059 to maintain its connection alive, those keep-alive packets will not be
6060 forwarded to the other side of the proxy.
6061
6062 Please note that this has nothing to do with HTTP keep-alive.
6063
6064 Using option "srvtcpka" enables the emission of TCP keep-alive probes on the
6065 server side of a connection, which should help when session expirations are
6066 noticed between HAProxy and a server.
6067
6068 If this option has been enabled in a "defaults" section, it can be disabled
6069 in a specific instance by prepending the "no" keyword before it.
6070
6071 See also : "option clitcpka", "option tcpka"
6072
6073
Willy Tarreaua453bdd2008-01-08 19:50:52 +01006074option ssl-hello-chk
6075 Use SSLv3 client hello health checks for server testing
6076 May be used in sections : defaults | frontend | listen | backend
6077 yes | no | yes | yes
6078 Arguments : none
6079
6080 When some SSL-based protocols are relayed in TCP mode through HAProxy, it is
6081 possible to test that the server correctly talks SSL instead of just testing
6082 that it accepts the TCP connection. When "option ssl-hello-chk" is set, pure
6083 SSLv3 client hello messages are sent once the connection is established to
6084 the server, and the response is analyzed to find an SSL server hello message.
6085 The server is considered valid only when the response contains this server
6086 hello message.
6087
6088 All servers tested till there correctly reply to SSLv3 client hello messages,
6089 and most servers tested do not even log the requests containing only hello
6090 messages, which is appreciable.
6091
Willy Tarreau763a95b2012-10-04 23:15:39 +02006092 Note that this check works even when SSL support was not built into haproxy
6093 because it forges the SSL message. When SSL support is available, it is best
6094 to use native SSL health checks instead of this one.
Willy Tarreaua453bdd2008-01-08 19:50:52 +01006095
Willy Tarreau763a95b2012-10-04 23:15:39 +02006096 See also: "option httpchk", "check-ssl"
6097
Willy Tarreaua453bdd2008-01-08 19:50:52 +01006098
Willy Tarreaued179852013-12-16 01:07:00 +01006099option tcp-check
6100 Perform health checks using tcp-check send/expect sequences
6101 May be used in sections: defaults | frontend | listen | backend
6102 yes | no | yes | yes
6103
6104 This health check method is intended to be combined with "tcp-check" command
6105 lists in order to support send/expect types of health check sequences.
6106
6107 TCP checks currently support 4 modes of operations :
6108 - no "tcp-check" directive : the health check only consists in a connection
6109 attempt, which remains the default mode.
6110
Jarno Huuskonen0e82b922014-04-12 18:22:19 +03006111 - "tcp-check send" or "tcp-check send-binary" only is mentioned : this is
Willy Tarreaued179852013-12-16 01:07:00 +01006112 used to send a string along with a connection opening. With some
6113 protocols, it helps sending a "QUIT" message for example that prevents
6114 the server from logging a connection error for each health check. The
6115 check result will still be based on the ability to open the connection
6116 only.
6117
Jarno Huuskonen0e82b922014-04-12 18:22:19 +03006118 - "tcp-check expect" only is mentioned : this is used to test a banner.
Willy Tarreaued179852013-12-16 01:07:00 +01006119 The connection is opened and haproxy waits for the server to present some
6120 contents which must validate some rules. The check result will be based
6121 on the matching between the contents and the rules. This is suited for
6122 POP, IMAP, SMTP, FTP, SSH, TELNET.
6123
Jarno Huuskonen0e82b922014-04-12 18:22:19 +03006124 - both "tcp-check send" and "tcp-check expect" are mentioned : this is
Willy Tarreaued179852013-12-16 01:07:00 +01006125 used to test a hello-type protocol. Haproxy sends a message, the server
6126 responds and its response is analysed. the check result will be based on
Jarno Huuskonen0e82b922014-04-12 18:22:19 +03006127 the matching between the response contents and the rules. This is often
Willy Tarreaued179852013-12-16 01:07:00 +01006128 suited for protocols which require a binding or a request/response model.
6129 LDAP, MySQL, Redis and SSL are example of such protocols, though they
6130 already all have their dedicated checks with a deeper understanding of
6131 the respective protocols.
6132 In this mode, many questions may be sent and many answers may be
6133 analysed.
6134
Baptiste Assmannd60a9e52015-04-25 16:27:23 +02006135 A fifth mode can be used to insert comments in different steps of the
6136 script.
6137
6138 For each tcp-check rule you create, you can add a "comment" directive,
6139 followed by a string. This string will be reported in the log and stderr
6140 in debug mode. It is useful to make user-friendly error reporting.
6141 The "comment" is of course optional.
6142
6143
Willy Tarreaued179852013-12-16 01:07:00 +01006144 Examples :
6145 # perform a POP check (analyse only server's banner)
6146 option tcp-check
Baptiste Assmannd60a9e52015-04-25 16:27:23 +02006147 tcp-check expect string +OK\ POP3\ ready comment POP\ protocol
Willy Tarreaued179852013-12-16 01:07:00 +01006148
6149 # perform an IMAP check (analyse only server's banner)
6150 option tcp-check
Baptiste Assmannd60a9e52015-04-25 16:27:23 +02006151 tcp-check expect string *\ OK\ IMAP4\ ready comment IMAP\ protocol
Willy Tarreaued179852013-12-16 01:07:00 +01006152
6153 # look for the redis master server after ensuring it speaks well
6154 # redis protocol, then it exits properly.
Jarno Huuskonen0e82b922014-04-12 18:22:19 +03006155 # (send a command then analyse the response 3 times)
Willy Tarreaued179852013-12-16 01:07:00 +01006156 option tcp-check
Baptiste Assmannd60a9e52015-04-25 16:27:23 +02006157 tcp-check comment PING\ phase
Willy Tarreaued179852013-12-16 01:07:00 +01006158 tcp-check send PING\r\n
Baptiste Assmanna3322992015-08-04 10:12:18 +02006159 tcp-check expect string +PONG
Baptiste Assmannd60a9e52015-04-25 16:27:23 +02006160 tcp-check comment role\ check
Willy Tarreaued179852013-12-16 01:07:00 +01006161 tcp-check send info\ replication\r\n
6162 tcp-check expect string role:master
Baptiste Assmannd60a9e52015-04-25 16:27:23 +02006163 tcp-check comment QUIT\ phase
Willy Tarreaued179852013-12-16 01:07:00 +01006164 tcp-check send QUIT\r\n
6165 tcp-check expect string +OK
6166
6167 forge a HTTP request, then analyse the response
6168 (send many headers before analyzing)
6169 option tcp-check
Baptiste Assmannd60a9e52015-04-25 16:27:23 +02006170 tcp-check comment forge\ and\ send\ HTTP\ request
Willy Tarreaued179852013-12-16 01:07:00 +01006171 tcp-check send HEAD\ /\ HTTP/1.1\r\n
6172 tcp-check send Host:\ www.mydomain.com\r\n
6173 tcp-check send User-Agent:\ HAProxy\ tcpcheck\r\n
6174 tcp-check send \r\n
Baptiste Assmannd60a9e52015-04-25 16:27:23 +02006175 tcp-check expect rstring HTTP/1\..\ (2..|3..) comment check\ HTTP\ response
Willy Tarreaued179852013-12-16 01:07:00 +01006176
6177
6178 See also : "tcp-check expect", "tcp-check send"
6179
6180
Willy Tarreau9ea05a72009-06-14 12:07:01 +02006181option tcp-smart-accept
6182no option tcp-smart-accept
6183 Enable or disable the saving of one ACK packet during the accept sequence
6184 May be used in sections : defaults | frontend | listen | backend
6185 yes | yes | yes | no
6186 Arguments : none
6187
6188 When an HTTP connection request comes in, the system acknowledges it on
6189 behalf of HAProxy, then the client immediately sends its request, and the
6190 system acknowledges it too while it is notifying HAProxy about the new
6191 connection. HAProxy then reads the request and responds. This means that we
6192 have one TCP ACK sent by the system for nothing, because the request could
6193 very well be acknowledged by HAProxy when it sends its response.
6194
6195 For this reason, in HTTP mode, HAProxy automatically asks the system to avoid
6196 sending this useless ACK on platforms which support it (currently at least
6197 Linux). It must not cause any problem, because the system will send it anyway
6198 after 40 ms if the response takes more time than expected to come.
6199
6200 During complex network debugging sessions, it may be desirable to disable
6201 this optimization because delayed ACKs can make troubleshooting more complex
6202 when trying to identify where packets are delayed. It is then possible to
6203 fall back to normal behaviour by specifying "no option tcp-smart-accept".
6204
6205 It is also possible to force it for non-HTTP proxies by simply specifying
6206 "option tcp-smart-accept". For instance, it can make sense with some services
6207 such as SMTP where the server speaks first.
6208
6209 It is recommended to avoid forcing this option in a defaults section. In case
6210 of doubt, consider setting it back to automatic values by prepending the
6211 "default" keyword before it, or disabling it using the "no" keyword.
6212
Willy Tarreaud88edf22009-06-14 15:48:17 +02006213 See also : "option tcp-smart-connect"
6214
6215
6216option tcp-smart-connect
6217no option tcp-smart-connect
6218 Enable or disable the saving of one ACK packet during the connect sequence
6219 May be used in sections : defaults | frontend | listen | backend
6220 yes | no | yes | yes
6221 Arguments : none
6222
6223 On certain systems (at least Linux), HAProxy can ask the kernel not to
6224 immediately send an empty ACK upon a connection request, but to directly
6225 send the buffer request instead. This saves one packet on the network and
6226 thus boosts performance. It can also be useful for some servers, because they
6227 immediately get the request along with the incoming connection.
6228
6229 This feature is enabled when "option tcp-smart-connect" is set in a backend.
6230 It is not enabled by default because it makes network troubleshooting more
6231 complex.
6232
6233 It only makes sense to enable it with protocols where the client speaks first
6234 such as HTTP. In other situations, if there is no data to send in place of
6235 the ACK, a normal ACK is sent.
6236
6237 If this option has been enabled in a "defaults" section, it can be disabled
6238 in a specific instance by prepending the "no" keyword before it.
6239
6240 See also : "option tcp-smart-accept"
6241
Willy Tarreau9ea05a72009-06-14 12:07:01 +02006242
Willy Tarreaubf1f8162007-12-28 17:42:56 +01006243option tcpka
6244 Enable or disable the sending of TCP keepalive packets on both sides
6245 May be used in sections : defaults | frontend | listen | backend
6246 yes | yes | yes | yes
6247 Arguments : none
6248
6249 When there is a firewall or any session-aware component between a client and
6250 a server, and when the protocol involves very long sessions with long idle
6251 periods (eg: remote desktops), there is a risk that one of the intermediate
6252 components decides to expire a session which has remained idle for too long.
6253
6254 Enabling socket-level TCP keep-alives makes the system regularly send packets
6255 to the other end of the connection, leaving it active. The delay between
6256 keep-alive probes is controlled by the system only and depends both on the
6257 operating system and its tuning parameters.
6258
6259 It is important to understand that keep-alive packets are neither emitted nor
6260 received at the application level. It is only the network stacks which sees
6261 them. For this reason, even if one side of the proxy already uses keep-alives
6262 to maintain its connection alive, those keep-alive packets will not be
6263 forwarded to the other side of the proxy.
6264
6265 Please note that this has nothing to do with HTTP keep-alive.
6266
6267 Using option "tcpka" enables the emission of TCP keep-alive probes on both
6268 the client and server sides of a connection. Note that this is meaningful
6269 only in "defaults" or "listen" sections. If this option is used in a
6270 frontend, only the client side will get keep-alives, and if this option is
6271 used in a backend, only the server side will get keep-alives. For this
6272 reason, it is strongly recommended to explicitly use "option clitcpka" and
6273 "option srvtcpka" when the configuration is split between frontends and
6274 backends.
6275
6276 See also : "option clitcpka", "option srvtcpka"
6277
Willy Tarreau844e3c52008-01-11 16:28:18 +01006278
6279option tcplog
6280 Enable advanced logging of TCP connections with session state and timers
6281 May be used in sections : defaults | frontend | listen | backend
6282 yes | yes | yes | yes
6283 Arguments : none
6284
6285 By default, the log output format is very poor, as it only contains the
6286 source and destination addresses, and the instance name. By specifying
6287 "option tcplog", each log line turns into a much richer format including, but
6288 not limited to, the connection timers, the session status, the connections
6289 numbers, the frontend, backend and server name, and of course the source
6290 address and ports. This option is useful for pure TCP proxies in order to
6291 find which of the client or server disconnects or times out. For normal HTTP
6292 proxies, it's better to use "option httplog" which is even more complete.
6293
6294 This option may be set either in the frontend or the backend.
6295
Willy Tarreauc57f0e22009-05-10 13:12:33 +02006296 See also : "option httplog", and section 8 about logging.
Willy Tarreau844e3c52008-01-11 16:28:18 +01006297
6298
Willy Tarreau844e3c52008-01-11 16:28:18 +01006299option transparent
6300no option transparent
6301 Enable client-side transparent proxying
6302 May be used in sections : defaults | frontend | listen | backend
Willy Tarreau4b1f8592008-12-23 23:13:55 +01006303 yes | no | yes | yes
Willy Tarreau844e3c52008-01-11 16:28:18 +01006304 Arguments : none
6305
6306 This option was introduced in order to provide layer 7 persistence to layer 3
6307 load balancers. The idea is to use the OS's ability to redirect an incoming
6308 connection for a remote address to a local process (here HAProxy), and let
6309 this process know what address was initially requested. When this option is
6310 used, sessions without cookies will be forwarded to the original destination
6311 IP address of the incoming request (which should match that of another
6312 equipment), while requests with cookies will still be forwarded to the
6313 appropriate server.
6314
6315 Note that contrary to a common belief, this option does NOT make HAProxy
6316 present the client's IP to the server when establishing the connection.
6317
Willy Tarreaua1146052011-03-01 09:51:54 +01006318 See also: the "usesrc" argument of the "source" keyword, and the
Willy Tarreaueabeafa2008-01-16 16:17:06 +01006319 "transparent" option of the "bind" keyword.
Willy Tarreau844e3c52008-01-11 16:28:18 +01006320
Willy Tarreaubf1f8162007-12-28 17:42:56 +01006321
Simon Horman98637e52014-06-20 12:30:16 +09006322external-check command <command>
6323 Executable to run when performing an external-check
6324 May be used in sections : defaults | frontend | listen | backend
6325 yes | no | yes | yes
6326
6327 Arguments :
6328 <command> is the external command to run
6329
Simon Horman98637e52014-06-20 12:30:16 +09006330 The arguments passed to the to the command are:
6331
Cyril Bonté777be862014-12-02 21:21:35 +01006332 <proxy_address> <proxy_port> <server_address> <server_port>
Simon Horman98637e52014-06-20 12:30:16 +09006333
Cyril Bonté777be862014-12-02 21:21:35 +01006334 The <proxy_address> and <proxy_port> are derived from the first listener
6335 that is either IPv4, IPv6 or a UNIX socket. In the case of a UNIX socket
6336 listener the proxy_address will be the path of the socket and the
6337 <proxy_port> will be the string "NOT_USED". In a backend section, it's not
6338 possible to determine a listener, and both <proxy_address> and <proxy_port>
6339 will have the string value "NOT_USED".
Simon Horman98637e52014-06-20 12:30:16 +09006340
Cyril Bonté72cda2a2014-12-27 22:28:39 +01006341 Some values are also provided through environment variables.
6342
6343 Environment variables :
6344 HAPROXY_PROXY_ADDR The first bind address if available (or empty if not
6345 applicable, for example in a "backend" section).
6346
6347 HAPROXY_PROXY_ID The backend id.
6348
6349 HAPROXY_PROXY_NAME The backend name.
6350
6351 HAPROXY_PROXY_PORT The first bind port if available (or empty if not
6352 applicable, for example in a "backend" section or
6353 for a UNIX socket).
6354
6355 HAPROXY_SERVER_ADDR The server address.
6356
6357 HAPROXY_SERVER_CURCONN The current number of connections on the server.
6358
6359 HAPROXY_SERVER_ID The server id.
6360
6361 HAPROXY_SERVER_MAXCONN The server max connections.
6362
6363 HAPROXY_SERVER_NAME The server name.
6364
6365 HAPROXY_SERVER_PORT The server port if available (or empty for a UNIX
6366 socket).
6367
6368 PATH The PATH environment variable used when executing
6369 the command may be set using "external-check path".
6370
Simon Horman98637e52014-06-20 12:30:16 +09006371 If the command executed and exits with a zero status then the check is
6372 considered to have passed, otherwise the check is considered to have
6373 failed.
6374
6375 Example :
6376 external-check command /bin/true
6377
6378 See also : "external-check", "option external-check", "external-check path"
6379
6380
6381external-check path <path>
6382 The value of the PATH environment variable used when running an external-check
6383 May be used in sections : defaults | frontend | listen | backend
6384 yes | no | yes | yes
6385
6386 Arguments :
6387 <path> is the path used when executing external command to run
6388
6389 The default path is "".
6390
6391 Example :
6392 external-check path "/usr/bin:/bin"
6393
6394 See also : "external-check", "option external-check",
6395 "external-check command"
6396
6397
Emeric Brun647caf12009-06-30 17:57:00 +02006398persist rdp-cookie
Hervé COMMOWICKa3eb39c2011-08-05 18:48:51 +02006399persist rdp-cookie(<name>)
Emeric Brun647caf12009-06-30 17:57:00 +02006400 Enable RDP cookie-based persistence
6401 May be used in sections : defaults | frontend | listen | backend
6402 yes | no | yes | yes
6403 Arguments :
6404 <name> is the optional name of the RDP cookie to check. If omitted, the
Willy Tarreau61e28f22010-05-16 22:31:05 +02006405 default cookie name "msts" will be used. There currently is no
6406 valid reason to change this name.
Emeric Brun647caf12009-06-30 17:57:00 +02006407
6408 This statement enables persistence based on an RDP cookie. The RDP cookie
6409 contains all information required to find the server in the list of known
6410 servers. So when this option is set in the backend, the request is analysed
6411 and if an RDP cookie is found, it is decoded. If it matches a known server
6412 which is still UP (or if "option persist" is set), then the connection is
6413 forwarded to this server.
6414
6415 Note that this only makes sense in a TCP backend, but for this to work, the
6416 frontend must have waited long enough to ensure that an RDP cookie is present
6417 in the request buffer. This is the same requirement as with the "rdp-cookie"
Krzysztof Piotr Oledzkif8645332009-12-13 21:55:50 +01006418 load-balancing method. Thus it is highly recommended to put all statements in
Emeric Brun647caf12009-06-30 17:57:00 +02006419 a single "listen" section.
6420
Willy Tarreau61e28f22010-05-16 22:31:05 +02006421 Also, it is important to understand that the terminal server will emit this
6422 RDP cookie only if it is configured for "token redirection mode", which means
6423 that the "IP address redirection" option is disabled.
6424
Emeric Brun647caf12009-06-30 17:57:00 +02006425 Example :
6426 listen tse-farm
6427 bind :3389
6428 # wait up to 5s for an RDP cookie in the request
6429 tcp-request inspect-delay 5s
6430 tcp-request content accept if RDP_COOKIE
6431 # apply RDP cookie persistence
6432 persist rdp-cookie
6433 # if server is unknown, let's balance on the same cookie.
Cyril Bontédc4d9032012-04-08 21:57:39 +02006434 # alternatively, "balance leastconn" may be useful too.
Emeric Brun647caf12009-06-30 17:57:00 +02006435 balance rdp-cookie
6436 server srv1 1.1.1.1:3389
6437 server srv2 1.1.1.2:3389
6438
Simon Hormanab814e02011-06-24 14:50:20 +09006439 See also : "balance rdp-cookie", "tcp-request", the "req_rdp_cookie" ACL and
6440 the rdp_cookie pattern fetch function.
Emeric Brun647caf12009-06-30 17:57:00 +02006441
6442
Willy Tarreau3a7d2072009-03-05 23:48:25 +01006443rate-limit sessions <rate>
6444 Set a limit on the number of new sessions accepted per second on a frontend
6445 May be used in sections : defaults | frontend | listen | backend
6446 yes | yes | yes | no
6447 Arguments :
6448 <rate> The <rate> parameter is an integer designating the maximum number
6449 of new sessions per second to accept on the frontend.
6450
6451 When the frontend reaches the specified number of new sessions per second, it
6452 stops accepting new connections until the rate drops below the limit again.
6453 During this time, the pending sessions will be kept in the socket's backlog
6454 (in system buffers) and haproxy will not even be aware that sessions are
6455 pending. When applying very low limit on a highly loaded service, it may make
6456 sense to increase the socket's backlog using the "backlog" keyword.
6457
6458 This feature is particularly efficient at blocking connection-based attacks
6459 or service abuse on fragile servers. Since the session rate is measured every
6460 millisecond, it is extremely accurate. Also, the limit applies immediately,
6461 no delay is needed at all to detect the threshold.
6462
6463 Example : limit the connection rate on SMTP to 10 per second max
6464 listen smtp
6465 mode tcp
6466 bind :25
6467 rate-limit sessions 10
6468 server 127.0.0.1:1025
6469
Willy Tarreaua17c2d92011-07-25 08:16:20 +02006470 Note : when the maximum rate is reached, the frontend's status is not changed
6471 but its sockets appear as "WAITING" in the statistics if the
6472 "socket-stats" option is enabled.
Willy Tarreau3a7d2072009-03-05 23:48:25 +01006473
6474 See also : the "backlog" keyword and the "fe_sess_rate" ACL criterion.
6475
6476
Willy Tarreau2e1dca82012-09-12 08:43:15 +02006477redirect location <loc> [code <code>] <option> [{if | unless} <condition>]
6478redirect prefix <pfx> [code <code>] <option> [{if | unless} <condition>]
6479redirect scheme <sch> [code <code>] <option> [{if | unless} <condition>]
Willy Tarreaub463dfb2008-06-07 23:08:56 +02006480 Return an HTTP redirection if/unless a condition is matched
6481 May be used in sections : defaults | frontend | listen | backend
6482 no | yes | yes | yes
6483
6484 If/unless the condition is matched, the HTTP request will lead to a redirect
Willy Tarreauf285f542010-01-03 20:03:03 +01006485 response. If no condition is specified, the redirect applies unconditionally.
Willy Tarreaub463dfb2008-06-07 23:08:56 +02006486
Willy Tarreau0140f252008-11-19 21:07:09 +01006487 Arguments :
Willy Tarreau2e1dca82012-09-12 08:43:15 +02006488 <loc> With "redirect location", the exact value in <loc> is placed into
Thierry FOURNIERd18cd0f2013-11-29 12:15:45 +01006489 the HTTP "Location" header. When used in an "http-request" rule,
6490 <loc> value follows the log-format rules and can include some
6491 dynamic values (see Custom Log Format in section 8.2.4).
Willy Tarreau2e1dca82012-09-12 08:43:15 +02006492
6493 <pfx> With "redirect prefix", the "Location" header is built from the
6494 concatenation of <pfx> and the complete URI path, including the
6495 query string, unless the "drop-query" option is specified (see
6496 below). As a special case, if <pfx> equals exactly "/", then
6497 nothing is inserted before the original URI. It allows one to
Thierry FOURNIERd18cd0f2013-11-29 12:15:45 +01006498 redirect to the same URL (for instance, to insert a cookie). When
6499 used in an "http-request" rule, <pfx> value follows the log-format
6500 rules and can include some dynamic values (see Custom Log Format
6501 in section 8.2.4).
Willy Tarreau2e1dca82012-09-12 08:43:15 +02006502
6503 <sch> With "redirect scheme", then the "Location" header is built by
6504 concatenating <sch> with "://" then the first occurrence of the
6505 "Host" header, and then the URI path, including the query string
6506 unless the "drop-query" option is specified (see below). If no
6507 path is found or if the path is "*", then "/" is used instead. If
6508 no "Host" header is found, then an empty host component will be
Jarno Huuskonen0e82b922014-04-12 18:22:19 +03006509 returned, which most recent browsers interpret as redirecting to
Willy Tarreau2e1dca82012-09-12 08:43:15 +02006510 the same host. This directive is mostly used to redirect HTTP to
Thierry FOURNIERd18cd0f2013-11-29 12:15:45 +01006511 HTTPS. When used in an "http-request" rule, <sch> value follows
6512 the log-format rules and can include some dynamic values (see
6513 Custom Log Format in section 8.2.4).
Willy Tarreau0140f252008-11-19 21:07:09 +01006514
6515 <code> The code is optional. It indicates which type of HTTP redirection
Willy Tarreaub67fdc42013-03-29 19:28:11 +01006516 is desired. Only codes 301, 302, 303, 307 and 308 are supported,
6517 with 302 used by default if no code is specified. 301 means
6518 "Moved permanently", and a browser may cache the Location. 302
Baptiste Assmannea849c02015-08-03 11:42:50 +02006519 means "Moved temporarily" and means that the browser should not
Willy Tarreaub67fdc42013-03-29 19:28:11 +01006520 cache the redirection. 303 is equivalent to 302 except that the
6521 browser will fetch the location with a GET method. 307 is just
6522 like 302 but makes it clear that the same method must be reused.
6523 Likewise, 308 replaces 301 if the same method must be used.
Willy Tarreau0140f252008-11-19 21:07:09 +01006524
6525 <option> There are several options which can be specified to adjust the
6526 expected behaviour of a redirection :
6527
6528 - "drop-query"
6529 When this keyword is used in a prefix-based redirection, then the
6530 location will be set without any possible query-string, which is useful
6531 for directing users to a non-secure page for instance. It has no effect
6532 with a location-type redirect.
6533
Willy Tarreau81e3b4f2010-01-10 00:42:19 +01006534 - "append-slash"
6535 This keyword may be used in conjunction with "drop-query" to redirect
6536 users who use a URL not ending with a '/' to the same one with the '/'.
6537 It can be useful to ensure that search engines will only see one URL.
6538 For this, a return code 301 is preferred.
6539
Willy Tarreau0140f252008-11-19 21:07:09 +01006540 - "set-cookie NAME[=value]"
6541 A "Set-Cookie" header will be added with NAME (and optionally "=value")
6542 to the response. This is sometimes used to indicate that a user has
6543 been seen, for instance to protect against some types of DoS. No other
6544 cookie option is added, so the cookie will be a session cookie. Note
6545 that for a browser, a sole cookie name without an equal sign is
6546 different from a cookie with an equal sign.
6547
6548 - "clear-cookie NAME[=]"
6549 A "Set-Cookie" header will be added with NAME (and optionally "="), but
6550 with the "Max-Age" attribute set to zero. This will tell the browser to
6551 delete this cookie. It is useful for instance on logout pages. It is
6552 important to note that clearing the cookie "NAME" will not remove a
6553 cookie set with "NAME=value". You have to clear the cookie "NAME=" for
6554 that, because the browser makes the difference.
Willy Tarreaub463dfb2008-06-07 23:08:56 +02006555
6556 Example: move the login URL only to HTTPS.
6557 acl clear dst_port 80
6558 acl secure dst_port 8080
6559 acl login_page url_beg /login
Willy Tarreau0140f252008-11-19 21:07:09 +01006560 acl logout url_beg /logout
Willy Tarreau79da4692008-11-19 20:03:04 +01006561 acl uid_given url_reg /login?userid=[^&]+
Willy Tarreau0140f252008-11-19 21:07:09 +01006562 acl cookie_set hdr_sub(cookie) SEEN=1
6563
6564 redirect prefix https://mysite.com set-cookie SEEN=1 if !cookie_set
Willy Tarreau79da4692008-11-19 20:03:04 +01006565 redirect prefix https://mysite.com if login_page !secure
6566 redirect prefix http://mysite.com drop-query if login_page !uid_given
6567 redirect location http://mysite.com/ if !login_page secure
Willy Tarreau0140f252008-11-19 21:07:09 +01006568 redirect location / clear-cookie USERID= if logout
Willy Tarreaub463dfb2008-06-07 23:08:56 +02006569
Willy Tarreau81e3b4f2010-01-10 00:42:19 +01006570 Example: send redirects for request for articles without a '/'.
6571 acl missing_slash path_reg ^/article/[^/]*$
6572 redirect code 301 prefix / drop-query append-slash if missing_slash
6573
Willy Tarreau2e1dca82012-09-12 08:43:15 +02006574 Example: redirect all HTTP traffic to HTTPS when SSL is handled by haproxy.
David BERARDe7153042012-11-03 00:11:31 +01006575 redirect scheme https if !{ ssl_fc }
Willy Tarreau2e1dca82012-09-12 08:43:15 +02006576
Thierry FOURNIERd18cd0f2013-11-29 12:15:45 +01006577 Example: append 'www.' prefix in front of all hosts not having it
6578 http-request redirect code 301 location www.%[hdr(host)]%[req.uri] \
6579 unless { hdr_beg(host) -i www }
6580
Willy Tarreauc57f0e22009-05-10 13:12:33 +02006581 See section 7 about ACL usage.
Willy Tarreaub463dfb2008-06-07 23:08:56 +02006582
6583
Krzysztof Piotr Oledzki25b501a2008-01-06 16:36:16 +01006584redisp (deprecated)
6585redispatch (deprecated)
6586 Enable or disable session redistribution in case of connection failure
6587 May be used in sections: defaults | frontend | listen | backend
6588 yes | no | yes | yes
Willy Tarreaueabeafa2008-01-16 16:17:06 +01006589 Arguments : none
Krzysztof Piotr Oledzki25b501a2008-01-06 16:36:16 +01006590
6591 In HTTP mode, if a server designated by a cookie is down, clients may
6592 definitely stick to it because they cannot flush the cookie, so they will not
6593 be able to access the service anymore.
6594
6595 Specifying "redispatch" will allow the proxy to break their persistence and
6596 redistribute them to a working server.
6597
6598 It also allows to retry last connection to another server in case of multiple
6599 connection failures. Of course, it requires having "retries" set to a nonzero
6600 value.
Willy Tarreaud72758d2010-01-12 10:42:19 +01006601
Krzysztof Piotr Oledzki25b501a2008-01-06 16:36:16 +01006602 This form is deprecated, do not use it in any new configuration, use the new
6603 "option redispatch" instead.
6604
6605 See also : "option redispatch"
6606
Willy Tarreaueabeafa2008-01-16 16:17:06 +01006607
Willy Tarreau8abd4cd2010-01-31 14:30:44 +01006608reqadd <string> [{if | unless} <cond>]
Willy Tarreau303c0352008-01-17 19:01:39 +01006609 Add a header at the end of the HTTP request
6610 May be used in sections : defaults | frontend | listen | backend
6611 no | yes | yes | yes
6612 Arguments :
6613 <string> is the complete line to be added. Any space or known delimiter
6614 must be escaped using a backslash ('\'). Please refer to section
Willy Tarreauc57f0e22009-05-10 13:12:33 +02006615 6 about HTTP header manipulation for more information.
Willy Tarreau303c0352008-01-17 19:01:39 +01006616
Willy Tarreau8abd4cd2010-01-31 14:30:44 +01006617 <cond> is an optional matching condition built from ACLs. It makes it
6618 possible to ignore this rule when other conditions are not met.
6619
Willy Tarreau303c0352008-01-17 19:01:39 +01006620 A new line consisting in <string> followed by a line feed will be added after
6621 the last header of an HTTP request.
6622
6623 Header transformations only apply to traffic which passes through HAProxy,
6624 and not to traffic generated by HAProxy, such as health-checks or error
6625 responses.
6626
Willy Tarreau8abd4cd2010-01-31 14:30:44 +01006627 Example : add "X-Proto: SSL" to requests coming via port 81
6628 acl is-ssl dst_port 81
6629 reqadd X-Proto:\ SSL if is-ssl
6630
6631 See also: "rspadd", section 6 about HTTP header manipulation, and section 7
6632 about ACLs.
Willy Tarreau303c0352008-01-17 19:01:39 +01006633
6634
Willy Tarreau5321c422010-01-28 20:35:13 +01006635reqallow <search> [{if | unless} <cond>]
6636reqiallow <search> [{if | unless} <cond>] (ignore case)
Willy Tarreau303c0352008-01-17 19:01:39 +01006637 Definitely allow an HTTP request if a line matches a regular expression
6638 May be used in sections : defaults | frontend | listen | backend
6639 no | yes | yes | yes
6640 Arguments :
6641 <search> is the regular expression applied to HTTP headers and to the
6642 request line. This is an extended regular expression. Parenthesis
6643 grouping is supported and no preliminary backslash is required.
6644 Any space or known delimiter must be escaped using a backslash
6645 ('\'). The pattern applies to a full line at a time. The
6646 "reqallow" keyword strictly matches case while "reqiallow"
6647 ignores case.
6648
Willy Tarreau5321c422010-01-28 20:35:13 +01006649 <cond> is an optional matching condition built from ACLs. It makes it
6650 possible to ignore this rule when other conditions are not met.
6651
Willy Tarreau303c0352008-01-17 19:01:39 +01006652 A request containing any line which matches extended regular expression
6653 <search> will mark the request as allowed, even if any later test would
6654 result in a deny. The test applies both to the request line and to request
6655 headers. Keep in mind that URLs in request line are case-sensitive while
Willy Tarreaud72758d2010-01-12 10:42:19 +01006656 header names are not.
Willy Tarreau303c0352008-01-17 19:01:39 +01006657
6658 It is easier, faster and more powerful to use ACLs to write access policies.
6659 Reqdeny, reqallow and reqpass should be avoided in new designs.
6660
6661 Example :
6662 # allow www.* but refuse *.local
6663 reqiallow ^Host:\ www\.
6664 reqideny ^Host:\ .*\.local
6665
Willy Tarreau5321c422010-01-28 20:35:13 +01006666 See also: "reqdeny", "block", section 6 about HTTP header manipulation, and
6667 section 7 about ACLs.
Willy Tarreau303c0352008-01-17 19:01:39 +01006668
6669
Willy Tarreau5321c422010-01-28 20:35:13 +01006670reqdel <search> [{if | unless} <cond>]
6671reqidel <search> [{if | unless} <cond>] (ignore case)
Willy Tarreau303c0352008-01-17 19:01:39 +01006672 Delete all headers matching a regular expression in an HTTP request
6673 May be used in sections : defaults | frontend | listen | backend
6674 no | yes | yes | yes
6675 Arguments :
6676 <search> is the regular expression applied to HTTP headers and to the
6677 request line. This is an extended regular expression. Parenthesis
6678 grouping is supported and no preliminary backslash is required.
6679 Any space or known delimiter must be escaped using a backslash
6680 ('\'). The pattern applies to a full line at a time. The "reqdel"
6681 keyword strictly matches case while "reqidel" ignores case.
6682
Willy Tarreau5321c422010-01-28 20:35:13 +01006683 <cond> is an optional matching condition built from ACLs. It makes it
6684 possible to ignore this rule when other conditions are not met.
6685
Willy Tarreau303c0352008-01-17 19:01:39 +01006686 Any header line matching extended regular expression <search> in the request
6687 will be completely deleted. Most common use of this is to remove unwanted
6688 and/or dangerous headers or cookies from a request before passing it to the
6689 next servers.
6690
6691 Header transformations only apply to traffic which passes through HAProxy,
6692 and not to traffic generated by HAProxy, such as health-checks or error
6693 responses. Keep in mind that header names are not case-sensitive.
6694
6695 Example :
6696 # remove X-Forwarded-For header and SERVER cookie
6697 reqidel ^X-Forwarded-For:.*
6698 reqidel ^Cookie:.*SERVER=
6699
Willy Tarreau5321c422010-01-28 20:35:13 +01006700 See also: "reqadd", "reqrep", "rspdel", section 6 about HTTP header
6701 manipulation, and section 7 about ACLs.
Willy Tarreau303c0352008-01-17 19:01:39 +01006702
6703
Willy Tarreau5321c422010-01-28 20:35:13 +01006704reqdeny <search> [{if | unless} <cond>]
6705reqideny <search> [{if | unless} <cond>] (ignore case)
Willy Tarreau303c0352008-01-17 19:01:39 +01006706 Deny an HTTP request if a line matches a regular expression
6707 May be used in sections : defaults | frontend | listen | backend
6708 no | yes | yes | yes
6709 Arguments :
6710 <search> is the regular expression applied to HTTP headers and to the
6711 request line. This is an extended regular expression. Parenthesis
6712 grouping is supported and no preliminary backslash is required.
6713 Any space or known delimiter must be escaped using a backslash
6714 ('\'). The pattern applies to a full line at a time. The
6715 "reqdeny" keyword strictly matches case while "reqideny" ignores
6716 case.
6717
Willy Tarreau5321c422010-01-28 20:35:13 +01006718 <cond> is an optional matching condition built from ACLs. It makes it
6719 possible to ignore this rule when other conditions are not met.
6720
Willy Tarreau303c0352008-01-17 19:01:39 +01006721 A request containing any line which matches extended regular expression
6722 <search> will mark the request as denied, even if any later test would
6723 result in an allow. The test applies both to the request line and to request
6724 headers. Keep in mind that URLs in request line are case-sensitive while
Willy Tarreaud72758d2010-01-12 10:42:19 +01006725 header names are not.
Willy Tarreau303c0352008-01-17 19:01:39 +01006726
Willy Tarreauced27012008-01-17 20:35:34 +01006727 A denied request will generate an "HTTP 403 forbidden" response once the
Willy Tarreaud2a4aa22008-01-31 15:28:22 +01006728 complete request has been parsed. This is consistent with what is practiced
Willy Tarreaud72758d2010-01-12 10:42:19 +01006729 using ACLs.
Willy Tarreauced27012008-01-17 20:35:34 +01006730
Willy Tarreau303c0352008-01-17 19:01:39 +01006731 It is easier, faster and more powerful to use ACLs to write access policies.
6732 Reqdeny, reqallow and reqpass should be avoided in new designs.
6733
6734 Example :
6735 # refuse *.local, then allow www.*
6736 reqideny ^Host:\ .*\.local
6737 reqiallow ^Host:\ www\.
6738
Willy Tarreau5321c422010-01-28 20:35:13 +01006739 See also: "reqallow", "rspdeny", "block", section 6 about HTTP header
6740 manipulation, and section 7 about ACLs.
Willy Tarreau303c0352008-01-17 19:01:39 +01006741
6742
Willy Tarreau5321c422010-01-28 20:35:13 +01006743reqpass <search> [{if | unless} <cond>]
6744reqipass <search> [{if | unless} <cond>] (ignore case)
Willy Tarreau303c0352008-01-17 19:01:39 +01006745 Ignore any HTTP request line matching a regular expression in next rules
6746 May be used in sections : defaults | frontend | listen | backend
6747 no | yes | yes | yes
6748 Arguments :
6749 <search> is the regular expression applied to HTTP headers and to the
6750 request line. This is an extended regular expression. Parenthesis
6751 grouping is supported and no preliminary backslash is required.
6752 Any space or known delimiter must be escaped using a backslash
6753 ('\'). The pattern applies to a full line at a time. The
6754 "reqpass" keyword strictly matches case while "reqipass" ignores
6755 case.
6756
Willy Tarreau5321c422010-01-28 20:35:13 +01006757 <cond> is an optional matching condition built from ACLs. It makes it
6758 possible to ignore this rule when other conditions are not met.
6759
Willy Tarreau303c0352008-01-17 19:01:39 +01006760 A request containing any line which matches extended regular expression
6761 <search> will skip next rules, without assigning any deny or allow verdict.
6762 The test applies both to the request line and to request headers. Keep in
6763 mind that URLs in request line are case-sensitive while header names are not.
6764
6765 It is easier, faster and more powerful to use ACLs to write access policies.
6766 Reqdeny, reqallow and reqpass should be avoided in new designs.
6767
6768 Example :
6769 # refuse *.local, then allow www.*, but ignore "www.private.local"
6770 reqipass ^Host:\ www.private\.local
6771 reqideny ^Host:\ .*\.local
6772 reqiallow ^Host:\ www\.
6773
Willy Tarreau5321c422010-01-28 20:35:13 +01006774 See also: "reqallow", "reqdeny", "block", section 6 about HTTP header
6775 manipulation, and section 7 about ACLs.
Willy Tarreau303c0352008-01-17 19:01:39 +01006776
6777
Willy Tarreau5321c422010-01-28 20:35:13 +01006778reqrep <search> <string> [{if | unless} <cond>]
6779reqirep <search> <string> [{if | unless} <cond>] (ignore case)
Willy Tarreau303c0352008-01-17 19:01:39 +01006780 Replace a regular expression with a string in an HTTP request line
6781 May be used in sections : defaults | frontend | listen | backend
6782 no | yes | yes | yes
6783 Arguments :
6784 <search> is the regular expression applied to HTTP headers and to the
6785 request line. This is an extended regular expression. Parenthesis
6786 grouping is supported and no preliminary backslash is required.
6787 Any space or known delimiter must be escaped using a backslash
6788 ('\'). The pattern applies to a full line at a time. The "reqrep"
6789 keyword strictly matches case while "reqirep" ignores case.
6790
6791 <string> is the complete line to be added. Any space or known delimiter
6792 must be escaped using a backslash ('\'). References to matched
6793 pattern groups are possible using the common \N form, with N
6794 being a single digit between 0 and 9. Please refer to section
Willy Tarreauc57f0e22009-05-10 13:12:33 +02006795 6 about HTTP header manipulation for more information.
Willy Tarreau303c0352008-01-17 19:01:39 +01006796
Willy Tarreau5321c422010-01-28 20:35:13 +01006797 <cond> is an optional matching condition built from ACLs. It makes it
6798 possible to ignore this rule when other conditions are not met.
6799
Willy Tarreau303c0352008-01-17 19:01:39 +01006800 Any line matching extended regular expression <search> in the request (both
6801 the request line and header lines) will be completely replaced with <string>.
6802 Most common use of this is to rewrite URLs or domain names in "Host" headers.
6803
6804 Header transformations only apply to traffic which passes through HAProxy,
6805 and not to traffic generated by HAProxy, such as health-checks or error
6806 responses. Note that for increased readability, it is suggested to add enough
6807 spaces between the request and the response. Keep in mind that URLs in
6808 request line are case-sensitive while header names are not.
6809
6810 Example :
6811 # replace "/static/" with "/" at the beginning of any request path.
Dmitry Sivachenko7823de32012-05-16 14:00:26 +04006812 reqrep ^([^\ :]*)\ /static/(.*) \1\ /\2
Willy Tarreau303c0352008-01-17 19:01:39 +01006813 # replace "www.mydomain.com" with "www" in the host name.
6814 reqirep ^Host:\ www.mydomain.com Host:\ www
6815
Dmitry Sivachenkof6f4f7b2012-10-21 18:10:25 +04006816 See also: "reqadd", "reqdel", "rsprep", "tune.bufsize", section 6 about
6817 HTTP header manipulation, and section 7 about ACLs.
Willy Tarreau303c0352008-01-17 19:01:39 +01006818
6819
Willy Tarreau5321c422010-01-28 20:35:13 +01006820reqtarpit <search> [{if | unless} <cond>]
6821reqitarpit <search> [{if | unless} <cond>] (ignore case)
Willy Tarreau303c0352008-01-17 19:01:39 +01006822 Tarpit an HTTP request containing a line matching a regular expression
6823 May be used in sections : defaults | frontend | listen | backend
6824 no | yes | yes | yes
6825 Arguments :
6826 <search> is the regular expression applied to HTTP headers and to the
6827 request line. This is an extended regular expression. Parenthesis
6828 grouping is supported and no preliminary backslash is required.
6829 Any space or known delimiter must be escaped using a backslash
6830 ('\'). The pattern applies to a full line at a time. The
6831 "reqtarpit" keyword strictly matches case while "reqitarpit"
6832 ignores case.
6833
Willy Tarreau5321c422010-01-28 20:35:13 +01006834 <cond> is an optional matching condition built from ACLs. It makes it
6835 possible to ignore this rule when other conditions are not met.
6836
Willy Tarreau303c0352008-01-17 19:01:39 +01006837 A request containing any line which matches extended regular expression
6838 <search> will be tarpitted, which means that it will connect to nowhere, will
Willy Tarreauced27012008-01-17 20:35:34 +01006839 be kept open for a pre-defined time, then will return an HTTP error 500 so
6840 that the attacker does not suspect it has been tarpitted. The status 500 will
6841 be reported in the logs, but the completion flags will indicate "PT". The
Willy Tarreau303c0352008-01-17 19:01:39 +01006842 delay is defined by "timeout tarpit", or "timeout connect" if the former is
6843 not set.
6844
6845 The goal of the tarpit is to slow down robots attacking servers with
6846 identifiable requests. Many robots limit their outgoing number of connections
6847 and stay connected waiting for a reply which can take several minutes to
6848 come. Depending on the environment and attack, it may be particularly
6849 efficient at reducing the load on the network and firewalls.
6850
Willy Tarreau5321c422010-01-28 20:35:13 +01006851 Examples :
Willy Tarreau303c0352008-01-17 19:01:39 +01006852 # ignore user-agents reporting any flavour of "Mozilla" or "MSIE", but
6853 # block all others.
6854 reqipass ^User-Agent:\.*(Mozilla|MSIE)
6855 reqitarpit ^User-Agent:
6856
Willy Tarreau5321c422010-01-28 20:35:13 +01006857 # block bad guys
6858 acl badguys src 10.1.0.3 172.16.13.20/28
6859 reqitarpit . if badguys
6860
6861 See also: "reqallow", "reqdeny", "reqpass", section 6 about HTTP header
6862 manipulation, and section 7 about ACLs.
Willy Tarreau303c0352008-01-17 19:01:39 +01006863
6864
Willy Tarreaue5c5ce92008-06-20 17:27:19 +02006865retries <value>
6866 Set the number of retries to perform on a server after a connection failure
6867 May be used in sections: defaults | frontend | listen | backend
6868 yes | no | yes | yes
6869 Arguments :
6870 <value> is the number of times a connection attempt should be retried on
6871 a server when a connection either is refused or times out. The
6872 default value is 3.
6873
6874 It is important to understand that this value applies to the number of
6875 connection attempts, not full requests. When a connection has effectively
6876 been established to a server, there will be no more retry.
6877
6878 In order to avoid immediate reconnections to a server which is restarting,
Joseph Lynch726ab712015-05-11 23:25:34 -07006879 a turn-around timer of min("timeout connect", one second) is applied before
6880 a retry occurs.
Willy Tarreaue5c5ce92008-06-20 17:27:19 +02006881
6882 When "option redispatch" is set, the last retry may be performed on another
6883 server even if a cookie references a different server.
6884
6885 See also : "option redispatch"
6886
6887
Willy Tarreaufdb563c2010-01-31 15:43:27 +01006888rspadd <string> [{if | unless} <cond>]
Willy Tarreau303c0352008-01-17 19:01:39 +01006889 Add a header at the end of the HTTP response
6890 May be used in sections : defaults | frontend | listen | backend
6891 no | yes | yes | yes
6892 Arguments :
6893 <string> is the complete line to be added. Any space or known delimiter
6894 must be escaped using a backslash ('\'). Please refer to section
Willy Tarreauc57f0e22009-05-10 13:12:33 +02006895 6 about HTTP header manipulation for more information.
Willy Tarreau303c0352008-01-17 19:01:39 +01006896
Willy Tarreaufdb563c2010-01-31 15:43:27 +01006897 <cond> is an optional matching condition built from ACLs. It makes it
6898 possible to ignore this rule when other conditions are not met.
6899
Willy Tarreau303c0352008-01-17 19:01:39 +01006900 A new line consisting in <string> followed by a line feed will be added after
6901 the last header of an HTTP response.
6902
6903 Header transformations only apply to traffic which passes through HAProxy,
6904 and not to traffic generated by HAProxy, such as health-checks or error
6905 responses.
6906
Willy Tarreaufdb563c2010-01-31 15:43:27 +01006907 See also: "reqadd", section 6 about HTTP header manipulation, and section 7
6908 about ACLs.
Willy Tarreau303c0352008-01-17 19:01:39 +01006909
6910
Willy Tarreaufdb563c2010-01-31 15:43:27 +01006911rspdel <search> [{if | unless} <cond>]
6912rspidel <search> [{if | unless} <cond>] (ignore case)
Willy Tarreau303c0352008-01-17 19:01:39 +01006913 Delete all headers matching a regular expression in an HTTP response
6914 May be used in sections : defaults | frontend | listen | backend
6915 no | yes | yes | yes
6916 Arguments :
6917 <search> is the regular expression applied to HTTP headers and to the
6918 response line. This is an extended regular expression, so
6919 parenthesis grouping is supported and no preliminary backslash
6920 is required. Any space or known delimiter must be escaped using
6921 a backslash ('\'). The pattern applies to a full line at a time.
6922 The "rspdel" keyword strictly matches case while "rspidel"
6923 ignores case.
6924
Willy Tarreaufdb563c2010-01-31 15:43:27 +01006925 <cond> is an optional matching condition built from ACLs. It makes it
6926 possible to ignore this rule when other conditions are not met.
6927
Willy Tarreau303c0352008-01-17 19:01:39 +01006928 Any header line matching extended regular expression <search> in the response
6929 will be completely deleted. Most common use of this is to remove unwanted
Willy Tarreau3c92c5f2011-08-28 09:45:47 +02006930 and/or sensitive headers or cookies from a response before passing it to the
Willy Tarreau303c0352008-01-17 19:01:39 +01006931 client.
6932
6933 Header transformations only apply to traffic which passes through HAProxy,
6934 and not to traffic generated by HAProxy, such as health-checks or error
6935 responses. Keep in mind that header names are not case-sensitive.
6936
6937 Example :
6938 # remove the Server header from responses
Willy Tarreau5e80e022013-05-25 08:31:25 +02006939 rspidel ^Server:.*
Willy Tarreau303c0352008-01-17 19:01:39 +01006940
Willy Tarreaufdb563c2010-01-31 15:43:27 +01006941 See also: "rspadd", "rsprep", "reqdel", section 6 about HTTP header
6942 manipulation, and section 7 about ACLs.
Willy Tarreau303c0352008-01-17 19:01:39 +01006943
6944
Willy Tarreaufdb563c2010-01-31 15:43:27 +01006945rspdeny <search> [{if | unless} <cond>]
6946rspideny <search> [{if | unless} <cond>] (ignore case)
Willy Tarreau303c0352008-01-17 19:01:39 +01006947 Block an HTTP response if a line matches a regular expression
6948 May be used in sections : defaults | frontend | listen | backend
6949 no | yes | yes | yes
6950 Arguments :
6951 <search> is the regular expression applied to HTTP headers and to the
6952 response line. This is an extended regular expression, so
6953 parenthesis grouping is supported and no preliminary backslash
6954 is required. Any space or known delimiter must be escaped using
6955 a backslash ('\'). The pattern applies to a full line at a time.
6956 The "rspdeny" keyword strictly matches case while "rspideny"
6957 ignores case.
6958
Willy Tarreaufdb563c2010-01-31 15:43:27 +01006959 <cond> is an optional matching condition built from ACLs. It makes it
6960 possible to ignore this rule when other conditions are not met.
6961
Willy Tarreau303c0352008-01-17 19:01:39 +01006962 A response containing any line which matches extended regular expression
6963 <search> will mark the request as denied. The test applies both to the
6964 response line and to response headers. Keep in mind that header names are not
6965 case-sensitive.
6966
6967 Main use of this keyword is to prevent sensitive information leak and to
Willy Tarreauced27012008-01-17 20:35:34 +01006968 block the response before it reaches the client. If a response is denied, it
6969 will be replaced with an HTTP 502 error so that the client never retrieves
6970 any sensitive data.
Willy Tarreau303c0352008-01-17 19:01:39 +01006971
6972 It is easier, faster and more powerful to use ACLs to write access policies.
6973 Rspdeny should be avoided in new designs.
6974
6975 Example :
6976 # Ensure that no content type matching ms-word will leak
6977 rspideny ^Content-type:\.*/ms-word
6978
Willy Tarreaufdb563c2010-01-31 15:43:27 +01006979 See also: "reqdeny", "acl", "block", section 6 about HTTP header manipulation
6980 and section 7 about ACLs.
Willy Tarreau303c0352008-01-17 19:01:39 +01006981
6982
Willy Tarreaufdb563c2010-01-31 15:43:27 +01006983rsprep <search> <string> [{if | unless} <cond>]
6984rspirep <search> <string> [{if | unless} <cond>] (ignore case)
Willy Tarreau303c0352008-01-17 19:01:39 +01006985 Replace a regular expression with a string in an HTTP response line
6986 May be used in sections : defaults | frontend | listen | backend
6987 no | yes | yes | yes
6988 Arguments :
6989 <search> is the regular expression applied to HTTP headers and to the
6990 response line. This is an extended regular expression, so
6991 parenthesis grouping is supported and no preliminary backslash
6992 is required. Any space or known delimiter must be escaped using
6993 a backslash ('\'). The pattern applies to a full line at a time.
6994 The "rsprep" keyword strictly matches case while "rspirep"
6995 ignores case.
6996
6997 <string> is the complete line to be added. Any space or known delimiter
6998 must be escaped using a backslash ('\'). References to matched
6999 pattern groups are possible using the common \N form, with N
7000 being a single digit between 0 and 9. Please refer to section
Willy Tarreauc57f0e22009-05-10 13:12:33 +02007001 6 about HTTP header manipulation for more information.
Willy Tarreau303c0352008-01-17 19:01:39 +01007002
Willy Tarreaufdb563c2010-01-31 15:43:27 +01007003 <cond> is an optional matching condition built from ACLs. It makes it
7004 possible to ignore this rule when other conditions are not met.
7005
Willy Tarreau303c0352008-01-17 19:01:39 +01007006 Any line matching extended regular expression <search> in the response (both
7007 the response line and header lines) will be completely replaced with
7008 <string>. Most common use of this is to rewrite Location headers.
7009
7010 Header transformations only apply to traffic which passes through HAProxy,
7011 and not to traffic generated by HAProxy, such as health-checks or error
7012 responses. Note that for increased readability, it is suggested to add enough
7013 spaces between the request and the response. Keep in mind that header names
7014 are not case-sensitive.
7015
7016 Example :
7017 # replace "Location: 127.0.0.1:8080" with "Location: www.mydomain.com"
7018 rspirep ^Location:\ 127.0.0.1:8080 Location:\ www.mydomain.com
7019
Willy Tarreaufdb563c2010-01-31 15:43:27 +01007020 See also: "rspadd", "rspdel", "reqrep", section 6 about HTTP header
7021 manipulation, and section 7 about ACLs.
Willy Tarreau303c0352008-01-17 19:01:39 +01007022
7023
David du Colombier486df472011-03-17 10:40:26 +01007024server <name> <address>[:[port]] [param*]
Willy Tarreaueabeafa2008-01-16 16:17:06 +01007025 Declare a server in a backend
7026 May be used in sections : defaults | frontend | listen | backend
7027 no | no | yes | yes
7028 Arguments :
7029 <name> is the internal name assigned to this server. This name will
Cyril Bonté941a0c62012-10-15 19:44:24 +02007030 appear in logs and alerts. If "http-send-name-header" is
Mark Lamourinec2247f02012-01-04 13:02:01 -05007031 set, it will be added to the request header sent to the server.
Willy Tarreaueabeafa2008-01-16 16:17:06 +01007032
David du Colombier486df472011-03-17 10:40:26 +01007033 <address> is the IPv4 or IPv6 address of the server. Alternatively, a
7034 resolvable hostname is supported, but this name will be resolved
7035 during start-up. Address "0.0.0.0" or "*" has a special meaning.
7036 It indicates that the connection will be forwarded to the same IP
Willy Tarreaud669a4f2010-07-13 14:49:50 +02007037 address as the one from the client connection. This is useful in
7038 transparent proxy architectures where the client's connection is
7039 intercepted and haproxy must forward to the original destination
7040 address. This is more or less what the "transparent" keyword does
7041 except that with a server it's possible to limit concurrency and
Willy Tarreau24709282013-03-10 21:32:12 +01007042 to report statistics. Optionally, an address family prefix may be
7043 used before the address to force the family regardless of the
7044 address format, which can be useful to specify a path to a unix
7045 socket with no slash ('/'). Currently supported prefixes are :
7046 - 'ipv4@' -> address is always IPv4
7047 - 'ipv6@' -> address is always IPv6
7048 - 'unix@' -> address is a path to a local unix socket
Willy Tarreauccfccef2014-05-10 01:49:15 +02007049 - 'abns@' -> address is in abstract namespace (Linux only)
William Lallemandb2f07452015-05-12 14:27:13 +02007050 You may want to reference some environment variables in the
7051 address parameter, see section 2.3 about environment
7052 variables.
Willy Tarreaueabeafa2008-01-16 16:17:06 +01007053
Willy Tarreaub6205fd2012-09-24 12:27:33 +02007054 <port> is an optional port specification. If set, all connections will
Willy Tarreaueabeafa2008-01-16 16:17:06 +01007055 be sent to this port. If unset, the same port the client
7056 connected to will be used. The port may also be prefixed by a "+"
7057 or a "-". In this case, the server's port will be determined by
7058 adding this value to the client's port.
7059
7060 <param*> is a list of parameters for this server. The "server" keywords
7061 accepts an important number of options and has a complete section
Willy Tarreauc57f0e22009-05-10 13:12:33 +02007062 dedicated to it. Please refer to section 5 for more details.
Willy Tarreaueabeafa2008-01-16 16:17:06 +01007063
7064 Examples :
7065 server first 10.1.1.1:1080 cookie first check inter 1000
7066 server second 10.1.1.2:1080 cookie second check inter 1000
Willy Tarreau24709282013-03-10 21:32:12 +01007067 server transp ipv4@
William Lallemandb2f07452015-05-12 14:27:13 +02007068 server backup "${SRV_BACKUP}:1080" backup
7069 server www1_dc1 "${LAN_DC1}.101:80"
7070 server www1_dc2 "${LAN_DC2}.101:80"
Willy Tarreaueabeafa2008-01-16 16:17:06 +01007071
Willy Tarreau55dcaf62015-09-27 15:03:15 +02007072 Note: regarding Linux's abstract namespace sockets, HAProxy uses the whole
7073 sun_path length is used for the address length. Some other programs
7074 such as socat use the string length only by default. Pass the option
7075 ",unix-tightsocklen=0" to any abstract socket definition in socat to
7076 make it compatible with HAProxy's.
7077
Mark Lamourinec2247f02012-01-04 13:02:01 -05007078 See also: "default-server", "http-send-name-header" and section 5 about
7079 server options
Willy Tarreaueabeafa2008-01-16 16:17:06 +01007080
Baptiste Assmann01c6cc32015-08-23 11:45:29 +02007081server-state-file-name [<file>]
7082 Set the server state file to read, load and apply to servers available in
7083 this backend. It only applies when the directive "load-server-state-from-file"
7084 is set to "local". When <file> is not provided or if this directive is not
7085 set, then backend name is used. If <file> starts with a slash '/', then it is
7086 considered as an absolute path. Otherwise, <file> is concatenated to the
7087 global directive "server-state-file-base".
7088
7089 Example: the minimal configuration below would make HAProxy look for the
7090 state server file '/etc/haproxy/states/bk':
7091
7092 global
7093 server-state-file-base /etc/haproxy/states
7094
7095 backend bk
7096 load-server-state-from-file
7097
7098 See also: "server-state-file-base", "load-server-state-from-file", and
7099 "show servers state"
Willy Tarreaueabeafa2008-01-16 16:17:06 +01007100
7101source <addr>[:<port>] [usesrc { <addr2>[:<port2>] | client | clientip } ]
Willy Tarreaubce70882009-09-07 11:51:47 +02007102source <addr>[:<port>] [usesrc { <addr2>[:<port2>] | hdr_ip(<hdr>[,<occ>]) } ]
Willy Tarreaud53f96b2009-02-04 18:46:54 +01007103source <addr>[:<port>] [interface <name>]
Willy Tarreaueabeafa2008-01-16 16:17:06 +01007104 Set the source address for outgoing connections
7105 May be used in sections : defaults | frontend | listen | backend
7106 yes | no | yes | yes
7107 Arguments :
7108 <addr> is the IPv4 address HAProxy will bind to before connecting to a
7109 server. This address is also used as a source for health checks.
Willy Tarreau24709282013-03-10 21:32:12 +01007110
Willy Tarreaueabeafa2008-01-16 16:17:06 +01007111 The default value of 0.0.0.0 means that the system will select
Willy Tarreau24709282013-03-10 21:32:12 +01007112 the most appropriate address to reach its destination. Optionally
7113 an address family prefix may be used before the address to force
7114 the family regardless of the address format, which can be useful
7115 to specify a path to a unix socket with no slash ('/'). Currently
7116 supported prefixes are :
7117 - 'ipv4@' -> address is always IPv4
7118 - 'ipv6@' -> address is always IPv6
7119 - 'unix@' -> address is a path to a local unix socket
Willy Tarreauccfccef2014-05-10 01:49:15 +02007120 - 'abns@' -> address is in abstract namespace (Linux only)
Cyril Bonté307ee1e2015-09-28 23:16:06 +02007121 You may want to reference some environment variables in the
7122 address parameter, see section 2.3 about environment variables.
Willy Tarreaueabeafa2008-01-16 16:17:06 +01007123
7124 <port> is an optional port. It is normally not needed but may be useful
7125 in some very specific contexts. The default value of zero means
Willy Tarreauc6f4ce82009-06-10 11:09:37 +02007126 the system will select a free port. Note that port ranges are not
7127 supported in the backend. If you want to force port ranges, you
7128 have to specify them on each "server" line.
Willy Tarreaueabeafa2008-01-16 16:17:06 +01007129
7130 <addr2> is the IP address to present to the server when connections are
7131 forwarded in full transparent proxy mode. This is currently only
7132 supported on some patched Linux kernels. When this address is
7133 specified, clients connecting to the server will be presented
7134 with this address, while health checks will still use the address
7135 <addr>.
7136
7137 <port2> is the optional port to present to the server when connections
7138 are forwarded in full transparent proxy mode (see <addr2> above).
7139 The default value of zero means the system will select a free
7140 port.
7141
Willy Tarreaubce70882009-09-07 11:51:47 +02007142 <hdr> is the name of a HTTP header in which to fetch the IP to bind to.
7143 This is the name of a comma-separated header list which can
7144 contain multiple IP addresses. By default, the last occurrence is
7145 used. This is designed to work with the X-Forwarded-For header
Baptiste Assmannea3e73b2013-02-02 23:47:49 +01007146 and to automatically bind to the client's IP address as seen
Willy Tarreaubce70882009-09-07 11:51:47 +02007147 by previous proxy, typically Stunnel. In order to use another
7148 occurrence from the last one, please see the <occ> parameter
7149 below. When the header (or occurrence) is not found, no binding
7150 is performed so that the proxy's default IP address is used. Also
7151 keep in mind that the header name is case insensitive, as for any
7152 HTTP header.
7153
7154 <occ> is the occurrence number of a value to be used in a multi-value
7155 header. This is to be used in conjunction with "hdr_ip(<hdr>)",
Jamie Gloudonaaa21002012-08-25 00:18:33 -04007156 in order to specify which occurrence to use for the source IP
Willy Tarreaubce70882009-09-07 11:51:47 +02007157 address. Positive values indicate a position from the first
7158 occurrence, 1 being the first one. Negative values indicate
7159 positions relative to the last one, -1 being the last one. This
7160 is helpful for situations where an X-Forwarded-For header is set
7161 at the entry point of an infrastructure and must be used several
7162 proxy layers away. When this value is not specified, -1 is
7163 assumed. Passing a zero here disables the feature.
7164
Willy Tarreaud53f96b2009-02-04 18:46:54 +01007165 <name> is an optional interface name to which to bind to for outgoing
7166 traffic. On systems supporting this features (currently, only
7167 Linux), this allows one to bind all traffic to the server to
7168 this interface even if it is not the one the system would select
7169 based on routing tables. This should be used with extreme care.
7170 Note that using this option requires root privileges.
7171
Willy Tarreaueabeafa2008-01-16 16:17:06 +01007172 The "source" keyword is useful in complex environments where a specific
7173 address only is allowed to connect to the servers. It may be needed when a
7174 private address must be used through a public gateway for instance, and it is
7175 known that the system cannot determine the adequate source address by itself.
7176
7177 An extension which is available on certain patched Linux kernels may be used
7178 through the "usesrc" optional keyword. It makes it possible to connect to the
7179 servers with an IP address which does not belong to the system itself. This
7180 is called "full transparent proxy mode". For this to work, the destination
7181 servers have to route their traffic back to this address through the machine
7182 running HAProxy, and IP forwarding must generally be enabled on this machine.
7183
7184 In this "full transparent proxy" mode, it is possible to force a specific IP
7185 address to be presented to the servers. This is not much used in fact. A more
7186 common use is to tell HAProxy to present the client's IP address. For this,
7187 there are two methods :
7188
7189 - present the client's IP and port addresses. This is the most transparent
7190 mode, but it can cause problems when IP connection tracking is enabled on
7191 the machine, because a same connection may be seen twice with different
7192 states. However, this solution presents the huge advantage of not
7193 limiting the system to the 64k outgoing address+port couples, because all
7194 of the client ranges may be used.
7195
7196 - present only the client's IP address and select a spare port. This
7197 solution is still quite elegant but slightly less transparent (downstream
7198 firewalls logs will not match upstream's). It also presents the downside
7199 of limiting the number of concurrent connections to the usual 64k ports.
7200 However, since the upstream and downstream ports are different, local IP
7201 connection tracking on the machine will not be upset by the reuse of the
7202 same session.
7203
Willy Tarreaueabeafa2008-01-16 16:17:06 +01007204 This option sets the default source for all servers in the backend. It may
7205 also be specified in a "defaults" section. Finer source address specification
7206 is possible at the server level using the "source" server option. Refer to
Willy Tarreauc57f0e22009-05-10 13:12:33 +02007207 section 5 for more information.
Willy Tarreaueabeafa2008-01-16 16:17:06 +01007208
Baptiste Assmann91bd3372015-07-17 21:59:42 +02007209 In order to work, "usesrc" requires root privileges.
7210
Willy Tarreaueabeafa2008-01-16 16:17:06 +01007211 Examples :
7212 backend private
7213 # Connect to the servers using our 192.168.1.200 source address
7214 source 192.168.1.200
7215
7216 backend transparent_ssl1
7217 # Connect to the SSL farm from the client's source address
7218 source 192.168.1.200 usesrc clientip
7219
7220 backend transparent_ssl2
7221 # Connect to the SSL farm from the client's source address and port
7222 # not recommended if IP conntrack is present on the local machine.
7223 source 192.168.1.200 usesrc client
7224
7225 backend transparent_ssl3
7226 # Connect to the SSL farm from the client's source address. It
7227 # is more conntrack-friendly.
7228 source 192.168.1.200 usesrc clientip
7229
7230 backend transparent_smtp
7231 # Connect to the SMTP farm from the client's source address/port
7232 # with Tproxy version 4.
7233 source 0.0.0.0 usesrc clientip
7234
Willy Tarreaubce70882009-09-07 11:51:47 +02007235 backend transparent_http
7236 # Connect to the servers using the client's IP as seen by previous
7237 # proxy.
7238 source 0.0.0.0 usesrc hdr_ip(x-forwarded-for,-1)
7239
Willy Tarreauc57f0e22009-05-10 13:12:33 +02007240 See also : the "source" server option in section 5, the Tproxy patches for
Willy Tarreaueabeafa2008-01-16 16:17:06 +01007241 the Linux kernel on www.balabit.com, the "bind" keyword.
7242
Krzysztof Piotr Oledzki25b501a2008-01-06 16:36:16 +01007243
Willy Tarreau844e3c52008-01-11 16:28:18 +01007244srvtimeout <timeout> (deprecated)
7245 Set the maximum inactivity time on the server side.
7246 May be used in sections : defaults | frontend | listen | backend
7247 yes | no | yes | yes
7248 Arguments :
7249 <timeout> is the timeout value specified in milliseconds by default, but
7250 can be in any other unit if the number is suffixed by the unit,
7251 as explained at the top of this document.
7252
7253 The inactivity timeout applies when the server is expected to acknowledge or
7254 send data. In HTTP mode, this timeout is particularly important to consider
7255 during the first phase of the server's response, when it has to send the
7256 headers, as it directly represents the server's processing time for the
7257 request. To find out what value to put there, it's often good to start with
7258 what would be considered as unacceptable response times, then check the logs
7259 to observe the response time distribution, and adjust the value accordingly.
7260
7261 The value is specified in milliseconds by default, but can be in any other
7262 unit if the number is suffixed by the unit, as specified at the top of this
7263 document. In TCP mode (and to a lesser extent, in HTTP mode), it is highly
7264 recommended that the client timeout remains equal to the server timeout in
7265 order to avoid complex situations to debug. Whatever the expected server
Willy Tarreaud2a4aa22008-01-31 15:28:22 +01007266 response times, it is a good practice to cover at least one or several TCP
Willy Tarreau844e3c52008-01-11 16:28:18 +01007267 packet losses by specifying timeouts that are slightly above multiples of 3
Willy Tarreaud72758d2010-01-12 10:42:19 +01007268 seconds (eg: 4 or 5 seconds minimum).
Willy Tarreau844e3c52008-01-11 16:28:18 +01007269
7270 This parameter is specific to backends, but can be specified once for all in
7271 "defaults" sections. This is in fact one of the easiest solutions not to
7272 forget about it. An unspecified timeout results in an infinite timeout, which
7273 is not recommended. Such a usage is accepted and works but reports a warning
7274 during startup because it may results in accumulation of expired sessions in
7275 the system if the system's timeouts are not configured either.
7276
7277 This parameter is provided for compatibility but is currently deprecated.
7278 Please use "timeout server" instead.
7279
Willy Tarreauce887fd2012-05-12 12:50:00 +02007280 See also : "timeout server", "timeout tunnel", "timeout client" and
7281 "clitimeout".
Willy Tarreau844e3c52008-01-11 16:28:18 +01007282
7283
Cyril Bonté66c327d2010-10-12 00:14:37 +02007284stats admin { if | unless } <cond>
7285 Enable statistics admin level if/unless a condition is matched
7286 May be used in sections : defaults | frontend | listen | backend
Willy Tarreaued2119c2014-04-24 22:10:39 +02007287 no | yes | yes | yes
Cyril Bonté66c327d2010-10-12 00:14:37 +02007288
7289 This statement enables the statistics admin level if/unless a condition is
7290 matched.
7291
7292 The admin level allows to enable/disable servers from the web interface. By
7293 default, statistics page is read-only for security reasons.
7294
Cyril Bonté02ff8ef2010-12-14 22:48:49 +01007295 Note : Consider not using this feature in multi-process mode (nbproc > 1)
7296 unless you know what you do : memory is not shared between the
7297 processes, which can result in random behaviours.
7298
Cyril Bonté23b39d92011-02-10 22:54:44 +01007299 Currently, the POST request is limited to the buffer size minus the reserved
7300 buffer space, which means that if the list of servers is too long, the
7301 request won't be processed. It is recommended to alter few servers at a
7302 time.
Cyril Bonté66c327d2010-10-12 00:14:37 +02007303
7304 Example :
7305 # statistics admin level only for localhost
7306 backend stats_localhost
7307 stats enable
7308 stats admin if LOCALHOST
7309
7310 Example :
7311 # statistics admin level always enabled because of the authentication
7312 backend stats_auth
7313 stats enable
7314 stats auth admin:AdMiN123
7315 stats admin if TRUE
7316
7317 Example :
7318 # statistics admin level depends on the authenticated user
7319 userlist stats-auth
7320 group admin users admin
7321 user admin insecure-password AdMiN123
7322 group readonly users haproxy
7323 user haproxy insecure-password haproxy
7324
7325 backend stats_auth
7326 stats enable
7327 acl AUTH http_auth(stats-auth)
7328 acl AUTH_ADMIN http_auth_group(stats-auth) admin
7329 stats http-request auth unless AUTH
7330 stats admin if AUTH_ADMIN
7331
Cyril Bonté02ff8ef2010-12-14 22:48:49 +01007332 See also : "stats enable", "stats auth", "stats http-request", "nbproc",
7333 "bind-process", section 3.4 about userlists and section 7 about
7334 ACL usage.
Cyril Bonté66c327d2010-10-12 00:14:37 +02007335
7336
Willy Tarreaueabeafa2008-01-16 16:17:06 +01007337stats auth <user>:<passwd>
7338 Enable statistics with authentication and grant access to an account
7339 May be used in sections : defaults | frontend | listen | backend
Willy Tarreaued2119c2014-04-24 22:10:39 +02007340 yes | yes | yes | yes
Willy Tarreaueabeafa2008-01-16 16:17:06 +01007341 Arguments :
7342 <user> is a user name to grant access to
7343
7344 <passwd> is the cleartext password associated to this user
7345
7346 This statement enables statistics with default settings, and restricts access
7347 to declared users only. It may be repeated as many times as necessary to
7348 allow as many users as desired. When a user tries to access the statistics
7349 without a valid account, a "401 Forbidden" response will be returned so that
7350 the browser asks the user to provide a valid user and password. The real
7351 which will be returned to the browser is configurable using "stats realm".
7352
7353 Since the authentication method is HTTP Basic Authentication, the passwords
7354 circulate in cleartext on the network. Thus, it was decided that the
7355 configuration file would also use cleartext passwords to remind the users
Willy Tarreau3c92c5f2011-08-28 09:45:47 +02007356 that those ones should not be sensitive and not shared with any other account.
Willy Tarreaueabeafa2008-01-16 16:17:06 +01007357
7358 It is also possible to reduce the scope of the proxies which appear in the
7359 report using "stats scope".
7360
7361 Though this statement alone is enough to enable statistics reporting, it is
7362 recommended to set all other settings in order to avoid relying on default
7363 unobvious parameters.
7364
7365 Example :
7366 # public access (limited to this backend only)
7367 backend public_www
7368 server srv1 192.168.0.1:80
7369 stats enable
7370 stats hide-version
7371 stats scope .
7372 stats uri /admin?stats
7373 stats realm Haproxy\ Statistics
7374 stats auth admin1:AdMiN123
7375 stats auth admin2:AdMiN321
7376
7377 # internal monitoring access (unlimited)
7378 backend private_monitoring
7379 stats enable
7380 stats uri /admin?stats
7381 stats refresh 5s
7382
7383 See also : "stats enable", "stats realm", "stats scope", "stats uri"
7384
7385
7386stats enable
7387 Enable statistics reporting with default settings
7388 May be used in sections : defaults | frontend | listen | backend
Willy Tarreaued2119c2014-04-24 22:10:39 +02007389 yes | yes | yes | yes
Willy Tarreaueabeafa2008-01-16 16:17:06 +01007390 Arguments : none
7391
7392 This statement enables statistics reporting with default settings defined
7393 at build time. Unless stated otherwise, these settings are used :
7394 - stats uri : /haproxy?stats
7395 - stats realm : "HAProxy Statistics"
7396 - stats auth : no authentication
7397 - stats scope : no restriction
7398
7399 Though this statement alone is enough to enable statistics reporting, it is
7400 recommended to set all other settings in order to avoid relying on default
7401 unobvious parameters.
7402
7403 Example :
7404 # public access (limited to this backend only)
7405 backend public_www
7406 server srv1 192.168.0.1:80
7407 stats enable
7408 stats hide-version
7409 stats scope .
7410 stats uri /admin?stats
7411 stats realm Haproxy\ Statistics
7412 stats auth admin1:AdMiN123
7413 stats auth admin2:AdMiN321
7414
7415 # internal monitoring access (unlimited)
7416 backend private_monitoring
7417 stats enable
7418 stats uri /admin?stats
7419 stats refresh 5s
7420
7421 See also : "stats auth", "stats realm", "stats uri"
7422
7423
Willy Tarreaud63335a2010-02-26 12:56:52 +01007424stats hide-version
7425 Enable statistics and hide HAProxy version reporting
Willy Tarreau1d45b7c2009-08-16 10:29:18 +02007426 May be used in sections : defaults | frontend | listen | backend
Willy Tarreaued2119c2014-04-24 22:10:39 +02007427 yes | yes | yes | yes
Willy Tarreaud63335a2010-02-26 12:56:52 +01007428 Arguments : none
Willy Tarreau1d45b7c2009-08-16 10:29:18 +02007429
Willy Tarreaud63335a2010-02-26 12:56:52 +01007430 By default, the stats page reports some useful status information along with
7431 the statistics. Among them is HAProxy's version. However, it is generally
7432 considered dangerous to report precise version to anyone, as it can help them
7433 target known weaknesses with specific attacks. The "stats hide-version"
7434 statement removes the version from the statistics report. This is recommended
7435 for public sites or any site with a weak login/password.
Willy Tarreau1d45b7c2009-08-16 10:29:18 +02007436
Krzysztof Piotr Oledzki48cb2ae2009-10-02 22:51:14 +02007437 Though this statement alone is enough to enable statistics reporting, it is
7438 recommended to set all other settings in order to avoid relying on default
7439 unobvious parameters.
7440
Willy Tarreaud63335a2010-02-26 12:56:52 +01007441 Example :
7442 # public access (limited to this backend only)
7443 backend public_www
7444 server srv1 192.168.0.1:80
Krzysztof Piotr Oledzki48cb2ae2009-10-02 22:51:14 +02007445 stats enable
Willy Tarreaud63335a2010-02-26 12:56:52 +01007446 stats hide-version
7447 stats scope .
7448 stats uri /admin?stats
7449 stats realm Haproxy\ Statistics
7450 stats auth admin1:AdMiN123
7451 stats auth admin2:AdMiN321
Willy Tarreau1d45b7c2009-08-16 10:29:18 +02007452
Willy Tarreau1d45b7c2009-08-16 10:29:18 +02007453 # internal monitoring access (unlimited)
7454 backend private_monitoring
7455 stats enable
Willy Tarreaud63335a2010-02-26 12:56:52 +01007456 stats uri /admin?stats
7457 stats refresh 5s
Krzysztof Piotr Oledzki15514c22010-01-04 16:03:09 +01007458
Willy Tarreaud63335a2010-02-26 12:56:52 +01007459 See also : "stats auth", "stats enable", "stats realm", "stats uri"
Willy Tarreau1d45b7c2009-08-16 10:29:18 +02007460
Willy Tarreau983e01e2010-01-11 18:42:06 +01007461
Cyril Bonté2be1b3f2010-09-30 23:46:30 +02007462stats http-request { allow | deny | auth [realm <realm>] }
7463 [ { if | unless } <condition> ]
7464 Access control for statistics
7465
7466 May be used in sections: defaults | frontend | listen | backend
7467 no | no | yes | yes
7468
7469 As "http-request", these set of options allow to fine control access to
7470 statistics. Each option may be followed by if/unless and acl.
7471 First option with matched condition (or option without condition) is final.
7472 For "deny" a 403 error will be returned, for "allow" normal processing is
7473 performed, for "auth" a 401/407 error code is returned so the client
7474 should be asked to enter a username and password.
7475
7476 There is no fixed limit to the number of http-request statements per
7477 instance.
7478
7479 See also : "http-request", section 3.4 about userlists and section 7
7480 about ACL usage.
7481
7482
Willy Tarreaueabeafa2008-01-16 16:17:06 +01007483stats realm <realm>
7484 Enable statistics and set authentication realm
7485 May be used in sections : defaults | frontend | listen | backend
Willy Tarreaued2119c2014-04-24 22:10:39 +02007486 yes | yes | yes | yes
Willy Tarreaueabeafa2008-01-16 16:17:06 +01007487 Arguments :
7488 <realm> is the name of the HTTP Basic Authentication realm reported to
7489 the browser. The browser uses it to display it in the pop-up
7490 inviting the user to enter a valid username and password.
7491
7492 The realm is read as a single word, so any spaces in it should be escaped
7493 using a backslash ('\').
7494
7495 This statement is useful only in conjunction with "stats auth" since it is
7496 only related to authentication.
7497
7498 Though this statement alone is enough to enable statistics reporting, it is
7499 recommended to set all other settings in order to avoid relying on default
7500 unobvious parameters.
7501
7502 Example :
7503 # public access (limited to this backend only)
7504 backend public_www
7505 server srv1 192.168.0.1:80
7506 stats enable
7507 stats hide-version
7508 stats scope .
7509 stats uri /admin?stats
7510 stats realm Haproxy\ Statistics
7511 stats auth admin1:AdMiN123
7512 stats auth admin2:AdMiN321
7513
7514 # internal monitoring access (unlimited)
7515 backend private_monitoring
7516 stats enable
7517 stats uri /admin?stats
7518 stats refresh 5s
7519
7520 See also : "stats auth", "stats enable", "stats uri"
7521
7522
7523stats refresh <delay>
7524 Enable statistics with automatic refresh
7525 May be used in sections : defaults | frontend | listen | backend
Willy Tarreaued2119c2014-04-24 22:10:39 +02007526 yes | yes | yes | yes
Willy Tarreaueabeafa2008-01-16 16:17:06 +01007527 Arguments :
7528 <delay> is the suggested refresh delay, specified in seconds, which will
7529 be returned to the browser consulting the report page. While the
7530 browser is free to apply any delay, it will generally respect it
7531 and refresh the page this every seconds. The refresh interval may
7532 be specified in any other non-default time unit, by suffixing the
7533 unit after the value, as explained at the top of this document.
7534
7535 This statement is useful on monitoring displays with a permanent page
7536 reporting the load balancer's activity. When set, the HTML report page will
7537 include a link "refresh"/"stop refresh" so that the user can select whether
7538 he wants automatic refresh of the page or not.
7539
7540 Though this statement alone is enough to enable statistics reporting, it is
7541 recommended to set all other settings in order to avoid relying on default
7542 unobvious parameters.
7543
7544 Example :
7545 # public access (limited to this backend only)
7546 backend public_www
7547 server srv1 192.168.0.1:80
7548 stats enable
7549 stats hide-version
7550 stats scope .
7551 stats uri /admin?stats
7552 stats realm Haproxy\ Statistics
7553 stats auth admin1:AdMiN123
7554 stats auth admin2:AdMiN321
7555
7556 # internal monitoring access (unlimited)
7557 backend private_monitoring
7558 stats enable
7559 stats uri /admin?stats
7560 stats refresh 5s
7561
7562 See also : "stats auth", "stats enable", "stats realm", "stats uri"
7563
7564
7565stats scope { <name> | "." }
7566 Enable statistics and limit access scope
7567 May be used in sections : defaults | frontend | listen | backend
Willy Tarreaued2119c2014-04-24 22:10:39 +02007568 yes | yes | yes | yes
Willy Tarreaueabeafa2008-01-16 16:17:06 +01007569 Arguments :
7570 <name> is the name of a listen, frontend or backend section to be
7571 reported. The special name "." (a single dot) designates the
7572 section in which the statement appears.
7573
7574 When this statement is specified, only the sections enumerated with this
7575 statement will appear in the report. All other ones will be hidden. This
7576 statement may appear as many times as needed if multiple sections need to be
7577 reported. Please note that the name checking is performed as simple string
7578 comparisons, and that it is never checked that a give section name really
7579 exists.
7580
7581 Though this statement alone is enough to enable statistics reporting, it is
7582 recommended to set all other settings in order to avoid relying on default
7583 unobvious parameters.
7584
7585 Example :
7586 # public access (limited to this backend only)
7587 backend public_www
7588 server srv1 192.168.0.1:80
7589 stats enable
7590 stats hide-version
7591 stats scope .
7592 stats uri /admin?stats
7593 stats realm Haproxy\ Statistics
7594 stats auth admin1:AdMiN123
7595 stats auth admin2:AdMiN321
7596
7597 # internal monitoring access (unlimited)
7598 backend private_monitoring
7599 stats enable
7600 stats uri /admin?stats
7601 stats refresh 5s
7602
7603 See also : "stats auth", "stats enable", "stats realm", "stats uri"
7604
Willy Tarreaud63335a2010-02-26 12:56:52 +01007605
Willy Tarreauc9705a12010-07-27 20:05:50 +02007606stats show-desc [ <desc> ]
Willy Tarreaud63335a2010-02-26 12:56:52 +01007607 Enable reporting of a description on the statistics page.
7608 May be used in sections : defaults | frontend | listen | backend
Willy Tarreaued2119c2014-04-24 22:10:39 +02007609 yes | yes | yes | yes
Willy Tarreaud63335a2010-02-26 12:56:52 +01007610
Willy Tarreauc9705a12010-07-27 20:05:50 +02007611 <desc> is an optional description to be reported. If unspecified, the
Willy Tarreaud63335a2010-02-26 12:56:52 +01007612 description from global section is automatically used instead.
7613
7614 This statement is useful for users that offer shared services to their
7615 customers, where node or description should be different for each customer.
7616
7617 Though this statement alone is enough to enable statistics reporting, it is
7618 recommended to set all other settings in order to avoid relying on default
Dmitry Sivachenko7823de32012-05-16 14:00:26 +04007619 unobvious parameters. By default description is not shown.
Willy Tarreaud63335a2010-02-26 12:56:52 +01007620
7621 Example :
7622 # internal monitoring access (unlimited)
7623 backend private_monitoring
7624 stats enable
7625 stats show-desc Master node for Europe, Asia, Africa
7626 stats uri /admin?stats
7627 stats refresh 5s
7628
7629 See also: "show-node", "stats enable", "stats uri" and "description" in
7630 global section.
7631
7632
7633stats show-legends
Willy Tarreaued2119c2014-04-24 22:10:39 +02007634 Enable reporting additional information on the statistics page
7635 May be used in sections : defaults | frontend | listen | backend
7636 yes | yes | yes | yes
7637 Arguments : none
7638
Jarno Huuskonen0e82b922014-04-12 18:22:19 +03007639 Enable reporting additional information on the statistics page :
Willy Tarreaud63335a2010-02-26 12:56:52 +01007640 - cap: capabilities (proxy)
7641 - mode: one of tcp, http or health (proxy)
7642 - id: SNMP ID (proxy, socket, server)
7643 - IP (socket, server)
7644 - cookie (backend, server)
7645
7646 Though this statement alone is enough to enable statistics reporting, it is
7647 recommended to set all other settings in order to avoid relying on default
Dmitry Sivachenko7823de32012-05-16 14:00:26 +04007648 unobvious parameters. Default behaviour is not to show this information.
Willy Tarreaud63335a2010-02-26 12:56:52 +01007649
7650 See also: "stats enable", "stats uri".
7651
7652
7653stats show-node [ <name> ]
7654 Enable reporting of a host name on the statistics page.
7655 May be used in sections : defaults | frontend | listen | backend
Willy Tarreaued2119c2014-04-24 22:10:39 +02007656 yes | yes | yes | yes
Willy Tarreaud63335a2010-02-26 12:56:52 +01007657 Arguments:
7658 <name> is an optional name to be reported. If unspecified, the
7659 node name from global section is automatically used instead.
7660
7661 This statement is useful for users that offer shared services to their
7662 customers, where node or description might be different on a stats page
Dmitry Sivachenko7823de32012-05-16 14:00:26 +04007663 provided for each customer. Default behaviour is not to show host name.
Willy Tarreaud63335a2010-02-26 12:56:52 +01007664
7665 Though this statement alone is enough to enable statistics reporting, it is
7666 recommended to set all other settings in order to avoid relying on default
7667 unobvious parameters.
7668
7669 Example:
7670 # internal monitoring access (unlimited)
7671 backend private_monitoring
7672 stats enable
7673 stats show-node Europe-1
7674 stats uri /admin?stats
7675 stats refresh 5s
7676
7677 See also: "show-desc", "stats enable", "stats uri", and "node" in global
7678 section.
7679
Willy Tarreaueabeafa2008-01-16 16:17:06 +01007680
7681stats uri <prefix>
7682 Enable statistics and define the URI prefix to access them
7683 May be used in sections : defaults | frontend | listen | backend
Willy Tarreaued2119c2014-04-24 22:10:39 +02007684 yes | yes | yes | yes
Willy Tarreaueabeafa2008-01-16 16:17:06 +01007685 Arguments :
7686 <prefix> is the prefix of any URI which will be redirected to stats. This
7687 prefix may contain a question mark ('?') to indicate part of a
7688 query string.
7689
7690 The statistics URI is intercepted on the relayed traffic, so it appears as a
7691 page within the normal application. It is strongly advised to ensure that the
7692 selected URI will never appear in the application, otherwise it will never be
7693 possible to reach it in the application.
7694
7695 The default URI compiled in haproxy is "/haproxy?stats", but this may be
Krzysztof Piotr Oledzkif8645332009-12-13 21:55:50 +01007696 changed at build time, so it's better to always explicitly specify it here.
Willy Tarreaueabeafa2008-01-16 16:17:06 +01007697 It is generally a good idea to include a question mark in the URI so that
7698 intermediate proxies refrain from caching the results. Also, since any string
7699 beginning with the prefix will be accepted as a stats request, the question
7700 mark helps ensuring that no valid URI will begin with the same words.
7701
7702 It is sometimes very convenient to use "/" as the URI prefix, and put that
7703 statement in a "listen" instance of its own. That makes it easy to dedicate
7704 an address or a port to statistics only.
7705
7706 Though this statement alone is enough to enable statistics reporting, it is
7707 recommended to set all other settings in order to avoid relying on default
7708 unobvious parameters.
7709
7710 Example :
7711 # public access (limited to this backend only)
7712 backend public_www
7713 server srv1 192.168.0.1:80
7714 stats enable
7715 stats hide-version
7716 stats scope .
7717 stats uri /admin?stats
7718 stats realm Haproxy\ Statistics
7719 stats auth admin1:AdMiN123
7720 stats auth admin2:AdMiN321
7721
7722 # internal monitoring access (unlimited)
7723 backend private_monitoring
7724 stats enable
7725 stats uri /admin?stats
7726 stats refresh 5s
7727
7728 See also : "stats auth", "stats enable", "stats realm"
7729
7730
Willy Tarreaud63335a2010-02-26 12:56:52 +01007731stick match <pattern> [table <table>] [{if | unless} <cond>]
7732 Define a request pattern matching condition to stick a user to a server
Willy Tarreaueabeafa2008-01-16 16:17:06 +01007733 May be used in sections : defaults | frontend | listen | backend
Willy Tarreaud63335a2010-02-26 12:56:52 +01007734 no | no | yes | yes
Willy Tarreaub937b7e2010-01-12 15:27:54 +01007735
7736 Arguments :
Willy Tarreaube722a22014-06-13 16:31:59 +02007737 <pattern> is a sample expression rule as described in section 7.3. It
Willy Tarreaub937b7e2010-01-12 15:27:54 +01007738 describes what elements of the incoming request or connection
7739 will be analysed in the hope to find a matching entry in a
7740 stickiness table. This rule is mandatory.
7741
7742 <table> is an optional stickiness table name. If unspecified, the same
7743 backend's table is used. A stickiness table is declared using
7744 the "stick-table" statement.
7745
7746 <cond> is an optional matching condition. It makes it possible to match
7747 on a certain criterion only when other conditions are met (or
7748 not met). For instance, it could be used to match on a source IP
7749 address except when a request passes through a known proxy, in
7750 which case we'd match on a header containing that IP address.
7751
7752 Some protocols or applications require complex stickiness rules and cannot
7753 always simply rely on cookies nor hashing. The "stick match" statement
7754 describes a rule to extract the stickiness criterion from an incoming request
7755 or connection. See section 7 for a complete list of possible patterns and
7756 transformation rules.
7757
7758 The table has to be declared using the "stick-table" statement. It must be of
7759 a type compatible with the pattern. By default it is the one which is present
7760 in the same backend. It is possible to share a table with other backends by
7761 referencing it using the "table" keyword. If another table is referenced,
7762 the server's ID inside the backends are used. By default, all server IDs
7763 start at 1 in each backend, so the server ordering is enough. But in case of
7764 doubt, it is highly recommended to force server IDs using their "id" setting.
7765
7766 It is possible to restrict the conditions where a "stick match" statement
7767 will apply, using "if" or "unless" followed by a condition. See section 7 for
7768 ACL based conditions.
7769
7770 There is no limit on the number of "stick match" statements. The first that
7771 applies and matches will cause the request to be directed to the same server
7772 as was used for the request which created the entry. That way, multiple
7773 matches can be used as fallbacks.
7774
7775 The stick rules are checked after the persistence cookies, so they will not
7776 affect stickiness if a cookie has already been used to select a server. That
7777 way, it becomes very easy to insert cookies and match on IP addresses in
7778 order to maintain stickiness between HTTP and HTTPS.
7779
Cyril Bonté02ff8ef2010-12-14 22:48:49 +01007780 Note : Consider not using this feature in multi-process mode (nbproc > 1)
7781 unless you know what you do : memory is not shared between the
7782 processes, which can result in random behaviours.
7783
Willy Tarreaub937b7e2010-01-12 15:27:54 +01007784 Example :
7785 # forward SMTP users to the same server they just used for POP in the
7786 # last 30 minutes
7787 backend pop
7788 mode tcp
7789 balance roundrobin
7790 stick store-request src
7791 stick-table type ip size 200k expire 30m
7792 server s1 192.168.1.1:110
7793 server s2 192.168.1.1:110
7794
7795 backend smtp
7796 mode tcp
7797 balance roundrobin
7798 stick match src table pop
7799 server s1 192.168.1.1:25
7800 server s2 192.168.1.1:25
7801
Cyril Bonté02ff8ef2010-12-14 22:48:49 +01007802 See also : "stick-table", "stick on", "nbproc", "bind-process" and section 7
Willy Tarreaube722a22014-06-13 16:31:59 +02007803 about ACLs and samples fetching.
Willy Tarreaub937b7e2010-01-12 15:27:54 +01007804
7805
7806stick on <pattern> [table <table>] [{if | unless} <condition>]
7807 Define a request pattern to associate a user to a server
7808 May be used in sections : defaults | frontend | listen | backend
7809 no | no | yes | yes
7810
7811 Note : This form is exactly equivalent to "stick match" followed by
7812 "stick store-request", all with the same arguments. Please refer
7813 to both keywords for details. It is only provided as a convenience
7814 for writing more maintainable configurations.
7815
Cyril Bonté02ff8ef2010-12-14 22:48:49 +01007816 Note : Consider not using this feature in multi-process mode (nbproc > 1)
7817 unless you know what you do : memory is not shared between the
7818 processes, which can result in random behaviours.
7819
Willy Tarreaub937b7e2010-01-12 15:27:54 +01007820 Examples :
7821 # The following form ...
Willy Tarreauec579d82010-02-26 19:15:04 +01007822 stick on src table pop if !localhost
Willy Tarreaub937b7e2010-01-12 15:27:54 +01007823
7824 # ...is strictly equivalent to this one :
7825 stick match src table pop if !localhost
7826 stick store-request src table pop if !localhost
7827
7828
7829 # Use cookie persistence for HTTP, and stick on source address for HTTPS as
7830 # well as HTTP without cookie. Share the same table between both accesses.
7831 backend http
7832 mode http
7833 balance roundrobin
7834 stick on src table https
7835 cookie SRV insert indirect nocache
7836 server s1 192.168.1.1:80 cookie s1
7837 server s2 192.168.1.1:80 cookie s2
7838
7839 backend https
7840 mode tcp
7841 balance roundrobin
7842 stick-table type ip size 200k expire 30m
7843 stick on src
7844 server s1 192.168.1.1:443
7845 server s2 192.168.1.1:443
7846
Cyril Bonté02ff8ef2010-12-14 22:48:49 +01007847 See also : "stick match", "stick store-request", "nbproc" and "bind-process".
Willy Tarreaub937b7e2010-01-12 15:27:54 +01007848
7849
7850stick store-request <pattern> [table <table>] [{if | unless} <condition>]
7851 Define a request pattern used to create an entry in a stickiness table
7852 May be used in sections : defaults | frontend | listen | backend
7853 no | no | yes | yes
7854
7855 Arguments :
Willy Tarreaube722a22014-06-13 16:31:59 +02007856 <pattern> is a sample expression rule as described in section 7.3. It
Willy Tarreaub937b7e2010-01-12 15:27:54 +01007857 describes what elements of the incoming request or connection
7858 will be analysed, extracted and stored in the table once a
7859 server is selected.
7860
7861 <table> is an optional stickiness table name. If unspecified, the same
7862 backend's table is used. A stickiness table is declared using
7863 the "stick-table" statement.
7864
7865 <cond> is an optional storage condition. It makes it possible to store
7866 certain criteria only when some conditions are met (or not met).
7867 For instance, it could be used to store the source IP address
7868 except when the request passes through a known proxy, in which
7869 case we'd store a converted form of a header containing that IP
7870 address.
7871
7872 Some protocols or applications require complex stickiness rules and cannot
7873 always simply rely on cookies nor hashing. The "stick store-request" statement
7874 describes a rule to decide what to extract from the request and when to do
7875 it, in order to store it into a stickiness table for further requests to
7876 match it using the "stick match" statement. Obviously the extracted part must
7877 make sense and have a chance to be matched in a further request. Storing a
7878 client's IP address for instance often makes sense. Storing an ID found in a
7879 URL parameter also makes sense. Storing a source port will almost never make
7880 any sense because it will be randomly matched. See section 7 for a complete
7881 list of possible patterns and transformation rules.
7882
7883 The table has to be declared using the "stick-table" statement. It must be of
7884 a type compatible with the pattern. By default it is the one which is present
7885 in the same backend. It is possible to share a table with other backends by
7886 referencing it using the "table" keyword. If another table is referenced,
7887 the server's ID inside the backends are used. By default, all server IDs
7888 start at 1 in each backend, so the server ordering is enough. But in case of
7889 doubt, it is highly recommended to force server IDs using their "id" setting.
7890
7891 It is possible to restrict the conditions where a "stick store-request"
7892 statement will apply, using "if" or "unless" followed by a condition. This
7893 condition will be evaluated while parsing the request, so any criteria can be
7894 used. See section 7 for ACL based conditions.
7895
7896 There is no limit on the number of "stick store-request" statements, but
7897 there is a limit of 8 simultaneous stores per request or response. This
7898 makes it possible to store up to 8 criteria, all extracted from either the
7899 request or the response, regardless of the number of rules. Only the 8 first
7900 ones which match will be kept. Using this, it is possible to feed multiple
7901 tables at once in the hope to increase the chance to recognize a user on
Willy Tarreau9667a802013-12-09 12:52:13 +01007902 another protocol or access method. Using multiple store-request rules with
7903 the same table is possible and may be used to find the best criterion to rely
7904 on, by arranging the rules by decreasing preference order. Only the first
7905 extracted criterion for a given table will be stored. All subsequent store-
7906 request rules referencing the same table will be skipped and their ACLs will
7907 not be evaluated.
Willy Tarreaub937b7e2010-01-12 15:27:54 +01007908
7909 The "store-request" rules are evaluated once the server connection has been
7910 established, so that the table will contain the real server that processed
7911 the request.
7912
Cyril Bonté02ff8ef2010-12-14 22:48:49 +01007913 Note : Consider not using this feature in multi-process mode (nbproc > 1)
7914 unless you know what you do : memory is not shared between the
7915 processes, which can result in random behaviours.
7916
Willy Tarreaub937b7e2010-01-12 15:27:54 +01007917 Example :
7918 # forward SMTP users to the same server they just used for POP in the
7919 # last 30 minutes
7920 backend pop
7921 mode tcp
7922 balance roundrobin
7923 stick store-request src
7924 stick-table type ip size 200k expire 30m
7925 server s1 192.168.1.1:110
7926 server s2 192.168.1.1:110
7927
7928 backend smtp
7929 mode tcp
7930 balance roundrobin
7931 stick match src table pop
7932 server s1 192.168.1.1:25
7933 server s2 192.168.1.1:25
7934
Cyril Bonté02ff8ef2010-12-14 22:48:49 +01007935 See also : "stick-table", "stick on", "nbproc", "bind-process" and section 7
Willy Tarreaube722a22014-06-13 16:31:59 +02007936 about ACLs and sample fetching.
Willy Tarreaub937b7e2010-01-12 15:27:54 +01007937
7938
Emeric Brun7c6b82e2010-09-24 16:34:28 +02007939stick-table type {ip | integer | string [len <length>] | binary [len <length>]}
Emeric Brunf099e792010-09-27 12:05:28 +02007940 size <size> [expire <expire>] [nopurge] [peers <peersect>]
7941 [store <data_type>]*
Godbach64cef792013-12-04 16:08:22 +08007942 Configure the stickiness table for the current section
Willy Tarreaub937b7e2010-01-12 15:27:54 +01007943 May be used in sections : defaults | frontend | listen | backend
Willy Tarreauc00cdc22010-06-06 16:48:26 +02007944 no | yes | yes | yes
Willy Tarreaub937b7e2010-01-12 15:27:54 +01007945
7946 Arguments :
7947 ip a table declared with "type ip" will only store IPv4 addresses.
7948 This form is very compact (about 50 bytes per entry) and allows
7949 very fast entry lookup and stores with almost no overhead. This
7950 is mainly used to store client source IP addresses.
7951
David du Colombier9a6d3c92011-03-17 10:40:24 +01007952 ipv6 a table declared with "type ipv6" will only store IPv6 addresses.
7953 This form is very compact (about 60 bytes per entry) and allows
7954 very fast entry lookup and stores with almost no overhead. This
7955 is mainly used to store client source IP addresses.
7956
Willy Tarreaub937b7e2010-01-12 15:27:54 +01007957 integer a table declared with "type integer" will store 32bit integers
7958 which can represent a client identifier found in a request for
7959 instance.
7960
7961 string a table declared with "type string" will store substrings of up
7962 to <len> characters. If the string provided by the pattern
7963 extractor is larger than <len>, it will be truncated before
7964 being stored. During matching, at most <len> characters will be
7965 compared between the string in the table and the extracted
7966 pattern. When not specified, the string is automatically limited
Emeric Brun7c6b82e2010-09-24 16:34:28 +02007967 to 32 characters.
7968
7969 binary a table declared with "type binary" will store binary blocks
7970 of <len> bytes. If the block provided by the pattern
7971 extractor is larger than <len>, it will be truncated before
Willy Tarreaube722a22014-06-13 16:31:59 +02007972 being stored. If the block provided by the sample expression
Emeric Brun7c6b82e2010-09-24 16:34:28 +02007973 is shorter than <len>, it will be padded by 0. When not
7974 specified, the block is automatically limited to 32 bytes.
Willy Tarreaub937b7e2010-01-12 15:27:54 +01007975
7976 <length> is the maximum number of characters that will be stored in a
Emeric Brun7c6b82e2010-09-24 16:34:28 +02007977 "string" type table (See type "string" above). Or the number
7978 of bytes of the block in "binary" type table. Be careful when
Willy Tarreaub937b7e2010-01-12 15:27:54 +01007979 changing this parameter as memory usage will proportionally
7980 increase.
7981
7982 <size> is the maximum number of entries that can fit in the table. This
Cyril Bonté78caf842010-03-10 22:41:43 +01007983 value directly impacts memory usage. Count approximately
7984 50 bytes per entry, plus the size of a string if any. The size
7985 supports suffixes "k", "m", "g" for 2^10, 2^20 and 2^30 factors.
Willy Tarreaub937b7e2010-01-12 15:27:54 +01007986
7987 [nopurge] indicates that we refuse to purge older entries when the table
7988 is full. When not specified and the table is full when haproxy
7989 wants to store an entry in it, it will flush a few of the oldest
7990 entries in order to release some space for the new ones. This is
7991 most often the desired behaviour. In some specific cases, it
7992 be desirable to refuse new entries instead of purging the older
7993 ones. That may be the case when the amount of data to store is
7994 far above the hardware limits and we prefer not to offer access
7995 to new clients than to reject the ones already connected. When
7996 using this parameter, be sure to properly set the "expire"
7997 parameter (see below).
7998
Emeric Brunf099e792010-09-27 12:05:28 +02007999 <peersect> is the name of the peers section to use for replication. Entries
8000 which associate keys to server IDs are kept synchronized with
8001 the remote peers declared in this section. All entries are also
8002 automatically learned from the local peer (old process) during a
8003 soft restart.
8004
Willy Tarreau1abc6732015-05-01 19:21:02 +02008005 NOTE : each peers section may be referenced only by tables
8006 belonging to the same unique process.
Cyril Bonté02ff8ef2010-12-14 22:48:49 +01008007
Willy Tarreaub937b7e2010-01-12 15:27:54 +01008008 <expire> defines the maximum duration of an entry in the table since it
8009 was last created, refreshed or matched. The expiration delay is
8010 defined using the standard time format, similarly as the various
8011 timeouts. The maximum duration is slightly above 24 days. See
8012 section 2.2 for more information. If this delay is not specified,
Cyril Bontédc4d9032012-04-08 21:57:39 +02008013 the session won't automatically expire, but older entries will
Willy Tarreaub937b7e2010-01-12 15:27:54 +01008014 be removed once full. Be sure not to use the "nopurge" parameter
8015 if not expiration delay is specified.
8016
Willy Tarreau08d5f982010-06-06 13:34:54 +02008017 <data_type> is used to store additional information in the stick-table. This
8018 may be used by ACLs in order to control various criteria related
8019 to the activity of the client matching the stick-table. For each
8020 item specified here, the size of each entry will be inflated so
Willy Tarreauc9705a12010-07-27 20:05:50 +02008021 that the additional data can fit. Several data types may be
8022 stored with an entry. Multiple data types may be specified after
8023 the "store" keyword, as a comma-separated list. Alternatively,
8024 it is possible to repeat the "store" keyword followed by one or
8025 several data types. Except for the "server_id" type which is
8026 automatically detected and enabled, all data types must be
8027 explicitly declared to be stored. If an ACL references a data
8028 type which is not stored, the ACL will simply not match. Some
8029 data types require an argument which must be passed just after
8030 the type between parenthesis. See below for the supported data
8031 types and their arguments.
8032
8033 The data types that can be stored with an entry are the following :
8034 - server_id : this is an integer which holds the numeric ID of the server a
8035 request was assigned to. It is used by the "stick match", "stick store",
8036 and "stick on" rules. It is automatically enabled when referenced.
8037
8038 - gpc0 : first General Purpose Counter. It is a positive 32-bit integer
8039 integer which may be used for anything. Most of the time it will be used
8040 to put a special tag on some entries, for instance to note that a
8041 specific behaviour was detected and must be known for future matches.
8042
Willy Tarreauba2ffd12013-05-29 15:54:14 +02008043 - gpc0_rate(<period>) : increment rate of the first General Purpose Counter
8044 over a period. It is a positive 32-bit integer integer which may be used
8045 for anything. Just like <gpc0>, it counts events, but instead of keeping
8046 a cumulative count, it maintains the rate at which the counter is
8047 incremented. Most of the time it will be used to measure the frequency of
8048 occurrence of certain events (eg: requests to a specific URL).
8049
Willy Tarreauc9705a12010-07-27 20:05:50 +02008050 - conn_cnt : Connection Count. It is a positive 32-bit integer which counts
8051 the absolute number of connections received from clients which matched
8052 this entry. It does not mean the connections were accepted, just that
8053 they were received.
8054
8055 - conn_cur : Current Connections. It is a positive 32-bit integer which
8056 stores the concurrent connection counts for the entry. It is incremented
8057 once an incoming connection matches the entry, and decremented once the
8058 connection leaves. That way it is possible to know at any time the exact
8059 number of concurrent connections for an entry.
8060
8061 - conn_rate(<period>) : frequency counter (takes 12 bytes). It takes an
8062 integer parameter <period> which indicates in milliseconds the length
8063 of the period over which the average is measured. It reports the average
8064 incoming connection rate over that period, in connections per period. The
8065 result is an integer which can be matched using ACLs.
8066
8067 - sess_cnt : Session Count. It is a positive 32-bit integer which counts
8068 the absolute number of sessions received from clients which matched this
8069 entry. A session is a connection that was accepted by the layer 4 rules.
8070
8071 - sess_rate(<period>) : frequency counter (takes 12 bytes). It takes an
8072 integer parameter <period> which indicates in milliseconds the length
8073 of the period over which the average is measured. It reports the average
8074 incoming session rate over that period, in sessions per period. The
8075 result is an integer which can be matched using ACLs.
8076
8077 - http_req_cnt : HTTP request Count. It is a positive 32-bit integer which
8078 counts the absolute number of HTTP requests received from clients which
8079 matched this entry. It does not matter whether they are valid requests or
8080 not. Note that this is different from sessions when keep-alive is used on
8081 the client side.
8082
8083 - http_req_rate(<period>) : frequency counter (takes 12 bytes). It takes an
8084 integer parameter <period> which indicates in milliseconds the length
8085 of the period over which the average is measured. It reports the average
8086 HTTP request rate over that period, in requests per period. The result is
8087 an integer which can be matched using ACLs. It does not matter whether
8088 they are valid requests or not. Note that this is different from sessions
8089 when keep-alive is used on the client side.
8090
8091 - http_err_cnt : HTTP Error Count. It is a positive 32-bit integer which
8092 counts the absolute number of HTTP requests errors induced by clients
8093 which matched this entry. Errors are counted on invalid and truncated
8094 requests, as well as on denied or tarpitted requests, and on failed
8095 authentications. If the server responds with 4xx, then the request is
8096 also counted as an error since it's an error triggered by the client
8097 (eg: vulnerability scan).
8098
8099 - http_err_rate(<period>) : frequency counter (takes 12 bytes). It takes an
8100 integer parameter <period> which indicates in milliseconds the length
8101 of the period over which the average is measured. It reports the average
8102 HTTP request error rate over that period, in requests per period (see
8103 http_err_cnt above for what is accounted as an error). The result is an
8104 integer which can be matched using ACLs.
8105
8106 - bytes_in_cnt : client to server byte count. It is a positive 64-bit
8107 integer which counts the cumulated amount of bytes received from clients
8108 which matched this entry. Headers are included in the count. This may be
8109 used to limit abuse of upload features on photo or video servers.
8110
8111 - bytes_in_rate(<period>) : frequency counter (takes 12 bytes). It takes an
8112 integer parameter <period> which indicates in milliseconds the length
8113 of the period over which the average is measured. It reports the average
8114 incoming bytes rate over that period, in bytes per period. It may be used
8115 to detect users which upload too much and too fast. Warning: with large
8116 uploads, it is possible that the amount of uploaded data will be counted
8117 once upon termination, thus causing spikes in the average transfer speed
8118 instead of having a smooth one. This may partially be smoothed with
8119 "option contstats" though this is not perfect yet. Use of byte_in_cnt is
8120 recommended for better fairness.
8121
8122 - bytes_out_cnt : server to client byte count. It is a positive 64-bit
8123 integer which counts the cumulated amount of bytes sent to clients which
8124 matched this entry. Headers are included in the count. This may be used
8125 to limit abuse of bots sucking the whole site.
8126
8127 - bytes_out_rate(<period>) : frequency counter (takes 12 bytes). It takes
8128 an integer parameter <period> which indicates in milliseconds the length
8129 of the period over which the average is measured. It reports the average
8130 outgoing bytes rate over that period, in bytes per period. It may be used
8131 to detect users which download too much and too fast. Warning: with large
8132 transfers, it is possible that the amount of transferred data will be
8133 counted once upon termination, thus causing spikes in the average
8134 transfer speed instead of having a smooth one. This may partially be
8135 smoothed with "option contstats" though this is not perfect yet. Use of
8136 byte_out_cnt is recommended for better fairness.
Willy Tarreau08d5f982010-06-06 13:34:54 +02008137
Willy Tarreauc00cdc22010-06-06 16:48:26 +02008138 There is only one stick-table per proxy. At the moment of writing this doc,
8139 it does not seem useful to have multiple tables per proxy. If this happens
Willy Tarreaub937b7e2010-01-12 15:27:54 +01008140 to be required, simply create a dummy backend with a stick-table in it and
8141 reference it.
8142
8143 It is important to understand that stickiness based on learning information
8144 has some limitations, including the fact that all learned associations are
8145 lost upon restart. In general it can be good as a complement but not always
8146 as an exclusive stickiness.
8147
Willy Tarreauc9705a12010-07-27 20:05:50 +02008148 Last, memory requirements may be important when storing many data types.
8149 Indeed, storing all indicators above at once in each entry requires 116 bytes
8150 per entry, or 116 MB for a 1-million entries table. This is definitely not
8151 something that can be ignored.
8152
8153 Example:
8154 # Keep track of counters of up to 1 million IP addresses over 5 minutes
8155 # and store a general purpose counter and the average connection rate
8156 # computed over a sliding window of 30 seconds.
8157 stick-table type ip size 1m expire 5m store gpc0,conn_rate(30s)
8158
8159 See also : "stick match", "stick on", "stick store-request", section 2.2
David du Colombiera13d1b92011-03-17 10:40:22 +01008160 about time format and section 7 about ACLs.
Willy Tarreaub937b7e2010-01-12 15:27:54 +01008161
8162
Emeric Brun6a1cefa2010-09-24 18:15:17 +02008163stick store-response <pattern> [table <table>] [{if | unless} <condition>]
8164 Define a request pattern used to create an entry in a stickiness table
8165 May be used in sections : defaults | frontend | listen | backend
8166 no | no | yes | yes
8167
8168 Arguments :
Willy Tarreaube722a22014-06-13 16:31:59 +02008169 <pattern> is a sample expression rule as described in section 7.3. It
Emeric Brun6a1cefa2010-09-24 18:15:17 +02008170 describes what elements of the response or connection will
8171 be analysed, extracted and stored in the table once a
8172 server is selected.
8173
8174 <table> is an optional stickiness table name. If unspecified, the same
8175 backend's table is used. A stickiness table is declared using
8176 the "stick-table" statement.
8177
8178 <cond> is an optional storage condition. It makes it possible to store
8179 certain criteria only when some conditions are met (or not met).
8180 For instance, it could be used to store the SSL session ID only
8181 when the response is a SSL server hello.
8182
8183 Some protocols or applications require complex stickiness rules and cannot
8184 always simply rely on cookies nor hashing. The "stick store-response"
8185 statement describes a rule to decide what to extract from the response and
8186 when to do it, in order to store it into a stickiness table for further
8187 requests to match it using the "stick match" statement. Obviously the
8188 extracted part must make sense and have a chance to be matched in a further
Cyril Bonté108cf6e2012-04-21 23:30:29 +02008189 request. Storing an ID found in a header of a response makes sense.
Emeric Brun6a1cefa2010-09-24 18:15:17 +02008190 See section 7 for a complete list of possible patterns and transformation
8191 rules.
8192
8193 The table has to be declared using the "stick-table" statement. It must be of
8194 a type compatible with the pattern. By default it is the one which is present
8195 in the same backend. It is possible to share a table with other backends by
8196 referencing it using the "table" keyword. If another table is referenced,
8197 the server's ID inside the backends are used. By default, all server IDs
8198 start at 1 in each backend, so the server ordering is enough. But in case of
8199 doubt, it is highly recommended to force server IDs using their "id" setting.
8200
8201 It is possible to restrict the conditions where a "stick store-response"
8202 statement will apply, using "if" or "unless" followed by a condition. This
8203 condition will be evaluated while parsing the response, so any criteria can
8204 be used. See section 7 for ACL based conditions.
8205
8206 There is no limit on the number of "stick store-response" statements, but
8207 there is a limit of 8 simultaneous stores per request or response. This
8208 makes it possible to store up to 8 criteria, all extracted from either the
8209 request or the response, regardless of the number of rules. Only the 8 first
8210 ones which match will be kept. Using this, it is possible to feed multiple
8211 tables at once in the hope to increase the chance to recognize a user on
Willy Tarreau9667a802013-12-09 12:52:13 +01008212 another protocol or access method. Using multiple store-response rules with
8213 the same table is possible and may be used to find the best criterion to rely
8214 on, by arranging the rules by decreasing preference order. Only the first
8215 extracted criterion for a given table will be stored. All subsequent store-
8216 response rules referencing the same table will be skipped and their ACLs will
8217 not be evaluated. However, even if a store-request rule references a table, a
8218 store-response rule may also use the same table. This means that each table
8219 may learn exactly one element from the request and one element from the
8220 response at once.
Emeric Brun6a1cefa2010-09-24 18:15:17 +02008221
8222 The table will contain the real server that processed the request.
8223
8224 Example :
8225 # Learn SSL session ID from both request and response and create affinity.
8226 backend https
8227 mode tcp
8228 balance roundrobin
Cyril Bontédc4d9032012-04-08 21:57:39 +02008229 # maximum SSL session ID length is 32 bytes.
Emeric Brun6a1cefa2010-09-24 18:15:17 +02008230 stick-table type binary len 32 size 30k expire 30m
Cyril Bonté108cf6e2012-04-21 23:30:29 +02008231
Emeric Brun6a1cefa2010-09-24 18:15:17 +02008232 acl clienthello req_ssl_hello_type 1
8233 acl serverhello rep_ssl_hello_type 2
8234
8235 # use tcp content accepts to detects ssl client and server hello.
8236 tcp-request inspect-delay 5s
8237 tcp-request content accept if clienthello
8238
8239 # no timeout on response inspect delay by default.
8240 tcp-response content accept if serverhello
Cyril Bonté108cf6e2012-04-21 23:30:29 +02008241
Emeric Brun6a1cefa2010-09-24 18:15:17 +02008242 # SSL session ID (SSLID) may be present on a client or server hello.
8243 # Its length is coded on 1 byte at offset 43 and its value starts
8244 # at offset 44.
8245
8246 # Match and learn on request if client hello.
8247 stick on payload_lv(43,1) if clienthello
8248
8249 # Learn on response if server hello.
8250 stick store-response payload_lv(43,1) if serverhello
Cyril Bontédc4d9032012-04-08 21:57:39 +02008251
Emeric Brun6a1cefa2010-09-24 18:15:17 +02008252 server s1 192.168.1.1:443
8253 server s2 192.168.1.1:443
8254
8255 See also : "stick-table", "stick on", and section 7 about ACLs and pattern
8256 extraction.
8257
8258
Willy Tarreau938c7fe2014-04-25 14:21:39 +02008259tcp-check connect [params*]
8260 Opens a new connection
8261 May be used in sections: defaults | frontend | listen | backend
8262 no | no | yes | yes
8263
8264 When an application lies on more than a single TCP port or when HAProxy
8265 load-balance many services in a single backend, it makes sense to probe all
8266 the services individually before considering a server as operational.
8267
8268 When there are no TCP port configured on the server line neither server port
8269 directive, then the 'tcp-check connect port <port>' must be the first step
8270 of the sequence.
8271
8272 In a tcp-check ruleset a 'connect' is required, it is also mandatory to start
8273 the ruleset with a 'connect' rule. Purpose is to ensure admin know what they
8274 do.
8275
8276 Parameters :
8277 They are optional and can be used to describe how HAProxy should open and
8278 use the TCP connection.
8279
8280 port if not set, check port or server port is used.
8281 It tells HAProxy where to open the connection to.
8282 <port> must be a valid TCP port source integer, from 1 to 65535.
8283
8284 send-proxy send a PROXY protocol string
8285
8286 ssl opens a ciphered connection
8287
8288 Examples:
8289 # check HTTP and HTTPs services on a server.
8290 # first open port 80 thanks to server line port directive, then
8291 # tcp-check opens port 443, ciphered and run a request on it:
8292 option tcp-check
8293 tcp-check connect
8294 tcp-check send GET\ /\ HTTP/1.0\r\n
8295 tcp-check send Host:\ haproxy.1wt.eu\r\n
8296 tcp-check send \r\n
8297 tcp-check expect rstring (2..|3..)
8298 tcp-check connect port 443 ssl
8299 tcp-check send GET\ /\ HTTP/1.0\r\n
8300 tcp-check send Host:\ haproxy.1wt.eu\r\n
8301 tcp-check send \r\n
8302 tcp-check expect rstring (2..|3..)
8303 server www 10.0.0.1 check port 80
8304
8305 # check both POP and IMAP from a single server:
8306 option tcp-check
8307 tcp-check connect port 110
8308 tcp-check expect string +OK\ POP3\ ready
8309 tcp-check connect port 143
8310 tcp-check expect string *\ OK\ IMAP4\ ready
8311 server mail 10.0.0.1 check
8312
8313 See also : "option tcp-check", "tcp-check send", "tcp-check expect"
8314
8315
8316tcp-check expect [!] <match> <pattern>
8317 Specify data to be collected and analysed during a generic health check
8318 May be used in sections: defaults | frontend | listen | backend
8319 no | no | yes | yes
8320
8321 Arguments :
8322 <match> is a keyword indicating how to look for a specific pattern in the
8323 response. The keyword may be one of "string", "rstring" or
8324 binary.
8325 The keyword may be preceded by an exclamation mark ("!") to negate
8326 the match. Spaces are allowed between the exclamation mark and the
8327 keyword. See below for more details on the supported keywords.
8328
8329 <pattern> is the pattern to look for. It may be a string or a regular
8330 expression. If the pattern contains spaces, they must be escaped
8331 with the usual backslash ('\').
8332 If the match is set to binary, then the pattern must be passed as
8333 a serie of hexadecimal digits in an even number. Each sequence of
8334 two digits will represent a byte. The hexadecimal digits may be
8335 used upper or lower case.
8336
8337
8338 The available matches are intentionally similar to their http-check cousins :
8339
8340 string <string> : test the exact string matches in the response buffer.
8341 A health check response will be considered valid if the
8342 response's buffer contains this exact string. If the
8343 "string" keyword is prefixed with "!", then the response
8344 will be considered invalid if the body contains this
8345 string. This can be used to look for a mandatory pattern
8346 in a protocol response, or to detect a failure when a
8347 specific error appears in a protocol banner.
8348
8349 rstring <regex> : test a regular expression on the response buffer.
8350 A health check response will be considered valid if the
8351 response's buffer matches this expression. If the
8352 "rstring" keyword is prefixed with "!", then the response
8353 will be considered invalid if the body matches the
8354 expression.
8355
8356 binary <hexstring> : test the exact string in its hexadecimal form matches
8357 in the response buffer. A health check response will
8358 be considered valid if the response's buffer contains
8359 this exact hexadecimal string.
8360 Purpose is to match data on binary protocols.
8361
8362 It is important to note that the responses will be limited to a certain size
8363 defined by the global "tune.chksize" option, which defaults to 16384 bytes.
8364 Thus, too large responses may not contain the mandatory pattern when using
8365 "string", "rstring" or binary. If a large response is absolutely required, it
8366 is possible to change the default max size by setting the global variable.
8367 However, it is worth keeping in mind that parsing very large responses can
8368 waste some CPU cycles, especially when regular expressions are used, and that
8369 it is always better to focus the checks on smaller resources. Also, in its
8370 current state, the check will not find any string nor regex past a null
8371 character in the response. Similarly it is not possible to request matching
8372 the null character.
8373
8374 Examples :
8375 # perform a POP check
8376 option tcp-check
8377 tcp-check expect string +OK\ POP3\ ready
8378
8379 # perform an IMAP check
8380 option tcp-check
8381 tcp-check expect string *\ OK\ IMAP4\ ready
8382
8383 # look for the redis master server
8384 option tcp-check
8385 tcp-check send PING\r\n
Baptiste Assmanna3322992015-08-04 10:12:18 +02008386 tcp-check expect string +PONG
Willy Tarreau938c7fe2014-04-25 14:21:39 +02008387 tcp-check send info\ replication\r\n
8388 tcp-check expect string role:master
8389 tcp-check send QUIT\r\n
8390 tcp-check expect string +OK
8391
8392
8393 See also : "option tcp-check", "tcp-check connect", "tcp-check send",
8394 "tcp-check send-binary", "http-check expect", tune.chksize
8395
8396
8397tcp-check send <data>
8398 Specify a string to be sent as a question during a generic health check
8399 May be used in sections: defaults | frontend | listen | backend
8400 no | no | yes | yes
8401
8402 <data> : the data to be sent as a question during a generic health check
8403 session. For now, <data> must be a string.
8404
8405 Examples :
8406 # look for the redis master server
8407 option tcp-check
8408 tcp-check send info\ replication\r\n
8409 tcp-check expect string role:master
8410
8411 See also : "option tcp-check", "tcp-check connect", "tcp-check expect",
8412 "tcp-check send-binary", tune.chksize
8413
8414
8415tcp-check send-binary <hexastring>
8416 Specify an hexa digits string to be sent as a binary question during a raw
8417 tcp health check
8418 May be used in sections: defaults | frontend | listen | backend
8419 no | no | yes | yes
8420
8421 <data> : the data to be sent as a question during a generic health check
8422 session. For now, <data> must be a string.
8423 <hexastring> : test the exact string in its hexadecimal form matches in the
8424 response buffer. A health check response will be considered
8425 valid if the response's buffer contains this exact
8426 hexadecimal string.
8427 Purpose is to send binary data to ask on binary protocols.
8428
8429 Examples :
8430 # redis check in binary
8431 option tcp-check
8432 tcp-check send-binary 50494e470d0a # PING\r\n
8433 tcp-check expect binary 2b504F4e47 # +PONG
8434
8435
8436 See also : "option tcp-check", "tcp-check connect", "tcp-check expect",
8437 "tcp-check send", tune.chksize
8438
8439
Willy Tarreaue9656522010-08-17 15:40:09 +02008440tcp-request connection <action> [{if | unless} <condition>]
8441 Perform an action on an incoming connection depending on a layer 4 condition
Willy Tarreau1a687942010-05-23 22:40:30 +02008442 May be used in sections : defaults | frontend | listen | backend
8443 no | yes | yes | no
Willy Tarreaue9656522010-08-17 15:40:09 +02008444 Arguments :
Willy Tarreauc870bfd2015-09-28 18:47:38 +02008445 <action> defines the action to perform if the condition applies. See
8446 below.
Willy Tarreau1a687942010-05-23 22:40:30 +02008447
Willy Tarreaue9656522010-08-17 15:40:09 +02008448 <condition> is a standard layer4-only ACL-based condition (see section 7).
Willy Tarreau68c03ab2010-08-06 15:08:45 +02008449
8450 Immediately after acceptance of a new incoming connection, it is possible to
8451 evaluate some conditions to decide whether this connection must be accepted
Willy Tarreaue9656522010-08-17 15:40:09 +02008452 or dropped or have its counters tracked. Those conditions cannot make use of
8453 any data contents because the connection has not been read from yet, and the
8454 buffers are not yet allocated. This is used to selectively and very quickly
8455 accept or drop connections from various sources with a very low overhead. If
8456 some contents need to be inspected in order to take the decision, the
8457 "tcp-request content" statements must be used instead.
Willy Tarreau68c03ab2010-08-06 15:08:45 +02008458
Willy Tarreaue9656522010-08-17 15:40:09 +02008459 The "tcp-request connection" rules are evaluated in their exact declaration
8460 order. If no rule matches or if there is no rule, the default action is to
8461 accept the incoming connection. There is no specific limit to the number of
8462 rules which may be inserted.
Willy Tarreau68c03ab2010-08-06 15:08:45 +02008463
Willy Tarreaua9083d02015-05-08 15:27:59 +02008464 Four types of actions are supported :
Willy Tarreaue9656522010-08-17 15:40:09 +02008465 - accept :
8466 accepts the connection if the condition is true (when used with "if")
8467 or false (when used with "unless"). The first such rule executed ends
8468 the rules evaluation.
Willy Tarreau68c03ab2010-08-06 15:08:45 +02008469
Willy Tarreaue9656522010-08-17 15:40:09 +02008470 - reject :
8471 rejects the connection if the condition is true (when used with "if")
8472 or false (when used with "unless"). The first such rule executed ends
8473 the rules evaluation. Rejected connections do not even become a
8474 session, which is why they are accounted separately for in the stats,
8475 as "denied connections". They are not considered for the session
8476 rate-limit and are not logged either. The reason is that these rules
8477 should only be used to filter extremely high connection rates such as
8478 the ones encountered during a massive DDoS attack. Under these extreme
8479 conditions, the simple action of logging each event would make the
8480 system collapse and would considerably lower the filtering capacity. If
8481 logging is absolutely desired, then "tcp-request content" rules should
8482 be used instead.
Willy Tarreau68c03ab2010-08-06 15:08:45 +02008483
Willy Tarreau4f0d9192013-06-11 20:40:55 +02008484 - expect-proxy layer4 :
8485 configures the client-facing connection to receive a PROXY protocol
8486 header before any byte is read from the socket. This is equivalent to
8487 having the "accept-proxy" keyword on the "bind" line, except that using
8488 the TCP rule allows the PROXY protocol to be accepted only for certain
8489 IP address ranges using an ACL. This is convenient when multiple layers
8490 of load balancers are passed through by traffic coming from public
8491 hosts.
8492
Willy Tarreau18bf01e2014-06-13 16:18:52 +02008493 - capture <sample> len <length> :
8494 This only applies to "tcp-request content" rules. It captures sample
8495 expression <sample> from the request buffer, and converts it to a
8496 string of at most <len> characters. The resulting string is stored into
8497 the next request "capture" slot, so it will possibly appear next to
8498 some captured HTTP headers. It will then automatically appear in the
8499 logs, and it will be possible to extract it using sample fetch rules to
8500 feed it into headers or anything. The length should be limited given
8501 that this size will be allocated for each capture during the whole
Willy Tarreaua9083d02015-05-08 15:27:59 +02008502 session life. Please check section 7.3 (Fetching samples) and "capture
8503 request header" for more information.
Willy Tarreau18bf01e2014-06-13 16:18:52 +02008504
Willy Tarreaube4a3ef2013-06-17 15:04:07 +02008505 - { track-sc0 | track-sc1 | track-sc2 } <key> [table <table>] :
Willy Tarreaue9656522010-08-17 15:40:09 +02008506 enables tracking of sticky counters from current connection. These
Willy Tarreau09448f72014-06-25 18:12:15 +02008507 rules do not stop evaluation and do not change default action. 3 sets
Willy Tarreaue9656522010-08-17 15:40:09 +02008508 of counters may be simultaneously tracked by the same connection. The
Willy Tarreaube4a3ef2013-06-17 15:04:07 +02008509 first "track-sc0" rule executed enables tracking of the counters of the
8510 specified table as the first set. The first "track-sc1" rule executed
Willy Tarreaue9656522010-08-17 15:40:09 +02008511 enables tracking of the counters of the specified table as the second
Willy Tarreaube4a3ef2013-06-17 15:04:07 +02008512 set. The first "track-sc2" rule executed enables tracking of the
8513 counters of the specified table as the third set. It is a recommended
8514 practice to use the first set of counters for the per-frontend counters
8515 and the second set for the per-backend ones. But this is just a
8516 guideline, all may be used everywhere.
Willy Tarreau68c03ab2010-08-06 15:08:45 +02008517
Willy Tarreaue9656522010-08-17 15:40:09 +02008518 These actions take one or two arguments :
Willy Tarreaube722a22014-06-13 16:31:59 +02008519 <key> is mandatory, and is a sample expression rule as described
Willy Tarreau74ca5042013-06-11 23:12:07 +02008520 in section 7.3. It describes what elements of the incoming
Willy Tarreau5d5b5d82012-12-09 12:00:04 +01008521 request or connection will be analysed, extracted, combined,
8522 and used to select which table entry to update the counters.
8523 Note that "tcp-request connection" cannot use content-based
8524 fetches.
Willy Tarreau68c03ab2010-08-06 15:08:45 +02008525
Willy Tarreaue9656522010-08-17 15:40:09 +02008526 <table> is an optional table to be used instead of the default one,
8527 which is the stick-table declared in the current proxy. All
8528 the counters for the matches and updates for the key will
8529 then be performed in that table until the session ends.
Willy Tarreau68c03ab2010-08-06 15:08:45 +02008530
Willy Tarreaue9656522010-08-17 15:40:09 +02008531 Once a "track-sc*" rule is executed, the key is looked up in the table
8532 and if it is not found, an entry is allocated for it. Then a pointer to
8533 that entry is kept during all the session's life, and this entry's
8534 counters are updated as often as possible, every time the session's
8535 counters are updated, and also systematically when the session ends.
Willy Tarreau5d5b5d82012-12-09 12:00:04 +01008536 Counters are only updated for events that happen after the tracking has
8537 been started. For example, connection counters will not be updated when
8538 tracking layer 7 information, since the connection event happens before
8539 layer7 information is extracted.
8540
Willy Tarreaue9656522010-08-17 15:40:09 +02008541 If the entry tracks concurrent connection counters, one connection is
8542 counted for as long as the entry is tracked, and the entry will not
8543 expire during that time. Tracking counters also provides a performance
8544 advantage over just checking the keys, because only one table lookup is
8545 performed for all ACL checks that make use of it.
Willy Tarreau68c03ab2010-08-06 15:08:45 +02008546
Thierry FOURNIERe0627bd2015-08-04 08:20:33 +02008547 - sc-inc-gpc0(<sc-id>):
8548 The "sc-inc-gpc0" increments the GPC0 counter according to the sticky
8549 counter designated by <sc-id>. If an error occurs, this action silently
8550 fails and the actions evaluation continues.
8551
Thierry FOURNIER236657b2015-08-19 08:25:14 +02008552 - sc-set-gpt0(<sc-id>) <int>:
8553 This action sets the GPT0 tag according to the sticky counter designated
8554 by <sc-id> and the value of <int>. The expected result is a boolean. If
8555 an error occurs, this action silently fails and the actions evaluation
8556 continues.
8557
Willy Tarreau2d392c22015-08-24 01:43:45 +02008558 - "silent-drop" :
8559 This stops the evaluation of the rules and makes the client-facing
8560 connection suddenly disappear using a system-dependant way that tries
8561 to prevent the client from being notified. The effect it then that the
8562 client still sees an established connection while there's none on
8563 HAProxy. The purpose is to achieve a comparable effect to "tarpit"
8564 except that it doesn't use any local resource at all on the machine
8565 running HAProxy. It can resist much higher loads than "tarpit", and
8566 slow down stronger attackers. It is important to undestand the impact
8567 of using this mechanism. All stateful equipments placed between the
8568 client and HAProxy (firewalls, proxies, load balancers) will also keep
8569 the established connection for a long time and may suffer from this
8570 action. On modern Linux systems running with enough privileges, the
8571 TCP_REPAIR socket option is used to block the emission of a TCP
8572 reset. On other systems, the socket's TTL is reduced to 1 so that the
8573 TCP reset doesn't pass the first router, though it's still delivered to
8574 local networks. Do not use it unless you fully understand how it works.
8575
Willy Tarreaue9656522010-08-17 15:40:09 +02008576 Note that the "if/unless" condition is optional. If no condition is set on
8577 the action, it is simply performed unconditionally. That can be useful for
8578 "track-sc*" actions as well as for changing the default action to a reject.
Willy Tarreau68c03ab2010-08-06 15:08:45 +02008579
Willy Tarreaue9656522010-08-17 15:40:09 +02008580 Example: accept all connections from white-listed hosts, reject too fast
8581 connection without counting them, and track accepted connections.
8582 This results in connection rate being capped from abusive sources.
Willy Tarreau68c03ab2010-08-06 15:08:45 +02008583
Willy Tarreaue9656522010-08-17 15:40:09 +02008584 tcp-request connection accept if { src -f /etc/haproxy/whitelist.lst }
Willy Tarreau68c03ab2010-08-06 15:08:45 +02008585 tcp-request connection reject if { src_conn_rate gt 10 }
Willy Tarreaube4a3ef2013-06-17 15:04:07 +02008586 tcp-request connection track-sc0 src
Willy Tarreau68c03ab2010-08-06 15:08:45 +02008587
Willy Tarreaue9656522010-08-17 15:40:09 +02008588 Example: accept all connections from white-listed hosts, count all other
8589 connections and reject too fast ones. This results in abusive ones
8590 being blocked as long as they don't slow down.
Willy Tarreau68c03ab2010-08-06 15:08:45 +02008591
Willy Tarreaue9656522010-08-17 15:40:09 +02008592 tcp-request connection accept if { src -f /etc/haproxy/whitelist.lst }
Willy Tarreaube4a3ef2013-06-17 15:04:07 +02008593 tcp-request connection track-sc0 src
8594 tcp-request connection reject if { sc0_conn_rate gt 10 }
Willy Tarreau68c03ab2010-08-06 15:08:45 +02008595
Willy Tarreau4f0d9192013-06-11 20:40:55 +02008596 Example: enable the PROXY protocol for traffic coming from all known proxies.
8597
8598 tcp-request connection expect-proxy layer4 if { src -f proxies.lst }
8599
Willy Tarreau68c03ab2010-08-06 15:08:45 +02008600 See section 7 about ACL usage.
8601
Willy Tarreaue9656522010-08-17 15:40:09 +02008602 See also : "tcp-request content", "stick-table"
Willy Tarreau68c03ab2010-08-06 15:08:45 +02008603
8604
Willy Tarreaue9656522010-08-17 15:40:09 +02008605tcp-request content <action> [{if | unless} <condition>]
8606 Perform an action on a new session depending on a layer 4-7 condition
Willy Tarreau62644772008-07-16 18:36:06 +02008607 May be used in sections : defaults | frontend | listen | backend
Willy Tarreaufb356202010-08-03 14:02:05 +02008608 no | yes | yes | yes
Willy Tarreaue9656522010-08-17 15:40:09 +02008609 Arguments :
Willy Tarreauc870bfd2015-09-28 18:47:38 +02008610 <action> defines the action to perform if the condition applies. See
8611 below.
Willy Tarreau62644772008-07-16 18:36:06 +02008612
Willy Tarreaue9656522010-08-17 15:40:09 +02008613 <condition> is a standard layer 4-7 ACL-based condition (see section 7).
Willy Tarreau62644772008-07-16 18:36:06 +02008614
Willy Tarreaue9656522010-08-17 15:40:09 +02008615 A request's contents can be analysed at an early stage of request processing
8616 called "TCP content inspection". During this stage, ACL-based rules are
8617 evaluated every time the request contents are updated, until either an
8618 "accept" or a "reject" rule matches, or the TCP request inspection delay
8619 expires with no matching rule.
Willy Tarreau62644772008-07-16 18:36:06 +02008620
Willy Tarreaue9656522010-08-17 15:40:09 +02008621 The first difference between these rules and "tcp-request connection" rules
8622 is that "tcp-request content" rules can make use of contents to take a
8623 decision. Most often, these decisions will consider a protocol recognition or
8624 validity. The second difference is that content-based rules can be used in
Willy Tarreauf3338342014-01-28 21:40:28 +01008625 both frontends and backends. In case of HTTP keep-alive with the client, all
8626 tcp-request content rules are evaluated again, so haproxy keeps a record of
8627 what sticky counters were assigned by a "tcp-request connection" versus a
8628 "tcp-request content" rule, and flushes all the content-related ones after
8629 processing an HTTP request, so that they may be evaluated again by the rules
8630 being evaluated again for the next request. This is of particular importance
Jarno Huuskonen0e82b922014-04-12 18:22:19 +03008631 when the rule tracks some L7 information or when it is conditioned by an
Willy Tarreauf3338342014-01-28 21:40:28 +01008632 L7-based ACL, since tracking may change between requests.
Willy Tarreau62644772008-07-16 18:36:06 +02008633
Willy Tarreaue9656522010-08-17 15:40:09 +02008634 Content-based rules are evaluated in their exact declaration order. If no
8635 rule matches or if there is no rule, the default action is to accept the
8636 contents. There is no specific limit to the number of rules which may be
8637 inserted.
Willy Tarreau62644772008-07-16 18:36:06 +02008638
Thierry FOURNIER236657b2015-08-19 08:25:14 +02008639 Several types of actions are supported :
Willy Tarreau18bf01e2014-06-13 16:18:52 +02008640 - accept : the request is accepted
8641 - reject : the request is rejected and the connection is closed
8642 - capture : the specified sample expression is captured
Willy Tarreaube4a3ef2013-06-17 15:04:07 +02008643 - { track-sc0 | track-sc1 | track-sc2 } <key> [table <table>]
Thierry FOURNIERe0627bd2015-08-04 08:20:33 +02008644 - sc-inc-gpc0(<sc-id>)
Thierry FOURNIER236657b2015-08-19 08:25:14 +02008645 - set-gpt0(<sc-id>) <int>
Thierry FOURNIER69717b42015-06-04 12:23:41 +02008646 - lua <function>
Thierry FOURNIER4834bc72015-06-06 19:29:07 +02008647 - set-var(<var-name>) <expr>
Willy Tarreau2d392c22015-08-24 01:43:45 +02008648 - silent-drop
Willy Tarreau62644772008-07-16 18:36:06 +02008649
Willy Tarreaue9656522010-08-17 15:40:09 +02008650 They have the same meaning as their counter-parts in "tcp-request connection"
8651 so please refer to that section for a complete description.
Willy Tarreau62644772008-07-16 18:36:06 +02008652
Willy Tarreauf3338342014-01-28 21:40:28 +01008653 While there is nothing mandatory about it, it is recommended to use the
8654 track-sc0 in "tcp-request connection" rules, track-sc1 for "tcp-request
8655 content" rules in the frontend, and track-sc2 for "tcp-request content"
8656 rules in the backend, because that makes the configuration more readable
8657 and easier to troubleshoot, but this is just a guideline and all counters
8658 may be used everywhere.
Willy Tarreau62644772008-07-16 18:36:06 +02008659
Krzysztof Piotr Oledzkif8645332009-12-13 21:55:50 +01008660 Note that the "if/unless" condition is optional. If no condition is set on
Willy Tarreaue9656522010-08-17 15:40:09 +02008661 the action, it is simply performed unconditionally. That can be useful for
8662 "track-sc*" actions as well as for changing the default action to a reject.
Willy Tarreau62644772008-07-16 18:36:06 +02008663
Willy Tarreaue9656522010-08-17 15:40:09 +02008664 It is perfectly possible to match layer 7 contents with "tcp-request content"
Willy Tarreauc0239e02012-04-16 14:42:55 +02008665 rules, since HTTP-specific ACL matches are able to preliminarily parse the
8666 contents of a buffer before extracting the required data. If the buffered
8667 contents do not parse as a valid HTTP message, then the ACL does not match.
8668 The parser which is involved there is exactly the same as for all other HTTP
Willy Tarreauf3338342014-01-28 21:40:28 +01008669 processing, so there is no risk of parsing something differently. In an HTTP
8670 backend connected to from an HTTP frontend, it is guaranteed that HTTP
8671 contents will always be immediately present when the rule is evaluated first.
Willy Tarreau62644772008-07-16 18:36:06 +02008672
Willy Tarreau5d5b5d82012-12-09 12:00:04 +01008673 Tracking layer7 information is also possible provided that the information
Willy Tarreau4d54c7c2014-09-16 15:48:15 +02008674 are present when the rule is processed. The rule processing engine is able to
8675 wait until the inspect delay expires when the data to be tracked is not yet
8676 available.
Willy Tarreau5d5b5d82012-12-09 12:00:04 +01008677
Thierry FOURNIER90da1912015-03-05 11:17:06 +01008678 The "lua" keyword is followed by a Lua function name. It is used to run a Lua
8679 function if the action is executed. The single parameter is the name of the
8680 function to run. The prototype of the function is documented in the API
8681 documentation.
8682
Thierry FOURNIER4834bc72015-06-06 19:29:07 +02008683 The "set-var" is used to set the content of a variable. The variable is
8684 declared inline.
8685
8686 <var-name> The name of the variable starts by an indication about its scope.
8687 The allowed scopes are:
8688 "sess" : the variable is shared with all the session,
8689 "txn" : the variable is shared with all the transaction
8690 (request and response)
8691 "req" : the variable is shared only during the request
8692 processing
8693 "res" : the variable is shared only during the response
8694 processing.
8695 This prefix is followed by a name. The separator is a '.'.
8696 The name may only contain characters 'a-z', 'A-Z', '0-9' and '_'.
8697
8698 <expr> Is a standard HAProxy expression formed by a sample-fetch
8699 followed by some converters.
8700
8701 Example:
8702
8703 tcp-request content set-var(sess.my_var) src
8704
Willy Tarreau62644772008-07-16 18:36:06 +02008705 Example:
Willy Tarreaue9656522010-08-17 15:40:09 +02008706 # Accept HTTP requests containing a Host header saying "example.com"
8707 # and reject everything else.
8708 acl is_host_com hdr(Host) -i example.com
8709 tcp-request inspect-delay 30s
Willy Tarreauc0239e02012-04-16 14:42:55 +02008710 tcp-request content accept if is_host_com
Willy Tarreaue9656522010-08-17 15:40:09 +02008711 tcp-request content reject
8712
8713 Example:
Willy Tarreau62644772008-07-16 18:36:06 +02008714 # reject SMTP connection if client speaks first
8715 tcp-request inspect-delay 30s
8716 acl content_present req_len gt 0
Willy Tarreau68c03ab2010-08-06 15:08:45 +02008717 tcp-request content reject if content_present
Willy Tarreau62644772008-07-16 18:36:06 +02008718
8719 # Forward HTTPS connection only if client speaks
8720 tcp-request inspect-delay 30s
8721 acl content_present req_len gt 0
Willy Tarreau68c03ab2010-08-06 15:08:45 +02008722 tcp-request content accept if content_present
Willy Tarreaue9656522010-08-17 15:40:09 +02008723 tcp-request content reject
8724
Willy Tarreau5d5b5d82012-12-09 12:00:04 +01008725 Example:
8726 # Track the last IP from X-Forwarded-For
8727 tcp-request inspect-delay 10s
Willy Tarreau4d54c7c2014-09-16 15:48:15 +02008728 tcp-request content track-sc0 hdr(x-forwarded-for,-1)
Willy Tarreau5d5b5d82012-12-09 12:00:04 +01008729
8730 Example:
8731 # track request counts per "base" (concatenation of Host+URL)
8732 tcp-request inspect-delay 10s
Willy Tarreau4d54c7c2014-09-16 15:48:15 +02008733 tcp-request content track-sc0 base table req-rate
Willy Tarreau5d5b5d82012-12-09 12:00:04 +01008734
Willy Tarreaue9656522010-08-17 15:40:09 +02008735 Example: track per-frontend and per-backend counters, block abusers at the
8736 frontend when the backend detects abuse.
8737
8738 frontend http
Willy Tarreaube4a3ef2013-06-17 15:04:07 +02008739 # Use General Purpose Couter 0 in SC0 as a global abuse counter
Willy Tarreaue9656522010-08-17 15:40:09 +02008740 # protecting all our sites
8741 stick-table type ip size 1m expire 5m store gpc0
Willy Tarreaube4a3ef2013-06-17 15:04:07 +02008742 tcp-request connection track-sc0 src
8743 tcp-request connection reject if { sc0_get_gpc0 gt 0 }
Willy Tarreaue9656522010-08-17 15:40:09 +02008744 ...
8745 use_backend http_dynamic if { path_end .php }
8746
8747 backend http_dynamic
8748 # if a source makes too fast requests to this dynamic site (tracked
Willy Tarreaube4a3ef2013-06-17 15:04:07 +02008749 # by SC1), block it globally in the frontend.
Willy Tarreaue9656522010-08-17 15:40:09 +02008750 stick-table type ip size 1m expire 5m store http_req_rate(10s)
Willy Tarreaube4a3ef2013-06-17 15:04:07 +02008751 acl click_too_fast sc1_http_req_rate gt 10
8752 acl mark_as_abuser sc0_inc_gpc0 gt 0
8753 tcp-request content track-sc1 src
Willy Tarreaue9656522010-08-17 15:40:09 +02008754 tcp-request content reject if click_too_fast mark_as_abuser
Willy Tarreau62644772008-07-16 18:36:06 +02008755
Willy Tarreauc57f0e22009-05-10 13:12:33 +02008756 See section 7 about ACL usage.
Willy Tarreau62644772008-07-16 18:36:06 +02008757
Willy Tarreaue9656522010-08-17 15:40:09 +02008758 See also : "tcp-request connection", "tcp-request inspect-delay"
Willy Tarreau62644772008-07-16 18:36:06 +02008759
8760
8761tcp-request inspect-delay <timeout>
8762 Set the maximum allowed time to wait for data during content inspection
8763 May be used in sections : defaults | frontend | listen | backend
Willy Tarreaufb356202010-08-03 14:02:05 +02008764 no | yes | yes | yes
Willy Tarreau62644772008-07-16 18:36:06 +02008765 Arguments :
8766 <timeout> is the timeout value specified in milliseconds by default, but
8767 can be in any other unit if the number is suffixed by the unit,
8768 as explained at the top of this document.
8769
8770 People using haproxy primarily as a TCP relay are often worried about the
8771 risk of passing any type of protocol to a server without any analysis. In
8772 order to be able to analyze the request contents, we must first withhold
8773 the data then analyze them. This statement simply enables withholding of
8774 data for at most the specified amount of time.
8775
Willy Tarreaufb356202010-08-03 14:02:05 +02008776 TCP content inspection applies very early when a connection reaches a
8777 frontend, then very early when the connection is forwarded to a backend. This
8778 means that a connection may experience a first delay in the frontend and a
8779 second delay in the backend if both have tcp-request rules.
8780
Willy Tarreau62644772008-07-16 18:36:06 +02008781 Note that when performing content inspection, haproxy will evaluate the whole
8782 rules for every new chunk which gets in, taking into account the fact that
Krzysztof Piotr Oledzkif8645332009-12-13 21:55:50 +01008783 those data are partial. If no rule matches before the aforementioned delay,
Willy Tarreau62644772008-07-16 18:36:06 +02008784 a last check is performed upon expiration, this time considering that the
Willy Tarreaud869b242009-03-15 14:43:58 +01008785 contents are definitive. If no delay is set, haproxy will not wait at all
8786 and will immediately apply a verdict based on the available information.
8787 Obviously this is unlikely to be very useful and might even be racy, so such
8788 setups are not recommended.
Willy Tarreau62644772008-07-16 18:36:06 +02008789
8790 As soon as a rule matches, the request is released and continues as usual. If
8791 the timeout is reached and no rule matches, the default policy will be to let
8792 it pass through unaffected.
8793
8794 For most protocols, it is enough to set it to a few seconds, as most clients
8795 send the full request immediately upon connection. Add 3 or more seconds to
8796 cover TCP retransmits but that's all. For some protocols, it may make sense
Willy Tarreaud72758d2010-01-12 10:42:19 +01008797 to use large values, for instance to ensure that the client never talks
Willy Tarreau62644772008-07-16 18:36:06 +02008798 before the server (eg: SMTP), or to wait for a client to talk before passing
8799 data to the server (eg: SSL). Note that the client timeout must cover at
Willy Tarreaub824b002010-09-29 16:36:16 +02008800 least the inspection delay, otherwise it will expire first. If the client
8801 closes the connection or if the buffer is full, the delay immediately expires
8802 since the contents will not be able to change anymore.
Willy Tarreau62644772008-07-16 18:36:06 +02008803
Willy Tarreau55165fe2009-05-10 12:02:55 +02008804 See also : "tcp-request content accept", "tcp-request content reject",
Willy Tarreau62644772008-07-16 18:36:06 +02008805 "timeout client".
8806
8807
Emeric Brun0a3b67f2010-09-24 15:34:53 +02008808tcp-response content <action> [{if | unless} <condition>]
8809 Perform an action on a session response depending on a layer 4-7 condition
8810 May be used in sections : defaults | frontend | listen | backend
8811 no | no | yes | yes
8812 Arguments :
Willy Tarreauc870bfd2015-09-28 18:47:38 +02008813 <action> defines the action to perform if the condition applies. See
8814 below.
Emeric Brun0a3b67f2010-09-24 15:34:53 +02008815
8816 <condition> is a standard layer 4-7 ACL-based condition (see section 7).
8817
8818 Response contents can be analysed at an early stage of response processing
8819 called "TCP content inspection". During this stage, ACL-based rules are
8820 evaluated every time the response contents are updated, until either an
Willy Tarreaucc1e04b2013-09-11 23:20:29 +02008821 "accept", "close" or a "reject" rule matches, or a TCP response inspection
8822 delay is set and expires with no matching rule.
Emeric Brun0a3b67f2010-09-24 15:34:53 +02008823
8824 Most often, these decisions will consider a protocol recognition or validity.
8825
8826 Content-based rules are evaluated in their exact declaration order. If no
8827 rule matches or if there is no rule, the default action is to accept the
8828 contents. There is no specific limit to the number of rules which may be
8829 inserted.
8830
Thierry FOURNIER236657b2015-08-19 08:25:14 +02008831 Several types of actions are supported :
Emeric Brun0a3b67f2010-09-24 15:34:53 +02008832 - accept :
8833 accepts the response if the condition is true (when used with "if")
8834 or false (when used with "unless"). The first such rule executed ends
8835 the rules evaluation.
8836
Willy Tarreaucc1e04b2013-09-11 23:20:29 +02008837 - close :
8838 immediately closes the connection with the server if the condition is
8839 true (when used with "if"), or false (when used with "unless"). The
8840 first such rule executed ends the rules evaluation. The main purpose of
8841 this action is to force a connection to be finished between a client
8842 and a server after an exchange when the application protocol expects
8843 some long time outs to elapse first. The goal is to eliminate idle
Jarno Huuskonen0e82b922014-04-12 18:22:19 +03008844 connections which take significant resources on servers with certain
Willy Tarreaucc1e04b2013-09-11 23:20:29 +02008845 protocols.
8846
Emeric Brun0a3b67f2010-09-24 15:34:53 +02008847 - reject :
8848 rejects the response if the condition is true (when used with "if")
8849 or false (when used with "unless"). The first such rule executed ends
Jamie Gloudonaaa21002012-08-25 00:18:33 -04008850 the rules evaluation. Rejected session are immediately closed.
Emeric Brun0a3b67f2010-09-24 15:34:53 +02008851
Thierry FOURNIER69717b42015-06-04 12:23:41 +02008852 - lua <function>
8853 Executes Lua.
8854
Thierry FOURNIER4834bc72015-06-06 19:29:07 +02008855 - set-var(<var-name>) <expr>
8856 Sets a variable.
8857
Thierry FOURNIERe0627bd2015-08-04 08:20:33 +02008858 - sc-inc-gpc0(<sc-id>):
8859 This action increments the GPC0 counter according to the sticky
8860 counter designated by <sc-id>. If an error occurs, this action fails
8861 silently and the actions evaluation continues.
8862
Thierry FOURNIER236657b2015-08-19 08:25:14 +02008863 - sc-set-gpt0(<sc-id>) <int> :
8864 This action sets the GPT0 tag according to the sticky counter designated
8865 by <sc-id> and the value of <int>. The expected result is a boolean. If
8866 an error occurs, this action silently fails and the actions evaluation
8867 continues.
8868
Willy Tarreau2d392c22015-08-24 01:43:45 +02008869 - "silent-drop" :
8870 This stops the evaluation of the rules and makes the client-facing
8871 connection suddenly disappear using a system-dependant way that tries
8872 to prevent the client from being notified. The effect it then that the
8873 client still sees an established connection while there's none on
8874 HAProxy. The purpose is to achieve a comparable effect to "tarpit"
8875 except that it doesn't use any local resource at all on the machine
8876 running HAProxy. It can resist much higher loads than "tarpit", and
8877 slow down stronger attackers. It is important to undestand the impact
8878 of using this mechanism. All stateful equipments placed between the
8879 client and HAProxy (firewalls, proxies, load balancers) will also keep
8880 the established connection for a long time and may suffer from this
8881 action. On modern Linux systems running with enough privileges, the
8882 TCP_REPAIR socket option is used to block the emission of a TCP
8883 reset. On other systems, the socket's TTL is reduced to 1 so that the
8884 TCP reset doesn't pass the first router, though it's still delivered to
8885 local networks. Do not use it unless you fully understand how it works.
8886
Emeric Brun0a3b67f2010-09-24 15:34:53 +02008887 Note that the "if/unless" condition is optional. If no condition is set on
8888 the action, it is simply performed unconditionally. That can be useful for
8889 for changing the default action to a reject.
8890
Jamie Gloudonaaa21002012-08-25 00:18:33 -04008891 It is perfectly possible to match layer 7 contents with "tcp-response
8892 content" rules, but then it is important to ensure that a full response has
8893 been buffered, otherwise no contents will match. In order to achieve this,
8894 the best solution involves detecting the HTTP protocol during the inspection
Emeric Brun0a3b67f2010-09-24 15:34:53 +02008895 period.
8896
Thierry FOURNIER90da1912015-03-05 11:17:06 +01008897 The "lua" keyword is followed by a Lua function name. It is used to run a Lua
8898 function if the action is executed. The single parameter is the name of the
8899 function to run. The prototype of the function is documented in the API
8900 documentation.
8901
Thierry FOURNIER4834bc72015-06-06 19:29:07 +02008902 The "set-var" is used to set the content of a variable. The variable is
8903 declared inline.
8904
8905 <var-name> The name of the variable starts by an indication about its scope.
8906 The allowed scopes are:
8907 "sess" : the variable is shared with all the session,
8908 "txn" : the variable is shared with all the transaction
8909 (request and response)
8910 "req" : the variable is shared only during the request
8911 processing
8912 "res" : the variable is shared only during the response
8913 processing.
8914 This prefix is followed by a name. The separator is a '.'.
8915 The name may only contain characters 'a-z', 'A-Z', '0-9' and '_'.
8916
8917 <expr> Is a standard HAProxy expression formed by a sample-fetch
8918 followed by some converters.
8919
8920 Example:
8921
8922 tcp-request content set-var(sess.my_var) src
8923
Emeric Brun0a3b67f2010-09-24 15:34:53 +02008924 See section 7 about ACL usage.
8925
8926 See also : "tcp-request content", "tcp-response inspect-delay"
8927
8928
8929tcp-response inspect-delay <timeout>
8930 Set the maximum allowed time to wait for a response during content inspection
8931 May be used in sections : defaults | frontend | listen | backend
8932 no | no | yes | yes
8933 Arguments :
8934 <timeout> is the timeout value specified in milliseconds by default, but
8935 can be in any other unit if the number is suffixed by the unit,
8936 as explained at the top of this document.
8937
8938 See also : "tcp-response content", "tcp-request inspect-delay".
8939
8940
Krzysztof Piotr Oledzki5259dfe2008-01-21 01:54:06 +01008941timeout check <timeout>
8942 Set additional check timeout, but only after a connection has been already
8943 established.
8944
8945 May be used in sections: defaults | frontend | listen | backend
8946 yes | no | yes | yes
8947 Arguments:
8948 <timeout> is the timeout value specified in milliseconds by default, but
8949 can be in any other unit if the number is suffixed by the unit,
8950 as explained at the top of this document.
8951
8952 If set, haproxy uses min("timeout connect", "inter") as a connect timeout
8953 for check and "timeout check" as an additional read timeout. The "min" is
8954 used so that people running with *very* long "timeout connect" (eg. those
8955 who needed this due to the queue or tarpit) do not slow down their checks.
Willy Tarreaud7550a22010-02-10 05:10:19 +01008956 (Please also note that there is no valid reason to have such long connect
8957 timeouts, because "timeout queue" and "timeout tarpit" can always be used to
8958 avoid that).
Krzysztof Piotr Oledzki5259dfe2008-01-21 01:54:06 +01008959
8960 If "timeout check" is not set haproxy uses "inter" for complete check
8961 timeout (connect + read) exactly like all <1.3.15 version.
8962
8963 In most cases check request is much simpler and faster to handle than normal
8964 requests and people may want to kick out laggy servers so this timeout should
Willy Tarreau41a340d2008-01-22 12:25:31 +01008965 be smaller than "timeout server".
Krzysztof Piotr Oledzki5259dfe2008-01-21 01:54:06 +01008966
8967 This parameter is specific to backends, but can be specified once for all in
8968 "defaults" sections. This is in fact one of the easiest solutions not to
8969 forget about it.
8970
Willy Tarreau41a340d2008-01-22 12:25:31 +01008971 See also: "timeout connect", "timeout queue", "timeout server",
8972 "timeout tarpit".
Krzysztof Piotr Oledzki5259dfe2008-01-21 01:54:06 +01008973
8974
Willy Tarreau0ba27502007-12-24 16:55:16 +01008975timeout client <timeout>
8976timeout clitimeout <timeout> (deprecated)
8977 Set the maximum inactivity time on the client side.
8978 May be used in sections : defaults | frontend | listen | backend
8979 yes | yes | yes | no
8980 Arguments :
Willy Tarreau844e3c52008-01-11 16:28:18 +01008981 <timeout> is the timeout value specified in milliseconds by default, but
Willy Tarreau0ba27502007-12-24 16:55:16 +01008982 can be in any other unit if the number is suffixed by the unit,
8983 as explained at the top of this document.
8984
8985 The inactivity timeout applies when the client is expected to acknowledge or
8986 send data. In HTTP mode, this timeout is particularly important to consider
8987 during the first phase, when the client sends the request, and during the
8988 response while it is reading data sent by the server. The value is specified
8989 in milliseconds by default, but can be in any other unit if the number is
8990 suffixed by the unit, as specified at the top of this document. In TCP mode
8991 (and to a lesser extent, in HTTP mode), it is highly recommended that the
8992 client timeout remains equal to the server timeout in order to avoid complex
Willy Tarreaud2a4aa22008-01-31 15:28:22 +01008993 situations to debug. It is a good practice to cover one or several TCP packet
Willy Tarreau0ba27502007-12-24 16:55:16 +01008994 losses by specifying timeouts that are slightly above multiples of 3 seconds
Willy Tarreauce887fd2012-05-12 12:50:00 +02008995 (eg: 4 or 5 seconds). If some long-lived sessions are mixed with short-lived
8996 sessions (eg: WebSocket and HTTP), it's worth considering "timeout tunnel",
Willy Tarreau05cdd962014-05-10 14:30:07 +02008997 which overrides "timeout client" and "timeout server" for tunnels, as well as
8998 "timeout client-fin" for half-closed connections.
Willy Tarreau0ba27502007-12-24 16:55:16 +01008999
9000 This parameter is specific to frontends, but can be specified once for all in
9001 "defaults" sections. This is in fact one of the easiest solutions not to
9002 forget about it. An unspecified timeout results in an infinite timeout, which
9003 is not recommended. Such a usage is accepted and works but reports a warning
9004 during startup because it may results in accumulation of expired sessions in
9005 the system if the system's timeouts are not configured either.
9006
9007 This parameter replaces the old, deprecated "clitimeout". It is recommended
9008 to use it to write new configurations. The form "timeout clitimeout" is
9009 provided only by backwards compatibility but its use is strongly discouraged.
9010
Willy Tarreauce887fd2012-05-12 12:50:00 +02009011 See also : "clitimeout", "timeout server", "timeout tunnel".
Willy Tarreau0ba27502007-12-24 16:55:16 +01009012
9013
Willy Tarreau05cdd962014-05-10 14:30:07 +02009014timeout client-fin <timeout>
9015 Set the inactivity timeout on the client side for half-closed connections.
9016 May be used in sections : defaults | frontend | listen | backend
9017 yes | yes | yes | no
9018 Arguments :
9019 <timeout> is the timeout value specified in milliseconds by default, but
9020 can be in any other unit if the number is suffixed by the unit,
9021 as explained at the top of this document.
9022
9023 The inactivity timeout applies when the client is expected to acknowledge or
9024 send data while one direction is already shut down. This timeout is different
9025 from "timeout client" in that it only applies to connections which are closed
9026 in one direction. This is particularly useful to avoid keeping connections in
9027 FIN_WAIT state for too long when clients do not disconnect cleanly. This
9028 problem is particularly common long connections such as RDP or WebSocket.
9029 Note that this timeout can override "timeout tunnel" when a connection shuts
9030 down in one direction.
9031
9032 This parameter is specific to frontends, but can be specified once for all in
9033 "defaults" sections. By default it is not set, so half-closed connections
9034 will use the other timeouts (timeout.client or timeout.tunnel).
9035
9036 See also : "timeout client", "timeout server-fin", and "timeout tunnel".
9037
9038
Willy Tarreau0ba27502007-12-24 16:55:16 +01009039timeout connect <timeout>
9040timeout contimeout <timeout> (deprecated)
9041 Set the maximum time to wait for a connection attempt to a server to succeed.
9042 May be used in sections : defaults | frontend | listen | backend
9043 yes | no | yes | yes
9044 Arguments :
Willy Tarreau844e3c52008-01-11 16:28:18 +01009045 <timeout> is the timeout value specified in milliseconds by default, but
Willy Tarreau0ba27502007-12-24 16:55:16 +01009046 can be in any other unit if the number is suffixed by the unit,
9047 as explained at the top of this document.
9048
9049 If the server is located on the same LAN as haproxy, the connection should be
Willy Tarreaud2a4aa22008-01-31 15:28:22 +01009050 immediate (less than a few milliseconds). Anyway, it is a good practice to
Willy Tarreaud72758d2010-01-12 10:42:19 +01009051 cover one or several TCP packet losses by specifying timeouts that are
Willy Tarreau0ba27502007-12-24 16:55:16 +01009052 slightly above multiples of 3 seconds (eg: 4 or 5 seconds). By default, the
Krzysztof Piotr Oledzki5259dfe2008-01-21 01:54:06 +01009053 connect timeout also presets both queue and tarpit timeouts to the same value
9054 if these have not been specified.
Willy Tarreau0ba27502007-12-24 16:55:16 +01009055
9056 This parameter is specific to backends, but can be specified once for all in
9057 "defaults" sections. This is in fact one of the easiest solutions not to
9058 forget about it. An unspecified timeout results in an infinite timeout, which
9059 is not recommended. Such a usage is accepted and works but reports a warning
9060 during startup because it may results in accumulation of failed sessions in
9061 the system if the system's timeouts are not configured either.
9062
9063 This parameter replaces the old, deprecated "contimeout". It is recommended
9064 to use it to write new configurations. The form "timeout contimeout" is
9065 provided only by backwards compatibility but its use is strongly discouraged.
9066
Willy Tarreau41a340d2008-01-22 12:25:31 +01009067 See also: "timeout check", "timeout queue", "timeout server", "contimeout",
9068 "timeout tarpit".
Willy Tarreau0ba27502007-12-24 16:55:16 +01009069
9070
Willy Tarreaub16a5742010-01-10 14:46:16 +01009071timeout http-keep-alive <timeout>
9072 Set the maximum allowed time to wait for a new HTTP request to appear
9073 May be used in sections : defaults | frontend | listen | backend
9074 yes | yes | yes | yes
9075 Arguments :
9076 <timeout> is the timeout value specified in milliseconds by default, but
9077 can be in any other unit if the number is suffixed by the unit,
9078 as explained at the top of this document.
9079
9080 By default, the time to wait for a new request in case of keep-alive is set
9081 by "timeout http-request". However this is not always convenient because some
9082 people want very short keep-alive timeouts in order to release connections
9083 faster, and others prefer to have larger ones but still have short timeouts
9084 once the request has started to present itself.
9085
9086 The "http-keep-alive" timeout covers these needs. It will define how long to
9087 wait for a new HTTP request to start coming after a response was sent. Once
9088 the first byte of request has been seen, the "http-request" timeout is used
9089 to wait for the complete request to come. Note that empty lines prior to a
9090 new request do not refresh the timeout and are not counted as a new request.
9091
9092 There is also another difference between the two timeouts : when a connection
9093 expires during timeout http-keep-alive, no error is returned, the connection
9094 just closes. If the connection expires in "http-request" while waiting for a
9095 connection to complete, a HTTP 408 error is returned.
9096
9097 In general it is optimal to set this value to a few tens to hundreds of
9098 milliseconds, to allow users to fetch all objects of a page at once but
9099 without waiting for further clicks. Also, if set to a very small value (eg:
9100 1 millisecond) it will probably only accept pipelined requests but not the
9101 non-pipelined ones. It may be a nice trade-off for very large sites running
Patrick Mézard2382ad62010-05-09 10:43:32 +02009102 with tens to hundreds of thousands of clients.
Willy Tarreaub16a5742010-01-10 14:46:16 +01009103
9104 If this parameter is not set, the "http-request" timeout applies, and if both
9105 are not set, "timeout client" still applies at the lower level. It should be
9106 set in the frontend to take effect, unless the frontend is in TCP mode, in
9107 which case the HTTP backend's timeout will be used.
9108
9109 See also : "timeout http-request", "timeout client".
9110
9111
Willy Tarreau036fae02008-01-06 13:24:40 +01009112timeout http-request <timeout>
9113 Set the maximum allowed time to wait for a complete HTTP request
9114 May be used in sections : defaults | frontend | listen | backend
Willy Tarreaucd7afc02009-07-12 10:03:17 +02009115 yes | yes | yes | yes
Willy Tarreau036fae02008-01-06 13:24:40 +01009116 Arguments :
Willy Tarreau844e3c52008-01-11 16:28:18 +01009117 <timeout> is the timeout value specified in milliseconds by default, but
Willy Tarreau036fae02008-01-06 13:24:40 +01009118 can be in any other unit if the number is suffixed by the unit,
9119 as explained at the top of this document.
9120
9121 In order to offer DoS protection, it may be required to lower the maximum
9122 accepted time to receive a complete HTTP request without affecting the client
9123 timeout. This helps protecting against established connections on which
9124 nothing is sent. The client timeout cannot offer a good protection against
9125 this abuse because it is an inactivity timeout, which means that if the
9126 attacker sends one character every now and then, the timeout will not
9127 trigger. With the HTTP request timeout, no matter what speed the client
Willy Tarreau2705a612014-05-23 17:38:34 +02009128 types, the request will be aborted if it does not complete in time. When the
9129 timeout expires, an HTTP 408 response is sent to the client to inform it
9130 about the problem, and the connection is closed. The logs will report
9131 termination codes "cR". Some recent browsers are having problems with this
9132 standard, well-documented behaviour, so it might be needed to hide the 408
Willy Tarreau0f228a02015-05-01 15:37:53 +02009133 code using "option http-ignore-probes" or "errorfile 408 /dev/null". See
9134 more details in the explanations of the "cR" termination code in section 8.5.
Willy Tarreau036fae02008-01-06 13:24:40 +01009135
9136 Note that this timeout only applies to the header part of the request, and
9137 not to any data. As soon as the empty line is received, this timeout is not
Willy Tarreaub16a5742010-01-10 14:46:16 +01009138 used anymore. It is used again on keep-alive connections to wait for a second
9139 request if "timeout http-keep-alive" is not set.
Willy Tarreau036fae02008-01-06 13:24:40 +01009140
9141 Generally it is enough to set it to a few seconds, as most clients send the
9142 full request immediately upon connection. Add 3 or more seconds to cover TCP
9143 retransmits but that's all. Setting it to very low values (eg: 50 ms) will
9144 generally work on local networks as long as there are no packet losses. This
9145 will prevent people from sending bare HTTP requests using telnet.
9146
9147 If this parameter is not set, the client timeout still applies between each
Willy Tarreaucd7afc02009-07-12 10:03:17 +02009148 chunk of the incoming request. It should be set in the frontend to take
9149 effect, unless the frontend is in TCP mode, in which case the HTTP backend's
9150 timeout will be used.
Willy Tarreau036fae02008-01-06 13:24:40 +01009151
Willy Tarreau0f228a02015-05-01 15:37:53 +02009152 See also : "errorfile", "http-ignore-probes", "timeout http-keep-alive", and
9153 "timeout client".
Willy Tarreau036fae02008-01-06 13:24:40 +01009154
Willy Tarreau844e3c52008-01-11 16:28:18 +01009155
9156timeout queue <timeout>
9157 Set the maximum time to wait in the queue for a connection slot to be free
9158 May be used in sections : defaults | frontend | listen | backend
9159 yes | no | yes | yes
9160 Arguments :
9161 <timeout> is the timeout value specified in milliseconds by default, but
9162 can be in any other unit if the number is suffixed by the unit,
9163 as explained at the top of this document.
9164
9165 When a server's maxconn is reached, connections are left pending in a queue
9166 which may be server-specific or global to the backend. In order not to wait
9167 indefinitely, a timeout is applied to requests pending in the queue. If the
9168 timeout is reached, it is considered that the request will almost never be
9169 served, so it is dropped and a 503 error is returned to the client.
9170
9171 The "timeout queue" statement allows to fix the maximum time for a request to
9172 be left pending in a queue. If unspecified, the same value as the backend's
9173 connection timeout ("timeout connect") is used, for backwards compatibility
9174 with older versions with no "timeout queue" parameter.
9175
9176 See also : "timeout connect", "contimeout".
9177
9178
9179timeout server <timeout>
9180timeout srvtimeout <timeout> (deprecated)
9181 Set the maximum inactivity time on the server side.
9182 May be used in sections : defaults | frontend | listen | backend
9183 yes | no | yes | yes
9184 Arguments :
9185 <timeout> is the timeout value specified in milliseconds by default, but
9186 can be in any other unit if the number is suffixed by the unit,
9187 as explained at the top of this document.
9188
9189 The inactivity timeout applies when the server is expected to acknowledge or
9190 send data. In HTTP mode, this timeout is particularly important to consider
9191 during the first phase of the server's response, when it has to send the
9192 headers, as it directly represents the server's processing time for the
9193 request. To find out what value to put there, it's often good to start with
9194 what would be considered as unacceptable response times, then check the logs
9195 to observe the response time distribution, and adjust the value accordingly.
9196
9197 The value is specified in milliseconds by default, but can be in any other
9198 unit if the number is suffixed by the unit, as specified at the top of this
9199 document. In TCP mode (and to a lesser extent, in HTTP mode), it is highly
9200 recommended that the client timeout remains equal to the server timeout in
9201 order to avoid complex situations to debug. Whatever the expected server
Willy Tarreaud2a4aa22008-01-31 15:28:22 +01009202 response times, it is a good practice to cover at least one or several TCP
Willy Tarreau844e3c52008-01-11 16:28:18 +01009203 packet losses by specifying timeouts that are slightly above multiples of 3
Willy Tarreauce887fd2012-05-12 12:50:00 +02009204 seconds (eg: 4 or 5 seconds minimum). If some long-lived sessions are mixed
9205 with short-lived sessions (eg: WebSocket and HTTP), it's worth considering
9206 "timeout tunnel", which overrides "timeout client" and "timeout server" for
9207 tunnels.
Willy Tarreau844e3c52008-01-11 16:28:18 +01009208
9209 This parameter is specific to backends, but can be specified once for all in
9210 "defaults" sections. This is in fact one of the easiest solutions not to
9211 forget about it. An unspecified timeout results in an infinite timeout, which
9212 is not recommended. Such a usage is accepted and works but reports a warning
9213 during startup because it may results in accumulation of expired sessions in
9214 the system if the system's timeouts are not configured either.
9215
9216 This parameter replaces the old, deprecated "srvtimeout". It is recommended
9217 to use it to write new configurations. The form "timeout srvtimeout" is
9218 provided only by backwards compatibility but its use is strongly discouraged.
9219
Willy Tarreauce887fd2012-05-12 12:50:00 +02009220 See also : "srvtimeout", "timeout client" and "timeout tunnel".
Willy Tarreau844e3c52008-01-11 16:28:18 +01009221
Willy Tarreau05cdd962014-05-10 14:30:07 +02009222
9223timeout server-fin <timeout>
9224 Set the inactivity timeout on the server side for half-closed connections.
9225 May be used in sections : defaults | frontend | listen | backend
9226 yes | no | yes | yes
9227 Arguments :
9228 <timeout> is the timeout value specified in milliseconds by default, but
9229 can be in any other unit if the number is suffixed by the unit,
9230 as explained at the top of this document.
9231
9232 The inactivity timeout applies when the server is expected to acknowledge or
9233 send data while one direction is already shut down. This timeout is different
9234 from "timeout server" in that it only applies to connections which are closed
9235 in one direction. This is particularly useful to avoid keeping connections in
9236 FIN_WAIT state for too long when a remote server does not disconnect cleanly.
9237 This problem is particularly common long connections such as RDP or WebSocket.
9238 Note that this timeout can override "timeout tunnel" when a connection shuts
9239 down in one direction. This setting was provided for completeness, but in most
9240 situations, it should not be needed.
9241
9242 This parameter is specific to backends, but can be specified once for all in
9243 "defaults" sections. By default it is not set, so half-closed connections
9244 will use the other timeouts (timeout.server or timeout.tunnel).
9245
9246 See also : "timeout client-fin", "timeout server", and "timeout tunnel".
9247
Willy Tarreau844e3c52008-01-11 16:28:18 +01009248
9249timeout tarpit <timeout>
Cyril Bonté78caf842010-03-10 22:41:43 +01009250 Set the duration for which tarpitted connections will be maintained
Willy Tarreau844e3c52008-01-11 16:28:18 +01009251 May be used in sections : defaults | frontend | listen | backend
9252 yes | yes | yes | yes
9253 Arguments :
9254 <timeout> is the tarpit duration specified in milliseconds by default, but
9255 can be in any other unit if the number is suffixed by the unit,
9256 as explained at the top of this document.
9257
9258 When a connection is tarpitted using "reqtarpit", it is maintained open with
9259 no activity for a certain amount of time, then closed. "timeout tarpit"
9260 defines how long it will be maintained open.
9261
9262 The value is specified in milliseconds by default, but can be in any other
9263 unit if the number is suffixed by the unit, as specified at the top of this
9264 document. If unspecified, the same value as the backend's connection timeout
9265 ("timeout connect") is used, for backwards compatibility with older versions
Cyril Bonté78caf842010-03-10 22:41:43 +01009266 with no "timeout tarpit" parameter.
Willy Tarreau844e3c52008-01-11 16:28:18 +01009267
9268 See also : "timeout connect", "contimeout".
9269
9270
Willy Tarreauce887fd2012-05-12 12:50:00 +02009271timeout tunnel <timeout>
9272 Set the maximum inactivity time on the client and server side for tunnels.
9273 May be used in sections : defaults | frontend | listen | backend
9274 yes | no | yes | yes
9275 Arguments :
9276 <timeout> is the timeout value specified in milliseconds by default, but
9277 can be in any other unit if the number is suffixed by the unit,
9278 as explained at the top of this document.
9279
Jamie Gloudonaaa21002012-08-25 00:18:33 -04009280 The tunnel timeout applies when a bidirectional connection is established
Willy Tarreauce887fd2012-05-12 12:50:00 +02009281 between a client and a server, and the connection remains inactive in both
9282 directions. This timeout supersedes both the client and server timeouts once
9283 the connection becomes a tunnel. In TCP, this timeout is used as soon as no
9284 analyser remains attached to either connection (eg: tcp content rules are
9285 accepted). In HTTP, this timeout is used when a connection is upgraded (eg:
9286 when switching to the WebSocket protocol, or forwarding a CONNECT request
9287 to a proxy), or after the first response when no keepalive/close option is
9288 specified.
9289
Willy Tarreau05cdd962014-05-10 14:30:07 +02009290 Since this timeout is usually used in conjunction with long-lived connections,
9291 it usually is a good idea to also set "timeout client-fin" to handle the
9292 situation where a client suddenly disappears from the net and does not
9293 acknowledge a close, or sends a shutdown and does not acknowledge pending
9294 data anymore. This can happen in lossy networks where firewalls are present,
9295 and is detected by the presence of large amounts of sessions in a FIN_WAIT
9296 state.
9297
Willy Tarreauce887fd2012-05-12 12:50:00 +02009298 The value is specified in milliseconds by default, but can be in any other
9299 unit if the number is suffixed by the unit, as specified at the top of this
9300 document. Whatever the expected normal idle time, it is a good practice to
9301 cover at least one or several TCP packet losses by specifying timeouts that
9302 are slightly above multiples of 3 seconds (eg: 4 or 5 seconds minimum).
9303
9304 This parameter is specific to backends, but can be specified once for all in
9305 "defaults" sections. This is in fact one of the easiest solutions not to
9306 forget about it.
9307
9308 Example :
9309 defaults http
9310 option http-server-close
9311 timeout connect 5s
9312 timeout client 30s
Willy Tarreau05cdd962014-05-10 14:30:07 +02009313 timeout client-fin 30s
Willy Tarreauce887fd2012-05-12 12:50:00 +02009314 timeout server 30s
9315 timeout tunnel 1h # timeout to use with WebSocket and CONNECT
9316
Willy Tarreau05cdd962014-05-10 14:30:07 +02009317 See also : "timeout client", "timeout client-fin", "timeout server".
Willy Tarreauce887fd2012-05-12 12:50:00 +02009318
9319
Willy Tarreau844e3c52008-01-11 16:28:18 +01009320transparent (deprecated)
9321 Enable client-side transparent proxying
9322 May be used in sections : defaults | frontend | listen | backend
Willy Tarreau4b1f8592008-12-23 23:13:55 +01009323 yes | no | yes | yes
Willy Tarreau844e3c52008-01-11 16:28:18 +01009324 Arguments : none
9325
9326 This keyword was introduced in order to provide layer 7 persistence to layer
9327 3 load balancers. The idea is to use the OS's ability to redirect an incoming
9328 connection for a remote address to a local process (here HAProxy), and let
9329 this process know what address was initially requested. When this option is
9330 used, sessions without cookies will be forwarded to the original destination
9331 IP address of the incoming request (which should match that of another
9332 equipment), while requests with cookies will still be forwarded to the
9333 appropriate server.
9334
9335 The "transparent" keyword is deprecated, use "option transparent" instead.
9336
9337 Note that contrary to a common belief, this option does NOT make HAProxy
9338 present the client's IP to the server when establishing the connection.
9339
Willy Tarreau844e3c52008-01-11 16:28:18 +01009340 See also: "option transparent"
9341
William Lallemanda73203e2012-03-12 12:48:57 +01009342unique-id-format <string>
9343 Generate a unique ID for each request.
9344 May be used in sections : defaults | frontend | listen | backend
9345 yes | yes | yes | no
9346 Arguments :
9347 <string> is a log-format string.
9348
Cyril Bonté108cf6e2012-04-21 23:30:29 +02009349 This keyword creates a ID for each request using the custom log format. A
9350 unique ID is useful to trace a request passing through many components of
9351 a complex infrastructure. The newly created ID may also be logged using the
9352 %ID tag the log-format string.
William Lallemanda73203e2012-03-12 12:48:57 +01009353
Cyril Bonté108cf6e2012-04-21 23:30:29 +02009354 The format should be composed from elements that are guaranteed to be
9355 unique when combined together. For instance, if multiple haproxy instances
9356 are involved, it might be important to include the node name. It is often
9357 needed to log the incoming connection's source and destination addresses
9358 and ports. Note that since multiple requests may be performed over the same
9359 connection, including a request counter may help differentiate them.
9360 Similarly, a timestamp may protect against a rollover of the counter.
9361 Logging the process ID will avoid collisions after a service restart.
William Lallemanda73203e2012-03-12 12:48:57 +01009362
Cyril Bonté108cf6e2012-04-21 23:30:29 +02009363 It is recommended to use hexadecimal notation for many fields since it
9364 makes them more compact and saves space in logs.
William Lallemanda73203e2012-03-12 12:48:57 +01009365
Cyril Bonté108cf6e2012-04-21 23:30:29 +02009366 Example:
William Lallemanda73203e2012-03-12 12:48:57 +01009367
Julien Vehentf21be322014-03-07 08:27:34 -05009368 unique-id-format %{+X}o\ %ci:%cp_%fi:%fp_%Ts_%rt:%pid
William Lallemanda73203e2012-03-12 12:48:57 +01009369
9370 will generate:
9371
9372 7F000001:8296_7F00001E:1F90_4F7B0A69_0003:790A
9373
9374 See also: "unique-id-header"
9375
9376unique-id-header <name>
9377 Add a unique ID header in the HTTP request.
9378 May be used in sections : defaults | frontend | listen | backend
9379 yes | yes | yes | no
9380 Arguments :
9381 <name> is the name of the header.
9382
Cyril Bonté108cf6e2012-04-21 23:30:29 +02009383 Add a unique-id header in the HTTP request sent to the server, using the
9384 unique-id-format. It can't work if the unique-id-format doesn't exist.
William Lallemanda73203e2012-03-12 12:48:57 +01009385
Cyril Bonté108cf6e2012-04-21 23:30:29 +02009386 Example:
William Lallemanda73203e2012-03-12 12:48:57 +01009387
Julien Vehentf21be322014-03-07 08:27:34 -05009388 unique-id-format %{+X}o\ %ci:%cp_%fi:%fp_%Ts_%rt:%pid
William Lallemanda73203e2012-03-12 12:48:57 +01009389 unique-id-header X-Unique-ID
9390
9391 will generate:
9392
9393 X-Unique-ID: 7F000001:8296_7F00001E:1F90_4F7B0A69_0003:790A
9394
9395 See also: "unique-id-format"
Willy Tarreau844e3c52008-01-11 16:28:18 +01009396
Willy Tarreauf51658d2014-04-23 01:21:56 +02009397use_backend <backend> [{if | unless} <condition>]
Willy Tarreau1d0dfb12009-07-07 15:10:31 +02009398 Switch to a specific backend if/unless an ACL-based condition is matched.
Willy Tarreau844e3c52008-01-11 16:28:18 +01009399 May be used in sections : defaults | frontend | listen | backend
9400 no | yes | yes | no
9401 Arguments :
Bertrand Jacquin702d44f2013-11-19 11:43:06 +01009402 <backend> is the name of a valid backend or "listen" section, or a
9403 "log-format" string resolving to a backend name.
Willy Tarreau844e3c52008-01-11 16:28:18 +01009404
Willy Tarreauf51658d2014-04-23 01:21:56 +02009405 <condition> is a condition composed of ACLs, as described in section 7. If
9406 it is omitted, the rule is unconditionally applied.
Willy Tarreau844e3c52008-01-11 16:28:18 +01009407
9408 When doing content-switching, connections arrive on a frontend and are then
9409 dispatched to various backends depending on a number of conditions. The
9410 relation between the conditions and the backends is described with the
Willy Tarreau1d0dfb12009-07-07 15:10:31 +02009411 "use_backend" keyword. While it is normally used with HTTP processing, it can
9412 also be used in pure TCP, either without content using stateless ACLs (eg:
9413 source address validation) or combined with a "tcp-request" rule to wait for
9414 some payload.
Willy Tarreau844e3c52008-01-11 16:28:18 +01009415
9416 There may be as many "use_backend" rules as desired. All of these rules are
9417 evaluated in their declaration order, and the first one which matches will
9418 assign the backend.
9419
9420 In the first form, the backend will be used if the condition is met. In the
9421 second form, the backend will be used if the condition is not met. If no
9422 condition is valid, the backend defined with "default_backend" will be used.
9423 If no default backend is defined, either the servers in the same section are
9424 used (in case of a "listen" section) or, in case of a frontend, no server is
9425 used and a 503 service unavailable response is returned.
9426
Willy Tarreau51aecc72009-07-12 09:47:04 +02009427 Note that it is possible to switch from a TCP frontend to an HTTP backend. In
Krzysztof Piotr Oledzkif8645332009-12-13 21:55:50 +01009428 this case, either the frontend has already checked that the protocol is HTTP,
Willy Tarreau51aecc72009-07-12 09:47:04 +02009429 and backend processing will immediately follow, or the backend will wait for
9430 a complete HTTP request to get in. This feature is useful when a frontend
9431 must decode several protocols on a unique port, one of them being HTTP.
9432
Bertrand Jacquin702d44f2013-11-19 11:43:06 +01009433 When <backend> is a simple name, it is resolved at configuration time, and an
9434 error is reported if the specified backend does not exist. If <backend> is
9435 a log-format string instead, no check may be done at configuration time, so
9436 the backend name is resolved dynamically at run time. If the resulting
9437 backend name does not correspond to any valid backend, no other rule is
9438 evaluated, and the default_backend directive is applied instead. Note that
9439 when using dynamic backend names, it is highly recommended to use a prefix
9440 that no other backend uses in order to ensure that an unauthorized backend
9441 cannot be forced from the request.
9442
Jarno Huuskonen0e82b922014-04-12 18:22:19 +03009443 It is worth mentioning that "use_backend" rules with an explicit name are
Bertrand Jacquin702d44f2013-11-19 11:43:06 +01009444 used to detect the association between frontends and backends to compute the
9445 backend's "fullconn" setting. This cannot be done for dynamic names.
9446
9447 See also: "default_backend", "tcp-request", "fullconn", "log-format", and
9448 section 7 about ACLs.
Willy Tarreaud72758d2010-01-12 10:42:19 +01009449
Willy Tarreau036fae02008-01-06 13:24:40 +01009450
Willy Tarreau4a5cade2012-04-05 21:09:48 +02009451use-server <server> if <condition>
9452use-server <server> unless <condition>
9453 Only use a specific server if/unless an ACL-based condition is matched.
9454 May be used in sections : defaults | frontend | listen | backend
9455 no | no | yes | yes
9456 Arguments :
Cyril Bonté108cf6e2012-04-21 23:30:29 +02009457 <server> is the name of a valid server in the same backend section.
Willy Tarreau4a5cade2012-04-05 21:09:48 +02009458
9459 <condition> is a condition composed of ACLs, as described in section 7.
9460
9461 By default, connections which arrive to a backend are load-balanced across
9462 the available servers according to the configured algorithm, unless a
9463 persistence mechanism such as a cookie is used and found in the request.
9464
9465 Sometimes it is desirable to forward a particular request to a specific
9466 server without having to declare a dedicated backend for this server. This
9467 can be achieved using the "use-server" rules. These rules are evaluated after
9468 the "redirect" rules and before evaluating cookies, and they have precedence
9469 on them. There may be as many "use-server" rules as desired. All of these
9470 rules are evaluated in their declaration order, and the first one which
9471 matches will assign the server.
9472
9473 If a rule designates a server which is down, and "option persist" is not used
9474 and no force-persist rule was validated, it is ignored and evaluation goes on
9475 with the next rules until one matches.
9476
9477 In the first form, the server will be used if the condition is met. In the
9478 second form, the server will be used if the condition is not met. If no
9479 condition is valid, the processing continues and the server will be assigned
9480 according to other persistence mechanisms.
9481
9482 Note that even if a rule is matched, cookie processing is still performed but
9483 does not assign the server. This allows prefixed cookies to have their prefix
9484 stripped.
9485
9486 The "use-server" statement works both in HTTP and TCP mode. This makes it
9487 suitable for use with content-based inspection. For instance, a server could
9488 be selected in a farm according to the TLS SNI field. And if these servers
9489 have their weight set to zero, they will not be used for other traffic.
9490
9491 Example :
9492 # intercept incoming TLS requests based on the SNI field
9493 use-server www if { req_ssl_sni -i www.example.com }
9494 server www 192.168.0.1:443 weight 0
9495 use-server mail if { req_ssl_sni -i mail.example.com }
9496 server mail 192.168.0.1:587 weight 0
9497 use-server imap if { req_ssl_sni -i imap.example.com }
9498 server mail 192.168.0.1:993 weight 0
9499 # all the rest is forwarded to this server
9500 server default 192.168.0.2:443 check
9501
Jarno Huuskonen0e82b922014-04-12 18:22:19 +03009502 See also: "use_backend", section 5 about server and section 7 about ACLs.
Willy Tarreau4a5cade2012-04-05 21:09:48 +02009503
Willy Tarreaub6205fd2012-09-24 12:27:33 +02009504
95055. Bind and Server options
9506--------------------------
9507
9508The "bind", "server" and "default-server" keywords support a number of settings
9509depending on some build options and on the system HAProxy was built on. These
9510settings generally each consist in one word sometimes followed by a value,
9511written on the same line as the "bind" or "server" line. All these options are
9512described in this section.
9513
9514
95155.1. Bind options
9516-----------------
9517
9518The "bind" keyword supports a certain number of settings which are all passed
9519as arguments on the same line. The order in which those arguments appear makes
9520no importance, provided that they appear after the bind address. All of these
9521parameters are optional. Some of them consist in a single words (booleans),
9522while other ones expect a value after them. In this case, the value must be
9523provided immediately after the setting name.
9524
9525The currently supported settings are the following ones.
9526
9527accept-proxy
9528 Enforces the use of the PROXY protocol over any connection accepted by any of
Willy Tarreau77992672014-06-14 11:06:17 +02009529 the sockets declared on the same line. Versions 1 and 2 of the PROXY protocol
9530 are supported and correctly detected. The PROXY protocol dictates the layer
Willy Tarreaub6205fd2012-09-24 12:27:33 +02009531 3/4 addresses of the incoming connection to be used everywhere an address is
9532 used, with the only exception of "tcp-request connection" rules which will
9533 only see the real connection address. Logs will reflect the addresses
9534 indicated in the protocol, unless it is violated, in which case the real
9535 address will still be used. This keyword combined with support from external
9536 components can be used as an efficient and reliable alternative to the
9537 X-Forwarded-For mechanism which is not always reliable and not even always
Willy Tarreau4f0d9192013-06-11 20:40:55 +02009538 usable. See also "tcp-request connection expect-proxy" for a finer-grained
9539 setting of which client is allowed to use the protocol.
Willy Tarreaub6205fd2012-09-24 12:27:33 +02009540
Willy Tarreauab861d32013-04-02 02:30:41 +02009541alpn <protocols>
9542 This enables the TLS ALPN extension and advertises the specified protocol
9543 list as supported on top of ALPN. The protocol list consists in a comma-
9544 delimited list of protocol names, for instance: "http/1.1,http/1.0" (without
9545 quotes). This requires that the SSL library is build with support for TLS
9546 extensions enabled (check with haproxy -vv). The ALPN extension replaces the
9547 initial NPN extension.
9548
Willy Tarreaub6205fd2012-09-24 12:27:33 +02009549backlog <backlog>
9550 Sets the socket's backlog to this value. If unspecified, the frontend's
9551 backlog is used instead, which generally defaults to the maxconn value.
9552
Emeric Brun7fb34422012-09-28 15:26:15 +02009553ecdhe <named curve>
9554 This setting is only available when support for OpenSSL was built in. It sets
Emeric Brun6924ef82013-03-06 14:08:53 +01009555 the named curve (RFC 4492) used to generate ECDH ephemeral keys. By default,
9556 used named curve is prime256v1.
Emeric Brun7fb34422012-09-28 15:26:15 +02009557
Emeric Brunfd33a262012-10-11 16:28:27 +02009558ca-file <cafile>
Emeric Brun1a073b42012-09-28 17:07:34 +02009559 This setting is only available when support for OpenSSL was built in. It
9560 designates a PEM file from which to load CA certificates used to verify
9561 client's certificate.
9562
Emeric Brunb6dc9342012-09-28 17:55:37 +02009563ca-ignore-err [all|<errorID>,...]
9564 This setting is only available when support for OpenSSL was built in.
9565 Sets a comma separated list of errorIDs to ignore during verify at depth > 0.
9566 If set to 'all', all errors are ignored. SSL handshake is not aborted if an
9567 error is ignored.
9568
Christopher Faulet31af49d2015-06-09 17:29:50 +02009569ca-sign-file <cafile>
9570 This setting is only available when support for OpenSSL was built in. It
9571 designates a PEM file containing both the CA certificate and the CA private
9572 key used to create and sign server's certificates. This is a mandatory
9573 setting when the dynamic generation of certificates is enabled. See
9574 'generate-certificates' for details.
9575
9576ca-sign-passphrase <passphrase>
9577 This setting is only available when support for OpenSSL was built in. It is
9578 the CA private key passphrase. This setting is optional and used only when
9579 the dynamic generation of certificates is enabled. See
9580 'generate-certificates' for details.
9581
Willy Tarreaub6205fd2012-09-24 12:27:33 +02009582ciphers <ciphers>
9583 This setting is only available when support for OpenSSL was built in. It sets
9584 the string describing the list of cipher algorithms ("cipher suite") that are
Jarno Huuskonen0e82b922014-04-12 18:22:19 +03009585 negotiated during the SSL/TLS handshake. The format of the string is defined
Willy Tarreaub6205fd2012-09-24 12:27:33 +02009586 in "man 1 ciphers" from OpenSSL man pages, and can be for instance a string
9587 such as "AES:ALL:!aNULL:!eNULL:+RC4:@STRENGTH" (without quotes).
9588
Emeric Brunfd33a262012-10-11 16:28:27 +02009589crl-file <crlfile>
Emeric Brun1a073b42012-09-28 17:07:34 +02009590 This setting is only available when support for OpenSSL was built in. It
9591 designates a PEM file from which to load certificate revocation list used
9592 to verify client's certificate.
9593
Willy Tarreaub6205fd2012-09-24 12:27:33 +02009594crt <cert>
Alex Davies0fbf0162013-03-02 16:04:50 +00009595 This setting is only available when support for OpenSSL was built in. It
9596 designates a PEM file containing both the required certificates and any
9597 associated private keys. This file can be built by concatenating multiple
9598 PEM files into one (e.g. cat cert.pem key.pem > combined.pem). If your CA
9599 requires an intermediate certificate, this can also be concatenated into this
9600 file.
9601
9602 If the OpenSSL used supports Diffie-Hellman, parameters present in this file
9603 are loaded.
9604
9605 If a directory name is used instead of a PEM file, then all files found in
Cyril Bonté3180f7b2015-01-25 00:16:08 +01009606 that directory will be loaded in alphabetic order unless their name ends with
Janusz Dziemidowicz2c701b52015-03-07 23:03:59 +01009607 '.issuer', '.ocsp' or '.sctl' (reserved extensions). This directive may be
9608 specified multiple times in order to load certificates from multiple files or
9609 directories. The certificates will be presented to clients who provide a
9610 valid TLS Server Name Indication field matching one of their CN or alt
9611 subjects. Wildcards are supported, where a wildcard character '*' is used
9612 instead of the first hostname component (eg: *.example.org matches
9613 www.example.org but not www.sub.example.org).
Alex Davies0fbf0162013-03-02 16:04:50 +00009614
9615 If no SNI is provided by the client or if the SSL library does not support
9616 TLS extensions, or if the client provides an SNI hostname which does not
9617 match any certificate, then the first loaded certificate will be presented.
9618 This means that when loading certificates from a directory, it is highly
Cyril Bonté3180f7b2015-01-25 00:16:08 +01009619 recommended to load the default one first as a file or to ensure that it will
9620 always be the first one in the directory.
Alex Davies0fbf0162013-03-02 16:04:50 +00009621
Emeric Brune032bfa2012-09-28 13:01:45 +02009622 Note that the same cert may be loaded multiple times without side effects.
Willy Tarreaub6205fd2012-09-24 12:27:33 +02009623
Alex Davies0fbf0162013-03-02 16:04:50 +00009624 Some CAs (such as Godaddy) offer a drop down list of server types that do not
9625 include HAProxy when obtaining a certificate. If this happens be sure to
Godbach8bf60a12014-04-21 21:42:41 +08009626 choose a webserver that the CA believes requires an intermediate CA (for
Alex Davies0fbf0162013-03-02 16:04:50 +00009627 Godaddy, selection Apache Tomcat will get the correct bundle, but many
9628 others, e.g. nginx, result in a wrong bundle that will not work for some
9629 clients).
9630
Emeric Brun4147b2e2014-06-16 18:36:30 +02009631 For each PEM file, haproxy checks for the presence of file at the same path
9632 suffixed by ".ocsp". If such file is found, support for the TLS Certificate
9633 Status Request extension (also known as "OCSP stapling") is automatically
9634 enabled. The content of this file is optional. If not empty, it must contain
9635 a valid OCSP Response in DER format. In order to be valid an OCSP Response
9636 must comply with the following rules: it has to indicate a good status,
9637 it has to be a single response for the certificate of the PEM file, and it
9638 has to be valid at the moment of addition. If these rules are not respected
9639 the OCSP Response is ignored and a warning is emitted. In order to identify
9640 which certificate an OCSP Response applies to, the issuer's certificate is
9641 necessary. If the issuer's certificate is not found in the PEM file, it will
9642 be loaded from a file at the same path as the PEM file suffixed by ".issuer"
9643 if it exists otherwise it will fail with an error.
9644
Janusz Dziemidowicz2c701b52015-03-07 23:03:59 +01009645 For each PEM file, haproxy also checks for the presence of file at the same
9646 path suffixed by ".sctl". If such file is found, support for Certificate
9647 Transparency (RFC6962) TLS extension is enabled. The file must contain a
9648 valid Signed Certificate Timestamp List, as described in RFC. File is parsed
9649 to check basic syntax, but no signatures are verified.
9650
Emeric Brunb6dc9342012-09-28 17:55:37 +02009651crt-ignore-err <errors>
Alex Davies0fbf0162013-03-02 16:04:50 +00009652 This setting is only available when support for OpenSSL was built in. Sets a
9653 comma separated list of errorIDs to ignore during verify at depth == 0. If
Jarno Huuskonen0e82b922014-04-12 18:22:19 +03009654 set to 'all', all errors are ignored. SSL handshake is not aborted if an error
Alex Davies0fbf0162013-03-02 16:04:50 +00009655 is ignored.
Emeric Brunb6dc9342012-09-28 17:55:37 +02009656
Emmanuel Hocdetfe616562013-01-22 15:31:15 +01009657crt-list <file>
9658 This setting is only available when support for OpenSSL was built in. It
Emmanuel Hocdet7c41a1b2013-05-07 20:20:06 +02009659 designates a list of PEM file with an optional list of SNI filter per
9660 certificate, with the following format for each line :
Emmanuel Hocdetfe616562013-01-22 15:31:15 +01009661
Emmanuel Hocdet7c41a1b2013-05-07 20:20:06 +02009662 <crtfile> [[!]<snifilter> ...]
Emmanuel Hocdetfe616562013-01-22 15:31:15 +01009663
Emmanuel Hocdet7c41a1b2013-05-07 20:20:06 +02009664 Wildcards are supported in the SNI filter. Negative filter are also supported,
9665 only useful in combination with a wildcard filter to exclude a particular SNI.
9666 The certificates will be presented to clients who provide a valid TLS Server
9667 Name Indication field matching one of the SNI filters. If no SNI filter is
9668 specified, the CN and alt subjects are used. This directive may be specified
9669 multiple times. See the "crt" option for more information. The default
9670 certificate is still needed to meet OpenSSL expectations. If it is not used,
9671 the 'strict-sni' option may be used.
Emmanuel Hocdetfe616562013-01-22 15:31:15 +01009672
Willy Tarreaub6205fd2012-09-24 12:27:33 +02009673defer-accept
9674 Is an optional keyword which is supported only on certain Linux kernels. It
9675 states that a connection will only be accepted once some data arrive on it,
9676 or at worst after the first retransmit. This should be used only on protocols
9677 for which the client talks first (eg: HTTP). It can slightly improve
9678 performance by ensuring that most of the request is already available when
9679 the connection is accepted. On the other hand, it will not be able to detect
9680 connections which don't talk. It is important to note that this option is
9681 broken in all kernels up to 2.6.31, as the connection is never accepted until
9682 the client talks. This can cause issues with front firewalls which would see
9683 an established connection while the proxy will only see it in SYN_RECV. This
9684 option is only supported on TCPv4/TCPv6 sockets and ignored by other ones.
9685
Emeric Brun2cb7ae52012-10-05 14:14:21 +02009686force-sslv3
Jarno Huuskonen0e82b922014-04-12 18:22:19 +03009687 This option enforces use of SSLv3 only on SSL connections instantiated from
Emeric Brun2cb7ae52012-10-05 14:14:21 +02009688 this listener. SSLv3 is generally less expensive than the TLS counterparts
Emeric Brun2c86cbf2014-10-30 15:56:50 +01009689 for high connection rates. This option is also available on global statement
9690 "ssl-default-bind-options". See also "no-tlsv*" and "no-sslv3".
Emeric Brun2cb7ae52012-10-05 14:14:21 +02009691
9692force-tlsv10
Jarno Huuskonen0e82b922014-04-12 18:22:19 +03009693 This option enforces use of TLSv1.0 only on SSL connections instantiated from
Emeric Brun2c86cbf2014-10-30 15:56:50 +01009694 this listener. This option is also available on global statement
9695 "ssl-default-bind-options". See also "no-tlsv*" and "no-sslv3".
Emeric Brun2cb7ae52012-10-05 14:14:21 +02009696
9697force-tlsv11
Jarno Huuskonen0e82b922014-04-12 18:22:19 +03009698 This option enforces use of TLSv1.1 only on SSL connections instantiated from
Emeric Brun2c86cbf2014-10-30 15:56:50 +01009699 this listener. This option is also available on global statement
9700 "ssl-default-bind-options". See also "no-tlsv*", and "no-sslv3".
Emeric Brun2cb7ae52012-10-05 14:14:21 +02009701
9702force-tlsv12
Jarno Huuskonen0e82b922014-04-12 18:22:19 +03009703 This option enforces use of TLSv1.2 only on SSL connections instantiated from
Emeric Brun2c86cbf2014-10-30 15:56:50 +01009704 this listener. This option is also available on global statement
9705 "ssl-default-bind-options". See also "no-tlsv*", and "no-sslv3".
Emeric Brun2cb7ae52012-10-05 14:14:21 +02009706
Christopher Faulet31af49d2015-06-09 17:29:50 +02009707generate-certificates
9708 This setting is only available when support for OpenSSL was built in. It
9709 enables the dynamic SSL certificates generation. A CA certificate and its
9710 private key are necessary (see 'ca-sign-file'). When HAProxy is configured as
9711 a transparent forward proxy, SSL requests generate errors because of a common
9712 name mismatch on the certificate presented to the client. With this option
9713 enabled, HAProxy will try to forge a certificate using the SNI hostname
9714 indicated by the client. This is done only if no certificate matches the SNI
9715 hostname (see 'crt-list'). If an error occurs, the default certificate is
9716 used, else the 'strict-sni' option is set.
9717 It can also be used when HAProxy is configured as a reverse proxy to ease the
9718 deployment of an architecture with many backends.
9719
9720 Creating a SSL certificate is an expensive operation, so a LRU cache is used
9721 to store forged certificates (see 'tune.ssl.ssl-ctx-cache-size'). It
9722 increases the HAProxy's memroy footprint to reduce latency when the same
9723 certificate is used many times.
9724
Willy Tarreaub6205fd2012-09-24 12:27:33 +02009725gid <gid>
9726 Sets the group of the UNIX sockets to the designated system gid. It can also
9727 be set by default in the global section's "unix-bind" statement. Note that
9728 some platforms simply ignore this. This setting is equivalent to the "group"
9729 setting except that the group ID is used instead of its name. This setting is
9730 ignored by non UNIX sockets.
9731
9732group <group>
9733 Sets the group of the UNIX sockets to the designated system group. It can
9734 also be set by default in the global section's "unix-bind" statement. Note
9735 that some platforms simply ignore this. This setting is equivalent to the
9736 "gid" setting except that the group name is used instead of its gid. This
9737 setting is ignored by non UNIX sockets.
9738
9739id <id>
9740 Fixes the socket ID. By default, socket IDs are automatically assigned, but
9741 sometimes it is more convenient to fix them to ease monitoring. This value
9742 must be strictly positive and unique within the listener/frontend. This
9743 option can only be used when defining only a single socket.
9744
9745interface <interface>
Lukas Tribusfce2e962013-02-12 22:13:19 +01009746 Restricts the socket to a specific interface. When specified, only packets
9747 received from that particular interface are processed by the socket. This is
9748 currently only supported on Linux. The interface must be a primary system
9749 interface, not an aliased interface. It is also possible to bind multiple
9750 frontends to the same address if they are bound to different interfaces. Note
9751 that binding to a network interface requires root privileges. This parameter
9752 is only compatible with TCPv4/TCPv6 sockets.
Willy Tarreaub6205fd2012-09-24 12:27:33 +02009753
Willy Tarreauabb175f2012-09-24 12:43:26 +02009754level <level>
9755 This setting is used with the stats sockets only to restrict the nature of
9756 the commands that can be issued on the socket. It is ignored by other
9757 sockets. <level> can be one of :
9758 - "user" is the least privileged level ; only non-sensitive stats can be
9759 read, and no change is allowed. It would make sense on systems where it
9760 is not easy to restrict access to the socket.
9761 - "operator" is the default level and fits most common uses. All data can
9762 be read, and only non-sensitive changes are permitted (eg: clear max
9763 counters).
9764 - "admin" should be used with care, as everything is permitted (eg: clear
9765 all counters).
9766
Willy Tarreaub6205fd2012-09-24 12:27:33 +02009767maxconn <maxconn>
9768 Limits the sockets to this number of concurrent connections. Extraneous
9769 connections will remain in the system's backlog until a connection is
9770 released. If unspecified, the limit will be the same as the frontend's
9771 maxconn. Note that in case of port ranges or multiple addresses, the same
9772 value will be applied to each socket. This setting enables different
9773 limitations on expensive sockets, for instance SSL entries which may easily
9774 eat all memory.
9775
9776mode <mode>
9777 Sets the octal mode used to define access permissions on the UNIX socket. It
9778 can also be set by default in the global section's "unix-bind" statement.
9779 Note that some platforms simply ignore this. This setting is ignored by non
9780 UNIX sockets.
9781
9782mss <maxseg>
9783 Sets the TCP Maximum Segment Size (MSS) value to be advertised on incoming
9784 connections. This can be used to force a lower MSS for certain specific
9785 ports, for instance for connections passing through a VPN. Note that this
9786 relies on a kernel feature which is theoretically supported under Linux but
9787 was buggy in all versions prior to 2.6.28. It may or may not work on other
9788 operating systems. It may also not change the advertised value but change the
9789 effective size of outgoing segments. The commonly advertised value for TCPv4
9790 over Ethernet networks is 1460 = 1500(MTU) - 40(IP+TCP). If this value is
9791 positive, it will be used as the advertised MSS. If it is negative, it will
9792 indicate by how much to reduce the incoming connection's advertised MSS for
9793 outgoing segments. This parameter is only compatible with TCP v4/v6 sockets.
9794
9795name <name>
9796 Sets an optional name for these sockets, which will be reported on the stats
9797 page.
9798
9799nice <nice>
9800 Sets the 'niceness' of connections initiated from the socket. Value must be
9801 in the range -1024..1024 inclusive, and defaults to zero. Positive values
9802 means that such connections are more friendly to others and easily offer
9803 their place in the scheduler. On the opposite, negative values mean that
9804 connections want to run with a higher priority than others. The difference
9805 only happens under high loads when the system is close to saturation.
9806 Negative values are appropriate for low-latency or administration services,
9807 and high values are generally recommended for CPU intensive tasks such as SSL
9808 processing or bulk transfers which are less sensible to latency. For example,
9809 it may make sense to use a positive value for an SMTP socket and a negative
9810 one for an RDP socket.
9811
Emeric Brun9b3009b2012-10-05 11:55:06 +02009812no-sslv3
Willy Tarreaub6205fd2012-09-24 12:27:33 +02009813 This setting is only available when support for OpenSSL was built in. It
Jarno Huuskonen0e82b922014-04-12 18:22:19 +03009814 disables support for SSLv3 on any sockets instantiated from the listener when
Willy Tarreaub6205fd2012-09-24 12:27:33 +02009815 SSL is supported. Note that SSLv2 is forced disabled in the code and cannot
Emeric Brun2c86cbf2014-10-30 15:56:50 +01009816 be enabled using any configuration option. This option is also available on
9817 global statement "ssl-default-bind-options". See also "force-tls*",
Emeric Brun2cb7ae52012-10-05 14:14:21 +02009818 and "force-sslv3".
Willy Tarreaub6205fd2012-09-24 12:27:33 +02009819
Emeric Brun90ad8722012-10-02 14:00:59 +02009820no-tls-tickets
9821 This setting is only available when support for OpenSSL was built in. It
9822 disables the stateless session resumption (RFC 5077 TLS Ticket
9823 extension) and force to use stateful session resumption. Stateless
Emeric Brun2c86cbf2014-10-30 15:56:50 +01009824 session resumption is more expensive in CPU usage. This option is also
9825 available on global statement "ssl-default-bind-options".
Emeric Brun90ad8722012-10-02 14:00:59 +02009826
Emeric Brun9b3009b2012-10-05 11:55:06 +02009827no-tlsv10
Willy Tarreaub6205fd2012-09-24 12:27:33 +02009828 This setting is only available when support for OpenSSL was built in. It
Jarno Huuskonen0e82b922014-04-12 18:22:19 +03009829 disables support for TLSv1.0 on any sockets instantiated from the listener
Emeric Brun2cb7ae52012-10-05 14:14:21 +02009830 when SSL is supported. Note that SSLv2 is forced disabled in the code and
Emeric Brun2c86cbf2014-10-30 15:56:50 +01009831 cannot be enabled using any configuration option. This option is also
9832 available on global statement "ssl-default-bind-options". See also
9833 "force-tlsv*", and "force-sslv3".
Willy Tarreaub6205fd2012-09-24 12:27:33 +02009834
Emeric Brun9b3009b2012-10-05 11:55:06 +02009835no-tlsv11
Emeric Brunf5da4932012-09-28 19:42:54 +02009836 This setting is only available when support for OpenSSL was built in. It
Jarno Huuskonen0e82b922014-04-12 18:22:19 +03009837 disables support for TLSv1.1 on any sockets instantiated from the listener
Emeric Brun2cb7ae52012-10-05 14:14:21 +02009838 when SSL is supported. Note that SSLv2 is forced disabled in the code and
Emeric Brun2c86cbf2014-10-30 15:56:50 +01009839 cannot be enabled using any configuration option. This option is also
9840 available on global statement "ssl-default-bind-options". See also
9841 "force-tlsv*", and "force-sslv3".
Emeric Brunf5da4932012-09-28 19:42:54 +02009842
Emeric Brun9b3009b2012-10-05 11:55:06 +02009843no-tlsv12
Emeric Brunf5da4932012-09-28 19:42:54 +02009844 This setting is only available when support for OpenSSL was built in. It
Jarno Huuskonen0e82b922014-04-12 18:22:19 +03009845 disables support for TLSv1.2 on any sockets instantiated from the listener
Emeric Brun2cb7ae52012-10-05 14:14:21 +02009846 when SSL is supported. Note that SSLv2 is forced disabled in the code and
Emeric Brun2c86cbf2014-10-30 15:56:50 +01009847 cannot be enabled using any configuration option. This option is also
9848 available on global statement "ssl-default-bind-options". See also
9849 "force-tlsv*", and "force-sslv3".
Emeric Brunf5da4932012-09-28 19:42:54 +02009850
Willy Tarreau6c9a3d52012-10-18 18:57:14 +02009851npn <protocols>
9852 This enables the NPN TLS extension and advertises the specified protocol list
9853 as supported on top of NPN. The protocol list consists in a comma-delimited
9854 list of protocol names, for instance: "http/1.1,http/1.0" (without quotes).
9855 This requires that the SSL library is build with support for TLS extensions
Willy Tarreauab861d32013-04-02 02:30:41 +02009856 enabled (check with haproxy -vv). Note that the NPN extension has been
9857 replaced with the ALPN extension (see the "alpn" keyword).
Willy Tarreau6c9a3d52012-10-18 18:57:14 +02009858
Willy Tarreau6ae1ba62014-05-07 19:01:58 +02009859process [ all | odd | even | <number 1-64>[-<number 1-64>] ]
9860 This restricts the list of processes on which this listener is allowed to
9861 run. It does not enforce any process but eliminates those which do not match.
9862 If the frontend uses a "bind-process" setting, the intersection between the
9863 two is applied. If in the end the listener is not allowed to run on any
9864 remaining process, a warning is emitted, and the listener will either run on
9865 the first process of the listener if a single process was specified, or on
9866 all of its processes if multiple processes were specified. For the unlikely
Willy Tarreauae302532014-05-07 19:22:24 +02009867 case where several ranges are needed, this directive may be repeated. The
9868 main purpose of this directive is to be used with the stats sockets and have
9869 one different socket per process. The second purpose is to have multiple bind
9870 lines sharing the same IP:port but not the same process in a listener, so
9871 that the system can distribute the incoming connections into multiple queues
9872 and allow a smoother inter-process load balancing. Currently Linux 3.9 and
9873 above is known for supporting this. See also "bind-process" and "nbproc".
Willy Tarreau6ae1ba62014-05-07 19:01:58 +02009874
Willy Tarreaub6205fd2012-09-24 12:27:33 +02009875ssl
9876 This setting is only available when support for OpenSSL was built in. It
Jarno Huuskonen0e82b922014-04-12 18:22:19 +03009877 enables SSL deciphering on connections instantiated from this listener. A
Willy Tarreaub6205fd2012-09-24 12:27:33 +02009878 certificate is necessary (see "crt" above). All contents in the buffers will
9879 appear in clear text, so that ACLs and HTTP processing will only have access
9880 to deciphered contents.
9881
Emmanuel Hocdet65623372013-01-24 17:17:15 +01009882strict-sni
9883 This setting is only available when support for OpenSSL was built in. The
9884 SSL/TLS negotiation is allow only if the client provided an SNI which match
9885 a certificate. The default certificate is not used.
9886 See the "crt" option for more information.
9887
Willy Tarreau2af207a2015-02-04 00:45:58 +01009888tcp-ut <delay>
9889 Sets the TCP User Timeout for all incoming connections instanciated from this
9890 listening socket. This option is available on Linux since version 2.6.37. It
9891 allows haproxy to configure a timeout for sockets which contain data not
9892 receiving an acknoledgement for the configured delay. This is especially
9893 useful on long-lived connections experiencing long idle periods such as
9894 remote terminals or database connection pools, where the client and server
9895 timeouts must remain high to allow a long period of idle, but where it is
9896 important to detect that the client has disappeared in order to release all
9897 resources associated with its connection (and the server's session). The
9898 argument is a delay expressed in milliseconds by default. This only works
9899 for regular TCP connections, and is ignored for other protocols.
9900
Willy Tarreau1c862c52012-10-05 16:21:00 +02009901tfo
Lukas Tribus0defb902013-02-13 23:35:39 +01009902 Is an optional keyword which is supported only on Linux kernels >= 3.7. It
Willy Tarreau1c862c52012-10-05 16:21:00 +02009903 enables TCP Fast Open on the listening socket, which means that clients which
9904 support this feature will be able to send a request and receive a response
9905 during the 3-way handshake starting from second connection, thus saving one
9906 round-trip after the first connection. This only makes sense with protocols
9907 that use high connection rates and where each round trip matters. This can
9908 possibly cause issues with many firewalls which do not accept data on SYN
9909 packets, so this option should only be enabled once well tested. This option
Lukas Tribus0999f762013-04-02 16:43:24 +02009910 is only supported on TCPv4/TCPv6 sockets and ignored by other ones. You may
9911 need to build HAProxy with USE_TFO=1 if your libc doesn't define
9912 TCP_FASTOPEN.
Willy Tarreau1c862c52012-10-05 16:21:00 +02009913
Nenad Merdanovic188ad3e2015-02-27 19:56:50 +01009914tls-ticket-keys <keyfile>
9915 Sets the TLS ticket keys file to load the keys from. The keys need to be 48
9916 bytes long, encoded with base64 (ex. openssl rand -base64 48). Number of keys
9917 is specified by the TLS_TICKETS_NO build option (default 3) and at least as
9918 many keys need to be present in the file. Last TLS_TICKETS_NO keys will be
9919 used for decryption and the penultimate one for encryption. This enables easy
9920 key rotation by just appending new key to the file and reloading the process.
9921 Keys must be periodically rotated (ex. every 12h) or Perfect Forward Secrecy
9922 is compromised. It is also a good idea to keep the keys off any permanent
9923 storage such as hard drives (hint: use tmpfs and don't swap those files).
9924 Lifetime hint can be changed using tune.ssl.timeout.
9925
Willy Tarreaub6205fd2012-09-24 12:27:33 +02009926transparent
9927 Is an optional keyword which is supported only on certain Linux kernels. It
9928 indicates that the addresses will be bound even if they do not belong to the
9929 local machine, and that packets targeting any of these addresses will be
9930 intercepted just as if the addresses were locally configured. This normally
9931 requires that IP forwarding is enabled. Caution! do not use this with the
9932 default address '*', as it would redirect any traffic for the specified port.
9933 This keyword is available only when HAProxy is built with USE_LINUX_TPROXY=1.
9934 This parameter is only compatible with TCPv4 and TCPv6 sockets, depending on
9935 kernel version. Some distribution kernels include backports of the feature,
9936 so check for support with your vendor.
9937
Willy Tarreau77e3af92012-11-24 15:07:23 +01009938v4v6
9939 Is an optional keyword which is supported only on most recent systems
9940 including Linux kernels >= 2.4.21. It is used to bind a socket to both IPv4
9941 and IPv6 when it uses the default address. Doing so is sometimes necessary
9942 on systems which bind to IPv6 only by default. It has no effect on non-IPv6
Jarno Huuskonen0e82b922014-04-12 18:22:19 +03009943 sockets, and is overridden by the "v6only" option.
Willy Tarreau77e3af92012-11-24 15:07:23 +01009944
Willy Tarreau9b6700f2012-11-24 11:55:28 +01009945v6only
9946 Is an optional keyword which is supported only on most recent systems
9947 including Linux kernels >= 2.4.21. It is used to bind a socket to IPv6 only
9948 when it uses the default address. Doing so is sometimes preferred to doing it
Willy Tarreau77e3af92012-11-24 15:07:23 +01009949 system-wide as it is per-listener. It has no effect on non-IPv6 sockets and
9950 has precedence over the "v4v6" option.
Willy Tarreau9b6700f2012-11-24 11:55:28 +01009951
Willy Tarreaub6205fd2012-09-24 12:27:33 +02009952uid <uid>
9953 Sets the owner of the UNIX sockets to the designated system uid. It can also
9954 be set by default in the global section's "unix-bind" statement. Note that
9955 some platforms simply ignore this. This setting is equivalent to the "user"
9956 setting except that the user numeric ID is used instead of its name. This
9957 setting is ignored by non UNIX sockets.
9958
9959user <user>
9960 Sets the owner of the UNIX sockets to the designated system user. It can also
9961 be set by default in the global section's "unix-bind" statement. Note that
9962 some platforms simply ignore this. This setting is equivalent to the "uid"
9963 setting except that the user name is used instead of its uid. This setting is
9964 ignored by non UNIX sockets.
9965
Emeric Brun1a073b42012-09-28 17:07:34 +02009966verify [none|optional|required]
9967 This setting is only available when support for OpenSSL was built in. If set
9968 to 'none', client certificate is not requested. This is the default. In other
9969 cases, a client certificate is requested. If the client does not provide a
9970 certificate after the request and if 'verify' is set to 'required', then the
9971 handshake is aborted, while it would have succeeded if set to 'optional'. The
Emeric Brunfd33a262012-10-11 16:28:27 +02009972 certificate provided by the client is always verified using CAs from
9973 'ca-file' and optional CRLs from 'crl-file'. On verify failure the handshake
9974 is aborted, regardless of the 'verify' option, unless the error code exactly
9975 matches one of those listed with 'ca-ignore-err' or 'crt-ignore-err'.
Willy Tarreau4a5cade2012-04-05 21:09:48 +02009976
Willy Tarreaub6205fd2012-09-24 12:27:33 +020099775.2. Server and default-server options
Cyril Bontéf0c60612010-02-06 14:44:47 +01009978------------------------------------
Willy Tarreau6a06a402007-07-15 20:15:28 +02009979
Krzysztof Piotr Oledzkic6df0662010-01-05 16:38:49 +01009980The "server" and "default-server" keywords support a certain number of settings
9981which are all passed as arguments on the server line. The order in which those
9982arguments appear does not count, and they are all optional. Some of those
9983settings are single words (booleans) while others expect one or several values
9984after them. In this case, the values must immediately follow the setting name.
9985Except default-server, all those settings must be specified after the server's
9986address if they are used:
Willy Tarreau6a06a402007-07-15 20:15:28 +02009987
Willy Tarreauc57f0e22009-05-10 13:12:33 +02009988 server <name> <address>[:port] [settings ...]
Krzysztof Piotr Oledzkic6df0662010-01-05 16:38:49 +01009989 default-server [settings ...]
Willy Tarreau6a06a402007-07-15 20:15:28 +02009990
Krzysztof Piotr Oledzkic53601c2010-01-06 10:50:42 +01009991The currently supported settings are the following ones.
Willy Tarreau0ba27502007-12-24 16:55:16 +01009992
Willy Tarreauceb4ac92012-04-28 00:41:46 +02009993addr <ipv4|ipv6>
Willy Tarreauc57f0e22009-05-10 13:12:33 +02009994 Using the "addr" parameter, it becomes possible to use a different IP address
9995 to send health-checks. On some servers, it may be desirable to dedicate an IP
9996 address to specific component able to perform complex tests which are more
9997 suitable to health-checks than the application. This parameter is ignored if
9998 the "check" parameter is not set. See also the "port" parameter.
Willy Tarreau6a06a402007-07-15 20:15:28 +02009999
Krzysztof Piotr Oledzkic53601c2010-01-06 10:50:42 +010010000 Supported in default-server: No
10001
Simon Hormand60d6912013-11-25 10:46:36 +090010002agent-check
10003 Enable an auxiliary agent check which is run independently of a regular
Willy Tarreau81f5d942013-12-09 20:51:51 +010010004 health check. An agent health check is performed by making a TCP connection
10005 to the port set by the "agent-port" parameter and reading an ASCII string.
10006 The string is made of a series of words delimited by spaces, tabs or commas
10007 in any order, optionally terminated by '\r' and/or '\n', each consisting of :
Simon Hormand60d6912013-11-25 10:46:36 +090010008
Willy Tarreau81f5d942013-12-09 20:51:51 +010010009 - An ASCII representation of a positive integer percentage, e.g. "75%".
Simon Hormand60d6912013-11-25 10:46:36 +090010010 Values in this format will set the weight proportional to the initial
Willy Tarreauc5af3a62014-10-07 15:27:33 +020010011 weight of a server as configured when haproxy starts. Note that a zero
10012 weight is reported on the stats page as "DRAIN" since it has the same
10013 effect on the server (it's removed from the LB farm).
Simon Hormand60d6912013-11-25 10:46:36 +090010014
Willy Tarreau81f5d942013-12-09 20:51:51 +010010015 - The word "ready". This will turn the server's administrative state to the
10016 READY mode, thus cancelling any DRAIN or MAINT state
Simon Hormand60d6912013-11-25 10:46:36 +090010017
Willy Tarreau81f5d942013-12-09 20:51:51 +010010018 - The word "drain". This will turn the server's administrative state to the
10019 DRAIN mode, thus it will not accept any new connections other than those
10020 that are accepted via persistence.
Simon Hormand60d6912013-11-25 10:46:36 +090010021
Willy Tarreau81f5d942013-12-09 20:51:51 +010010022 - The word "maint". This will turn the server's administrative state to the
10023 MAINT mode, thus it will not accept any new connections at all, and health
10024 checks will be stopped.
Simon Hormand60d6912013-11-25 10:46:36 +090010025
Willy Tarreau81f5d942013-12-09 20:51:51 +010010026 - The words "down", "failed", or "stopped", optionally followed by a
10027 description string after a sharp ('#'). All of these mark the server's
10028 operating state as DOWN, but since the word itself is reported on the stats
10029 page, the difference allows an administrator to know if the situation was
10030 expected or not : the service may intentionally be stopped, may appear up
10031 but fail some validity tests, or may be seen as down (eg: missing process,
10032 or port not responding).
Simon Hormand60d6912013-11-25 10:46:36 +090010033
Willy Tarreau81f5d942013-12-09 20:51:51 +010010034 - The word "up" sets back the server's operating state as UP if health checks
10035 also report that the service is accessible.
Simon Hormand60d6912013-11-25 10:46:36 +090010036
Willy Tarreau81f5d942013-12-09 20:51:51 +010010037 Parameters which are not advertised by the agent are not changed. For
10038 example, an agent might be designed to monitor CPU usage and only report a
10039 relative weight and never interact with the operating status. Similarly, an
10040 agent could be designed as an end-user interface with 3 radio buttons
10041 allowing an administrator to change only the administrative state. However,
10042 it is important to consider that only the agent may revert its own actions,
10043 so if a server is set to DRAIN mode or to DOWN state using the agent, the
10044 agent must implement the other equivalent actions to bring the service into
10045 operations again.
Simon Hormand60d6912013-11-25 10:46:36 +090010046
Simon Horman2f1f9552013-11-25 10:46:37 +090010047 Failure to connect to the agent is not considered an error as connectivity
10048 is tested by the regular health check which is enabled by the "check"
Willy Tarreau81f5d942013-12-09 20:51:51 +010010049 parameter. Warning though, it is not a good idea to stop an agent after it
10050 reports "down", since only an agent reporting "up" will be able to turn the
10051 server up again. Note that the CLI on the Unix stats socket is also able to
10052 force an agent's result in order to workaround a bogus agent if needed.
Simon Horman2f1f9552013-11-25 10:46:37 +090010053
Willy Tarreau81f5d942013-12-09 20:51:51 +010010054 Requires the "agent-port" parameter to be set. See also the "agent-inter"
10055 parameter.
Simon Hormand60d6912013-11-25 10:46:36 +090010056
10057 Supported in default-server: No
10058
10059agent-inter <delay>
10060 The "agent-inter" parameter sets the interval between two agent checks
10061 to <delay> milliseconds. If left unspecified, the delay defaults to 2000 ms.
10062
10063 Just as with every other time-based parameter, it may be entered in any
10064 other explicit unit among { us, ms, s, m, h, d }. The "agent-inter"
10065 parameter also serves as a timeout for agent checks "timeout check" is
10066 not set. In order to reduce "resonance" effects when multiple servers are
10067 hosted on the same hardware, the agent and health checks of all servers
10068 are started with a small time offset between them. It is also possible to
10069 add some random noise in the agent and health checks interval using the
10070 global "spread-checks" keyword. This makes sense for instance when a lot
10071 of backends use the same servers.
10072
10073 See also the "agent-check" and "agent-port" parameters.
10074
10075 Supported in default-server: Yes
10076
10077agent-port <port>
10078 The "agent-port" parameter sets the TCP port used for agent checks.
10079
10080 See also the "agent-check" and "agent-inter" parameters.
10081
10082 Supported in default-server: Yes
10083
Willy Tarreauc57f0e22009-05-10 13:12:33 +020010084backup
10085 When "backup" is present on a server line, the server is only used in load
10086 balancing when all other non-backup servers are unavailable. Requests coming
10087 with a persistence cookie referencing the server will always be served
10088 though. By default, only the first operational backup server is used, unless
10089 the "allbackups" option is set in the backend. See also the "allbackups"
10090 option.
Willy Tarreau6a06a402007-07-15 20:15:28 +020010091
Krzysztof Piotr Oledzkic53601c2010-01-06 10:50:42 +010010092 Supported in default-server: No
10093
Emeric Brunef42d922012-10-11 16:11:36 +020010094ca-file <cafile>
10095 This setting is only available when support for OpenSSL was built in. It
10096 designates a PEM file from which to load CA certificates used to verify
10097 server's certificate.
10098
10099 Supported in default-server: No
10100
Willy Tarreauc57f0e22009-05-10 13:12:33 +020010101check
10102 This option enables health checks on the server. By default, a server is
Patrick Mézardb7aeec62012-01-22 16:01:22 +010010103 always considered available. If "check" is set, the server is available when
10104 accepting periodic TCP connections, to ensure that it is really able to serve
10105 requests. The default address and port to send the tests to are those of the
10106 server, and the default source is the same as the one defined in the
10107 backend. It is possible to change the address using the "addr" parameter, the
10108 port using the "port" parameter, the source address using the "source"
10109 address, and the interval and timers using the "inter", "rise" and "fall"
Simon Hormanafc47ee2013-11-25 10:46:35 +090010110 parameters. The request method is define in the backend using the "httpchk",
10111 "smtpchk", "mysql-check", "pgsql-check" and "ssl-hello-chk" options. Please
10112 refer to those options and parameters for more information.
Willy Tarreauc57f0e22009-05-10 13:12:33 +020010113
Krzysztof Piotr Oledzkic53601c2010-01-06 10:50:42 +010010114 Supported in default-server: No
10115
Willy Tarreau6c16adc2012-10-05 00:04:16 +020010116check-send-proxy
10117 This option forces emission of a PROXY protocol line with outgoing health
10118 checks, regardless of whether the server uses send-proxy or not for the
10119 normal traffic. By default, the PROXY protocol is enabled for health checks
10120 if it is already enabled for normal traffic and if no "port" nor "addr"
10121 directive is present. However, if such a directive is present, the
10122 "check-send-proxy" option needs to be used to force the use of the
10123 protocol. See also the "send-proxy" option for more information.
10124
10125 Supported in default-server: No
10126
Willy Tarreau763a95b2012-10-04 23:15:39 +020010127check-ssl
10128 This option forces encryption of all health checks over SSL, regardless of
10129 whether the server uses SSL or not for the normal traffic. This is generally
10130 used when an explicit "port" or "addr" directive is specified and SSL health
10131 checks are not inherited. It is important to understand that this option
Jarno Huuskonen0e82b922014-04-12 18:22:19 +030010132 inserts an SSL transport layer below the checks, so that a simple TCP connect
Willy Tarreau763a95b2012-10-04 23:15:39 +020010133 check becomes an SSL connect, which replaces the old ssl-hello-chk. The most
10134 common use is to send HTTPS checks by combining "httpchk" with SSL checks.
10135 All SSL settings are common to health checks and traffic (eg: ciphers).
10136 See the "ssl" option for more information.
10137
10138 Supported in default-server: No
10139
Willy Tarreaua0ee1d02012-09-10 09:01:23 +020010140ciphers <ciphers>
10141 This option sets the string describing the list of cipher algorithms that is
Jarno Huuskonen0e82b922014-04-12 18:22:19 +030010142 is negotiated during the SSL/TLS handshake with the server. The format of the
Willy Tarreaua0ee1d02012-09-10 09:01:23 +020010143 string is defined in "man 1 ciphers". When SSL is used to communicate with
10144 servers on the local network, it is common to see a weaker set of algorithms
10145 than what is used over the internet. Doing so reduces CPU usage on both the
10146 server and haproxy while still keeping it compatible with deployed software.
10147 Some algorithms such as RC4-SHA1 are reasonably cheap. If no security at all
10148 is needed and just connectivity, using DES can be appropriate.
10149
Willy Tarreau763a95b2012-10-04 23:15:39 +020010150 Supported in default-server: No
10151
Willy Tarreauc57f0e22009-05-10 13:12:33 +020010152cookie <value>
10153 The "cookie" parameter sets the cookie value assigned to the server to
10154 <value>. This value will be checked in incoming requests, and the first
10155 operational server possessing the same value will be selected. In return, in
10156 cookie insertion or rewrite modes, this value will be assigned to the cookie
10157 sent to the client. There is nothing wrong in having several servers sharing
10158 the same cookie value, and it is in fact somewhat common between normal and
10159 backup servers. See also the "cookie" keyword in backend section.
10160
Krzysztof Piotr Oledzkic53601c2010-01-06 10:50:42 +010010161 Supported in default-server: No
10162
Emeric Brunef42d922012-10-11 16:11:36 +020010163crl-file <crlfile>
10164 This setting is only available when support for OpenSSL was built in. It
10165 designates a PEM file from which to load certificate revocation list used
10166 to verify server's certificate.
10167
10168 Supported in default-server: No
10169
Emeric Bruna7aa3092012-10-26 12:58:00 +020010170crt <cert>
10171 This setting is only available when support for OpenSSL was built in.
10172 It designates a PEM file from which to load both a certificate and the
10173 associated private key. This file can be built by concatenating both PEM
10174 files into one. This certificate will be sent if the server send a client
10175 certificate request.
10176
10177 Supported in default-server: No
10178
Willy Tarreau96839092010-03-29 10:02:24 +020010179disabled
10180 The "disabled" keyword starts the server in the "disabled" state. That means
10181 that it is marked down in maintenance mode, and no connection other than the
10182 ones allowed by persist mode will reach it. It is very well suited to setup
10183 new servers, because normal traffic will never reach them, while it is still
10184 possible to test the service by making use of the force-persist mechanism.
10185
10186 Supported in default-server: No
10187
Krzysztof Piotr Oledzkic53601c2010-01-06 10:50:42 +010010188error-limit <count>
Willy Tarreau983e01e2010-01-11 18:42:06 +010010189 If health observing is enabled, the "error-limit" parameter specifies the
10190 number of consecutive errors that triggers event selected by the "on-error"
10191 option. By default it is set to 10 consecutive errors.
Krzysztof Piotr Oledzki97f07b82009-12-15 22:31:24 +010010192
Krzysztof Piotr Oledzkic53601c2010-01-06 10:50:42 +010010193 Supported in default-server: Yes
10194
10195 See also the "check", "error-limit" and "on-error".
Krzysztof Piotr Oledzki97f07b82009-12-15 22:31:24 +010010196
Krzysztof Piotr Oledzkic53601c2010-01-06 10:50:42 +010010197fall <count>
Willy Tarreauc57f0e22009-05-10 13:12:33 +020010198 The "fall" parameter states that a server will be considered as dead after
10199 <count> consecutive unsuccessful health checks. This value defaults to 3 if
10200 unspecified. See also the "check", "inter" and "rise" parameters.
10201
Krzysztof Piotr Oledzkic53601c2010-01-06 10:50:42 +010010202 Supported in default-server: Yes
10203
Emeric Brun8694b9a2012-10-05 14:39:07 +020010204force-sslv3
10205 This option enforces use of SSLv3 only when SSL is used to communicate with
10206 the server. SSLv3 is generally less expensive than the TLS counterparts for
Emeric Brun2c86cbf2014-10-30 15:56:50 +010010207 high connection rates. This option is also available on global statement
10208 "ssl-default-server-options". See also "no-tlsv*", "no-sslv3".
Emeric Brun8694b9a2012-10-05 14:39:07 +020010209
10210 Supported in default-server: No
10211
10212force-tlsv10
10213 This option enforces use of TLSv1.0 only when SSL is used to communicate with
Emeric Brun2c86cbf2014-10-30 15:56:50 +010010214 the server. This option is also available on global statement
10215 "ssl-default-server-options". See also "no-tlsv*", "no-sslv3".
Emeric Brun8694b9a2012-10-05 14:39:07 +020010216
10217 Supported in default-server: No
10218
10219force-tlsv11
10220 This option enforces use of TLSv1.1 only when SSL is used to communicate with
Emeric Brun2c86cbf2014-10-30 15:56:50 +010010221 the server. This option is also available on global statement
10222 "ssl-default-server-options". See also "no-tlsv*", "no-sslv3".
Emeric Brun8694b9a2012-10-05 14:39:07 +020010223
10224 Supported in default-server: No
10225
10226force-tlsv12
10227 This option enforces use of TLSv1.2 only when SSL is used to communicate with
Emeric Brun2c86cbf2014-10-30 15:56:50 +010010228 the server. This option is also available on global statement
10229 "ssl-default-server-options". See also "no-tlsv*", "no-sslv3".
Emeric Brun8694b9a2012-10-05 14:39:07 +020010230
10231 Supported in default-server: No
10232
Willy Tarreauc57f0e22009-05-10 13:12:33 +020010233id <value>
Willy Tarreau53fb4ae2009-10-04 23:04:08 +020010234 Set a persistent ID for the server. This ID must be positive and unique for
10235 the proxy. An unused ID will automatically be assigned if unset. The first
10236 assigned value will be 1. This ID is currently only returned in statistics.
Willy Tarreauc57f0e22009-05-10 13:12:33 +020010237
Krzysztof Piotr Oledzkic53601c2010-01-06 10:50:42 +010010238 Supported in default-server: No
10239
10240inter <delay>
10241fastinter <delay>
10242downinter <delay>
Willy Tarreauc57f0e22009-05-10 13:12:33 +020010243 The "inter" parameter sets the interval between two consecutive health checks
10244 to <delay> milliseconds. If left unspecified, the delay defaults to 2000 ms.
10245 It is also possible to use "fastinter" and "downinter" to optimize delays
10246 between checks depending on the server state :
10247
Pieter Baauw44fc9df2015-09-17 21:30:46 +020010248 Server state | Interval used
10249 ----------------------------------------+----------------------------------
10250 UP 100% (non-transitional) | "inter"
10251 ----------------------------------------+----------------------------------
10252 Transitionally UP (going down "fall"), | "fastinter" if set,
10253 Transitionally DOWN (going up "rise"), | "inter" otherwise.
10254 or yet unchecked. |
10255 ----------------------------------------+----------------------------------
10256 DOWN 100% (non-transitional) | "downinter" if set,
10257 | "inter" otherwise.
10258 ----------------------------------------+----------------------------------
Willy Tarreaud72758d2010-01-12 10:42:19 +010010259
Willy Tarreauc57f0e22009-05-10 13:12:33 +020010260 Just as with every other time-based parameter, they can be entered in any
10261 other explicit unit among { us, ms, s, m, h, d }. The "inter" parameter also
10262 serves as a timeout for health checks sent to servers if "timeout check" is
10263 not set. In order to reduce "resonance" effects when multiple servers are
Simon Hormand60d6912013-11-25 10:46:36 +090010264 hosted on the same hardware, the agent and health checks of all servers
10265 are started with a small time offset between them. It is also possible to
10266 add some random noise in the agent and health checks interval using the
10267 global "spread-checks" keyword. This makes sense for instance when a lot
10268 of backends use the same servers.
Willy Tarreauc57f0e22009-05-10 13:12:33 +020010269
Krzysztof Piotr Oledzkic53601c2010-01-06 10:50:42 +010010270 Supported in default-server: Yes
10271
10272maxconn <maxconn>
Willy Tarreauc57f0e22009-05-10 13:12:33 +020010273 The "maxconn" parameter specifies the maximal number of concurrent
10274 connections that will be sent to this server. If the number of incoming
10275 concurrent requests goes higher than this value, they will be queued, waiting
10276 for a connection to be released. This parameter is very important as it can
10277 save fragile servers from going down under extreme loads. If a "minconn"
10278 parameter is specified, the limit becomes dynamic. The default value is "0"
10279 which means unlimited. See also the "minconn" and "maxqueue" parameters, and
10280 the backend's "fullconn" keyword.
10281
Krzysztof Piotr Oledzkic53601c2010-01-06 10:50:42 +010010282 Supported in default-server: Yes
10283
10284maxqueue <maxqueue>
Willy Tarreauc57f0e22009-05-10 13:12:33 +020010285 The "maxqueue" parameter specifies the maximal number of connections which
10286 will wait in the queue for this server. If this limit is reached, next
10287 requests will be redispatched to other servers instead of indefinitely
10288 waiting to be served. This will break persistence but may allow people to
10289 quickly re-log in when the server they try to connect to is dying. The
10290 default value is "0" which means the queue is unlimited. See also the
10291 "maxconn" and "minconn" parameters.
10292
Krzysztof Piotr Oledzkic53601c2010-01-06 10:50:42 +010010293 Supported in default-server: Yes
10294
10295minconn <minconn>
Willy Tarreauc57f0e22009-05-10 13:12:33 +020010296 When the "minconn" parameter is set, the maxconn limit becomes a dynamic
10297 limit following the backend's load. The server will always accept at least
10298 <minconn> connections, never more than <maxconn>, and the limit will be on
10299 the ramp between both values when the backend has less than <fullconn>
10300 concurrent connections. This makes it possible to limit the load on the
10301 server during normal loads, but push it further for important loads without
Krzysztof Piotr Oledzkif8645332009-12-13 21:55:50 +010010302 overloading the server during exceptional loads. See also the "maxconn"
Willy Tarreauc57f0e22009-05-10 13:12:33 +020010303 and "maxqueue" parameters, as well as the "fullconn" backend keyword.
Krzysztof Piotr Oledzki97f07b82009-12-15 22:31:24 +010010304
Krzysztof Piotr Oledzkic53601c2010-01-06 10:50:42 +010010305 Supported in default-server: Yes
10306
Willy Tarreau2a3fb1c2015-02-05 16:47:07 +010010307no-ssl-reuse
10308 This option disables SSL session reuse when SSL is used to communicate with
10309 the server. It will force the server to perform a full handshake for every
10310 new connection. It's probably only useful for benchmarking, troubleshooting,
10311 and for paranoid users.
10312
10313 Supported in default-server: No
10314
Emeric Brun9b3009b2012-10-05 11:55:06 +020010315no-sslv3
Willy Tarreaua0ee1d02012-09-10 09:01:23 +020010316 This option disables support for SSLv3 when SSL is used to communicate with
10317 the server. Note that SSLv2 is disabled in the code and cannot be enabled
Emeric Brun8694b9a2012-10-05 14:39:07 +020010318 using any configuration option. See also "force-sslv3", "force-tlsv*".
Willy Tarreaua0ee1d02012-09-10 09:01:23 +020010319
Willy Tarreau763a95b2012-10-04 23:15:39 +020010320 Supported in default-server: No
10321
Emeric Brunf9c5c472012-10-11 15:28:34 +020010322no-tls-tickets
10323 This setting is only available when support for OpenSSL was built in. It
10324 disables the stateless session resumption (RFC 5077 TLS Ticket
10325 extension) and force to use stateful session resumption. Stateless
Emeric Brun2c86cbf2014-10-30 15:56:50 +010010326 session resumption is more expensive in CPU usage for servers. This option
10327 is also available on global statement "ssl-default-server-options".
Emeric Brunf9c5c472012-10-11 15:28:34 +020010328
10329 Supported in default-server: No
10330
Emeric Brun9b3009b2012-10-05 11:55:06 +020010331no-tlsv10
Emeric Brun8694b9a2012-10-05 14:39:07 +020010332 This option disables support for TLSv1.0 when SSL is used to communicate with
Emeric Brunf5da4932012-09-28 19:42:54 +020010333 the server. Note that SSLv2 is disabled in the code and cannot be enabled
10334 using any configuration option. TLSv1 is more expensive than SSLv3 so it
Emeric Brun2c86cbf2014-10-30 15:56:50 +010010335 often makes sense to disable it when communicating with local servers. This
10336 option is also available on global statement "ssl-default-server-options".
10337 See also "force-sslv3", "force-tlsv*".
Emeric Brunf5da4932012-09-28 19:42:54 +020010338
Willy Tarreau763a95b2012-10-04 23:15:39 +020010339 Supported in default-server: No
10340
Emeric Brun9b3009b2012-10-05 11:55:06 +020010341no-tlsv11
Emeric Brun8694b9a2012-10-05 14:39:07 +020010342 This option disables support for TLSv1.1 when SSL is used to communicate with
Emeric Brunf5da4932012-09-28 19:42:54 +020010343 the server. Note that SSLv2 is disabled in the code and cannot be enabled
10344 using any configuration option. TLSv1 is more expensive than SSLv3 so it
Emeric Brun2c86cbf2014-10-30 15:56:50 +010010345 often makes sense to disable it when communicating with local servers. This
10346 option is also available on global statement "ssl-default-server-options".
10347 See also "force-sslv3", "force-tlsv*".
Emeric Brunf5da4932012-09-28 19:42:54 +020010348
Willy Tarreau763a95b2012-10-04 23:15:39 +020010349 Supported in default-server: No
10350
Emeric Brun9b3009b2012-10-05 11:55:06 +020010351no-tlsv12
Emeric Brun8694b9a2012-10-05 14:39:07 +020010352 This option disables support for TLSv1.2 when SSL is used to communicate with
Willy Tarreaua0ee1d02012-09-10 09:01:23 +020010353 the server. Note that SSLv2 is disabled in the code and cannot be enabled
10354 using any configuration option. TLSv1 is more expensive than SSLv3 so it
Emeric Brun2c86cbf2014-10-30 15:56:50 +010010355 often makes sense to disable it when communicating with local servers. This
10356 option is also available on global statement "ssl-default-server-options".
10357 See also "force-sslv3", "force-tlsv*".
Willy Tarreaua0ee1d02012-09-10 09:01:23 +020010358
Willy Tarreau763a95b2012-10-04 23:15:39 +020010359 Supported in default-server: No
10360
Simon Hormanfa461682011-06-25 09:39:49 +090010361non-stick
10362 Never add connections allocated to this sever to a stick-table.
10363 This may be used in conjunction with backup to ensure that
10364 stick-table persistence is disabled for backup servers.
10365
Willy Tarreau763a95b2012-10-04 23:15:39 +020010366 Supported in default-server: No
10367
Krzysztof Piotr Oledzki97f07b82009-12-15 22:31:24 +010010368observe <mode>
10369 This option enables health adjusting based on observing communication with
10370 the server. By default this functionality is disabled and enabling it also
10371 requires to enable health checks. There are two supported modes: "layer4" and
10372 "layer7". In layer4 mode, only successful/unsuccessful tcp connections are
10373 significant. In layer7, which is only allowed for http proxies, responses
10374 received from server are verified, like valid/wrong http code, unparsable
Willy Tarreau150d1462012-03-10 08:19:02 +010010375 headers, a timeout, etc. Valid status codes include 100 to 499, 501 and 505.
Krzysztof Piotr Oledzki97f07b82009-12-15 22:31:24 +010010376
Krzysztof Piotr Oledzkic53601c2010-01-06 10:50:42 +010010377 Supported in default-server: No
10378
Krzysztof Piotr Oledzki97f07b82009-12-15 22:31:24 +010010379 See also the "check", "on-error" and "error-limit".
10380
Krzysztof Piotr Oledzkic53601c2010-01-06 10:50:42 +010010381on-error <mode>
Krzysztof Piotr Oledzki97f07b82009-12-15 22:31:24 +010010382 Select what should happen when enough consecutive errors are detected.
10383 Currently, four modes are available:
10384 - fastinter: force fastinter
10385 - fail-check: simulate a failed check, also forces fastinter (default)
10386 - sudden-death: simulate a pre-fatal failed health check, one more failed
10387 check will mark a server down, forces fastinter
10388 - mark-down: mark the server immediately down and force fastinter
10389
Krzysztof Piotr Oledzkic53601c2010-01-06 10:50:42 +010010390 Supported in default-server: Yes
10391
Krzysztof Piotr Oledzki97f07b82009-12-15 22:31:24 +010010392 See also the "check", "observe" and "error-limit".
10393
Simon Hormane0d1bfb2011-06-21 14:34:58 +090010394on-marked-down <action>
10395 Modify what occurs when a server is marked down.
10396 Currently one action is available:
Justin Karnegeseb2c24a2012-05-24 15:28:52 -070010397 - shutdown-sessions: Shutdown peer sessions. When this setting is enabled,
10398 all connections to the server are immediately terminated when the server
10399 goes down. It might be used if the health check detects more complex cases
10400 than a simple connection status, and long timeouts would cause the service
10401 to remain unresponsive for too long a time. For instance, a health check
10402 might detect that a database is stuck and that there's no chance to reuse
10403 existing connections anymore. Connections killed this way are logged with
10404 a 'D' termination code (for "Down").
Simon Hormane0d1bfb2011-06-21 14:34:58 +090010405
10406 Actions are disabled by default
10407
10408 Supported in default-server: Yes
10409
Justin Karnegeseb2c24a2012-05-24 15:28:52 -070010410on-marked-up <action>
10411 Modify what occurs when a server is marked up.
10412 Currently one action is available:
10413 - shutdown-backup-sessions: Shutdown sessions on all backup servers. This is
10414 done only if the server is not in backup state and if it is not disabled
10415 (it must have an effective weight > 0). This can be used sometimes to force
10416 an active server to take all the traffic back after recovery when dealing
10417 with long sessions (eg: LDAP, SQL, ...). Doing this can cause more trouble
10418 than it tries to solve (eg: incomplete transactions), so use this feature
10419 with extreme care. Sessions killed because a server comes up are logged
10420 with an 'U' termination code (for "Up").
10421
10422 Actions are disabled by default
10423
10424 Supported in default-server: Yes
10425
Krzysztof Piotr Oledzkic53601c2010-01-06 10:50:42 +010010426port <port>
Willy Tarreauc57f0e22009-05-10 13:12:33 +020010427 Using the "port" parameter, it becomes possible to use a different port to
10428 send health-checks. On some servers, it may be desirable to dedicate a port
10429 to a specific component able to perform complex tests which are more suitable
10430 to health-checks than the application. It is common to run a simple script in
10431 inetd for instance. This parameter is ignored if the "check" parameter is not
10432 set. See also the "addr" parameter.
10433
Krzysztof Piotr Oledzkic53601c2010-01-06 10:50:42 +010010434 Supported in default-server: Yes
10435
Willy Tarreauc57f0e22009-05-10 13:12:33 +020010436redir <prefix>
10437 The "redir" parameter enables the redirection mode for all GET and HEAD
10438 requests addressing this server. This means that instead of having HAProxy
10439 forward the request to the server, it will send an "HTTP 302" response with
10440 the "Location" header composed of this prefix immediately followed by the
10441 requested URI beginning at the leading '/' of the path component. That means
10442 that no trailing slash should be used after <prefix>. All invalid requests
10443 will be rejected, and all non-GET or HEAD requests will be normally served by
10444 the server. Note that since the response is completely forged, no header
Krzysztof Piotr Oledzkif8645332009-12-13 21:55:50 +010010445 mangling nor cookie insertion is possible in the response. However, cookies in
Willy Tarreauc57f0e22009-05-10 13:12:33 +020010446 requests are still analysed, making this solution completely usable to direct
10447 users to a remote location in case of local disaster. Main use consists in
10448 increasing bandwidth for static servers by having the clients directly
10449 connect to them. Note: never use a relative location here, it would cause a
10450 loop between the client and HAProxy!
10451
10452 Example : server srv1 192.168.1.1:80 redir http://image1.mydomain.com check
10453
Krzysztof Piotr Oledzkic53601c2010-01-06 10:50:42 +010010454 Supported in default-server: No
10455
10456rise <count>
Willy Tarreauc57f0e22009-05-10 13:12:33 +020010457 The "rise" parameter states that a server will be considered as operational
10458 after <count> consecutive successful health checks. This value defaults to 2
10459 if unspecified. See also the "check", "inter" and "fall" parameters.
10460
Krzysztof Piotr Oledzkic53601c2010-01-06 10:50:42 +010010461 Supported in default-server: Yes
10462
Baptiste Assmann1fa66662015-04-14 00:28:47 +020010463resolve-prefer <family>
10464 When DNS resolution is enabled for a server and multiple IP addresses from
10465 different families are returned, HAProxy will prefer using an IP address
10466 from the family mentioned in the "resolve-prefer" parameter.
10467 Available families: "ipv4" and "ipv6"
10468
Baptiste Assmannc4aabae2015-08-04 22:43:06 +020010469 Default value: ipv6
10470
10471 Supported in default-server: Yes
Baptiste Assmann1fa66662015-04-14 00:28:47 +020010472
10473 Example: server s1 app1.domain.com:80 resolvers mydns resolve-prefer ipv6
10474
10475resolvers <id>
10476 Points to an existing "resolvers" section to resolve current server's
10477 hostname.
Baptiste Assmann62b75b42015-09-09 01:11:36 +020010478 In order to be operational, DNS resolution requires that health check is
10479 enabled on the server. Actually, health checks triggers the DNS resolution.
10480 You must precise one 'resolvers' parameter on each server line where DNS
10481 resolution is required.
Baptiste Assmann1fa66662015-04-14 00:28:47 +020010482
Baptiste Assmann62b75b42015-09-09 01:11:36 +020010483 Supported in default-server: No
10484
10485 Example: server s1 app1.domain.com:80 check resolvers mydns
Baptiste Assmann1fa66662015-04-14 00:28:47 +020010486
10487 See also chapter 5.3
10488
Willy Tarreau5ab04ec2011-03-20 10:32:26 +010010489send-proxy
10490 The "send-proxy" parameter enforces use of the PROXY protocol over any
10491 connection established to this server. The PROXY protocol informs the other
10492 end about the layer 3/4 addresses of the incoming connection, so that it can
10493 know the client's address or the public address it accessed to, whatever the
10494 upper layer protocol. For connections accepted by an "accept-proxy" listener,
10495 the advertised address will be used. Only TCPv4 and TCPv6 address families
10496 are supported. Other families such as Unix sockets, will report an UNKNOWN
10497 family. Servers using this option can fully be chained to another instance of
10498 haproxy listening with an "accept-proxy" setting. This setting must not be
Willy Tarreau6c16adc2012-10-05 00:04:16 +020010499 used if the server isn't aware of the protocol. When health checks are sent
10500 to the server, the PROXY protocol is automatically used when this option is
10501 set, unless there is an explicit "port" or "addr" directive, in which case an
10502 explicit "check-send-proxy" directive would also be needed to use the PROXY
10503 protocol. See also the "accept-proxy" option of the "bind" keyword.
Willy Tarreau5ab04ec2011-03-20 10:32:26 +010010504
10505 Supported in default-server: No
10506
David Safb76832014-05-08 23:42:08 -040010507send-proxy-v2
10508 The "send-proxy-v2" parameter enforces use of the PROXY protocol version 2
10509 over any connection established to this server. The PROXY protocol informs
10510 the other end about the layer 3/4 addresses of the incoming connection, so
10511 that it can know the client's address or the public address it accessed to,
10512 whatever the upper layer protocol. This setting must not be used if the
10513 server isn't aware of this version of the protocol. See also the "send-proxy"
10514 option of the "bind" keyword.
10515
10516 Supported in default-server: No
10517
10518send-proxy-v2-ssl
10519 The "send-proxy-v2-ssl" parameter enforces use of the PROXY protocol version
10520 2 over any connection established to this server. The PROXY protocol informs
10521 the other end about the layer 3/4 addresses of the incoming connection, so
10522 that it can know the client's address or the public address it accessed to,
10523 whatever the upper layer protocol. In addition, the SSL information extension
10524 of the PROXY protocol is added to the PROXY protocol header. This setting
10525 must not be used if the server isn't aware of this version of the protocol.
10526 See also the "send-proxy-v2" option of the "bind" keyword.
10527
10528 Supported in default-server: No
10529
10530send-proxy-v2-ssl-cn
10531 The "send-proxy-v2-ssl" parameter enforces use of the PROXY protocol version
10532 2 over any connection established to this server. The PROXY protocol informs
10533 the other end about the layer 3/4 addresses of the incoming connection, so
10534 that it can know the client's address or the public address it accessed to,
10535 whatever the upper layer protocol. In addition, the SSL information extension
10536 of the PROXY protocol, along along with the Common Name from the subject of
10537 the client certificate (if any), is added to the PROXY protocol header. This
10538 setting must not be used if the server isn't aware of this version of the
10539 protocol. See also the "send-proxy-v2" option of the "bind" keyword.
10540
10541 Supported in default-server: No
10542
Krzysztof Piotr Oledzkic53601c2010-01-06 10:50:42 +010010543slowstart <start_time_in_ms>
Willy Tarreauc57f0e22009-05-10 13:12:33 +020010544 The "slowstart" parameter for a server accepts a value in milliseconds which
10545 indicates after how long a server which has just come back up will run at
10546 full speed. Just as with every other time-based parameter, it can be entered
10547 in any other explicit unit among { us, ms, s, m, h, d }. The speed grows
10548 linearly from 0 to 100% during this time. The limitation applies to two
10549 parameters :
10550
10551 - maxconn: the number of connections accepted by the server will grow from 1
10552 to 100% of the usual dynamic limit defined by (minconn,maxconn,fullconn).
10553
10554 - weight: when the backend uses a dynamic weighted algorithm, the weight
10555 grows linearly from 1 to 100%. In this case, the weight is updated at every
10556 health-check. For this reason, it is important that the "inter" parameter
10557 is smaller than the "slowstart", in order to maximize the number of steps.
10558
10559 The slowstart never applies when haproxy starts, otherwise it would cause
10560 trouble to running servers. It only applies when a server has been previously
10561 seen as failed.
10562
Krzysztof Piotr Oledzkic53601c2010-01-06 10:50:42 +010010563 Supported in default-server: Yes
10564
Willy Tarreau732eac42015-07-09 11:40:25 +020010565sni <expression>
10566 The "sni" parameter evaluates the sample fetch expression, converts it to a
10567 string and uses the result as the host name sent in the SNI TLS extension to
10568 the server. A typical use case is to send the SNI received from the client in
10569 a bridged HTTPS scenario, using the "ssl_fc_sni" sample fetch for the
10570 expression, though alternatives such as req.hdr(host) can also make sense.
10571
10572 Supported in default-server: no
10573
Willy Tarreauc6f4ce82009-06-10 11:09:37 +020010574source <addr>[:<pl>[-<ph>]] [usesrc { <addr2>[:<port2>] | client | clientip } ]
Willy Tarreaubce70882009-09-07 11:51:47 +020010575source <addr>[:<port>] [usesrc { <addr2>[:<port2>] | hdr_ip(<hdr>[,<occ>]) } ]
Willy Tarreauc6f4ce82009-06-10 11:09:37 +020010576source <addr>[:<pl>[-<ph>]] [interface <name>] ...
Willy Tarreauc57f0e22009-05-10 13:12:33 +020010577 The "source" parameter sets the source address which will be used when
10578 connecting to the server. It follows the exact same parameters and principle
10579 as the backend "source" keyword, except that it only applies to the server
10580 referencing it. Please consult the "source" keyword for details.
10581
Willy Tarreauc6f4ce82009-06-10 11:09:37 +020010582 Additionally, the "source" statement on a server line allows one to specify a
10583 source port range by indicating the lower and higher bounds delimited by a
10584 dash ('-'). Some operating systems might require a valid IP address when a
10585 source port range is specified. It is permitted to have the same IP/range for
10586 several servers. Doing so makes it possible to bypass the maximum of 64k
10587 total concurrent connections. The limit will then reach 64k connections per
10588 server.
10589
Krzysztof Piotr Oledzkic53601c2010-01-06 10:50:42 +010010590 Supported in default-server: No
10591
Willy Tarreaua0ee1d02012-09-10 09:01:23 +020010592ssl
Willy Tarreau44f65392013-06-25 07:56:20 +020010593 This option enables SSL ciphering on outgoing connections to the server. It
10594 is critical to verify server certificates using "verify" when using SSL to
10595 connect to servers, otherwise the communication is prone to trivial man in
10596 the-middle attacks rendering SSL useless. When this option is used, health
10597 checks are automatically sent in SSL too unless there is a "port" or an
10598 "addr" directive indicating the check should be sent to a different location.
Jarno Huuskonen0e82b922014-04-12 18:22:19 +030010599 See the "check-ssl" option to force SSL health checks.
Willy Tarreau763a95b2012-10-04 23:15:39 +020010600
10601 Supported in default-server: No
Willy Tarreaua0ee1d02012-09-10 09:01:23 +020010602
Willy Tarreauc57f0e22009-05-10 13:12:33 +020010603track [<proxy>/]<server>
Willy Tarreau32091232014-05-16 13:52:00 +020010604 This option enables ability to set the current state of the server by tracking
10605 another one. It is possible to track a server which itself tracks another
10606 server, provided that at the end of the chain, a server has health checks
10607 enabled. If <proxy> is omitted the current one is used. If disable-on-404 is
Willy Tarreauc57f0e22009-05-10 13:12:33 +020010608 used, it has to be enabled on both proxies.
10609
Krzysztof Piotr Oledzkic53601c2010-01-06 10:50:42 +010010610 Supported in default-server: No
10611
Emeric Brunef42d922012-10-11 16:11:36 +020010612verify [none|required]
10613 This setting is only available when support for OpenSSL was built in. If set
Emeric Brun850efd52014-01-29 12:24:34 +010010614 to 'none', server certificate is not verified. In the other case, The
10615 certificate provided by the server is verified using CAs from 'ca-file'
10616 and optional CRLs from 'crl-file'. If 'ssl_server_verify' is not specified
10617 in global section, this is the default. On verify failure the handshake
Willy Tarreau44f65392013-06-25 07:56:20 +020010618 is aborted. It is critically important to verify server certificates when
10619 using SSL to connect to servers, otherwise the communication is prone to
10620 trivial man-in-the-middle attacks rendering SSL totally useless.
Emeric Brunef42d922012-10-11 16:11:36 +020010621
10622 Supported in default-server: No
10623
Evan Broderbe554312013-06-27 00:05:25 -070010624verifyhost <hostname>
10625 This setting is only available when support for OpenSSL was built in, and
10626 only takes effect if 'verify required' is also specified. When set, the
10627 hostnames in the subject and subjectAlternateNames of the certificate
10628 provided by the server are checked. If none of the hostnames in the
10629 certificate match the specified hostname, the handshake is aborted. The
10630 hostnames in the server-provided certificate may include wildcards.
10631
10632 Supported in default-server: No
10633
Krzysztof Piotr Oledzkic53601c2010-01-06 10:50:42 +010010634weight <weight>
Willy Tarreauc57f0e22009-05-10 13:12:33 +020010635 The "weight" parameter is used to adjust the server's weight relative to
10636 other servers. All servers will receive a load proportional to their weight
10637 relative to the sum of all weights, so the higher the weight, the higher the
Willy Tarreau6704d672009-06-15 10:56:05 +020010638 load. The default weight is 1, and the maximal value is 256. A value of 0
10639 means the server will not participate in load-balancing but will still accept
10640 persistent connections. If this parameter is used to distribute the load
10641 according to server's capacity, it is recommended to start with values which
10642 can both grow and shrink, for instance between 10 and 100 to leave enough
10643 room above and below for later adjustments.
Willy Tarreauc57f0e22009-05-10 13:12:33 +020010644
Krzysztof Piotr Oledzkic53601c2010-01-06 10:50:42 +010010645 Supported in default-server: Yes
10646
Willy Tarreauc57f0e22009-05-10 13:12:33 +020010647
Cyril Bonté46175dd2015-07-02 22:45:32 +0200106485.3. Server IP address resolution using DNS
10649-------------------------------------------
Baptiste Assmann1fa66662015-04-14 00:28:47 +020010650
Baptiste Assmann62b75b42015-09-09 01:11:36 +020010651HAProxy allows using a host name on the server line to retrieve its IP address
10652using name servers. By default, HAProxy resolves the name when parsing the
10653configuration file, at startup and cache the result for the process' life.
Baptiste Assmann1fa66662015-04-14 00:28:47 +020010654This is not sufficient in some cases, such as in Amazon where a server's IP
10655can change after a reboot or an ELB Virtual IP can change based on current
10656workload.
10657This chapter describes how HAProxy can be configured to process server's name
10658resolution at run time.
10659Whether run time server name resolution has been enable or not, HAProxy will
10660carry on doing the first resolution when parsing the configuration.
10661
Baptiste Assmann62b75b42015-09-09 01:11:36 +020010662Bear in mind that DNS resolution is triggered by health checks. This makes
10663health checks mandatory to allow DNS resolution.
10664
Baptiste Assmann1fa66662015-04-14 00:28:47 +020010665
Cyril Bonté46175dd2015-07-02 22:45:32 +0200106665.3.1. Global overview
10667----------------------
Baptiste Assmann1fa66662015-04-14 00:28:47 +020010668
10669As we've seen in introduction, name resolution in HAProxy occurs at two
10670different steps of the process life:
10671
10672 1. when starting up, HAProxy parses the server line definition and matches a
10673 host name. It uses libc functions to get the host name resolved. This
10674 resolution relies on /etc/resolv.conf file.
10675
10676 2. at run time, when HAProxy gets prepared to run a health check on a server,
10677 it verifies if the current name resolution is still considered as valid.
10678 If not, it processes a new resolution, in parallel of the health check.
10679
10680A few other events can trigger a name resolution at run time:
10681 - when a server's health check ends up in a connection timeout: this may be
10682 because the server has a new IP address. So we need to trigger a name
10683 resolution to know this new IP.
10684
10685A few things important to notice:
10686 - all the name servers are queried in the mean time. HAProxy will process the
10687 first valid response.
10688
10689 - a resolution is considered as invalid (NX, timeout, refused), when all the
10690 servers return an error.
10691
10692
Cyril Bonté46175dd2015-07-02 22:45:32 +0200106935.3.2. The resolvers section
10694----------------------------
Baptiste Assmann1fa66662015-04-14 00:28:47 +020010695
10696This section is dedicated to host information related to name resolution in
10697HAProxy.
10698There can be as many as resolvers section as needed. Each section can contain
10699many name servers.
10700
Baptiste Assmann62b75b42015-09-09 01:11:36 +020010701When multiple name servers are configured in a resolvers section, then HAProxy
10702uses the first valid response. In case of invalid responses, only the last one
10703is treated. Purpose is to give the chance to a slow server to deliver a valid
10704answer after a fast faulty or outdated server.
10705
10706When each server returns a different error type, then only the last error is
10707used by HAProxy to decide what type of behavior to apply.
10708
10709Two types of behavior can be applied:
10710 1. stop DNS resolution
10711 2. replay the DNS query with a new query type
10712 In such case, the following types are applied in this exact order:
10713 1. ANY query type
10714 2. query type corresponding to family pointed by resolve-prefer
10715 server's parameter
10716 3. remaining family type
10717
10718HAProxy stops DNS resolution when the following errors occur:
10719 - invalid DNS response packet
10720 - wrong name in the query section of the response
10721 - NX domain
10722 - Query refused by server
10723 - CNAME not pointing to an IP address
10724
10725HAProxy tries a new query type when the following errors occur:
10726 - no Answer records in the response
10727 - DNS response truncated
10728 - Error in DNS response
10729 - No expected DNS records found in the response
10730 - name server timeout
10731
10732For example, with 2 name servers configured in a resolvers section:
10733 - first response is valid and is applied directly, second response is ignored
10734 - first response is invalid and second one is valid, then second response is
10735 applied;
10736 - first response is a NX domain and second one a truncated response, then
10737 HAProxy replays the query with a new type;
10738 - first response is truncated and second one is a NX Domain, then HAProxy
10739 stops resolution.
10740
10741
Baptiste Assmann1fa66662015-04-14 00:28:47 +020010742resolvers <resolvers id>
10743 Creates a new name server list labelled <resolvers id>
10744
10745A resolvers section accept the following parameters:
10746
10747nameserver <id> <ip>:<port>
10748 DNS server description:
10749 <id> : label of the server, should be unique
10750 <ip> : IP address of the server
10751 <port> : port where the DNS service actually runs
10752
10753hold <status> <period>
10754 Defines <period> during which the last name resolution should be kept based
10755 on last resolution <status>
10756 <status> : last name resolution status. Only "valid" is accepted for now.
10757 <period> : interval between two successive name resolution when the last
10758 answer was in <status>. It follows the HAProxy time format.
10759 <period> is in milliseconds by default.
10760
10761 Default value is 10s for "valid".
10762
10763 Note: since the name resolution is triggered by the health checks, a new
10764 resolution is triggered after <period> modulo the <inter> parameter of
10765 the healch check.
10766
10767resolve_retries <nb>
10768 Defines the number <nb> of queries to send to resolve a server name before
10769 giving up.
10770 Default value: 3
10771
Baptiste Assmann62b75b42015-09-09 01:11:36 +020010772 A retry occurs on name server timeout or when the full sequence of DNS query
10773 type failover is over and we need to start up from the default ANY query
10774 type.
10775
Baptiste Assmann1fa66662015-04-14 00:28:47 +020010776timeout <event> <time>
10777 Defines timeouts related to name resolution
10778 <event> : the event on which the <time> timeout period applies to.
10779 events available are:
10780 - retry: time between two DNS queries, when no response have
10781 been received.
10782 Default value: 1s
10783 <time> : time related to the event. It follows the HAProxy time format.
10784 <time> is expressed in milliseconds.
10785
10786Example of a resolvers section (with default values):
10787
10788 resolvers mydns
10789 nameserver dns1 10.0.0.1:53
10790 nameserver dns2 10.0.0.2:53
10791 resolve_retries 3
10792 timeout retry 1s
10793 hold valid 10s
10794
10795
Willy Tarreauc57f0e22009-05-10 13:12:33 +0200107966. HTTP header manipulation
10797---------------------------
10798
10799In HTTP mode, it is possible to rewrite, add or delete some of the request and
10800response headers based on regular expressions. It is also possible to block a
10801request or a response if a particular header matches a regular expression,
10802which is enough to stop most elementary protocol attacks, and to protect
Willy Tarreau70dffda2014-01-30 03:07:23 +010010803against information leak from the internal network.
Willy Tarreauc57f0e22009-05-10 13:12:33 +020010804
Willy Tarreau70dffda2014-01-30 03:07:23 +010010805If HAProxy encounters an "Informational Response" (status code 1xx), it is able
10806to process all rsp* rules which can allow, deny, rewrite or delete a header,
10807but it will refuse to add a header to any such messages as this is not
10808HTTP-compliant. The reason for still processing headers in such responses is to
10809stop and/or fix any possible information leak which may happen, for instance
10810because another downstream equipment would unconditionally add a header, or if
10811a server name appears there. When such messages are seen, normal processing
10812still occurs on the next non-informational messages.
Willy Tarreau816b9792009-09-15 21:25:21 +020010813
Willy Tarreauc57f0e22009-05-10 13:12:33 +020010814This section covers common usage of the following keywords, described in detail
10815in section 4.2 :
10816
10817 - reqadd <string>
10818 - reqallow <search>
10819 - reqiallow <search>
10820 - reqdel <search>
10821 - reqidel <search>
10822 - reqdeny <search>
10823 - reqideny <search>
10824 - reqpass <search>
10825 - reqipass <search>
10826 - reqrep <search> <replace>
10827 - reqirep <search> <replace>
10828 - reqtarpit <search>
10829 - reqitarpit <search>
10830 - rspadd <string>
10831 - rspdel <search>
10832 - rspidel <search>
10833 - rspdeny <search>
10834 - rspideny <search>
10835 - rsprep <search> <replace>
10836 - rspirep <search> <replace>
10837
10838With all these keywords, the same conventions are used. The <search> parameter
10839is a POSIX extended regular expression (regex) which supports grouping through
10840parenthesis (without the backslash). Spaces and other delimiters must be
10841prefixed with a backslash ('\') to avoid confusion with a field delimiter.
10842Other characters may be prefixed with a backslash to change their meaning :
10843
10844 \t for a tab
10845 \r for a carriage return (CR)
10846 \n for a new line (LF)
10847 \ to mark a space and differentiate it from a delimiter
10848 \# to mark a sharp and differentiate it from a comment
10849 \\ to use a backslash in a regex
10850 \\\\ to use a backslash in the text (*2 for regex, *2 for haproxy)
10851 \xXX to write the ASCII hex code XX as in the C language
10852
10853The <replace> parameter contains the string to be used to replace the largest
10854portion of text matching the regex. It can make use of the special characters
10855above, and can reference a substring which is delimited by parenthesis in the
10856regex, by writing a backslash ('\') immediately followed by one digit from 0 to
108579 indicating the group position (0 designating the entire line). This practice
10858is very common to users of the "sed" program.
10859
10860The <string> parameter represents the string which will systematically be added
10861after the last header line. It can also use special character sequences above.
10862
10863Notes related to these keywords :
10864---------------------------------
10865 - these keywords are not always convenient to allow/deny based on header
10866 contents. It is strongly recommended to use ACLs with the "block" keyword
10867 instead, resulting in far more flexible and manageable rules.
10868
10869 - lines are always considered as a whole. It is not possible to reference
10870 a header name only or a value only. This is important because of the way
10871 headers are written (notably the number of spaces after the colon).
10872
10873 - the first line is always considered as a header, which makes it possible to
10874 rewrite or filter HTTP requests URIs or response codes, but in turn makes
10875 it harder to distinguish between headers and request line. The regex prefix
10876 ^[^\ \t]*[\ \t] matches any HTTP method followed by a space, and the prefix
10877 ^[^ \t:]*: matches any header name followed by a colon.
10878
10879 - for performances reasons, the number of characters added to a request or to
10880 a response is limited at build time to values between 1 and 4 kB. This
10881 should normally be far more than enough for most usages. If it is too short
10882 on occasional usages, it is possible to gain some space by removing some
10883 useless headers before adding new ones.
10884
Krzysztof Piotr Oledzkif8645332009-12-13 21:55:50 +010010885 - keywords beginning with "reqi" and "rspi" are the same as their counterpart
Willy Tarreauc57f0e22009-05-10 13:12:33 +020010886 without the 'i' letter except that they ignore case when matching patterns.
10887
10888 - when a request passes through a frontend then a backend, all req* rules
10889 from the frontend will be evaluated, then all req* rules from the backend
10890 will be evaluated. The reverse path is applied to responses.
10891
10892 - req* statements are applied after "block" statements, so that "block" is
10893 always the first one, but before "use_backend" in order to permit rewriting
Willy Tarreaud72758d2010-01-12 10:42:19 +010010894 before switching.
Willy Tarreauc57f0e22009-05-10 13:12:33 +020010895
10896
Willy Tarreau74ca5042013-06-11 23:12:07 +0200108977. Using ACLs and fetching samples
10898----------------------------------
10899
10900Haproxy is capable of extracting data from request or response streams, from
10901client or server information, from tables, environmental information etc...
10902The action of extracting such data is called fetching a sample. Once retrieved,
10903these samples may be used for various purposes such as a key to a stick-table,
10904but most common usages consist in matching them against predefined constant
10905data called patterns.
10906
10907
109087.1. ACL basics
10909---------------
Willy Tarreauc57f0e22009-05-10 13:12:33 +020010910
10911The use of Access Control Lists (ACL) provides a flexible solution to perform
10912content switching and generally to take decisions based on content extracted
10913from the request, the response or any environmental status. The principle is
10914simple :
10915
Willy Tarreau74ca5042013-06-11 23:12:07 +020010916 - extract a data sample from a stream, table or the environment
Willy Tarreaue6b11e42013-11-26 19:02:32 +010010917 - optionally apply some format conversion to the extracted sample
Willy Tarreau74ca5042013-06-11 23:12:07 +020010918 - apply one or multiple pattern matching methods on this sample
10919 - perform actions only when a pattern matches the sample
Willy Tarreauc57f0e22009-05-10 13:12:33 +020010920
Willy Tarreau74ca5042013-06-11 23:12:07 +020010921The actions generally consist in blocking a request, selecting a backend, or
10922adding a header.
Willy Tarreauc57f0e22009-05-10 13:12:33 +020010923
10924In order to define a test, the "acl" keyword is used. The syntax is :
10925
Willy Tarreau74ca5042013-06-11 23:12:07 +020010926 acl <aclname> <criterion> [flags] [operator] [<value>] ...
Willy Tarreauc57f0e22009-05-10 13:12:33 +020010927
10928This creates a new ACL <aclname> or completes an existing one with new tests.
10929Those tests apply to the portion of request/response specified in <criterion>
10930and may be adjusted with optional flags [flags]. Some criteria also support
Willy Tarreaue6b11e42013-11-26 19:02:32 +010010931an operator which may be specified before the set of values. Optionally some
10932conversion operators may be applied to the sample, and they will be specified
10933as a comma-delimited list of keywords just after the first keyword. The values
10934are of the type supported by the criterion, and are separated by spaces.
Willy Tarreauc57f0e22009-05-10 13:12:33 +020010935
10936ACL names must be formed from upper and lower case letters, digits, '-' (dash),
10937'_' (underscore) , '.' (dot) and ':' (colon). ACL names are case-sensitive,
10938which means that "my_acl" and "My_Acl" are two different ACLs.
10939
10940There is no enforced limit to the number of ACLs. The unused ones do not affect
10941performance, they just consume a small amount of memory.
10942
Willy Tarreau74ca5042013-06-11 23:12:07 +020010943The criterion generally is the name of a sample fetch method, or one of its ACL
10944specific declinations. The default test method is implied by the output type of
10945this sample fetch method. The ACL declinations can describe alternate matching
Willy Tarreaue6b11e42013-11-26 19:02:32 +010010946methods of a same sample fetch method. The sample fetch methods are the only
10947ones supporting a conversion.
Willy Tarreau74ca5042013-06-11 23:12:07 +020010948
10949Sample fetch methods return data which can be of the following types :
10950 - boolean
10951 - integer (signed or unsigned)
10952 - IPv4 or IPv6 address
10953 - string
10954 - data block
10955
Willy Tarreaue6b11e42013-11-26 19:02:32 +010010956Converters transform any of these data into any of these. For example, some
10957converters might convert a string to a lower-case string while other ones
10958would turn a string to an IPv4 address, or apply a netmask to an IP address.
10959The resulting sample is of the type of the last converter applied to the list,
10960which defaults to the type of the sample fetch method.
10961
Thierry FOURNIER2a06e392014-05-11 15:49:55 +020010962Each sample or converter returns data of a specific type, specified with its
10963keyword in this documentation. When an ACL is declared using a standard sample
10964fetch method, certain types automatically involved a default matching method
10965which are summarized in the table below :
10966
10967 +---------------------+-----------------+
10968 | Sample or converter | Default |
10969 | output type | matching method |
10970 +---------------------+-----------------+
10971 | boolean | bool |
10972 +---------------------+-----------------+
10973 | integer | int |
10974 +---------------------+-----------------+
10975 | ip | ip |
10976 +---------------------+-----------------+
10977 | string | str |
10978 +---------------------+-----------------+
10979 | binary | none, use "-m" |
10980 +---------------------+-----------------+
10981
10982Note that in order to match a binary samples, it is mandatory to specify a
10983matching method, see below.
10984
Willy Tarreau74ca5042013-06-11 23:12:07 +020010985The ACL engine can match these types against patterns of the following types :
10986 - boolean
10987 - integer or integer range
10988 - IP address / network
10989 - string (exact, substring, suffix, prefix, subdir, domain)
10990 - regular expression
10991 - hex block
10992
Willy Tarreauc57f0e22009-05-10 13:12:33 +020010993The following ACL flags are currently supported :
10994
Willy Tarreau2b5285d2010-05-09 23:45:24 +020010995 -i : ignore case during matching of all subsequent patterns.
10996 -f : load patterns from a file.
Willy Tarreau74ca5042013-06-11 23:12:07 +020010997 -m : use a specific pattern matching method
Thierry FOURNIERb7729c92014-02-11 16:24:41 +010010998 -n : forbid the DNS resolutions
Thierry FOURNIER9860c412014-01-29 14:23:29 +010010999 -M : load the file pointed by -f like a map file.
Thierry FOURNIER3534d882014-01-20 17:01:44 +010011000 -u : force the unique id of the ACL
Willy Tarreau6a06a402007-07-15 20:15:28 +020011001 -- : force end of flags. Useful when a string looks like one of the flags.
11002
Willy Tarreau74ca5042013-06-11 23:12:07 +020011003The "-f" flag is followed by the name of a file from which all lines will be
11004read as individual values. It is even possible to pass multiple "-f" arguments
11005if the patterns are to be loaded from multiple files. Empty lines as well as
11006lines beginning with a sharp ('#') will be ignored. All leading spaces and tabs
11007will be stripped. If it is absolutely necessary to insert a valid pattern
11008beginning with a sharp, just prefix it with a space so that it is not taken for
11009a comment. Depending on the data type and match method, haproxy may load the
11010lines into a binary tree, allowing very fast lookups. This is true for IPv4 and
11011exact string matching. In this case, duplicates will automatically be removed.
11012
Thierry FOURNIER9860c412014-01-29 14:23:29 +010011013The "-M" flag allows an ACL to use a map file. If this flag is set, the file is
11014parsed as two column file. The first column contains the patterns used by the
11015ACL, and the second column contain the samples. The sample can be used later by
11016a map. This can be useful in some rare cases where an ACL would just be used to
11017check for the existence of a pattern in a map before a mapping is applied.
11018
Thierry FOURNIER3534d882014-01-20 17:01:44 +010011019The "-u" flag forces the unique id of the ACL. This unique id is used with the
11020socket interface to identify ACL and dynamically change its values. Note that a
11021file is always identified by its name even if an id is set.
11022
Willy Tarreau74ca5042013-06-11 23:12:07 +020011023Also, note that the "-i" flag applies to subsequent entries and not to entries
11024loaded from files preceding it. For instance :
11025
11026 acl valid-ua hdr(user-agent) -f exact-ua.lst -i -f generic-ua.lst test
11027
11028In this example, each line of "exact-ua.lst" will be exactly matched against
11029the "user-agent" header of the request. Then each line of "generic-ua" will be
11030case-insensitively matched. Then the word "test" will be insensitively matched
11031as well.
11032
11033The "-m" flag is used to select a specific pattern matching method on the input
11034sample. All ACL-specific criteria imply a pattern matching method and generally
11035do not need this flag. However, this flag is useful with generic sample fetch
11036methods to describe how they're going to be matched against the patterns. This
11037is required for sample fetches which return data type for which there is no
11038obvious matching method (eg: string or binary). When "-m" is specified and
11039followed by a pattern matching method name, this method is used instead of the
11040default one for the criterion. This makes it possible to match contents in ways
11041that were not initially planned, or with sample fetch methods which return a
11042string. The matching method also affects the way the patterns are parsed.
11043
Thierry FOURNIERb7729c92014-02-11 16:24:41 +010011044The "-n" flag forbids the dns resolutions. It is used with the load of ip files.
11045By default, if the parser cannot parse ip address it considers that the parsed
11046string is maybe a domain name and try dns resolution. The flag "-n" disable this
11047resolution. It is useful for detecting malformed ip lists. Note that if the DNS
11048server is not reachable, the haproxy configuration parsing may last many minutes
11049waiting fir the timeout. During this time no error messages are displayed. The
11050flag "-n" disable this behavior. Note also that during the runtime, this
11051function is disabled for the dynamic acl modifications.
11052
Willy Tarreau74ca5042013-06-11 23:12:07 +020011053There are some restrictions however. Not all methods can be used with all
11054sample fetch methods. Also, if "-m" is used in conjunction with "-f", it must
11055be placed first. The pattern matching method must be one of the following :
Willy Tarreau5adeda12013-03-31 22:13:34 +020011056
11057 - "found" : only check if the requested sample could be found in the stream,
11058 but do not compare it against any pattern. It is recommended not
Willy Tarreau74ca5042013-06-11 23:12:07 +020011059 to pass any pattern to avoid confusion. This matching method is
11060 particularly useful to detect presence of certain contents such
11061 as headers, cookies, etc... even if they are empty and without
11062 comparing them to anything nor counting them.
Willy Tarreau5adeda12013-03-31 22:13:34 +020011063
11064 - "bool" : check the value as a boolean. It can only be applied to fetches
11065 which return a boolean or integer value, and takes no pattern.
Willy Tarreau74ca5042013-06-11 23:12:07 +020011066 Value zero or false does not match, all other values do match.
Willy Tarreau5adeda12013-03-31 22:13:34 +020011067
11068 - "int" : match the value as an integer. It can be used with integer and
Willy Tarreau74ca5042013-06-11 23:12:07 +020011069 boolean samples. Boolean false is integer 0, true is integer 1.
Willy Tarreau5adeda12013-03-31 22:13:34 +020011070
11071 - "ip" : match the value as an IPv4 or IPv6 address. It is compatible
Willy Tarreau74ca5042013-06-11 23:12:07 +020011072 with IP address samples only, so it is implied and never needed.
Willy Tarreau5adeda12013-03-31 22:13:34 +020011073
11074 - "bin" : match the contents against an hexadecimal string representing a
11075 binary sequence. This may be used with binary or string samples.
11076
11077 - "len" : match the sample's length as an integer. This may be used with
11078 binary or string samples.
11079
Willy Tarreau74ca5042013-06-11 23:12:07 +020011080 - "str" : exact match : match the contents against a string. This may be
11081 used with binary or string samples.
Willy Tarreau5adeda12013-03-31 22:13:34 +020011082
Willy Tarreau74ca5042013-06-11 23:12:07 +020011083 - "sub" : substring match : check that the contents contain at least one of
11084 the provided string patterns. This may be used with binary or
11085 string samples.
Willy Tarreau5adeda12013-03-31 22:13:34 +020011086
Willy Tarreau74ca5042013-06-11 23:12:07 +020011087 - "reg" : regex match : match the contents against a list of regular
11088 expressions. This may be used with binary or string samples.
Willy Tarreau5adeda12013-03-31 22:13:34 +020011089
Willy Tarreau74ca5042013-06-11 23:12:07 +020011090 - "beg" : prefix match : check that the contents begin like the provided
11091 string patterns. This may be used with binary or string samples.
Willy Tarreau5adeda12013-03-31 22:13:34 +020011092
Willy Tarreau74ca5042013-06-11 23:12:07 +020011093 - "end" : suffix match : check that the contents end like the provided
11094 string patterns. This may be used with binary or string samples.
Willy Tarreau5adeda12013-03-31 22:13:34 +020011095
Willy Tarreau74ca5042013-06-11 23:12:07 +020011096 - "dir" : subdir match : check that a slash-delimited portion of the
11097 contents exactly matches one of the provided string patterns.
Willy Tarreau5adeda12013-03-31 22:13:34 +020011098 This may be used with binary or string samples.
11099
Willy Tarreau74ca5042013-06-11 23:12:07 +020011100 - "dom" : domain match : check that a dot-delimited portion of the contents
11101 exactly match one of the provided string patterns. This may be
11102 used with binary or string samples.
Willy Tarreau5adeda12013-03-31 22:13:34 +020011103
11104For example, to quickly detect the presence of cookie "JSESSIONID" in an HTTP
11105request, it is possible to do :
11106
11107 acl jsess_present cook(JSESSIONID) -m found
11108
11109In order to apply a regular expression on the 500 first bytes of data in the
11110buffer, one would use the following acl :
11111
11112 acl script_tag payload(0,500) -m reg -i <script>
11113
Willy Tarreaue6b11e42013-11-26 19:02:32 +010011114On systems where the regex library is much slower when using "-i", it is
11115possible to convert the sample to lowercase before matching, like this :
11116
11117 acl script_tag payload(0,500),lower -m reg <script>
11118
Willy Tarreau74ca5042013-06-11 23:12:07 +020011119All ACL-specific criteria imply a default matching method. Most often, these
11120criteria are composed by concatenating the name of the original sample fetch
11121method and the matching method. For example, "hdr_beg" applies the "beg" match
11122to samples retrieved using the "hdr" fetch method. Since all ACL-specific
11123criteria rely on a sample fetch method, it is always possible instead to use
11124the original sample fetch method and the explicit matching method using "-m".
Willy Tarreau2b5285d2010-05-09 23:45:24 +020011125
Willy Tarreau74ca5042013-06-11 23:12:07 +020011126If an alternate match is specified using "-m" on an ACL-specific criterion,
Jarno Huuskonen0e82b922014-04-12 18:22:19 +030011127the matching method is simply applied to the underlying sample fetch method.
11128For example, all ACLs below are exact equivalent :
Willy Tarreau2b5285d2010-05-09 23:45:24 +020011129
Willy Tarreau74ca5042013-06-11 23:12:07 +020011130 acl short_form hdr_beg(host) www.
11131 acl alternate1 hdr_beg(host) -m beg www.
11132 acl alternate2 hdr_dom(host) -m beg www.
11133 acl alternate3 hdr(host) -m beg www.
Willy Tarreau2b5285d2010-05-09 23:45:24 +020011134
Willy Tarreau2b5285d2010-05-09 23:45:24 +020011135
Thierry FOURNIER2a06e392014-05-11 15:49:55 +020011136The table below summarizes the compatibility matrix between sample or converter
11137types and the pattern types to fetch against. It indicates for each compatible
11138combination the name of the matching method to be used, surrounded with angle
11139brackets ">" and "<" when the method is the default one and will work by
11140default without "-m".
Willy Tarreau0ba27502007-12-24 16:55:16 +010011141
Willy Tarreau74ca5042013-06-11 23:12:07 +020011142 +-------------------------------------------------+
11143 | Input sample type |
11144 +----------------------+---------+---------+---------+---------+---------+
Thierry FOURNIER2a06e392014-05-11 15:49:55 +020011145 | pattern type | boolean | integer | ip | string | binary |
Willy Tarreau74ca5042013-06-11 23:12:07 +020011146 +----------------------+---------+---------+---------+---------+---------+
11147 | none (presence only) | found | found | found | found | found |
11148 +----------------------+---------+---------+---------+---------+---------+
Thierry FOURNIER2a06e392014-05-11 15:49:55 +020011149 | none (boolean value) |> bool <| bool | | bool | |
Willy Tarreau74ca5042013-06-11 23:12:07 +020011150 +----------------------+---------+---------+---------+---------+---------+
Thierry FOURNIER2a06e392014-05-11 15:49:55 +020011151 | integer (value) | int |> int <| int | int | |
Willy Tarreau74ca5042013-06-11 23:12:07 +020011152 +----------------------+---------+---------+---------+---------+---------+
Thierry FOURNIERe3ded592013-12-06 15:36:54 +010011153 | integer (length) | len | len | len | len | len |
Willy Tarreau74ca5042013-06-11 23:12:07 +020011154 +----------------------+---------+---------+---------+---------+---------+
Thierry FOURNIER2a06e392014-05-11 15:49:55 +020011155 | IP address | | |> ip <| ip | ip |
Willy Tarreau74ca5042013-06-11 23:12:07 +020011156 +----------------------+---------+---------+---------+---------+---------+
Thierry FOURNIER2a06e392014-05-11 15:49:55 +020011157 | exact string | str | str | str |> str <| str |
Willy Tarreau74ca5042013-06-11 23:12:07 +020011158 +----------------------+---------+---------+---------+---------+---------+
Thierry FOURNIERe3ded592013-12-06 15:36:54 +010011159 | prefix | beg | beg | beg | beg | beg |
Willy Tarreau74ca5042013-06-11 23:12:07 +020011160 +----------------------+---------+---------+---------+---------+---------+
Thierry FOURNIERe3ded592013-12-06 15:36:54 +010011161 | suffix | end | end | end | end | end |
Willy Tarreau74ca5042013-06-11 23:12:07 +020011162 +----------------------+---------+---------+---------+---------+---------+
Thierry FOURNIERe3ded592013-12-06 15:36:54 +010011163 | substring | sub | sub | sub | sub | sub |
Willy Tarreau74ca5042013-06-11 23:12:07 +020011164 +----------------------+---------+---------+---------+---------+---------+
Thierry FOURNIERe3ded592013-12-06 15:36:54 +010011165 | subdir | dir | dir | dir | dir | dir |
Willy Tarreau74ca5042013-06-11 23:12:07 +020011166 +----------------------+---------+---------+---------+---------+---------+
Thierry FOURNIERe3ded592013-12-06 15:36:54 +010011167 | domain | dom | dom | dom | dom | dom |
Willy Tarreau74ca5042013-06-11 23:12:07 +020011168 +----------------------+---------+---------+---------+---------+---------+
Thierry FOURNIERe3ded592013-12-06 15:36:54 +010011169 | regex | reg | reg | reg | reg | reg |
Willy Tarreau74ca5042013-06-11 23:12:07 +020011170 +----------------------+---------+---------+---------+---------+---------+
11171 | hex block | | | | bin | bin |
11172 +----------------------+---------+---------+---------+---------+---------+
Willy Tarreau6a06a402007-07-15 20:15:28 +020011173
11174
Willy Tarreau74ca5042013-06-11 23:12:07 +0200111757.1.1. Matching booleans
11176------------------------
11177
11178In order to match a boolean, no value is needed and all values are ignored.
11179Boolean matching is used by default for all fetch methods of type "boolean".
11180When boolean matching is used, the fetched value is returned as-is, which means
11181that a boolean "true" will always match and a boolean "false" will never match.
11182
11183Boolean matching may also be enforced using "-m bool" on fetch methods which
11184return an integer value. Then, integer value 0 is converted to the boolean
11185"false" and all other values are converted to "true".
11186
Willy Tarreau6a06a402007-07-15 20:15:28 +020011187
Willy Tarreau74ca5042013-06-11 23:12:07 +0200111887.1.2. Matching integers
11189------------------------
11190
11191Integer matching applies by default to integer fetch methods. It can also be
11192enforced on boolean fetches using "-m int". In this case, "false" is converted
11193to the integer 0, and "true" is converted to the integer 1.
11194
11195Integer matching also supports integer ranges and operators. Note that integer
11196matching only applies to positive values. A range is a value expressed with a
11197lower and an upper bound separated with a colon, both of which may be omitted.
Willy Tarreau6a06a402007-07-15 20:15:28 +020011198
11199For instance, "1024:65535" is a valid range to represent a range of
11200unprivileged ports, and "1024:" would also work. "0:1023" is a valid
11201representation of privileged ports, and ":1023" would also work.
11202
Willy Tarreau62644772008-07-16 18:36:06 +020011203As a special case, some ACL functions support decimal numbers which are in fact
11204two integers separated by a dot. This is used with some version checks for
11205instance. All integer properties apply to those decimal numbers, including
11206ranges and operators.
11207
Willy Tarreau6a06a402007-07-15 20:15:28 +020011208For an easier usage, comparison operators are also supported. Note that using
Willy Tarreau0ba27502007-12-24 16:55:16 +010011209operators with ranges does not make much sense and is strongly discouraged.
11210Similarly, it does not make much sense to perform order comparisons with a set
11211of values.
Willy Tarreau6a06a402007-07-15 20:15:28 +020011212
Willy Tarreau0ba27502007-12-24 16:55:16 +010011213Available operators for integer matching are :
Willy Tarreau6a06a402007-07-15 20:15:28 +020011214
11215 eq : true if the tested value equals at least one value
11216 ge : true if the tested value is greater than or equal to at least one value
11217 gt : true if the tested value is greater than at least one value
11218 le : true if the tested value is less than or equal to at least one value
11219 lt : true if the tested value is less than at least one value
11220
Willy Tarreau0ba27502007-12-24 16:55:16 +010011221For instance, the following ACL matches any negative Content-Length header :
Willy Tarreau6a06a402007-07-15 20:15:28 +020011222
11223 acl negative-length hdr_val(content-length) lt 0
11224
Willy Tarreau62644772008-07-16 18:36:06 +020011225This one matches SSL versions between 3.0 and 3.1 (inclusive) :
11226
11227 acl sslv3 req_ssl_ver 3:3.1
11228
Willy Tarreau6a06a402007-07-15 20:15:28 +020011229
Willy Tarreau74ca5042013-06-11 23:12:07 +0200112307.1.3. Matching strings
11231-----------------------
11232
11233String matching applies to string or binary fetch methods, and exists in 6
11234different forms :
11235
11236 - exact match (-m str) : the extracted string must exactly match the
11237 patterns ;
11238
11239 - substring match (-m sub) : the patterns are looked up inside the
11240 extracted string, and the ACL matches if any of them is found inside ;
11241
11242 - prefix match (-m beg) : the patterns are compared with the beginning of
11243 the extracted string, and the ACL matches if any of them matches.
11244
11245 - suffix match (-m end) : the patterns are compared with the end of the
11246 extracted string, and the ACL matches if any of them matches.
11247
11248 - subdir match (-m sub) : the patterns are looked up inside the extracted
11249 string, delimited with slashes ("/"), and the ACL matches if any of them
11250 matches.
11251
11252 - domain match (-m dom) : the patterns are looked up inside the extracted
11253 string, delimited with dots ("."), and the ACL matches if any of them
11254 matches.
Willy Tarreau6a06a402007-07-15 20:15:28 +020011255
11256String matching applies to verbatim strings as they are passed, with the
11257exception of the backslash ("\") which makes it possible to escape some
11258characters such as the space. If the "-i" flag is passed before the first
11259string, then the matching will be performed ignoring the case. In order
11260to match the string "-i", either set it second, or pass the "--" flag
Willy Tarreau0ba27502007-12-24 16:55:16 +010011261before the first string. Same applies of course to match the string "--".
Willy Tarreau6a06a402007-07-15 20:15:28 +020011262
11263
Willy Tarreau74ca5042013-06-11 23:12:07 +0200112647.1.4. Matching regular expressions (regexes)
11265---------------------------------------------
Willy Tarreau6a06a402007-07-15 20:15:28 +020011266
11267Just like with string matching, regex matching applies to verbatim strings as
11268they are passed, with the exception of the backslash ("\") which makes it
11269possible to escape some characters such as the space. If the "-i" flag is
11270passed before the first regex, then the matching will be performed ignoring
11271the case. In order to match the string "-i", either set it second, or pass
Willy Tarreau0ba27502007-12-24 16:55:16 +010011272the "--" flag before the first string. Same principle applies of course to
11273match the string "--".
Willy Tarreau6a06a402007-07-15 20:15:28 +020011274
11275
Willy Tarreau74ca5042013-06-11 23:12:07 +0200112767.1.5. Matching arbitrary data blocks
11277-------------------------------------
11278
11279It is possible to match some extracted samples against a binary block which may
11280not safely be represented as a string. For this, the patterns must be passed as
11281a series of hexadecimal digits in an even number, when the match method is set
11282to binary. Each sequence of two digits will represent a byte. The hexadecimal
11283digits may be used upper or lower case.
11284
11285Example :
11286 # match "Hello\n" in the input stream (\x48 \x65 \x6c \x6c \x6f \x0a)
11287 acl hello payload(0,6) -m bin 48656c6c6f0a
11288
11289
112907.1.6. Matching IPv4 and IPv6 addresses
11291---------------------------------------
Willy Tarreau6a06a402007-07-15 20:15:28 +020011292
11293IPv4 addresses values can be specified either as plain addresses or with a
11294netmask appended, in which case the IPv4 address matches whenever it is
11295within the network. Plain addresses may also be replaced with a resolvable
Willy Tarreaud2a4aa22008-01-31 15:28:22 +010011296host name, but this practice is generally discouraged as it makes it more
Willy Tarreau0ba27502007-12-24 16:55:16 +010011297difficult to read and debug configurations. If hostnames are used, you should
11298at least ensure that they are present in /etc/hosts so that the configuration
11299does not depend on any random DNS match at the moment the configuration is
11300parsed.
Willy Tarreau6a06a402007-07-15 20:15:28 +020011301
Willy Tarreauceb4ac92012-04-28 00:41:46 +020011302IPv6 may be entered in their usual form, with or without a netmask appended.
11303Only bit counts are accepted for IPv6 netmasks. In order to avoid any risk of
11304trouble with randomly resolved IP addresses, host names are never allowed in
11305IPv6 patterns.
11306
11307HAProxy is also able to match IPv4 addresses with IPv6 addresses in the
11308following situations :
11309 - tested address is IPv4, pattern address is IPv4, the match applies
11310 in IPv4 using the supplied mask if any.
11311 - tested address is IPv6, pattern address is IPv6, the match applies
11312 in IPv6 using the supplied mask if any.
11313 - tested address is IPv6, pattern address is IPv4, the match applies in IPv4
11314 using the pattern's mask if the IPv6 address matches with 2002:IPV4::,
11315 ::IPV4 or ::ffff:IPV4, otherwise it fails.
11316 - tested address is IPv4, pattern address is IPv6, the IPv4 address is first
11317 converted to IPv6 by prefixing ::ffff: in front of it, then the match is
11318 applied in IPv6 using the supplied IPv6 mask.
11319
Willy Tarreau74ca5042013-06-11 23:12:07 +020011320
113217.2. Using ACLs to form conditions
11322----------------------------------
11323
11324Some actions are only performed upon a valid condition. A condition is a
11325combination of ACLs with operators. 3 operators are supported :
11326
11327 - AND (implicit)
11328 - OR (explicit with the "or" keyword or the "||" operator)
11329 - Negation with the exclamation mark ("!")
Willy Tarreau6a06a402007-07-15 20:15:28 +020011330
Willy Tarreau74ca5042013-06-11 23:12:07 +020011331A condition is formed as a disjunctive form:
Willy Tarreau6a06a402007-07-15 20:15:28 +020011332
Willy Tarreau74ca5042013-06-11 23:12:07 +020011333 [!]acl1 [!]acl2 ... [!]acln { or [!]acl1 [!]acl2 ... [!]acln } ...
Willy Tarreaubef91e72013-03-31 23:14:46 +020011334
Willy Tarreau74ca5042013-06-11 23:12:07 +020011335Such conditions are generally used after an "if" or "unless" statement,
11336indicating when the condition will trigger the action.
Willy Tarreaubef91e72013-03-31 23:14:46 +020011337
Willy Tarreau74ca5042013-06-11 23:12:07 +020011338For instance, to block HTTP requests to the "*" URL with methods other than
11339"OPTIONS", as well as POST requests without content-length, and GET or HEAD
11340requests with a content-length greater than 0, and finally every request which
11341is not either GET/HEAD/POST/OPTIONS !
11342
11343 acl missing_cl hdr_cnt(Content-length) eq 0
11344 block if HTTP_URL_STAR !METH_OPTIONS || METH_POST missing_cl
11345 block if METH_GET HTTP_CONTENT
11346 block unless METH_GET or METH_POST or METH_OPTIONS
11347
11348To select a different backend for requests to static contents on the "www" site
11349and to every request on the "img", "video", "download" and "ftp" hosts :
11350
11351 acl url_static path_beg /static /images /img /css
11352 acl url_static path_end .gif .png .jpg .css .js
11353 acl host_www hdr_beg(host) -i www
11354 acl host_static hdr_beg(host) -i img. video. download. ftp.
11355
11356 # now use backend "static" for all static-only hosts, and for static urls
11357 # of host "www". Use backend "www" for the rest.
11358 use_backend static if host_static or host_www url_static
11359 use_backend www if host_www
11360
11361It is also possible to form rules using "anonymous ACLs". Those are unnamed ACL
11362expressions that are built on the fly without needing to be declared. They must
11363be enclosed between braces, with a space before and after each brace (because
11364the braces must be seen as independent words). Example :
11365
11366 The following rule :
11367
11368 acl missing_cl hdr_cnt(Content-length) eq 0
11369 block if METH_POST missing_cl
11370
11371 Can also be written that way :
11372
11373 block if METH_POST { hdr_cnt(Content-length) eq 0 }
11374
11375It is generally not recommended to use this construct because it's a lot easier
11376to leave errors in the configuration when written that way. However, for very
11377simple rules matching only one source IP address for instance, it can make more
11378sense to use them than to declare ACLs with random names. Another example of
11379good use is the following :
11380
11381 With named ACLs :
11382
11383 acl site_dead nbsrv(dynamic) lt 2
11384 acl site_dead nbsrv(static) lt 2
11385 monitor fail if site_dead
11386
11387 With anonymous ACLs :
11388
11389 monitor fail if { nbsrv(dynamic) lt 2 } || { nbsrv(static) lt 2 }
11390
11391See section 4.2 for detailed help on the "block" and "use_backend" keywords.
11392
11393
113947.3. Fetching samples
11395---------------------
11396
11397Historically, sample fetch methods were only used to retrieve data to match
11398against patterns using ACLs. With the arrival of stick-tables, a new class of
11399sample fetch methods was created, most often sharing the same syntax as their
11400ACL counterpart. These sample fetch methods are also known as "fetches". As
11401of now, ACLs and fetches have converged. All ACL fetch methods have been made
11402available as fetch methods, and ACLs may use any sample fetch method as well.
11403
11404This section details all available sample fetch methods and their output type.
11405Some sample fetch methods have deprecated aliases that are used to maintain
11406compatibility with existing configurations. They are then explicitly marked as
11407deprecated and should not be used in new setups.
11408
11409The ACL derivatives are also indicated when available, with their respective
11410matching methods. These ones all have a well defined default pattern matching
11411method, so it is never necessary (though allowed) to pass the "-m" option to
11412indicate how the sample will be matched using ACLs.
11413
11414As indicated in the sample type versus matching compatibility matrix above,
11415when using a generic sample fetch method in an ACL, the "-m" option is
11416mandatory unless the sample type is one of boolean, integer, IPv4 or IPv6. When
11417the same keyword exists as an ACL keyword and as a standard fetch method, the
11418ACL engine will automatically pick the ACL-only one by default.
11419
11420Some of these keywords support one or multiple mandatory arguments, and one or
11421multiple optional arguments. These arguments are strongly typed and are checked
11422when the configuration is parsed so that there is no risk of running with an
11423incorrect argument (eg: an unresolved backend name). Fetch function arguments
11424are passed between parenthesis and are delimited by commas. When an argument
11425is optional, it will be indicated below between square brackets ('[ ]'). When
11426all arguments are optional, the parenthesis may be omitted.
11427
11428Thus, the syntax of a standard sample fetch method is one of the following :
11429 - name
11430 - name(arg1)
11431 - name(arg1,arg2)
11432
Thierry FOURNIER060762e2014-04-23 13:29:15 +020011433
114347.3.1. Converters
11435-----------------
11436
Willy Tarreaue6b11e42013-11-26 19:02:32 +010011437Sample fetch methods may be combined with transformations to be applied on top
11438of the fetched sample (also called "converters"). These combinations form what
11439is called "sample expressions" and the result is a "sample". Initially this
11440was only supported by "stick on" and "stick store-request" directives but this
11441has now be extended to all places where samples may be used (acls, log-format,
11442unique-id-format, add-header, ...).
11443
11444These transformations are enumerated as a series of specific keywords after the
11445sample fetch method. These keywords may equally be appended immediately after
11446the fetch keyword's argument, delimited by a comma. These keywords can also
11447support some arguments (eg: a netmask) which must be passed in parenthesis.
Willy Tarreau0ba27502007-12-24 16:55:16 +010011448
Willy Tarreau97707872015-01-27 15:12:13 +010011449A certain category of converters are bitwise and arithmetic operators which
11450support performing basic operations on integers. Some bitwise operations are
11451supported (and, or, xor, cpl) and some arithmetic operations are supported
11452(add, sub, mul, div, mod, neg). Some comparators are provided (odd, even, not,
11453bool) which make it possible to report a match without having to write an ACL.
11454
Willy Tarreau74ca5042013-06-11 23:12:07 +020011455The currently available list of transformation keywords include :
Willy Tarreau0ba27502007-12-24 16:55:16 +010011456
Willy Tarreau97707872015-01-27 15:12:13 +010011457add(<value>)
Thierry FOURNIER07ee64e2015-07-06 23:43:03 +020011458 Adds <value> to the input value of type signed integer, and returns the
Thierry FOURNIER5d86fae2015-07-07 21:10:16 +020011459 result as a signed integer. <value> can be a numeric value or a variable
11460 name. The name of the variable starts by an indication about its scope. The
11461 allowed scopes are:
11462 "sess" : the variable is shared with all the session,
11463 "txn" : the variable is shared with all the transaction (request and
11464 response),
11465 "req" : the variable is shared only during the request processing,
11466 "res" : the variable is shared only during the response processing.
11467 This prefix is followed by a name. The separator is a '.'. The name may only
11468 contain characters 'a-z', 'A-Z', '0-9' and '_'.
Willy Tarreau97707872015-01-27 15:12:13 +010011469
11470and(<value>)
Thierry FOURNIER07ee64e2015-07-06 23:43:03 +020011471 Performs a bitwise "AND" between <value> and the input value of type signed
Thierry FOURNIER5d86fae2015-07-07 21:10:16 +020011472 integer, and returns the result as an signed integer. <value> can be a
11473 numeric value or a variable name. The name of the variable starts by an
11474 indication about its scope. The allowed scopes are:
11475 "sess" : the variable is shared with all the session,
11476 "txn" : the variable is shared with all the transaction (request and
11477 response),
11478 "req" : the variable is shared only during the request processing,
11479 "res" : the variable is shared only during the response processing.
11480 This prefix is followed by a name. The separator is a '.'. The name may only
11481 contain characters 'a-z', 'A-Z', '0-9' and '_'.
Willy Tarreau97707872015-01-27 15:12:13 +010011482
Emeric Brun53d1a982014-04-30 18:21:37 +020011483base64
11484 Converts a binary input sample to a base64 string. It is used to log or
11485 transfer binary content in a way that can be reliably transferred (eg:
11486 an SSL ID can be copied in a header).
11487
Willy Tarreau97707872015-01-27 15:12:13 +010011488bool
Thierry FOURNIER07ee64e2015-07-06 23:43:03 +020011489 Returns a boolean TRUE if the input value of type signed integer is
Willy Tarreau97707872015-01-27 15:12:13 +010011490 non-null, otherwise returns FALSE. Used in conjunction with and(), it can be
11491 used to report true/false for bit testing on input values (eg: verify the
11492 presence of a flag).
11493
Emeric Brun54c4ac82014-11-03 15:32:43 +010011494bytes(<offset>[,<length>])
11495 Extracts some bytes from an input binary sample. The result is a binary
11496 sample starting at an offset (in bytes) of the original sample and
11497 optionnaly truncated at the given length.
11498
Willy Tarreau97707872015-01-27 15:12:13 +010011499cpl
Thierry FOURNIER07ee64e2015-07-06 23:43:03 +020011500 Takes the input value of type signed integer, applies a ones-complement
11501 (flips all bits) and returns the result as an signed integer.
Willy Tarreau97707872015-01-27 15:12:13 +010011502
Willy Tarreau80599772015-01-20 19:35:24 +010011503crc32([<avalanche>])
11504 Hashes a binary input sample into an unsigned 32-bit quantity using the CRC32
11505 hash function. Optionally, it is possible to apply a full avalanche hash
11506 function to the output if the optional <avalanche> argument equals 1. This
11507 converter uses the same functions as used by the various hash-based load
11508 balancing algorithms, so it will provide exactly the same results. It is
11509 provided for compatibility with other software which want a CRC32 to be
11510 computed on some input keys, so it follows the most common implementation as
11511 found in Ethernet, Gzip, PNG, etc... It is slower than the other algorithms
11512 but may provide a better or at least less predictable distribution. It must
11513 not be used for security purposes as a 32-bit hash is trivial to break. See
11514 also "djb2", "sdbm", "wt6" and the "hash-type" directive.
11515
David Carlier29b3ca32015-09-25 14:09:21 +010011516da-csv-conv(<prop>[,<prop>*])
David Carlier4542b102015-06-01 13:54:29 +020011517 Asks the DeviceAtlas converter to identify the User Agent string passed on
11518 input, and to emit a string made of the concatenation of the properties
11519 enumerated in argument, delimited by the separator defined by the global
11520 keyword "deviceatlas-property-separator", or by default the pipe character
11521 ('|'). There's a limit of 5 different properties imposed by the haproxy
11522 configuration language.
11523
11524 Example:
11525 frontend www
Cyril Bonté307ee1e2015-09-28 23:16:06 +020011526 bind *:8881
11527 default_backend servers
11528 http-request set-header X-DeviceAtlas-Data %[req.fhdr(User-Agent),da-csv(primaryHardwareType,osName,osVersion,browserName,browserVersion)]
David Carlier4542b102015-06-01 13:54:29 +020011529
Thierry FOURNIER9687c772015-05-07 15:46:29 +020011530debug
11531 This converter is used as debug tool. It dumps on screen the content and the
11532 type of the input sample. The sample is returned as is on its output. This
11533 converter only exists when haproxy was built with debugging enabled.
11534
Willy Tarreau97707872015-01-27 15:12:13 +010011535div(<value>)
Thierry FOURNIER07ee64e2015-07-06 23:43:03 +020011536 Divides the input value of type signed integer by <value>, and returns the
11537 result as an signed integer. If <value> is null, the largest unsigned
Thierry FOURNIER5d86fae2015-07-07 21:10:16 +020011538 integer is returned (typically 2^63-1). <value> can be a numeric value or a
11539 variable name. The name of the variable starts by an indication about it
11540 scope. The scope allowed are:
11541 "sess" : the variable is shared with all the session,
11542 "txn" : the variable is shared with all the transaction (request and
11543 response),
11544 "req" : the variable is shared only during the request processing,
11545 "res" : the variable is shared only during the response processing.
11546 This prefix is followed by a name. The separator is a '.'. The name may only
11547 contain characters 'a-z', 'A-Z', '0-9' and '_'.
Willy Tarreau97707872015-01-27 15:12:13 +010011548
Willy Tarreau23ec4ca2014-07-15 20:15:37 +020011549djb2([<avalanche>])
11550 Hashes a binary input sample into an unsigned 32-bit quantity using the DJB2
11551 hash function. Optionally, it is possible to apply a full avalanche hash
11552 function to the output if the optional <avalanche> argument equals 1. This
11553 converter uses the same functions as used by the various hash-based load
11554 balancing algorithms, so it will provide exactly the same results. It is
11555 mostly intended for debugging, but can be used as a stick-table entry to
11556 collect rough statistics. It must not be used for security purposes as a
Willy Tarreau80599772015-01-20 19:35:24 +010011557 32-bit hash is trivial to break. See also "crc32", "sdbm", "wt6" and the
11558 "hash-type" directive.
Willy Tarreau23ec4ca2014-07-15 20:15:37 +020011559
Willy Tarreau97707872015-01-27 15:12:13 +010011560even
Thierry FOURNIER07ee64e2015-07-06 23:43:03 +020011561 Returns a boolean TRUE if the input value of type signed integer is even
Willy Tarreau97707872015-01-27 15:12:13 +010011562 otherwise returns FALSE. It is functionally equivalent to "not,and(1),bool".
11563
Emeric Brunf399b0d2014-11-03 17:07:03 +010011564field(<index>,<delimiters>)
11565 Extracts the substring at the given index considering given delimiters from
11566 an input string. Indexes start at 1 and delimiters are a string formatted
11567 list of chars.
11568
Thierry FOURNIER060762e2014-04-23 13:29:15 +020011569hex
11570 Converts a binary input sample to an hex string containing two hex digits per
11571 input byte. It is used to log or transfer hex dumps of some binary input data
11572 in a way that can be reliably transferred (eg: an SSL ID can be copied in a
11573 header).
Thierry FOURNIER2f49d6d2014-03-12 15:01:52 +010011574
Thierry FOURNIER060762e2014-04-23 13:29:15 +020011575http_date([<offset>])
11576 Converts an integer supposed to contain a date since epoch to a string
11577 representing this date in a format suitable for use in HTTP header fields. If
11578 an offset value is specified, then it is a number of seconds that is added to
11579 the date before the conversion is operated. This is particularly useful to
11580 emit Date header fields, Expires values in responses when combined with a
11581 positive offset, or Last-Modified values when the offset is negative.
Willy Tarreau74ca5042013-06-11 23:12:07 +020011582
Willy Tarreaud9f316a2014-07-10 14:03:38 +020011583in_table(<table>)
11584 Uses the string representation of the input sample to perform a look up in
11585 the specified table. If the key is not found in the table, a boolean false
11586 is returned. Otherwise a boolean true is returned. This can be used to verify
11587 the presence of a certain key in a table tracking some elements (eg: whether
11588 or not a source IP address or an Authorization header was already seen).
11589
Willy Tarreauffcb2e42014-07-10 16:29:08 +020011590ipmask(<mask>)
11591 Apply a mask to an IPv4 address, and use the result for lookups and storage.
11592 This can be used to make all hosts within a certain mask to share the same
11593 table entries and as such use the same server. The mask can be passed in
11594 dotted form (eg: 255.255.255.0) or in CIDR form (eg: 24).
11595
Thierry FOURNIER317e1c42014-08-12 10:20:47 +020011596json([<input-code>])
11597 Escapes the input string and produces an ASCII ouput string ready to use as a
11598 JSON string. The converter tries to decode the input string according to the
11599 <input-code> parameter. It can be "ascii", "utf8", "utf8s", "utf8"" or
11600 "utf8ps". The "ascii" decoder never fails. The "utf8" decoder detects 3 types
11601 of errors:
11602 - bad UTF-8 sequence (lone continuation byte, bad number of continuation
11603 bytes, ...)
11604 - invalid range (the decoded value is within a UTF-8 prohibited range),
11605 - code overlong (the value is encoded with more bytes than necessary).
11606
11607 The UTF-8 JSON encoding can produce a "too long value" error when the UTF-8
11608 character is greater than 0xffff because the JSON string escape specification
11609 only authorizes 4 hex digits for the value encoding. The UTF-8 decoder exists
11610 in 4 variants designated by a combination of two suffix letters : "p" for
11611 "permissive" and "s" for "silently ignore". The behaviors of the decoders
11612 are :
11613 - "ascii" : never fails ;
11614 - "utf8" : fails on any detected errors ;
11615 - "utf8s" : never fails, but removes characters corresponding to errors ;
11616 - "utf8p" : accepts and fixes the overlong errors, but fails on any other
11617 error ;
11618 - "utf8ps" : never fails, accepts and fixes the overlong errors, but removes
11619 characters corresponding to the other errors.
11620
11621 This converter is particularly useful for building properly escaped JSON for
11622 logging to servers which consume JSON-formated traffic logs.
11623
11624 Example:
11625 capture request header user-agent len 150
11626 capture request header Host len 15
11627 log-format {"ip":"%[src]","user-agent":"%[capture.req.hdr(1),json]"}
11628
11629 Input request from client 127.0.0.1:
11630 GET / HTTP/1.0
11631 User-Agent: Very "Ugly" UA 1/2
11632
11633 Output log:
11634 {"ip":"127.0.0.1","user-agent":"Very \"Ugly\" UA 1\/2"}
11635
Thierry FOURNIER060762e2014-04-23 13:29:15 +020011636language(<value>[,<default>])
11637 Returns the value with the highest q-factor from a list as extracted from the
11638 "accept-language" header using "req.fhdr". Values with no q-factor have a
11639 q-factor of 1. Values with a q-factor of 0 are dropped. Only values which
11640 belong to the list of semi-colon delimited <values> will be considered. The
11641 argument <value> syntax is "lang[;lang[;lang[;...]]]". If no value matches the
11642 given list and a default value is provided, it is returned. Note that language
11643 names may have a variant after a dash ('-'). If this variant is present in the
11644 list, it will be matched, but if it is not, only the base language is checked.
11645 The match is case-sensitive, and the output string is always one of those
11646 provided in arguments. The ordering of arguments is meaningless, only the
11647 ordering of the values in the request counts, as the first value among
11648 multiple sharing the same q-factor is used.
Thierry FOURNIERad903512014-04-11 17:51:01 +020011649
Thierry FOURNIER060762e2014-04-23 13:29:15 +020011650 Example :
Thierry FOURNIERad903512014-04-11 17:51:01 +020011651
Thierry FOURNIER060762e2014-04-23 13:29:15 +020011652 # this configuration switches to the backend matching a
11653 # given language based on the request :
Thierry FOURNIERad903512014-04-11 17:51:01 +020011654
Thierry FOURNIER060762e2014-04-23 13:29:15 +020011655 acl es req.fhdr(accept-language),language(es;fr;en) -m str es
11656 acl fr req.fhdr(accept-language),language(es;fr;en) -m str fr
11657 acl en req.fhdr(accept-language),language(es;fr;en) -m str en
11658 use_backend spanish if es
11659 use_backend french if fr
11660 use_backend english if en
11661 default_backend choose_your_language
Thierry FOURNIERad903512014-04-11 17:51:01 +020011662
Willy Tarreauffcb2e42014-07-10 16:29:08 +020011663lower
11664 Convert a string sample to lower case. This can only be placed after a string
11665 sample fetch function or after a transformation keyword returning a string
11666 type. The result is of type string.
11667
Willy Tarreau0dbfdba2014-07-10 16:37:47 +020011668ltime(<format>[,<offset>])
11669 Converts an integer supposed to contain a date since epoch to a string
11670 representing this date in local time using a format defined by the <format>
11671 string using strftime(3). The purpose is to allow any date format to be used
11672 in logs. An optional <offset> in seconds may be applied to the input date
11673 (positive or negative). See the strftime() man page for the format supported
11674 by your operating system. See also the utime converter.
11675
11676 Example :
11677
11678 # Emit two colons, one with the local time and another with ip:port
11679 # Eg: 20140710162350 127.0.0.1:57325
11680 log-format %[date,ltime(%Y%m%d%H%M%S)]\ %ci:%cp
11681
Thierry FOURNIER060762e2014-04-23 13:29:15 +020011682map(<map_file>[,<default_value>])
11683map_<match_type>(<map_file>[,<default_value>])
11684map_<match_type>_<output_type>(<map_file>[,<default_value>])
11685 Search the input value from <map_file> using the <match_type> matching method,
11686 and return the associated value converted to the type <output_type>. If the
11687 input value cannot be found in the <map_file>, the converter returns the
11688 <default_value>. If the <default_value> is not set, the converter fails and
11689 acts as if no input value could be fetched. If the <match_type> is not set, it
11690 defaults to "str". Likewise, if the <output_type> is not set, it defaults to
11691 "str". For convenience, the "map" keyword is an alias for "map_str" and maps a
11692 string to another string.
Thierry FOURNIERd5f624d2013-11-26 11:52:33 +010011693
Thierry FOURNIER060762e2014-04-23 13:29:15 +020011694 It is important to avoid overlapping between the keys : IP addresses and
11695 strings are stored in trees, so the first of the finest match will be used.
11696 Other keys are stored in lists, so the first matching occurrence will be used.
Thierry FOURNIERd5f624d2013-11-26 11:52:33 +010011697
Thierry FOURNIER060762e2014-04-23 13:29:15 +020011698 The following array contains the list of all map functions avalaible sorted by
11699 input type, match type and output type.
Thierry FOURNIERd5f624d2013-11-26 11:52:33 +010011700
Thierry FOURNIER060762e2014-04-23 13:29:15 +020011701 input type | match method | output type str | output type int | output type ip
11702 -----------+--------------+-----------------+-----------------+---------------
11703 str | str | map_str | map_str_int | map_str_ip
11704 -----------+--------------+-----------------+-----------------+---------------
Willy Tarreau787a4c02014-05-10 07:55:30 +020011705 str | beg | map_beg | map_beg_int | map_end_ip
11706 -----------+--------------+-----------------+-----------------+---------------
Thierry FOURNIER060762e2014-04-23 13:29:15 +020011707 str | sub | map_sub | map_sub_int | map_sub_ip
11708 -----------+--------------+-----------------+-----------------+---------------
11709 str | dir | map_dir | map_dir_int | map_dir_ip
11710 -----------+--------------+-----------------+-----------------+---------------
11711 str | dom | map_dom | map_dom_int | map_dom_ip
11712 -----------+--------------+-----------------+-----------------+---------------
11713 str | end | map_end | map_end_int | map_end_ip
11714 -----------+--------------+-----------------+-----------------+---------------
11715 str | reg | map_reg | map_reg_int | map_reg_ip
11716 -----------+--------------+-----------------+-----------------+---------------
11717 int | int | map_int | map_int_int | map_int_ip
11718 -----------+--------------+-----------------+-----------------+---------------
11719 ip | ip | map_ip | map_ip_int | map_ip_ip
11720 -----------+--------------+-----------------+-----------------+---------------
Thierry FOURNIERd5f624d2013-11-26 11:52:33 +010011721
Thierry FOURNIER060762e2014-04-23 13:29:15 +020011722 The file contains one key + value per line. Lines which start with '#' are
11723 ignored, just like empty lines. Leading tabs and spaces are stripped. The key
11724 is then the first "word" (series of non-space/tabs characters), and the value
11725 is what follows this series of space/tab till the end of the line excluding
11726 trailing spaces/tabs.
Thierry FOURNIERd5f624d2013-11-26 11:52:33 +010011727
Thierry FOURNIER060762e2014-04-23 13:29:15 +020011728 Example :
11729
11730 # this is a comment and is ignored
11731 2.22.246.0/23 United Kingdom \n
11732 <-><-----------><--><------------><---->
11733 | | | | `- trailing spaces ignored
11734 | | | `---------- value
11735 | | `-------------------- middle spaces ignored
11736 | `---------------------------- key
11737 `------------------------------------ leading spaces ignored
11738
Willy Tarreau97707872015-01-27 15:12:13 +010011739mod(<value>)
Thierry FOURNIER07ee64e2015-07-06 23:43:03 +020011740 Divides the input value of type signed integer by <value>, and returns the
11741 remainder as an signed integer. If <value> is null, then zero is returned.
Thierry FOURNIER5d86fae2015-07-07 21:10:16 +020011742 <value> can be a numeric value or a variable name. The name of the variable
11743 starts by an indication about its scope. The allowed scopes are:
11744 "sess" : the variable is shared with all the session,
11745 "txn" : the variable is shared with all the transaction (request and
11746 response),
11747 "req" : the variable is shared only during the request processing,
11748 "res" : the variable is shared only during the response processing.
11749 This prefix is followed by a name. The separator is a '.'. The name may only
11750 contain characters 'a-z', 'A-Z', '0-9' and '_'.
Willy Tarreau97707872015-01-27 15:12:13 +010011751
11752mul(<value>)
Thierry FOURNIER07ee64e2015-07-06 23:43:03 +020011753 Multiplies the input value of type signed integer by <value>, and returns
Thierry FOURNIER00c005c2015-07-08 01:10:21 +020011754 the product as an signed integer. In case of overflow, the largest possible
11755 value for the sign is returned so that the operation doesn't wrap around.
Thierry FOURNIER5d86fae2015-07-07 21:10:16 +020011756 <value> can be a numeric value or a variable name. The name of the variable
11757 starts by an indication about its scope. The allowed scopes are:
11758 "sess" : the variable is shared with all the session,
11759 "txn" : the variable is shared with all the transaction (request and
11760 response),
11761 "req" : the variable is shared only during the request processing,
11762 "res" : the variable is shared only during the response processing.
11763 This prefix is followed by a name. The separator is a '.'. The name may only
11764 contain characters 'a-z', 'A-Z', '0-9' and '_'.
Willy Tarreau97707872015-01-27 15:12:13 +010011765
11766neg
Thierry FOURNIER07ee64e2015-07-06 23:43:03 +020011767 Takes the input value of type signed integer, computes the opposite value,
11768 and returns the remainder as an signed integer. 0 is identity. This operator
11769 is provided for reversed subtracts : in order to subtract the input from a
11770 constant, simply perform a "neg,add(value)".
Willy Tarreau97707872015-01-27 15:12:13 +010011771
11772not
Thierry FOURNIER07ee64e2015-07-06 23:43:03 +020011773 Returns a boolean FALSE if the input value of type signed integer is
Willy Tarreau97707872015-01-27 15:12:13 +010011774 non-null, otherwise returns TRUE. Used in conjunction with and(), it can be
11775 used to report true/false for bit testing on input values (eg: verify the
11776 absence of a flag).
11777
11778odd
Thierry FOURNIER07ee64e2015-07-06 23:43:03 +020011779 Returns a boolean TRUE if the input value of type signed integer is odd
Willy Tarreau97707872015-01-27 15:12:13 +010011780 otherwise returns FALSE. It is functionally equivalent to "and(1),bool".
11781
11782or(<value>)
Thierry FOURNIER07ee64e2015-07-06 23:43:03 +020011783 Performs a bitwise "OR" between <value> and the input value of type signed
Thierry FOURNIER5d86fae2015-07-07 21:10:16 +020011784 integer, and returns the result as an signed integer. <value> can be a
11785 numeric value or a variable name. The name of the variable starts by an
11786 indication about its scope. The allowed scopes are:
11787 "sess" : the variable is shared with all the session,
11788 "txn" : the variable is shared with all the transaction (request and
11789 response),
11790 "req" : the variable is shared only during the request processing,
11791 "res" : the variable is shared only during the response processing.
11792 This prefix is followed by a name. The separator is a '.'. The name may only
11793 contain characters 'a-z', 'A-Z', '0-9' and '_'.
Willy Tarreau97707872015-01-27 15:12:13 +010011794
Willy Tarreauc4dc3502015-01-23 20:39:28 +010011795regsub(<regex>,<subst>[,<flags>])
Willy Tarreau7eda8492015-01-20 19:47:06 +010011796 Applies a regex-based substitution to the input string. It does the same
11797 operation as the well-known "sed" utility with "s/<regex>/<subst>/". By
11798 default it will replace in the input string the first occurrence of the
11799 largest part matching the regular expression <regex> with the substitution
11800 string <subst>. It is possible to replace all occurrences instead by adding
11801 the flag "g" in the third argument <flags>. It is also possible to make the
11802 regex case insensitive by adding the flag "i" in <flags>. Since <flags> is a
11803 string, it is made up from the concatenation of all desired flags. Thus if
11804 both "i" and "g" are desired, using "gi" or "ig" will have the same effect.
11805 It is important to note that due to the current limitations of the
11806 configuration parser, some characters such as closing parenthesis or comma
11807 are not possible to use in the arguments. The first use of this converter is
11808 to replace certain characters or sequence of characters with other ones.
11809
11810 Example :
11811
11812 # de-duplicate "/" in header "x-path".
11813 # input: x-path: /////a///b/c/xzxyz/
11814 # output: x-path: /a/b/c/xzxyz/
11815 http-request set-header x-path %[hdr(x-path),regsub(/+,/,g)]
11816
Thierry FOURNIER35ab2752015-05-28 13:22:03 +020011817capture-req(<id>)
11818 Capture the string entry in the request slot <id> and returns the entry as
11819 is. If the slot doesn't exist, the capture fails silently.
11820
11821 See also: "declare capture", "http-request capture",
11822 "http-response capture", "req.hdr.capture" and
11823 "res.hdr.capture" (sample fetches).
11824
11825capture-res(<id>)
11826 Capture the string entry in the response slot <id> and returns the entry as
11827 is. If the slot doesn't exist, the capture fails silently.
11828
11829 See also: "declare capture", "http-request capture",
11830 "http-response capture", "req.hdr.capture" and
11831 "res.hdr.capture" (sample fetches).
11832
Willy Tarreau23ec4ca2014-07-15 20:15:37 +020011833sdbm([<avalanche>])
11834 Hashes a binary input sample into an unsigned 32-bit quantity using the SDBM
11835 hash function. Optionally, it is possible to apply a full avalanche hash
11836 function to the output if the optional <avalanche> argument equals 1. This
11837 converter uses the same functions as used by the various hash-based load
11838 balancing algorithms, so it will provide exactly the same results. It is
11839 mostly intended for debugging, but can be used as a stick-table entry to
11840 collect rough statistics. It must not be used for security purposes as a
Willy Tarreau80599772015-01-20 19:35:24 +010011841 32-bit hash is trivial to break. See also "crc32", "djb2", "wt6" and the
11842 "hash-type" directive.
Willy Tarreau23ec4ca2014-07-15 20:15:37 +020011843
Thierry FOURNIER4834bc72015-06-06 19:29:07 +020011844set-var(<var name>)
11845 Sets a variable with the input content and return the content on the output as
11846 is. The variable keep the value and the associated input type. The name of the
11847 variable starts by an indication about it scope. The scope allowed are:
11848 "sess" : the variable is shared with all the session,
11849 "txn" : the variable is shared with all the transaction (request and
11850 response),
11851 "req" : the variable is shared only during the request processing,
11852 "res" : the variable is shared only during the response processing.
11853 This prefix is followed by a name. The separator is a '.'. The name may only
11854 contain characters 'a-z', 'A-Z', '0-9' and '_'.
11855
Willy Tarreau97707872015-01-27 15:12:13 +010011856sub(<value>)
Thierry FOURNIER07ee64e2015-07-06 23:43:03 +020011857 Subtracts <value> from the input value of type signed integer, and returns
11858 the result as an signed integer. Note: in order to subtract the input from
Thierry FOURNIER5d86fae2015-07-07 21:10:16 +020011859 a constant, simply perform a "neg,add(value)". <value> can be a numeric value
11860 or a variable name. The name of the variable starts by an indication about its
11861 scope. The allowed scopes are:
11862 "sess" : the variable is shared with all the session,
11863 "txn" : the variable is shared with all the transaction (request and
11864 response),
11865 "req" : the variable is shared only during the request processing,
11866 "res" : the variable is shared only during the response processing.
11867 This prefix is followed by a name. The separator is a '.'. The name may only
11868 contain characters 'a-z', 'A-Z', '0-9' and '_'.
Willy Tarreau97707872015-01-27 15:12:13 +010011869
Willy Tarreaud9f316a2014-07-10 14:03:38 +020011870table_bytes_in_rate(<table>)
11871 Uses the string representation of the input sample to perform a look up in
11872 the specified table. If the key is not found in the table, integer value zero
11873 is returned. Otherwise the converter returns the average client-to-server
11874 bytes rate associated with the input sample in the designated table, measured
11875 in amount of bytes over the period configured in the table. See also the
11876 sc_bytes_in_rate sample fetch keyword.
11877
11878
11879table_bytes_out_rate(<table>)
11880 Uses the string representation of the input sample to perform a look up in
11881 the specified table. If the key is not found in the table, integer value zero
11882 is returned. Otherwise the converter returns the average server-to-client
11883 bytes rate associated with the input sample in the designated table, measured
11884 in amount of bytes over the period configured in the table. See also the
11885 sc_bytes_out_rate sample fetch keyword.
11886
11887table_conn_cnt(<table>)
11888 Uses the string representation of the input sample to perform a look up in
11889 the specified table. If the key is not found in the table, integer value zero
11890 is returned. Otherwise the converter returns the cumulated amount of incoming
11891 connections associated with the input sample in the designated table. See
11892 also the sc_conn_cnt sample fetch keyword.
11893
11894table_conn_cur(<table>)
11895 Uses the string representation of the input sample to perform a look up in
11896 the specified table. If the key is not found in the table, integer value zero
11897 is returned. Otherwise the converter returns the current amount of concurrent
11898 tracked connections associated with the input sample in the designated table.
11899 See also the sc_conn_cur sample fetch keyword.
11900
11901table_conn_rate(<table>)
11902 Uses the string representation of the input sample to perform a look up in
11903 the specified table. If the key is not found in the table, integer value zero
11904 is returned. Otherwise the converter returns the average incoming connection
11905 rate associated with the input sample in the designated table. See also the
11906 sc_conn_rate sample fetch keyword.
11907
Thierry FOURNIER236657b2015-08-19 08:25:14 +020011908table_gpt0(<table>)
11909 Uses the string representation of the input sample to perform a look up in
11910 the specified table. If the key is not found in the table, boolean value zero
11911 is returned. Otherwise the converter returns the current value of the first
11912 general purpose tag associated with the input sample in the designated table.
11913 See also the sc_get_gpt0 sample fetch keyword.
11914
Willy Tarreaud9f316a2014-07-10 14:03:38 +020011915table_gpc0(<table>)
11916 Uses the string representation of the input sample to perform a look up in
11917 the specified table. If the key is not found in the table, integer value zero
11918 is returned. Otherwise the converter returns the current value of the first
11919 general purpose counter associated with the input sample in the designated
11920 table. See also the sc_get_gpc0 sample fetch keyword.
11921
11922table_gpc0_rate(<table>)
11923 Uses the string representation of the input sample to perform a look up in
11924 the specified table. If the key is not found in the table, integer value zero
11925 is returned. Otherwise the converter returns the frequency which the gpc0
11926 counter was incremented over the configured period in the table, associated
11927 with the input sample in the designated table. See also the sc_get_gpc0_rate
11928 sample fetch keyword.
11929
11930table_http_err_cnt(<table>)
11931 Uses the string representation of the input sample to perform a look up in
11932 the specified table. If the key is not found in the table, integer value zero
11933 is returned. Otherwise the converter returns the cumulated amount of HTTP
11934 errors associated with the input sample in the designated table. See also the
11935 sc_http_err_cnt sample fetch keyword.
11936
11937table_http_err_rate(<table>)
11938 Uses the string representation of the input sample to perform a look up in
11939 the specified table. If the key is not found in the table, integer value zero
11940 is returned. Otherwise the average rate of HTTP errors associated with the
11941 input sample in the designated table, measured in amount of errors over the
11942 period configured in the table. See also the sc_http_err_rate sample fetch
11943 keyword.
11944
11945table_http_req_cnt(<table>)
11946 Uses the string representation of the input sample to perform a look up in
11947 the specified table. If the key is not found in the table, integer value zero
11948 is returned. Otherwise the converter returns the cumulated amount of HTTP
11949 requests associated with the input sample in the designated table. See also
11950 the sc_http_req_cnt sample fetch keyword.
11951
11952table_http_req_rate(<table>)
11953 Uses the string representation of the input sample to perform a look up in
11954 the specified table. If the key is not found in the table, integer value zero
11955 is returned. Otherwise the average rate of HTTP requests associated with the
11956 input sample in the designated table, measured in amount of requests over the
11957 period configured in the table. See also the sc_http_req_rate sample fetch
11958 keyword.
11959
11960table_kbytes_in(<table>)
11961 Uses the string representation of the input sample to perform a look up in
11962 the specified table. If the key is not found in the table, integer value zero
11963 is returned. Otherwise the converter returns the cumulated amount of client-
11964 to-server data associated with the input sample in the designated table,
11965 measured in kilobytes. The test is currently performed on 32-bit integers,
11966 which limits values to 4 terabytes. See also the sc_kbytes_in sample fetch
11967 keyword.
11968
11969table_kbytes_out(<table>)
11970 Uses the string representation of the input sample to perform a look up in
11971 the specified table. If the key is not found in the table, integer value zero
11972 is returned. Otherwise the converter returns the cumulated amount of server-
11973 to-client data associated with the input sample in the designated table,
11974 measured in kilobytes. The test is currently performed on 32-bit integers,
11975 which limits values to 4 terabytes. See also the sc_kbytes_out sample fetch
11976 keyword.
11977
11978table_server_id(<table>)
11979 Uses the string representation of the input sample to perform a look up in
11980 the specified table. If the key is not found in the table, integer value zero
11981 is returned. Otherwise the converter returns the server ID associated with
11982 the input sample in the designated table. A server ID is associated to a
11983 sample by a "stick" rule when a connection to a server succeeds. A server ID
11984 zero means that no server is associated with this key.
11985
11986table_sess_cnt(<table>)
11987 Uses the string representation of the input sample to perform a look up in
11988 the specified table. If the key is not found in the table, integer value zero
11989 is returned. Otherwise the converter returns the cumulated amount of incoming
11990 sessions associated with the input sample in the designated table. Note that
11991 a session here refers to an incoming connection being accepted by the
11992 "tcp-request connection" rulesets. See also the sc_sess_cnt sample fetch
11993 keyword.
11994
11995table_sess_rate(<table>)
11996 Uses the string representation of the input sample to perform a look up in
11997 the specified table. If the key is not found in the table, integer value zero
11998 is returned. Otherwise the converter returns the average incoming session
11999 rate associated with the input sample in the designated table. Note that a
12000 session here refers to an incoming connection being accepted by the
12001 "tcp-request connection" rulesets. See also the sc_sess_rate sample fetch
12002 keyword.
12003
12004table_trackers(<table>)
12005 Uses the string representation of the input sample to perform a look up in
12006 the specified table. If the key is not found in the table, integer value zero
12007 is returned. Otherwise the converter returns the current amount of concurrent
12008 connections tracking the same key as the input sample in the designated
12009 table. It differs from table_conn_cur in that it does not rely on any stored
12010 information but on the table's reference count (the "use" value which is
12011 returned by "show table" on the CLI). This may sometimes be more suited for
12012 layer7 tracking. It can be used to tell a server how many concurrent
12013 connections there are from a given address for example. See also the
12014 sc_trackers sample fetch keyword.
12015
Willy Tarreauffcb2e42014-07-10 16:29:08 +020012016upper
12017 Convert a string sample to upper case. This can only be placed after a string
12018 sample fetch function or after a transformation keyword returning a string
12019 type. The result is of type string.
12020
Thierry FOURNIER82ff3c92015-05-07 15:46:20 +020012021url_dec
12022 Takes an url-encoded string provided as input and returns the decoded
12023 version as output. The input and the output are of type string.
12024
Willy Tarreau0dbfdba2014-07-10 16:37:47 +020012025utime(<format>[,<offset>])
12026 Converts an integer supposed to contain a date since epoch to a string
12027 representing this date in UTC time using a format defined by the <format>
12028 string using strftime(3). The purpose is to allow any date format to be used
12029 in logs. An optional <offset> in seconds may be applied to the input date
12030 (positive or negative). See the strftime() man page for the format supported
12031 by your operating system. See also the ltime converter.
12032
12033 Example :
12034
12035 # Emit two colons, one with the UTC time and another with ip:port
12036 # Eg: 20140710162350 127.0.0.1:57325
12037 log-format %[date,utime(%Y%m%d%H%M%S)]\ %ci:%cp
12038
Emeric Brunc9a0f6d2014-11-25 14:09:01 +010012039word(<index>,<delimiters>)
12040 Extracts the nth word considering given delimiters from an input string.
12041 Indexes start at 1 and delimiters are a string formatted list of chars.
12042
Willy Tarreau23ec4ca2014-07-15 20:15:37 +020012043wt6([<avalanche>])
12044 Hashes a binary input sample into an unsigned 32-bit quantity using the WT6
12045 hash function. Optionally, it is possible to apply a full avalanche hash
12046 function to the output if the optional <avalanche> argument equals 1. This
12047 converter uses the same functions as used by the various hash-based load
12048 balancing algorithms, so it will provide exactly the same results. It is
12049 mostly intended for debugging, but can be used as a stick-table entry to
12050 collect rough statistics. It must not be used for security purposes as a
Willy Tarreau80599772015-01-20 19:35:24 +010012051 32-bit hash is trivial to break. See also "crc32", "djb2", "sdbm", and the
12052 "hash-type" directive.
Willy Tarreau23ec4ca2014-07-15 20:15:37 +020012053
Willy Tarreau97707872015-01-27 15:12:13 +010012054xor(<value>)
12055 Performs a bitwise "XOR" (exclusive OR) between <value> and the input value
Thierry FOURNIER07ee64e2015-07-06 23:43:03 +020012056 of type signed integer, and returns the result as an signed integer.
Thierry FOURNIER5d86fae2015-07-07 21:10:16 +020012057 <value> can be a numeric value or a variable name. The name of the variable
12058 starts by an indication about its scope. The allowed scopes are:
12059 "sess" : the variable is shared with all the session,
12060 "txn" : the variable is shared with all the transaction (request and
12061 response),
12062 "req" : the variable is shared only during the request processing,
12063 "res" : the variable is shared only during the response processing.
12064 This prefix is followed by a name. The separator is a '.'. The name may only
12065 contain characters 'a-z', 'A-Z', '0-9' and '_'.
Willy Tarreau97707872015-01-27 15:12:13 +010012066
Thierry FOURNIERd5f624d2013-11-26 11:52:33 +010012067
Thierry FOURNIER060762e2014-04-23 13:29:15 +0200120687.3.2. Fetching samples from internal states
Willy Tarreau74ca5042013-06-11 23:12:07 +020012069--------------------------------------------
12070
12071A first set of sample fetch methods applies to internal information which does
12072not even relate to any client information. These ones are sometimes used with
12073"monitor-fail" directives to report an internal status to external watchers.
12074The sample fetch methods described in this section are usable anywhere.
12075
12076always_false : boolean
12077 Always returns the boolean "false" value. It may be used with ACLs as a
12078 temporary replacement for another one when adjusting configurations.
12079
12080always_true : boolean
12081 Always returns the boolean "true" value. It may be used with ACLs as a
12082 temporary replacement for another one when adjusting configurations.
12083
12084avg_queue([<backend>]) : integer
Willy Tarreaud63335a2010-02-26 12:56:52 +010012085 Returns the total number of queued connections of the designated backend
Willy Tarreau74ca5042013-06-11 23:12:07 +020012086 divided by the number of active servers. The current backend is used if no
12087 backend is specified. This is very similar to "queue" except that the size of
12088 the farm is considered, in order to give a more accurate measurement of the
12089 time it may take for a new connection to be processed. The main usage is with
12090 ACL to return a sorry page to new users when it becomes certain they will get
12091 a degraded service, or to pass to the backend servers in a header so that
12092 they decide to work in degraded mode or to disable some functions to speed up
12093 the processing a bit. Note that in the event there would not be any active
12094 server anymore, twice the number of queued connections would be considered as
12095 the measured value. This is a fair estimate, as we expect one server to get
12096 back soon anyway, but we still prefer to send new traffic to another backend
12097 if in better shape. See also the "queue", "be_conn", and "be_sess_rate"
12098 sample fetches.
Krzysztof Piotr Oledzki346f76d2010-01-12 21:59:30 +010012099
Willy Tarreau74ca5042013-06-11 23:12:07 +020012100be_conn([<backend>]) : integer
Willy Tarreaua36af912009-10-10 12:02:45 +020012101 Applies to the number of currently established connections on the backend,
12102 possibly including the connection being evaluated. If no backend name is
12103 specified, the current one is used. But it is also possible to check another
12104 backend. It can be used to use a specific farm when the nominal one is full.
12105 See also the "fe_conn", "queue" and "be_sess_rate" criteria.
Willy Tarreau6a06a402007-07-15 20:15:28 +020012106
Willy Tarreau74ca5042013-06-11 23:12:07 +020012107be_sess_rate([<backend>]) : integer
12108 Returns an integer value corresponding to the sessions creation rate on the
12109 backend, in number of new sessions per second. This is used with ACLs to
12110 switch to an alternate backend when an expensive or fragile one reaches too
12111 high a session rate, or to limit abuse of service (eg. prevent sucking of an
12112 online dictionary). It can also be useful to add this element to logs using a
12113 log-format directive.
Willy Tarreaud63335a2010-02-26 12:56:52 +010012114
12115 Example :
12116 # Redirect to an error page if the dictionary is requested too often
12117 backend dynamic
12118 mode http
12119 acl being_scanned be_sess_rate gt 100
12120 redirect location /denied.html if being_scanned
Willy Tarreau0ba27502007-12-24 16:55:16 +010012121
Thierry FOURNIERcc103292015-06-06 19:30:17 +020012122bin(<hexa>) : bin
12123 Returns a binary chain. The input is the hexadecimal representation
12124 of the string.
12125
12126bool(<bool>) : bool
12127 Returns a boolean value. <bool> can be 'true', 'false', '1' or '0'.
12128 'false' and '0' are the same. 'true' and '1' are the same.
12129
Willy Tarreau74ca5042013-06-11 23:12:07 +020012130connslots([<backend>]) : integer
12131 Returns an integer value corresponding to the number of connection slots
Jarno Huuskonen0e82b922014-04-12 18:22:19 +030012132 still available in the backend, by totaling the maximum amount of
Willy Tarreau74ca5042013-06-11 23:12:07 +020012133 connections on all servers and the maximum queue size. This is probably only
12134 used with ACLs.
Tait Clarridge7896d522012-12-05 21:39:31 -050012135
Jeffrey 'jf' Lim5051d7b2008-09-04 01:03:03 +080012136 The basic idea here is to be able to measure the number of connection "slots"
Willy Tarreau55165fe2009-05-10 12:02:55 +020012137 still available (connection + queue), so that anything beyond that (intended
Jeffrey 'jf' Lim5051d7b2008-09-04 01:03:03 +080012138 usage; see "use_backend" keyword) can be redirected to a different backend.
12139
Willy Tarreau55165fe2009-05-10 12:02:55 +020012140 'connslots' = number of available server connection slots, + number of
12141 available server queue slots.
Jeffrey 'jf' Lim5051d7b2008-09-04 01:03:03 +080012142
Willy Tarreaua36af912009-10-10 12:02:45 +020012143 Note that while "fe_conn" may be used, "connslots" comes in especially
Willy Tarreau55165fe2009-05-10 12:02:55 +020012144 useful when you have a case of traffic going to one single ip, splitting into
Willy Tarreau74ca5042013-06-11 23:12:07 +020012145 multiple backends (perhaps using ACLs to do name-based load balancing) and
Willy Tarreau55165fe2009-05-10 12:02:55 +020012146 you want to be able to differentiate between different backends, and their
12147 available "connslots". Also, whereas "nbsrv" only measures servers that are
Willy Tarreau74ca5042013-06-11 23:12:07 +020012148 actually *down*, this fetch is more fine-grained and looks into the number of
Willy Tarreaua36af912009-10-10 12:02:45 +020012149 available connection slots as well. See also "queue" and "avg_queue".
Jeffrey 'jf' Lim5051d7b2008-09-04 01:03:03 +080012150
Willy Tarreau55165fe2009-05-10 12:02:55 +020012151 OTHER CAVEATS AND NOTES: at this point in time, the code does not take care
12152 of dynamic connections. Also, if any of the server maxconn, or maxqueue is 0,
Willy Tarreau74ca5042013-06-11 23:12:07 +020012153 then this fetch clearly does not make sense, in which case the value returned
Willy Tarreau55165fe2009-05-10 12:02:55 +020012154 will be -1.
Jeffrey 'jf' Lim5051d7b2008-09-04 01:03:03 +080012155
Willy Tarreau6236d3a2013-07-25 14:28:25 +020012156date([<offset>]) : integer
12157 Returns the current date as the epoch (number of seconds since 01/01/1970).
12158 If an offset value is specified, then it is a number of seconds that is added
12159 to the current date before returning the value. This is particularly useful
12160 to compute relative dates, as both positive and negative offsets are allowed.
Willy Tarreau276fae92013-07-25 14:36:01 +020012161 It is useful combined with the http_date converter.
12162
12163 Example :
12164
12165 # set an expires header to now+1 hour in every response
12166 http-response set-header Expires %[date(3600),http_date]
Willy Tarreau6236d3a2013-07-25 14:28:25 +020012167
Willy Tarreau595ec542013-06-12 21:34:28 +020012168env(<name>) : string
12169 Returns a string containing the value of environment variable <name>. As a
12170 reminder, environment variables are per-process and are sampled when the
12171 process starts. This can be useful to pass some information to a next hop
12172 server, or with ACLs to take specific action when the process is started a
12173 certain way.
12174
12175 Examples :
12176 # Pass the Via header to next hop with the local hostname in it
12177 http-request add-header Via 1.1\ %[env(HOSTNAME)]
12178
12179 # reject cookie-less requests when the STOP environment variable is set
12180 http-request deny if !{ cook(SESSIONID) -m found } { env(STOP) -m found }
12181
Willy Tarreau74ca5042013-06-11 23:12:07 +020012182fe_conn([<frontend>]) : integer
12183 Returns the number of currently established connections on the frontend,
Willy Tarreaud63335a2010-02-26 12:56:52 +010012184 possibly including the connection being evaluated. If no frontend name is
12185 specified, the current one is used. But it is also possible to check another
Willy Tarreau74ca5042013-06-11 23:12:07 +020012186 frontend. It can be used to return a sorry page before hard-blocking, or to
12187 use a specific backend to drain new requests when the farm is considered
12188 full. This is mostly used with ACLs but can also be used to pass some
12189 statistics to servers in HTTP headers. See also the "dst_conn", "be_conn",
12190 "fe_sess_rate" fetches.
Willy Tarreaua36af912009-10-10 12:02:45 +020012191
Willy Tarreau74ca5042013-06-11 23:12:07 +020012192fe_sess_rate([<frontend>]) : integer
12193 Returns an integer value corresponding to the sessions creation rate on the
12194 frontend, in number of new sessions per second. This is used with ACLs to
12195 limit the incoming session rate to an acceptable range in order to prevent
12196 abuse of service at the earliest moment, for example when combined with other
12197 layer 4 ACLs in order to force the clients to wait a bit for the rate to go
12198 down below the limit. It can also be useful to add this element to logs using
12199 a log-format directive. See also the "rate-limit sessions" directive for use
12200 in frontends.
Willy Tarreau079ff0a2009-03-05 21:34:28 +010012201
12202 Example :
12203 # This frontend limits incoming mails to 10/s with a max of 100
12204 # concurrent connections. We accept any connection below 10/s, and
12205 # force excess clients to wait for 100 ms. Since clients are limited to
12206 # 100 max, there cannot be more than 10 incoming mails per second.
12207 frontend mail
12208 bind :25
12209 mode tcp
12210 maxconn 100
12211 acl too_fast fe_sess_rate ge 10
12212 tcp-request inspect-delay 100ms
12213 tcp-request content accept if ! too_fast
12214 tcp-request content accept if WAIT_END
Willy Tarreaud72758d2010-01-12 10:42:19 +010012215
Thierry FOURNIER07ee64e2015-07-06 23:43:03 +020012216int(<integer>) : signed integer
12217 Returns a signed integer.
12218
Thierry FOURNIERcc103292015-06-06 19:30:17 +020012219ipv4(<ipv4>) : ipv4
12220 Returns an ipv4.
12221
12222ipv6(<ipv6>) : ipv6
12223 Returns an ipv6.
12224
12225meth(<method>) : method
12226 Returns a method.
12227
Willy Tarreau0f30d262014-11-24 16:02:05 +010012228nbproc : integer
12229 Returns an integer value corresponding to the number of processes that were
12230 started (it equals the global "nbproc" setting). This is useful for logging
12231 and debugging purposes.
12232
Willy Tarreau74ca5042013-06-11 23:12:07 +020012233nbsrv([<backend>]) : integer
12234 Returns an integer value corresponding to the number of usable servers of
12235 either the current backend or the named backend. This is mostly used with
12236 ACLs but can also be useful when added to logs. This is normally used to
Willy Tarreaud63335a2010-02-26 12:56:52 +010012237 switch to an alternate backend when the number of servers is too low to
12238 to handle some load. It is useful to report a failure when combined with
12239 "monitor fail".
Willy Tarreau079ff0a2009-03-05 21:34:28 +010012240
Willy Tarreau0f30d262014-11-24 16:02:05 +010012241proc : integer
12242 Returns an integer value corresponding to the position of the process calling
12243 the function, between 1 and global.nbproc. This is useful for logging and
12244 debugging purposes.
12245
Willy Tarreau74ca5042013-06-11 23:12:07 +020012246queue([<backend>]) : integer
Willy Tarreaud63335a2010-02-26 12:56:52 +010012247 Returns the total number of queued connections of the designated backend,
12248 including all the connections in server queues. If no backend name is
12249 specified, the current one is used, but it is also possible to check another
Willy Tarreau74ca5042013-06-11 23:12:07 +020012250 one. This is useful with ACLs or to pass statistics to backend servers. This
12251 can be used to take actions when queuing goes above a known level, generally
12252 indicating a surge of traffic or a massive slowdown on the servers. One
12253 possible action could be to reject new users but still accept old ones. See
12254 also the "avg_queue", "be_conn", and "be_sess_rate" fetches.
12255
Willy Tarreau84310e22014-02-14 11:59:04 +010012256rand([<range>]) : integer
12257 Returns a random integer value within a range of <range> possible values,
12258 starting at zero. If the range is not specified, it defaults to 2^32, which
12259 gives numbers between 0 and 4294967295. It can be useful to pass some values
12260 needed to take some routing decisions for example, or just for debugging
12261 purposes. This random must not be used for security purposes.
12262
Willy Tarreau74ca5042013-06-11 23:12:07 +020012263srv_conn([<backend>/]<server>) : integer
12264 Returns an integer value corresponding to the number of currently established
12265 connections on the designated server, possibly including the connection being
12266 evaluated. If <backend> is omitted, then the server is looked up in the
12267 current backend. It can be used to use a specific farm when one server is
12268 full, or to inform the server about our view of the number of active
12269 connections with it. See also the "fe_conn", "be_conn" and "queue" fetch
12270 methods.
12271
12272srv_is_up([<backend>/]<server>) : boolean
12273 Returns true when the designated server is UP, and false when it is either
12274 DOWN or in maintenance mode. If <backend> is omitted, then the server is
12275 looked up in the current backend. It is mainly used to take action based on
12276 an external status reported via a health check (eg: a geographical site's
12277 availability). Another possible use which is more of a hack consists in
12278 using dummy servers as boolean variables that can be enabled or disabled from
12279 the CLI, so that rules depending on those ACLs can be tweaked in realtime.
12280
12281srv_sess_rate([<backend>/]<server>) : integer
12282 Returns an integer corresponding to the sessions creation rate on the
12283 designated server, in number of new sessions per second. If <backend> is
Jarno Huuskonen0e82b922014-04-12 18:22:19 +030012284 omitted, then the server is looked up in the current backend. This is mostly
Willy Tarreau74ca5042013-06-11 23:12:07 +020012285 used with ACLs but can make sense with logs too. This is used to switch to an
12286 alternate backend when an expensive or fragile one reaches too high a session
12287 rate, or to limit abuse of service (eg. prevent latent requests from
12288 overloading servers).
12289
12290 Example :
12291 # Redirect to a separate back
12292 acl srv1_full srv_sess_rate(be1/srv1) gt 50
12293 acl srv2_full srv_sess_rate(be1/srv2) gt 50
12294 use_backend be2 if srv1_full or srv2_full
12295
Willy Tarreau0f30d262014-11-24 16:02:05 +010012296stopping : boolean
12297 Returns TRUE if the process calling the function is currently stopping. This
12298 can be useful for logging, or for relaxing certain checks or helping close
12299 certain connections upon graceful shutdown.
12300
Thierry FOURNIERcc103292015-06-06 19:30:17 +020012301str(<string>) : string
12302 Returns a string.
12303
Willy Tarreau74ca5042013-06-11 23:12:07 +020012304table_avl([<table>]) : integer
12305 Returns the total number of available entries in the current proxy's
12306 stick-table or in the designated stick-table. See also table_cnt.
12307
12308table_cnt([<table>]) : integer
12309 Returns the total number of entries currently in use in the current proxy's
12310 stick-table or in the designated stick-table. See also src_conn_cnt and
12311 table_avl for other entry counting methods.
12312
Thierry FOURNIER4834bc72015-06-06 19:29:07 +020012313var(<var-name>) : undefined
12314 Returns a variable with the stored type. If the variable is not set, the
12315 sample fetch fails. The name of the variable starts by an indication about its
12316 scope. The scope allowed are:
12317 "sess" : the variable is shared with all the session,
12318 "txn" : the variable is shared with all the transaction (request and
12319 response),
12320 "req" : the variable is shared only during the request processing,
12321 "res" : the variable is shared only during the response processing.
12322 This prefix is followed by a name. The separator is a '.'. The name may only
12323 contain characters 'a-z', 'A-Z', '0-9' and '_'.
12324
Willy Tarreau74ca5042013-06-11 23:12:07 +020012325
Thierry FOURNIER060762e2014-04-23 13:29:15 +0200123267.3.3. Fetching samples at Layer 4
Willy Tarreau74ca5042013-06-11 23:12:07 +020012327----------------------------------
12328
12329The layer 4 usually describes just the transport layer which in haproxy is
12330closest to the connection, where no content is yet made available. The fetch
12331methods described here are usable as low as the "tcp-request connection" rule
12332sets unless they require some future information. Those generally include
12333TCP/IP addresses and ports, as well as elements from stick-tables related to
Willy Tarreau4d4149c2013-07-23 19:33:46 +020012334the incoming connection. For retrieving a value from a sticky counters, the
12335counter number can be explicitly set as 0, 1, or 2 using the pre-defined
12336"sc0_", "sc1_", or "sc2_" prefix, or it can be specified as the first integer
Willy Tarreau0f791d42013-07-23 19:56:43 +020012337argument when using the "sc_" prefix. An optional table may be specified with
12338the "sc*" form, in which case the currently tracked key will be looked up into
12339this alternate table instead of the table currently being tracked.
Willy Tarreau74ca5042013-06-11 23:12:07 +020012340
12341be_id : integer
12342 Returns an integer containing the current backend's id. It can be used in
12343 frontends with responses to check which backend processed the request.
12344
12345dst : ip
12346 This is the destination IPv4 address of the connection on the client side,
12347 which is the address the client connected to. It can be useful when running
12348 in transparent mode. It is of type IP and works on both IPv4 and IPv6 tables.
12349 On IPv6 tables, IPv4 address is mapped to its IPv6 equivalent, according to
12350 RFC 4291.
12351
12352dst_conn : integer
12353 Returns an integer value corresponding to the number of currently established
12354 connections on the same socket including the one being evaluated. It is
12355 normally used with ACLs but can as well be used to pass the information to
12356 servers in an HTTP header or in logs. It can be used to either return a sorry
12357 page before hard-blocking, or to use a specific backend to drain new requests
12358 when the socket is considered saturated. This offers the ability to assign
12359 different limits to different listening ports or addresses. See also the
12360 "fe_conn" and "be_conn" fetches.
Willy Tarreaud63335a2010-02-26 12:56:52 +010012361
Willy Tarreau74ca5042013-06-11 23:12:07 +020012362dst_port : integer
12363 Returns an integer value corresponding to the destination TCP port of the
12364 connection on the client side, which is the port the client connected to.
12365 This might be used when running in transparent mode, when assigning dynamic
12366 ports to some clients for a whole application session, to stick all users to
12367 a same server, or to pass the destination port information to a server using
12368 an HTTP header.
12369
12370fe_id : integer
12371 Returns an integer containing the current frontend's id. It can be used in
12372 backends to check from which backend it was called, or to stick all users
12373 coming via a same frontend to the same server.
12374
Cyril Bonté62ba8702014-04-22 23:52:25 +020012375sc_bytes_in_rate(<ctr>[,<table>]) : integer
Willy Tarreau0f791d42013-07-23 19:56:43 +020012376sc0_bytes_in_rate([<table>]) : integer
12377sc1_bytes_in_rate([<table>]) : integer
12378sc2_bytes_in_rate([<table>]) : integer
Willy Tarreaue9656522010-08-17 15:40:09 +020012379 Returns the average client-to-server bytes rate from the currently tracked
12380 counters, measured in amount of bytes over the period configured in the
12381 table. See also src_bytes_in_rate.
12382
Cyril Bonté62ba8702014-04-22 23:52:25 +020012383sc_bytes_out_rate(<ctr>[,<table>]) : integer
Willy Tarreau0f791d42013-07-23 19:56:43 +020012384sc0_bytes_out_rate([<table>]) : integer
12385sc1_bytes_out_rate([<table>]) : integer
12386sc2_bytes_out_rate([<table>]) : integer
Willy Tarreaue9656522010-08-17 15:40:09 +020012387 Returns the average server-to-client bytes rate from the currently tracked
12388 counters, measured in amount of bytes over the period configured in the
12389 table. See also src_bytes_out_rate.
12390
Cyril Bonté62ba8702014-04-22 23:52:25 +020012391sc_clr_gpc0(<ctr>[,<table>]) : integer
Willy Tarreau0f791d42013-07-23 19:56:43 +020012392sc0_clr_gpc0([<table>]) : integer
12393sc1_clr_gpc0([<table>]) : integer
12394sc2_clr_gpc0([<table>]) : integer
Willy Tarreauf73cd112011-08-13 01:45:16 +020012395 Clears the first General Purpose Counter associated to the currently tracked
12396 counters, and returns its previous value. Before the first invocation, the
Willy Tarreau869948b2013-01-04 14:14:57 +010012397 stored value is zero, so first invocation will always return zero. This is
12398 typically used as a second ACL in an expression in order to mark a connection
12399 when a first ACL was verified :
Willy Tarreauf73cd112011-08-13 01:45:16 +020012400
12401 # block if 5 consecutive requests continue to come faster than 10 sess
12402 # per second, and reset the counter as soon as the traffic slows down.
Willy Tarreaube4a3ef2013-06-17 15:04:07 +020012403 acl abuse sc0_http_req_rate gt 10
12404 acl kill sc0_inc_gpc0 gt 5
12405 acl save sc0_clr_gpc0 ge 0
Willy Tarreauf73cd112011-08-13 01:45:16 +020012406 tcp-request connection accept if !abuse save
12407 tcp-request connection reject if abuse kill
12408
Cyril Bonté62ba8702014-04-22 23:52:25 +020012409sc_conn_cnt(<ctr>[,<table>]) : integer
Willy Tarreau0f791d42013-07-23 19:56:43 +020012410sc0_conn_cnt([<table>]) : integer
12411sc1_conn_cnt([<table>]) : integer
12412sc2_conn_cnt([<table>]) : integer
Willy Tarreaue9656522010-08-17 15:40:09 +020012413 Returns the cumulated number of incoming connections from currently tracked
12414 counters. See also src_conn_cnt.
12415
Cyril Bonté62ba8702014-04-22 23:52:25 +020012416sc_conn_cur(<ctr>[,<table>]) : integer
Willy Tarreau0f791d42013-07-23 19:56:43 +020012417sc0_conn_cur([<table>]) : integer
12418sc1_conn_cur([<table>]) : integer
12419sc2_conn_cur([<table>]) : integer
Willy Tarreaue9656522010-08-17 15:40:09 +020012420 Returns the current amount of concurrent connections tracking the same
12421 tracked counters. This number is automatically incremented when tracking
12422 begins and decremented when tracking stops. See also src_conn_cur.
12423
Cyril Bonté62ba8702014-04-22 23:52:25 +020012424sc_conn_rate(<ctr>[,<table>]) : integer
Willy Tarreau0f791d42013-07-23 19:56:43 +020012425sc0_conn_rate([<table>]) : integer
12426sc1_conn_rate([<table>]) : integer
12427sc2_conn_rate([<table>]) : integer
Willy Tarreaue9656522010-08-17 15:40:09 +020012428 Returns the average connection rate from the currently tracked counters,
12429 measured in amount of connections over the period configured in the table.
12430 See also src_conn_rate.
12431
Cyril Bonté62ba8702014-04-22 23:52:25 +020012432sc_get_gpc0(<ctr>[,<table>]) : integer
Willy Tarreau0f791d42013-07-23 19:56:43 +020012433sc0_get_gpc0([<table>]) : integer
12434sc1_get_gpc0([<table>]) : integer
12435sc2_get_gpc0([<table>]) : integer
Willy Tarreaue9656522010-08-17 15:40:09 +020012436 Returns the value of the first General Purpose Counter associated to the
Willy Tarreau4d4149c2013-07-23 19:33:46 +020012437 currently tracked counters. See also src_get_gpc0 and sc/sc0/sc1/sc2_inc_gpc0.
Willy Tarreauba2ffd12013-05-29 15:54:14 +020012438
Thierry FOURNIER236657b2015-08-19 08:25:14 +020012439sc_get_gpt0(<ctr>[,<table>]) : integer
12440sc0_get_gpt0([<table>]) : integer
12441sc1_get_gpt0([<table>]) : integer
12442sc2_get_gpt0([<table>]) : integer
12443 Returns the value of the first General Purpose Tag associated to the
12444 currently tracked counters. See also src_get_gpt0.
12445
Cyril Bonté62ba8702014-04-22 23:52:25 +020012446sc_gpc0_rate(<ctr>[,<table>]) : integer
Willy Tarreau0f791d42013-07-23 19:56:43 +020012447sc0_gpc0_rate([<table>]) : integer
12448sc1_gpc0_rate([<table>]) : integer
12449sc2_gpc0_rate([<table>]) : integer
Willy Tarreauba2ffd12013-05-29 15:54:14 +020012450 Returns the average increment rate of the first General Purpose Counter
12451 associated to the currently tracked counters. It reports the frequency
12452 which the gpc0 counter was incremented over the configured period. See also
Willy Tarreau4d4149c2013-07-23 19:33:46 +020012453 src_gpc0_rate, sc/sc0/sc1/sc2_get_gpc0, and sc/sc0/sc1/sc2_inc_gpc0. Note
12454 that the "gpc0_rate" counter must be stored in the stick-table for a value to
12455 be returned, as "gpc0" only holds the event count.
Willy Tarreaue9656522010-08-17 15:40:09 +020012456
Cyril Bonté62ba8702014-04-22 23:52:25 +020012457sc_http_err_cnt(<ctr>[,<table>]) : integer
Willy Tarreau0f791d42013-07-23 19:56:43 +020012458sc0_http_err_cnt([<table>]) : integer
12459sc1_http_err_cnt([<table>]) : integer
12460sc2_http_err_cnt([<table>]) : integer
Willy Tarreaue9656522010-08-17 15:40:09 +020012461 Returns the cumulated number of HTTP errors from the currently tracked
12462 counters. This includes the both request errors and 4xx error responses.
12463 See also src_http_err_cnt.
12464
Cyril Bonté62ba8702014-04-22 23:52:25 +020012465sc_http_err_rate(<ctr>[,<table>]) : integer
Willy Tarreau0f791d42013-07-23 19:56:43 +020012466sc0_http_err_rate([<table>]) : integer
12467sc1_http_err_rate([<table>]) : integer
12468sc2_http_err_rate([<table>]) : integer
Willy Tarreaue9656522010-08-17 15:40:09 +020012469 Returns the average rate of HTTP errors from the currently tracked counters,
12470 measured in amount of errors over the period configured in the table. This
12471 includes the both request errors and 4xx error responses. See also
12472 src_http_err_rate.
12473
Cyril Bonté62ba8702014-04-22 23:52:25 +020012474sc_http_req_cnt(<ctr>[,<table>]) : integer
Willy Tarreau0f791d42013-07-23 19:56:43 +020012475sc0_http_req_cnt([<table>]) : integer
12476sc1_http_req_cnt([<table>]) : integer
12477sc2_http_req_cnt([<table>]) : integer
Willy Tarreaue9656522010-08-17 15:40:09 +020012478 Returns the cumulated number of HTTP requests from the currently tracked
12479 counters. This includes every started request, valid or not. See also
12480 src_http_req_cnt.
12481
Cyril Bonté62ba8702014-04-22 23:52:25 +020012482sc_http_req_rate(<ctr>[,<table>]) : integer
Willy Tarreau0f791d42013-07-23 19:56:43 +020012483sc0_http_req_rate([<table>]) : integer
12484sc1_http_req_rate([<table>]) : integer
12485sc2_http_req_rate([<table>]) : integer
Willy Tarreaue9656522010-08-17 15:40:09 +020012486 Returns the average rate of HTTP requests from the currently tracked
12487 counters, measured in amount of requests over the period configured in
12488 the table. This includes every started request, valid or not. See also
12489 src_http_req_rate.
12490
Cyril Bonté62ba8702014-04-22 23:52:25 +020012491sc_inc_gpc0(<ctr>[,<table>]) : integer
Willy Tarreau0f791d42013-07-23 19:56:43 +020012492sc0_inc_gpc0([<table>]) : integer
12493sc1_inc_gpc0([<table>]) : integer
12494sc2_inc_gpc0([<table>]) : integer
Willy Tarreaue9656522010-08-17 15:40:09 +020012495 Increments the first General Purpose Counter associated to the currently
Willy Tarreau869948b2013-01-04 14:14:57 +010012496 tracked counters, and returns its new value. Before the first invocation,
12497 the stored value is zero, so first invocation will increase it to 1 and will
12498 return 1. This is typically used as a second ACL in an expression in order
12499 to mark a connection when a first ACL was verified :
Willy Tarreaue9656522010-08-17 15:40:09 +020012500
Willy Tarreaube4a3ef2013-06-17 15:04:07 +020012501 acl abuse sc0_http_req_rate gt 10
12502 acl kill sc0_inc_gpc0 gt 0
Willy Tarreaue9656522010-08-17 15:40:09 +020012503 tcp-request connection reject if abuse kill
12504
Cyril Bonté62ba8702014-04-22 23:52:25 +020012505sc_kbytes_in(<ctr>[,<table>]) : integer
Willy Tarreau0f791d42013-07-23 19:56:43 +020012506sc0_kbytes_in([<table>]) : integer
12507sc1_kbytes_in([<table>]) : integer
12508sc2_kbytes_in([<table>]) : integer
Willy Tarreaua01b9742014-07-10 15:29:24 +020012509 Returns the total amount of client-to-server data from the currently tracked
12510 counters, measured in kilobytes. The test is currently performed on 32-bit
12511 integers, which limits values to 4 terabytes. See also src_kbytes_in.
Willy Tarreaue9656522010-08-17 15:40:09 +020012512
Cyril Bonté62ba8702014-04-22 23:52:25 +020012513sc_kbytes_out(<ctr>[,<table>]) : integer
Willy Tarreau0f791d42013-07-23 19:56:43 +020012514sc0_kbytes_out([<table>]) : integer
12515sc1_kbytes_out([<table>]) : integer
12516sc2_kbytes_out([<table>]) : integer
Willy Tarreaua01b9742014-07-10 15:29:24 +020012517 Returns the total amount of server-to-client data from the currently tracked
12518 counters, measured in kilobytes. The test is currently performed on 32-bit
12519 integers, which limits values to 4 terabytes. See also src_kbytes_out.
Willy Tarreaue9656522010-08-17 15:40:09 +020012520
Cyril Bonté62ba8702014-04-22 23:52:25 +020012521sc_sess_cnt(<ctr>[,<table>]) : integer
Willy Tarreau0f791d42013-07-23 19:56:43 +020012522sc0_sess_cnt([<table>]) : integer
12523sc1_sess_cnt([<table>]) : integer
12524sc2_sess_cnt([<table>]) : integer
Willy Tarreaue9656522010-08-17 15:40:09 +020012525 Returns the cumulated number of incoming connections that were transformed
12526 into sessions, which means that they were accepted by a "tcp-request
12527 connection" rule, from the currently tracked counters. A backend may count
12528 more sessions than connections because each connection could result in many
Jamie Gloudonaaa21002012-08-25 00:18:33 -040012529 backend sessions if some HTTP keep-alive is performed over the connection
Willy Tarreaue9656522010-08-17 15:40:09 +020012530 with the client. See also src_sess_cnt.
12531
Cyril Bonté62ba8702014-04-22 23:52:25 +020012532sc_sess_rate(<ctr>[,<table>]) : integer
Willy Tarreau0f791d42013-07-23 19:56:43 +020012533sc0_sess_rate([<table>]) : integer
12534sc1_sess_rate([<table>]) : integer
12535sc2_sess_rate([<table>]) : integer
Willy Tarreaue9656522010-08-17 15:40:09 +020012536 Returns the average session rate from the currently tracked counters,
12537 measured in amount of sessions over the period configured in the table. A
12538 session is a connection that got past the early "tcp-request connection"
12539 rules. A backend may count more sessions than connections because each
12540 connection could result in many backend sessions if some HTTP keep-alive is
Jamie Gloudonaaa21002012-08-25 00:18:33 -040012541 performed over the connection with the client. See also src_sess_rate.
Willy Tarreaue9656522010-08-17 15:40:09 +020012542
Cyril Bonté62ba8702014-04-22 23:52:25 +020012543sc_tracked(<ctr>[,<table>]) : boolean
Willy Tarreau0f791d42013-07-23 19:56:43 +020012544sc0_tracked([<table>]) : boolean
12545sc1_tracked([<table>]) : boolean
12546sc2_tracked([<table>]) : boolean
Willy Tarreau6f1615f2013-06-03 15:15:22 +020012547 Returns true if the designated session counter is currently being tracked by
12548 the current session. This can be useful when deciding whether or not we want
12549 to set some values in a header passed to the server.
12550
Cyril Bonté62ba8702014-04-22 23:52:25 +020012551sc_trackers(<ctr>[,<table>]) : integer
Willy Tarreau0f791d42013-07-23 19:56:43 +020012552sc0_trackers([<table>]) : integer
12553sc1_trackers([<table>]) : integer
12554sc2_trackers([<table>]) : integer
Willy Tarreau2406db42012-12-09 12:16:43 +010012555 Returns the current amount of concurrent connections tracking the same
12556 tracked counters. This number is automatically incremented when tracking
Willy Tarreaube4a3ef2013-06-17 15:04:07 +020012557 begins and decremented when tracking stops. It differs from sc0_conn_cur in
Willy Tarreau2406db42012-12-09 12:16:43 +010012558 that it does not rely on any stored information but on the table's reference
12559 count (the "use" value which is returned by "show table" on the CLI). This
Willy Tarreau74ca5042013-06-11 23:12:07 +020012560 may sometimes be more suited for layer7 tracking. It can be used to tell a
12561 server how many concurrent connections there are from a given address for
12562 example.
Willy Tarreau2406db42012-12-09 12:16:43 +010012563
Willy Tarreau74ca5042013-06-11 23:12:07 +020012564so_id : integer
12565 Returns an integer containing the current listening socket's id. It is useful
12566 in frontends involving many "bind" lines, or to stick all users coming via a
12567 same socket to the same server.
Willy Tarreaud63335a2010-02-26 12:56:52 +010012568
Willy Tarreau74ca5042013-06-11 23:12:07 +020012569src : ip
12570 This is the source IPv4 address of the client of the session. It is of type
12571 IP and works on both IPv4 and IPv6 tables. On IPv6 tables, IPv4 addresses are
12572 mapped to their IPv6 equivalent, according to RFC 4291. Note that it is the
12573 TCP-level source address which is used, and not the address of a client
12574 behind a proxy. However if the "accept-proxy" bind directive is used, it can
12575 be the address of a client behind another PROXY-protocol compatible component
12576 for all rule sets except "tcp-request connection" which sees the real address.
Willy Tarreaud63335a2010-02-26 12:56:52 +010012577
Thierry FOURNIERd5f624d2013-11-26 11:52:33 +010012578 Example:
12579 # add an HTTP header in requests with the originating address' country
12580 http-request set-header X-Country %[src,map_ip(geoip.lst)]
12581
Willy Tarreau74ca5042013-06-11 23:12:07 +020012582src_bytes_in_rate([<table>]) : integer
12583 Returns the average bytes rate from the incoming connection's source address
12584 in the current proxy's stick-table or in the designated stick-table, measured
12585 in amount of bytes over the period configured in the table. If the address is
Willy Tarreau4d4149c2013-07-23 19:33:46 +020012586 not found, zero is returned. See also sc/sc0/sc1/sc2_bytes_in_rate.
Willy Tarreauc9705a12010-07-27 20:05:50 +020012587
Willy Tarreau74ca5042013-06-11 23:12:07 +020012588src_bytes_out_rate([<table>]) : integer
12589 Returns the average bytes rate to the incoming connection's source address in
12590 the current proxy's stick-table or in the designated stick-table, measured in
Willy Tarreauc9705a12010-07-27 20:05:50 +020012591 amount of bytes over the period configured in the table. If the address is
Willy Tarreau4d4149c2013-07-23 19:33:46 +020012592 not found, zero is returned. See also sc/sc0/sc1/sc2_bytes_out_rate.
Willy Tarreauc9705a12010-07-27 20:05:50 +020012593
Willy Tarreau74ca5042013-06-11 23:12:07 +020012594src_clr_gpc0([<table>]) : integer
12595 Clears the first General Purpose Counter associated to the incoming
12596 connection's source address in the current proxy's stick-table or in the
12597 designated stick-table, and returns its previous value. If the address is not
12598 found, an entry is created and 0 is returned. This is typically used as a
12599 second ACL in an expression in order to mark a connection when a first ACL
12600 was verified :
Willy Tarreauf73cd112011-08-13 01:45:16 +020012601
12602 # block if 5 consecutive requests continue to come faster than 10 sess
12603 # per second, and reset the counter as soon as the traffic slows down.
12604 acl abuse src_http_req_rate gt 10
12605 acl kill src_inc_gpc0 gt 5
Willy Tarreau869948b2013-01-04 14:14:57 +010012606 acl save src_clr_gpc0 ge 0
Willy Tarreauf73cd112011-08-13 01:45:16 +020012607 tcp-request connection accept if !abuse save
12608 tcp-request connection reject if abuse kill
12609
Willy Tarreau74ca5042013-06-11 23:12:07 +020012610src_conn_cnt([<table>]) : integer
Willy Tarreauc9705a12010-07-27 20:05:50 +020012611 Returns the cumulated number of connections initiated from the current
Willy Tarreau74ca5042013-06-11 23:12:07 +020012612 incoming connection's source address in the current proxy's stick-table or in
Willy Tarreauc9705a12010-07-27 20:05:50 +020012613 the designated stick-table. If the address is not found, zero is returned.
Willy Tarreau4d4149c2013-07-23 19:33:46 +020012614 See also sc/sc0/sc1/sc2_conn_cnt.
Willy Tarreauc9705a12010-07-27 20:05:50 +020012615
Willy Tarreau74ca5042013-06-11 23:12:07 +020012616src_conn_cur([<table>]) : integer
Willy Tarreauc9705a12010-07-27 20:05:50 +020012617 Returns the current amount of concurrent connections initiated from the
Willy Tarreau74ca5042013-06-11 23:12:07 +020012618 current incoming connection's source address in the current proxy's
12619 stick-table or in the designated stick-table. If the address is not found,
Willy Tarreau4d4149c2013-07-23 19:33:46 +020012620 zero is returned. See also sc/sc0/sc1/sc2_conn_cur.
Willy Tarreauc9705a12010-07-27 20:05:50 +020012621
Willy Tarreau74ca5042013-06-11 23:12:07 +020012622src_conn_rate([<table>]) : integer
12623 Returns the average connection rate from the incoming connection's source
12624 address in the current proxy's stick-table or in the designated stick-table,
12625 measured in amount of connections over the period configured in the table. If
Willy Tarreau4d4149c2013-07-23 19:33:46 +020012626 the address is not found, zero is returned. See also sc/sc0/sc1/sc2_conn_rate.
Willy Tarreauc9705a12010-07-27 20:05:50 +020012627
Willy Tarreau74ca5042013-06-11 23:12:07 +020012628src_get_gpc0([<table>]) : integer
Willy Tarreauc9705a12010-07-27 20:05:50 +020012629 Returns the value of the first General Purpose Counter associated to the
Willy Tarreau74ca5042013-06-11 23:12:07 +020012630 incoming connection's source address in the current proxy's stick-table or in
Willy Tarreauc9705a12010-07-27 20:05:50 +020012631 the designated stick-table. If the address is not found, zero is returned.
Willy Tarreau4d4149c2013-07-23 19:33:46 +020012632 See also sc/sc0/sc1/sc2_get_gpc0 and src_inc_gpc0.
Willy Tarreauc9705a12010-07-27 20:05:50 +020012633
Thierry FOURNIER236657b2015-08-19 08:25:14 +020012634src_get_gpt0([<table>]) : integer
12635 Returns the value of the first General Purpose Tag associated to the
12636 incoming connection's source address in the current proxy's stick-table or in
12637 the designated stick-table. If the address is not found, zero is returned.
12638 See also sc/sc0/sc1/sc2_get_gpt0.
12639
Willy Tarreau74ca5042013-06-11 23:12:07 +020012640src_gpc0_rate([<table>]) : integer
Willy Tarreauba2ffd12013-05-29 15:54:14 +020012641 Returns the average increment rate of the first General Purpose Counter
Willy Tarreau74ca5042013-06-11 23:12:07 +020012642 associated to the incoming connection's source address in the current proxy's
Willy Tarreauba2ffd12013-05-29 15:54:14 +020012643 stick-table or in the designated stick-table. It reports the frequency
12644 which the gpc0 counter was incremented over the configured period. See also
Willy Tarreau4d4149c2013-07-23 19:33:46 +020012645 sc/sc0/sc1/sc2_gpc0_rate, src_get_gpc0, and sc/sc0/sc1/sc2_inc_gpc0. Note
12646 that the "gpc0_rate" counter must be stored in the stick-table for a value to
12647 be returned, as "gpc0" only holds the event count.
Willy Tarreauba2ffd12013-05-29 15:54:14 +020012648
Willy Tarreau74ca5042013-06-11 23:12:07 +020012649src_http_err_cnt([<table>]) : integer
12650 Returns the cumulated number of HTTP errors from the incoming connection's
12651 source address in the current proxy's stick-table or in the designated
Willy Tarreauc9705a12010-07-27 20:05:50 +020012652 stick-table. This includes the both request errors and 4xx error responses.
Willy Tarreau4d4149c2013-07-23 19:33:46 +020012653 See also sc/sc0/sc1/sc2_http_err_cnt. If the address is not found, zero is
Willy Tarreau74ca5042013-06-11 23:12:07 +020012654 returned.
Willy Tarreauc9705a12010-07-27 20:05:50 +020012655
Willy Tarreau74ca5042013-06-11 23:12:07 +020012656src_http_err_rate([<table>]) : integer
12657 Returns the average rate of HTTP errors from the incoming connection's source
12658 address in the current proxy's stick-table or in the designated stick-table,
12659 measured in amount of errors over the period configured in the table. This
12660 includes the both request errors and 4xx error responses. If the address is
Willy Tarreau4d4149c2013-07-23 19:33:46 +020012661 not found, zero is returned. See also sc/sc0/sc1/sc2_http_err_rate.
Willy Tarreauc9705a12010-07-27 20:05:50 +020012662
Willy Tarreau74ca5042013-06-11 23:12:07 +020012663src_http_req_cnt([<table>]) : integer
12664 Returns the cumulated number of HTTP requests from the incoming connection's
12665 source address in the current proxy's stick-table or in the designated stick-
12666 table. This includes every started request, valid or not. If the address is
Willy Tarreau4d4149c2013-07-23 19:33:46 +020012667 not found, zero is returned. See also sc/sc0/sc1/sc2_http_req_cnt.
Willy Tarreauc9705a12010-07-27 20:05:50 +020012668
Willy Tarreau74ca5042013-06-11 23:12:07 +020012669src_http_req_rate([<table>]) : integer
12670 Returns the average rate of HTTP requests from the incoming connection's
12671 source address in the current proxy's stick-table or in the designated stick-
12672 table, measured in amount of requests over the period configured in the
Willy Tarreauc9705a12010-07-27 20:05:50 +020012673 table. This includes every started request, valid or not. If the address is
Willy Tarreau4d4149c2013-07-23 19:33:46 +020012674 not found, zero is returned. See also sc/sc0/sc1/sc2_http_req_rate.
Willy Tarreauc9705a12010-07-27 20:05:50 +020012675
Willy Tarreau74ca5042013-06-11 23:12:07 +020012676src_inc_gpc0([<table>]) : integer
12677 Increments the first General Purpose Counter associated to the incoming
12678 connection's source address in the current proxy's stick-table or in the
12679 designated stick-table, and returns its new value. If the address is not
Willy Tarreaube4a3ef2013-06-17 15:04:07 +020012680 found, an entry is created and 1 is returned. See also sc0/sc2/sc2_inc_gpc0.
Willy Tarreau74ca5042013-06-11 23:12:07 +020012681 This is typically used as a second ACL in an expression in order to mark a
12682 connection when a first ACL was verified :
Willy Tarreauc9705a12010-07-27 20:05:50 +020012683
12684 acl abuse src_http_req_rate gt 10
Willy Tarreau869948b2013-01-04 14:14:57 +010012685 acl kill src_inc_gpc0 gt 0
Willy Tarreaue9656522010-08-17 15:40:09 +020012686 tcp-request connection reject if abuse kill
Willy Tarreauc9705a12010-07-27 20:05:50 +020012687
Willy Tarreau74ca5042013-06-11 23:12:07 +020012688src_kbytes_in([<table>]) : integer
Willy Tarreaua01b9742014-07-10 15:29:24 +020012689 Returns the total amount of data received from the incoming connection's
12690 source address in the current proxy's stick-table or in the designated
12691 stick-table, measured in kilobytes. If the address is not found, zero is
12692 returned. The test is currently performed on 32-bit integers, which limits
12693 values to 4 terabytes. See also sc/sc0/sc1/sc2_kbytes_in.
Willy Tarreauc9705a12010-07-27 20:05:50 +020012694
Willy Tarreau74ca5042013-06-11 23:12:07 +020012695src_kbytes_out([<table>]) : integer
Willy Tarreaua01b9742014-07-10 15:29:24 +020012696 Returns the total amount of data sent to the incoming connection's source
12697 address in the current proxy's stick-table or in the designated stick-table,
12698 measured in kilobytes. If the address is not found, zero is returned. The
12699 test is currently performed on 32-bit integers, which limits values to 4
12700 terabytes. See also sc/sc0/sc1/sc2_kbytes_out.
Willy Tarreaua975b8f2010-06-05 19:13:27 +020012701
Willy Tarreau74ca5042013-06-11 23:12:07 +020012702src_port : integer
12703 Returns an integer value corresponding to the TCP source port of the
12704 connection on the client side, which is the port the client connected from.
12705 Usage of this function is very limited as modern protocols do not care much
12706 about source ports nowadays.
Willy Tarreau079ff0a2009-03-05 21:34:28 +010012707
Willy Tarreau74ca5042013-06-11 23:12:07 +020012708src_sess_cnt([<table>]) : integer
12709 Returns the cumulated number of connections initiated from the incoming
Willy Tarreauc9705a12010-07-27 20:05:50 +020012710 connection's source IPv4 address in the current proxy's stick-table or in the
12711 designated stick-table, that were transformed into sessions, which means that
12712 they were accepted by "tcp-request" rules. If the address is not found, zero
Willy Tarreau4d4149c2013-07-23 19:33:46 +020012713 is returned. See also sc/sc0/sc1/sc2_sess_cnt.
Willy Tarreauc9705a12010-07-27 20:05:50 +020012714
Willy Tarreau74ca5042013-06-11 23:12:07 +020012715src_sess_rate([<table>]) : integer
12716 Returns the average session rate from the incoming connection's source
12717 address in the current proxy's stick-table or in the designated stick-table,
12718 measured in amount of sessions over the period configured in the table. A
12719 session is a connection that went past the early "tcp-request" rules. If the
Willy Tarreau4d4149c2013-07-23 19:33:46 +020012720 address is not found, zero is returned. See also sc/sc0/sc1/sc2_sess_rate.
Willy Tarreauc9705a12010-07-27 20:05:50 +020012721
Willy Tarreau74ca5042013-06-11 23:12:07 +020012722src_updt_conn_cnt([<table>]) : integer
12723 Creates or updates the entry associated to the incoming connection's source
12724 address in the current proxy's stick-table or in the designated stick-table.
12725 This table must be configured to store the "conn_cnt" data type, otherwise
12726 the match will be ignored. The current count is incremented by one, and the
12727 expiration timer refreshed. The updated count is returned, so this match
12728 can't return zero. This was used to reject service abusers based on their
12729 source address. Note: it is recommended to use the more complete "track-sc*"
12730 actions in "tcp-request" rules instead.
Willy Tarreaua975b8f2010-06-05 19:13:27 +020012731
12732 Example :
12733 # This frontend limits incoming SSH connections to 3 per 10 second for
12734 # each source address, and rejects excess connections until a 10 second
12735 # silence is observed. At most 20 addresses are tracked.
12736 listen ssh
12737 bind :22
12738 mode tcp
12739 maxconn 100
Willy Tarreauc9705a12010-07-27 20:05:50 +020012740 stick-table type ip size 20 expire 10s store conn_cnt
Willy Tarreau74ca5042013-06-11 23:12:07 +020012741 tcp-request content reject if { src_updt_conn_cnt gt 3 }
Willy Tarreaua975b8f2010-06-05 19:13:27 +020012742 server local 127.0.0.1:22
12743
Willy Tarreau74ca5042013-06-11 23:12:07 +020012744srv_id : integer
12745 Returns an integer containing the server's id when processing the response.
12746 While it's almost only used with ACLs, it may be used for logging or
12747 debugging.
Hervé COMMOWICKdaa824e2011-08-05 12:09:44 +020012748
Hervé COMMOWICK35ed8012010-12-15 14:04:51 +010012749
Thierry FOURNIER060762e2014-04-23 13:29:15 +0200127507.3.4. Fetching samples at Layer 5
Willy Tarreau74ca5042013-06-11 23:12:07 +020012751----------------------------------
Willy Tarreau0b1cd942010-05-16 22:18:27 +020012752
Willy Tarreau74ca5042013-06-11 23:12:07 +020012753The layer 5 usually describes just the session layer which in haproxy is
12754closest to the session once all the connection handshakes are finished, but
12755when no content is yet made available. The fetch methods described here are
12756usable as low as the "tcp-request content" rule sets unless they require some
Jarno Huuskonen0e82b922014-04-12 18:22:19 +030012757future information. Those generally include the results of SSL negotiations.
Willy Tarreauc735a072011-03-29 00:57:02 +020012758
Emeric Brun645ae792014-04-30 14:21:06 +020012759ssl_bc : boolean
12760 Returns true when the back connection was made via an SSL/TLS transport
12761 layer and is locally deciphered. This means the outgoing connection was made
12762 other a server with the "ssl" option.
12763
12764ssl_bc_alg_keysize : integer
12765 Returns the symmetric cipher key size supported in bits when the outgoing
12766 connection was made over an SSL/TLS transport layer.
12767
12768ssl_bc_cipher : string
12769 Returns the name of the used cipher when the outgoing connection was made
12770 over an SSL/TLS transport layer.
12771
12772ssl_bc_protocol : string
12773 Returns the name of the used protocol when the outgoing connection was made
12774 over an SSL/TLS transport layer.
12775
Emeric Brunb73a9b02014-04-30 18:49:19 +020012776ssl_bc_unique_id : binary
Emeric Brun645ae792014-04-30 14:21:06 +020012777 When the outgoing connection was made over an SSL/TLS transport layer,
Emeric Brunb73a9b02014-04-30 18:49:19 +020012778 returns the TLS unique ID as defined in RFC5929 section 3. The unique id
12779 can be encoded to base64 using the converter: "ssl_bc_unique_id,base64".
Emeric Brun645ae792014-04-30 14:21:06 +020012780
12781ssl_bc_session_id : binary
12782 Returns the SSL ID of the back connection when the outgoing connection was
12783 made over an SSL/TLS transport layer. It is useful to log if we want to know
12784 if session was reused or not.
12785
12786ssl_bc_use_keysize : integer
12787 Returns the symmetric cipher key size used in bits when the outgoing
12788 connection was made over an SSL/TLS transport layer.
12789
Willy Tarreau74ca5042013-06-11 23:12:07 +020012790ssl_c_ca_err : integer
12791 When the incoming connection was made over an SSL/TLS transport layer,
12792 returns the ID of the first error detected during verification of the client
12793 certificate at depth > 0, or 0 if no error was encountered during this
12794 verification process. Please refer to your SSL library's documentation to
12795 find the exhaustive list of error codes.
Willy Tarreauc735a072011-03-29 00:57:02 +020012796
Willy Tarreau74ca5042013-06-11 23:12:07 +020012797ssl_c_ca_err_depth : integer
12798 When the incoming connection was made over an SSL/TLS transport layer,
12799 returns the depth in the CA chain of the first error detected during the
12800 verification of the client certificate. If no error is encountered, 0 is
12801 returned.
Willy Tarreau0ba27502007-12-24 16:55:16 +010012802
Emeric Brun43e79582014-10-29 19:03:26 +010012803ssl_c_der : binary
12804 Returns the DER formatted certificate presented by the client when the
12805 incoming connection was made over an SSL/TLS transport layer. When used for
12806 an ACL, the value(s) to match against can be passed in hexadecimal form.
12807
Willy Tarreau74ca5042013-06-11 23:12:07 +020012808ssl_c_err : integer
12809 When the incoming connection was made over an SSL/TLS transport layer,
12810 returns the ID of the first error detected during verification at depth 0, or
12811 0 if no error was encountered during this verification process. Please refer
12812 to your SSL library's documentation to find the exhaustive list of error
12813 codes.
Willy Tarreau62644772008-07-16 18:36:06 +020012814
Willy Tarreau74ca5042013-06-11 23:12:07 +020012815ssl_c_i_dn([<entry>[,<occ>]]) : string
12816 When the incoming connection was made over an SSL/TLS transport layer,
12817 returns the full distinguished name of the issuer of the certificate
12818 presented by the client when no <entry> is specified, or the value of the
12819 first given entry found from the beginning of the DN. If a positive/negative
12820 occurrence number is specified as the optional second argument, it returns
12821 the value of the nth given entry value from the beginning/end of the DN.
12822 For instance, "ssl_c_i_dn(OU,2)" the second organization unit, and
12823 "ssl_c_i_dn(CN)" retrieves the common name.
Willy Tarreau62644772008-07-16 18:36:06 +020012824
Willy Tarreau74ca5042013-06-11 23:12:07 +020012825ssl_c_key_alg : string
12826 Returns the name of the algorithm used to generate the key of the certificate
12827 presented by the client when the incoming connection was made over an SSL/TLS
12828 transport layer.
Willy Tarreau62644772008-07-16 18:36:06 +020012829
Willy Tarreau74ca5042013-06-11 23:12:07 +020012830ssl_c_notafter : string
12831 Returns the end date presented by the client as a formatted string
12832 YYMMDDhhmmss[Z] when the incoming connection was made over an SSL/TLS
12833 transport layer.
Emeric Brunbede3d02009-06-30 17:54:00 +020012834
Willy Tarreau74ca5042013-06-11 23:12:07 +020012835ssl_c_notbefore : string
12836 Returns the start date presented by the client as a formatted string
12837 YYMMDDhhmmss[Z] when the incoming connection was made over an SSL/TLS
12838 transport layer.
Willy Tarreaub6672b52011-12-12 17:23:41 +010012839
Willy Tarreau74ca5042013-06-11 23:12:07 +020012840ssl_c_s_dn([<entry>[,<occ>]]) : string
12841 When the incoming connection was made over an SSL/TLS transport layer,
12842 returns the full distinguished name of the subject of the certificate
12843 presented by the client when no <entry> is specified, or the value of the
12844 first given entry found from the beginning of the DN. If a positive/negative
12845 occurrence number is specified as the optional second argument, it returns
12846 the value of the nth given entry value from the beginning/end of the DN.
12847 For instance, "ssl_c_s_dn(OU,2)" the second organization unit, and
12848 "ssl_c_s_dn(CN)" retrieves the common name.
Willy Tarreaub6672b52011-12-12 17:23:41 +010012849
Willy Tarreau74ca5042013-06-11 23:12:07 +020012850ssl_c_serial : binary
12851 Returns the serial of the certificate presented by the client when the
12852 incoming connection was made over an SSL/TLS transport layer. When used for
12853 an ACL, the value(s) to match against can be passed in hexadecimal form.
Emeric Brun2525b6b2012-10-18 15:59:43 +020012854
Willy Tarreau74ca5042013-06-11 23:12:07 +020012855ssl_c_sha1 : binary
12856 Returns the SHA-1 fingerprint of the certificate presented by the client when
12857 the incoming connection was made over an SSL/TLS transport layer. This can be
12858 used to stick a client to a server, or to pass this information to a server.
Willy Tarreau2d0caa32014-07-02 19:01:22 +020012859 Note that the output is binary, so if you want to pass that signature to the
12860 server, you need to encode it in hex or base64, such as in the example below:
12861
12862 http-request set-header X-SSL-Client-SHA1 %[ssl_c_sha1,hex]
Emeric Brun2525b6b2012-10-18 15:59:43 +020012863
Willy Tarreau74ca5042013-06-11 23:12:07 +020012864ssl_c_sig_alg : string
12865 Returns the name of the algorithm used to sign the certificate presented by
12866 the client when the incoming connection was made over an SSL/TLS transport
12867 layer.
Emeric Brun87855892012-10-17 17:39:35 +020012868
Willy Tarreau74ca5042013-06-11 23:12:07 +020012869ssl_c_used : boolean
12870 Returns true if current SSL session uses a client certificate even if current
12871 connection uses SSL session resumption. See also "ssl_fc_has_crt".
Emeric Brun7f56e742012-10-19 18:15:40 +020012872
Willy Tarreau74ca5042013-06-11 23:12:07 +020012873ssl_c_verify : integer
12874 Returns the verify result error ID when the incoming connection was made over
12875 an SSL/TLS transport layer, otherwise zero if no error is encountered. Please
12876 refer to your SSL library's documentation for an exhaustive list of error
12877 codes.
Emeric Brunce5ad802012-10-22 14:11:22 +020012878
Willy Tarreau74ca5042013-06-11 23:12:07 +020012879ssl_c_version : integer
12880 Returns the version of the certificate presented by the client when the
12881 incoming connection was made over an SSL/TLS transport layer.
Emeric Brunce5ad802012-10-22 14:11:22 +020012882
Emeric Brun43e79582014-10-29 19:03:26 +010012883ssl_f_der : binary
12884 Returns the DER formatted certificate presented by the frontend when the
12885 incoming connection was made over an SSL/TLS transport layer. When used for
12886 an ACL, the value(s) to match against can be passed in hexadecimal form.
12887
Willy Tarreau74ca5042013-06-11 23:12:07 +020012888ssl_f_i_dn([<entry>[,<occ>]]) : string
12889 When the incoming connection was made over an SSL/TLS transport layer,
12890 returns the full distinguished name of the issuer of the certificate
12891 presented by the frontend when no <entry> is specified, or the value of the
12892 first given entry found from the beginning of the DN. If a positive/negative
Emeric Brun87855892012-10-17 17:39:35 +020012893 occurrence number is specified as the optional second argument, it returns
Willy Tarreau74ca5042013-06-11 23:12:07 +020012894 the value of the nth given entry value from the beginning/end of the DN.
12895 For instance, "ssl_f_i_dn(OU,2)" the second organization unit, and
12896 "ssl_f_i_dn(CN)" retrieves the common name.
Emeric Brun87855892012-10-17 17:39:35 +020012897
Willy Tarreau74ca5042013-06-11 23:12:07 +020012898ssl_f_key_alg : string
12899 Returns the name of the algorithm used to generate the key of the certificate
12900 presented by the frontend when the incoming connection was made over an
12901 SSL/TLS transport layer.
Emeric Brun7f56e742012-10-19 18:15:40 +020012902
Willy Tarreau74ca5042013-06-11 23:12:07 +020012903ssl_f_notafter : string
12904 Returns the end date presented by the frontend as a formatted string
12905 YYMMDDhhmmss[Z] when the incoming connection was made over an SSL/TLS
12906 transport layer.
Emeric Brun2525b6b2012-10-18 15:59:43 +020012907
Willy Tarreau74ca5042013-06-11 23:12:07 +020012908ssl_f_notbefore : string
12909 Returns the start date presented by the frontend as a formatted string
12910 YYMMDDhhmmss[Z] when the incoming connection was made over an SSL/TLS
12911 transport layer.
Emeric Brun87855892012-10-17 17:39:35 +020012912
Willy Tarreau74ca5042013-06-11 23:12:07 +020012913ssl_f_s_dn([<entry>[,<occ>]]) : string
12914 When the incoming connection was made over an SSL/TLS transport layer,
12915 returns the full distinguished name of the subject of the certificate
12916 presented by the frontend when no <entry> is specified, or the value of the
12917 first given entry found from the beginning of the DN. If a positive/negative
12918 occurrence number is specified as the optional second argument, it returns
12919 the value of the nth given entry value from the beginning/end of the DN.
12920 For instance, "ssl_f_s_dn(OU,2)" the second organization unit, and
12921 "ssl_f_s_dn(CN)" retrieves the common name.
Emeric Brunce5ad802012-10-22 14:11:22 +020012922
Willy Tarreau74ca5042013-06-11 23:12:07 +020012923ssl_f_serial : binary
12924 Returns the serial of the certificate presented by the frontend when the
12925 incoming connection was made over an SSL/TLS transport layer. When used for
12926 an ACL, the value(s) to match against can be passed in hexadecimal form.
Emeric Brun87855892012-10-17 17:39:35 +020012927
Emeric Brun55f4fa82014-04-30 17:11:25 +020012928ssl_f_sha1 : binary
12929 Returns the SHA-1 fingerprint of the certificate presented by the frontend
12930 when the incoming connection was made over an SSL/TLS transport layer. This
12931 can be used to know which certificate was chosen using SNI.
12932
Willy Tarreau74ca5042013-06-11 23:12:07 +020012933ssl_f_sig_alg : string
12934 Returns the name of the algorithm used to sign the certificate presented by
12935 the frontend when the incoming connection was made over an SSL/TLS transport
12936 layer.
Emeric Brun7f56e742012-10-19 18:15:40 +020012937
Willy Tarreau74ca5042013-06-11 23:12:07 +020012938ssl_f_version : integer
12939 Returns the version of the certificate presented by the frontend when the
12940 incoming connection was made over an SSL/TLS transport layer.
12941
12942ssl_fc : boolean
Emeric Brun2525b6b2012-10-18 15:59:43 +020012943 Returns true when the front connection was made via an SSL/TLS transport
12944 layer and is locally deciphered. This means it has matched a socket declared
12945 with a "bind" line having the "ssl" option.
12946
Willy Tarreau74ca5042013-06-11 23:12:07 +020012947 Example :
12948 # This passes "X-Proto: https" to servers when client connects over SSL
12949 listen http-https
12950 bind :80
12951 bind :443 ssl crt /etc/haproxy.pem
12952 http-request add-header X-Proto https if { ssl_fc }
12953
12954ssl_fc_alg_keysize : integer
12955 Returns the symmetric cipher key size supported in bits when the incoming
12956 connection was made over an SSL/TLS transport layer.
12957
12958ssl_fc_alpn : string
Jarno Huuskonen0e82b922014-04-12 18:22:19 +030012959 This extracts the Application Layer Protocol Negotiation field from an
Willy Tarreau74ca5042013-06-11 23:12:07 +020012960 incoming connection made via a TLS transport layer and locally deciphered by
12961 haproxy. The result is a string containing the protocol name advertised by
12962 the client. The SSL library must have been built with support for TLS
12963 extensions enabled (check haproxy -vv). Note that the TLS ALPN extension is
12964 not advertised unless the "alpn" keyword on the "bind" line specifies a
12965 protocol list. Also, nothing forces the client to pick a protocol from this
12966 list, any other one may be requested. The TLS ALPN extension is meant to
12967 replace the TLS NPN extension. See also "ssl_fc_npn".
12968
Willy Tarreau74ca5042013-06-11 23:12:07 +020012969ssl_fc_cipher : string
12970 Returns the name of the used cipher when the incoming connection was made
12971 over an SSL/TLS transport layer.
Willy Tarreauab861d32013-04-02 02:30:41 +020012972
Willy Tarreau74ca5042013-06-11 23:12:07 +020012973ssl_fc_has_crt : boolean
Emeric Brun2525b6b2012-10-18 15:59:43 +020012974 Returns true if a client certificate is present in an incoming connection over
12975 SSL/TLS transport layer. Useful if 'verify' statement is set to 'optional'.
Emeric Brun9143d372012-12-20 15:44:16 +010012976 Note: on SSL session resumption with Session ID or TLS ticket, client
12977 certificate is not present in the current connection but may be retrieved
12978 from the cache or the ticket. So prefer "ssl_c_used" if you want to check if
12979 current SSL session uses a client certificate.
Emeric Brun2525b6b2012-10-18 15:59:43 +020012980
Willy Tarreau74ca5042013-06-11 23:12:07 +020012981ssl_fc_has_sni : boolean
12982 This checks for the presence of a Server Name Indication TLS extension (SNI)
Willy Tarreauf7bc57c2012-10-03 00:19:48 +020012983 in an incoming connection was made over an SSL/TLS transport layer. Returns
12984 true when the incoming connection presents a TLS SNI field. This requires
12985 that the SSL library is build with support for TLS extensions enabled (check
12986 haproxy -vv).
Willy Tarreau7875d092012-09-10 08:20:03 +020012987
Nenad Merdanovic26ea8222015-05-18 02:28:57 +020012988ssl_fc_is_resumed: boolean
12989 Returns true if the SSL/TLS session has been resumed through the use of
12990 SSL session cache or TLS tickets.
12991
Willy Tarreau74ca5042013-06-11 23:12:07 +020012992ssl_fc_npn : string
Jarno Huuskonen0e82b922014-04-12 18:22:19 +030012993 This extracts the Next Protocol Negotiation field from an incoming connection
Willy Tarreau74ca5042013-06-11 23:12:07 +020012994 made via a TLS transport layer and locally deciphered by haproxy. The result
12995 is a string containing the protocol name advertised by the client. The SSL
12996 library must have been built with support for TLS extensions enabled (check
12997 haproxy -vv). Note that the TLS NPN extension is not advertised unless the
12998 "npn" keyword on the "bind" line specifies a protocol list. Also, nothing
12999 forces the client to pick a protocol from this list, any other one may be
13000 requested. Please note that the TLS NPN extension was replaced with ALPN.
Willy Tarreaua33c6542012-10-15 13:19:06 +020013001
Willy Tarreau74ca5042013-06-11 23:12:07 +020013002ssl_fc_protocol : string
13003 Returns the name of the used protocol when the incoming connection was made
13004 over an SSL/TLS transport layer.
Willy Tarreau7875d092012-09-10 08:20:03 +020013005
Emeric Brunb73a9b02014-04-30 18:49:19 +020013006ssl_fc_unique_id : binary
David Sc1ad52e2014-04-08 18:48:47 -040013007 When the incoming connection was made over an SSL/TLS transport layer,
Emeric Brunb73a9b02014-04-30 18:49:19 +020013008 returns the TLS unique ID as defined in RFC5929 section 3. The unique id
13009 can be encoded to base64 using the converter: "ssl_bc_unique_id,base64".
David Sc1ad52e2014-04-08 18:48:47 -040013010
Willy Tarreau74ca5042013-06-11 23:12:07 +020013011ssl_fc_session_id : binary
13012 Returns the SSL ID of the front connection when the incoming connection was
13013 made over an SSL/TLS transport layer. It is useful to stick a given client to
13014 a server. It is important to note that some browsers refresh their session ID
13015 every few minutes.
Willy Tarreau7875d092012-09-10 08:20:03 +020013016
Willy Tarreau74ca5042013-06-11 23:12:07 +020013017ssl_fc_sni : string
13018 This extracts the Server Name Indication TLS extension (SNI) field from an
13019 incoming connection made via an SSL/TLS transport layer and locally
13020 deciphered by haproxy. The result (when present) typically is a string
13021 matching the HTTPS host name (253 chars or less). The SSL library must have
13022 been built with support for TLS extensions enabled (check haproxy -vv).
13023
13024 This fetch is different from "req_ssl_sni" above in that it applies to the
13025 connection being deciphered by haproxy and not to SSL contents being blindly
13026 forwarded. See also "ssl_fc_sni_end" and "ssl_fc_sni_reg" below. This
Cyril Bonté9c1eb1e2012-10-09 22:45:34 +020013027 requires that the SSL library is build with support for TLS extensions
13028 enabled (check haproxy -vv).
Willy Tarreau62644772008-07-16 18:36:06 +020013029
Willy Tarreau74ca5042013-06-11 23:12:07 +020013030 ACL derivatives :
Willy Tarreau74ca5042013-06-11 23:12:07 +020013031 ssl_fc_sni_end : suffix match
13032 ssl_fc_sni_reg : regex match
Emeric Brun589fcad2012-10-16 14:13:26 +020013033
Willy Tarreau74ca5042013-06-11 23:12:07 +020013034ssl_fc_use_keysize : integer
13035 Returns the symmetric cipher key size used in bits when the incoming
13036 connection was made over an SSL/TLS transport layer.
Willy Tarreaub6fb4202008-07-20 11:18:28 +020013037
Willy Tarreaub6fb4202008-07-20 11:18:28 +020013038
Thierry FOURNIER060762e2014-04-23 13:29:15 +0200130397.3.5. Fetching samples from buffer contents (Layer 6)
Willy Tarreau74ca5042013-06-11 23:12:07 +020013040------------------------------------------------------
Willy Tarreaub6fb4202008-07-20 11:18:28 +020013041
Willy Tarreau74ca5042013-06-11 23:12:07 +020013042Fetching samples from buffer contents is a bit different from the previous
13043sample fetches above because the sampled data are ephemeral. These data can
13044only be used when they're available and will be lost when they're forwarded.
13045For this reason, samples fetched from buffer contents during a request cannot
13046be used in a response for example. Even while the data are being fetched, they
13047can change. Sometimes it is necessary to set some delays or combine multiple
13048sample fetch methods to ensure that the expected data are complete and usable,
13049for example through TCP request content inspection. Please see the "tcp-request
13050content" keyword for more detailed information on the subject.
Willy Tarreau62644772008-07-16 18:36:06 +020013051
Willy Tarreau74ca5042013-06-11 23:12:07 +020013052payload(<offset>,<length>) : binary (deprecated)
13053 This is an alias for "req.payload" when used in the context of a request (eg:
13054 "stick on", "stick match"), and for "res.payload" when used in the context of
13055 a response such as in "stick store response".
Willy Tarreau0ba27502007-12-24 16:55:16 +010013056
Willy Tarreau74ca5042013-06-11 23:12:07 +020013057payload_lv(<offset1>,<length>[,<offset2>]) : binary (deprecated)
13058 This is an alias for "req.payload_lv" when used in the context of a request
13059 (eg: "stick on", "stick match"), and for "res.payload_lv" when used in the
13060 context of a response such as in "stick store response".
Willy Tarreau0ba27502007-12-24 16:55:16 +010013061
Willy Tarreau74ca5042013-06-11 23:12:07 +020013062req.len : integer
13063req_len : integer (deprecated)
13064 Returns an integer value corresponding to the number of bytes present in the
13065 request buffer. This is mostly used in ACL. It is important to understand
13066 that this test does not return false as long as the buffer is changing. This
13067 means that a check with equality to zero will almost always immediately match
13068 at the beginning of the session, while a test for more data will wait for
13069 that data to come in and return false only when haproxy is certain that no
13070 more data will come in. This test was designed to be used with TCP request
13071 content inspection.
Willy Tarreaua7ad50c2012-04-29 15:39:40 +020013072
Willy Tarreau74ca5042013-06-11 23:12:07 +020013073req.payload(<offset>,<length>) : binary
13074 This extracts a binary block of <length> bytes and starting at byte <offset>
Willy Tarreau00f00842013-08-02 11:07:32 +020013075 in the request buffer. As a special case, if the <length> argument is zero,
13076 the the whole buffer from <offset> to the end is extracted. This can be used
13077 with ACLs in order to check for the presence of some content in a buffer at
13078 any location.
Willy Tarreaua7ad50c2012-04-29 15:39:40 +020013079
Willy Tarreau74ca5042013-06-11 23:12:07 +020013080 ACL alternatives :
13081 payload(<offset>,<length>) : hex binary match
Willy Tarreaua7ad50c2012-04-29 15:39:40 +020013082
Willy Tarreau74ca5042013-06-11 23:12:07 +020013083req.payload_lv(<offset1>,<length>[,<offset2>]) : binary
13084 This extracts a binary block whose size is specified at <offset1> for <length>
13085 bytes, and which starts at <offset2> if specified or just after the length in
13086 the request buffer. The <offset2> parameter also supports relative offsets if
13087 prepended with a '+' or '-' sign.
Willy Tarreaua7ad50c2012-04-29 15:39:40 +020013088
Willy Tarreau74ca5042013-06-11 23:12:07 +020013089 ACL alternatives :
13090 payload_lv(<offset1>,<length>[,<offset2>]) : hex binary match
Willy Tarreaua7ad50c2012-04-29 15:39:40 +020013091
Willy Tarreau74ca5042013-06-11 23:12:07 +020013092 Example : please consult the example from the "stick store-response" keyword.
Willy Tarreaua7ad50c2012-04-29 15:39:40 +020013093
Willy Tarreau74ca5042013-06-11 23:12:07 +020013094req.proto_http : boolean
13095req_proto_http : boolean (deprecated)
13096 Returns true when data in the request buffer look like HTTP and correctly
13097 parses as such. It is the same parser as the common HTTP request parser which
13098 is used so there should be no surprises. The test does not match until the
13099 request is complete, failed or timed out. This test may be used to report the
13100 protocol in TCP logs, but the biggest use is to block TCP request analysis
13101 until a complete HTTP request is present in the buffer, for example to track
13102 a header.
Willy Tarreaua7ad50c2012-04-29 15:39:40 +020013103
Willy Tarreau74ca5042013-06-11 23:12:07 +020013104 Example:
13105 # track request counts per "base" (concatenation of Host+URL)
13106 tcp-request inspect-delay 10s
13107 tcp-request content reject if !HTTP
Willy Tarreaube4a3ef2013-06-17 15:04:07 +020013108 tcp-request content track-sc0 base table req-rate
Willy Tarreaua7ad50c2012-04-29 15:39:40 +020013109
Willy Tarreau74ca5042013-06-11 23:12:07 +020013110req.rdp_cookie([<name>]) : string
13111rdp_cookie([<name>]) : string (deprecated)
13112 When the request buffer looks like the RDP protocol, extracts the RDP cookie
13113 <name>, or any cookie if unspecified. The parser only checks for the first
13114 cookie, as illustrated in the RDP protocol specification. The cookie name is
13115 case insensitive. Generally the "MSTS" cookie name will be used, as it can
13116 contain the user name of the client connecting to the server if properly
13117 configured on the client. The "MSTSHASH" cookie is often used as well for
13118 session stickiness to servers.
Willy Tarreau04aa6a92012-04-06 18:57:55 +020013119
Willy Tarreau74ca5042013-06-11 23:12:07 +020013120 This differs from "balance rdp-cookie" in that any balancing algorithm may be
13121 used and thus the distribution of clients to backend servers is not linked to
13122 a hash of the RDP cookie. It is envisaged that using a balancing algorithm
13123 such as "balance roundrobin" or "balance leastconn" will lead to a more even
13124 distribution of clients to backend servers than the hash used by "balance
13125 rdp-cookie".
Willy Tarreau04aa6a92012-04-06 18:57:55 +020013126
Willy Tarreau74ca5042013-06-11 23:12:07 +020013127 ACL derivatives :
13128 req_rdp_cookie([<name>]) : exact string match
Willy Tarreau04aa6a92012-04-06 18:57:55 +020013129
Willy Tarreau74ca5042013-06-11 23:12:07 +020013130 Example :
13131 listen tse-farm
13132 bind 0.0.0.0:3389
13133 # wait up to 5s for an RDP cookie in the request
13134 tcp-request inspect-delay 5s
13135 tcp-request content accept if RDP_COOKIE
13136 # apply RDP cookie persistence
13137 persist rdp-cookie
13138 # Persist based on the mstshash cookie
13139 # This is only useful makes sense if
13140 # balance rdp-cookie is not used
13141 stick-table type string size 204800
13142 stick on req.rdp_cookie(mstshash)
13143 server srv1 1.1.1.1:3389
13144 server srv1 1.1.1.2:3389
Willy Tarreau04aa6a92012-04-06 18:57:55 +020013145
Willy Tarreau74ca5042013-06-11 23:12:07 +020013146 See also : "balance rdp-cookie", "persist rdp-cookie", "tcp-request" and the
13147 "req_rdp_cookie" ACL.
Willy Tarreau04aa6a92012-04-06 18:57:55 +020013148
Willy Tarreau74ca5042013-06-11 23:12:07 +020013149req.rdp_cookie_cnt([name]) : integer
13150rdp_cookie_cnt([name]) : integer (deprecated)
13151 Tries to parse the request buffer as RDP protocol, then returns an integer
13152 corresponding to the number of RDP cookies found. If an optional cookie name
13153 is passed, only cookies matching this name are considered. This is mostly
13154 used in ACL.
Willy Tarreau04aa6a92012-04-06 18:57:55 +020013155
Willy Tarreau74ca5042013-06-11 23:12:07 +020013156 ACL derivatives :
13157 req_rdp_cookie_cnt([<name>]) : integer match
Willy Tarreau04aa6a92012-04-06 18:57:55 +020013158
Nenad Merdanovic5fc7d7e2015-07-07 22:00:17 +020013159req.ssl_ec_ext : boolean
13160 Returns a boolean identifying if client sent the Supported Elliptic Curves
13161 Extension as defined in RFC4492, section 5.1. within the SSL ClientHello
Cyril Bonté307ee1e2015-09-28 23:16:06 +020013162 message. This can be used to present ECC compatible clients with EC
13163 certificate and to use RSA for all others, on the same IP address. Note that
13164 this only applies to raw contents found in the request buffer and not to
13165 contents deciphered via an SSL data layer, so this will not work with "bind"
13166 lines having the "ssl" option.
Nenad Merdanovic5fc7d7e2015-07-07 22:00:17 +020013167
Willy Tarreau74ca5042013-06-11 23:12:07 +020013168req.ssl_hello_type : integer
13169req_ssl_hello_type : integer (deprecated)
13170 Returns an integer value containing the type of the SSL hello message found
13171 in the request buffer if the buffer contains data that parse as a complete
13172 SSL (v3 or superior) client hello message. Note that this only applies to raw
13173 contents found in the request buffer and not to contents deciphered via an
13174 SSL data layer, so this will not work with "bind" lines having the "ssl"
13175 option. This is mostly used in ACL to detect presence of an SSL hello message
13176 that is supposed to contain an SSL session ID usable for stickiness.
Willy Tarreau04aa6a92012-04-06 18:57:55 +020013177
Willy Tarreau74ca5042013-06-11 23:12:07 +020013178req.ssl_sni : string
13179req_ssl_sni : string (deprecated)
13180 Returns a string containing the value of the Server Name TLS extension sent
13181 by a client in a TLS stream passing through the request buffer if the buffer
13182 contains data that parse as a complete SSL (v3 or superior) client hello
13183 message. Note that this only applies to raw contents found in the request
13184 buffer and not to contents deciphered via an SSL data layer, so this will not
13185 work with "bind" lines having the "ssl" option. SNI normally contains the
13186 name of the host the client tries to connect to (for recent browsers). SNI is
13187 useful for allowing or denying access to certain hosts when SSL/TLS is used
13188 by the client. This test was designed to be used with TCP request content
13189 inspection. If content switching is needed, it is recommended to first wait
13190 for a complete client hello (type 1), like in the example below. See also
13191 "ssl_fc_sni".
Willy Tarreau04aa6a92012-04-06 18:57:55 +020013192
Willy Tarreau74ca5042013-06-11 23:12:07 +020013193 ACL derivatives :
13194 req_ssl_sni : exact string match
Willy Tarreau04aa6a92012-04-06 18:57:55 +020013195
Willy Tarreau74ca5042013-06-11 23:12:07 +020013196 Examples :
13197 # Wait for a client hello for at most 5 seconds
13198 tcp-request inspect-delay 5s
13199 tcp-request content accept if { req_ssl_hello_type 1 }
13200 use_backend bk_allow if { req_ssl_sni -f allowed_sites }
13201 default_backend bk_sorry_page
Willy Tarreau04aa6a92012-04-06 18:57:55 +020013202
Pradeep Jindalbb2acf52015-09-29 10:12:57 +053013203req.ssl_st_ext : integer
13204 Returns 0 if the client didn't send a SessionTicket TLS Extension (RFC5077)
13205 Returns 1 if the client sent SessionTicket TLS Extension
13206 Returns 2 if the client also sent non-zero length TLS SessionTicket
13207 Note that this only applies to raw contents found in the request buffer and
13208 not to contents deciphered via an SSL data layer, so this will not work with
13209 "bind" lines having the "ssl" option. This can for example be used to detect
13210 whether the client sent a SessionTicket or not and stick it accordingly, if
13211 no SessionTicket then stick on SessionID or don't stick as there's no server
13212 side state is there when SessionTickets are in use.
13213
Willy Tarreau74ca5042013-06-11 23:12:07 +020013214req.ssl_ver : integer
13215req_ssl_ver : integer (deprecated)
13216 Returns an integer value containing the version of the SSL/TLS protocol of a
13217 stream present in the request buffer. Both SSLv2 hello messages and SSLv3
13218 messages are supported. TLSv1 is announced as SSL version 3.1. The value is
13219 composed of the major version multiplied by 65536, added to the minor
13220 version. Note that this only applies to raw contents found in the request
13221 buffer and not to contents deciphered via an SSL data layer, so this will not
13222 work with "bind" lines having the "ssl" option. The ACL version of the test
13223 matches against a decimal notation in the form MAJOR.MINOR (eg: 3.1). This
13224 fetch is mostly used in ACL.
Willy Tarreaud63335a2010-02-26 12:56:52 +010013225
Willy Tarreau74ca5042013-06-11 23:12:07 +020013226 ACL derivatives :
13227 req_ssl_ver : decimal match
Willy Tarreaud63335a2010-02-26 12:56:52 +010013228
Willy Tarreau47e8eba2013-09-11 23:28:46 +020013229res.len : integer
13230 Returns an integer value corresponding to the number of bytes present in the
13231 response buffer. This is mostly used in ACL. It is important to understand
13232 that this test does not return false as long as the buffer is changing. This
13233 means that a check with equality to zero will almost always immediately match
13234 at the beginning of the session, while a test for more data will wait for
13235 that data to come in and return false only when haproxy is certain that no
13236 more data will come in. This test was designed to be used with TCP response
13237 content inspection.
13238
Willy Tarreau74ca5042013-06-11 23:12:07 +020013239res.payload(<offset>,<length>) : binary
13240 This extracts a binary block of <length> bytes and starting at byte <offset>
Willy Tarreau00f00842013-08-02 11:07:32 +020013241 in the response buffer. As a special case, if the <length> argument is zero,
13242 the the whole buffer from <offset> to the end is extracted. This can be used
13243 with ACLs in order to check for the presence of some content in a buffer at
13244 any location.
Willy Tarreaud63335a2010-02-26 12:56:52 +010013245
Willy Tarreau74ca5042013-06-11 23:12:07 +020013246res.payload_lv(<offset1>,<length>[,<offset2>]) : binary
13247 This extracts a binary block whose size is specified at <offset1> for <length>
13248 bytes, and which starts at <offset2> if specified or just after the length in
13249 the response buffer. The <offset2> parameter also supports relative offsets
13250 if prepended with a '+' or '-' sign.
Willy Tarreaud63335a2010-02-26 12:56:52 +010013251
Willy Tarreau74ca5042013-06-11 23:12:07 +020013252 Example : please consult the example from the "stick store-response" keyword.
Willy Tarreaud63335a2010-02-26 12:56:52 +010013253
Willy Tarreau971f7b62015-09-29 14:06:59 +020013254res.ssl_hello_type : integer
13255rep_ssl_hello_type : integer (deprecated)
13256 Returns an integer value containing the type of the SSL hello message found
13257 in the response buffer if the buffer contains data that parses as a complete
13258 SSL (v3 or superior) hello message. Note that this only applies to raw
13259 contents found in the response buffer and not to contents deciphered via an
13260 SSL data layer, so this will not work with "server" lines having the "ssl"
13261 option. This is mostly used in ACL to detect presence of an SSL hello message
13262 that is supposed to contain an SSL session ID usable for stickiness.
13263
Willy Tarreau74ca5042013-06-11 23:12:07 +020013264wait_end : boolean
13265 This fetch either returns true when the inspection period is over, or does
13266 not fetch. It is only used in ACLs, in conjunction with content analysis to
13267 avoid returning a wrong verdict early. It may also be used to delay some
13268 actions, such as a delayed reject for some special addresses. Since it either
13269 stops the rules evaluation or immediately returns true, it is recommended to
13270 use this acl as the last one in a rule. Please note that the default ACL
13271 "WAIT_END" is always usable without prior declaration. This test was designed
13272 to be used with TCP request content inspection.
Willy Tarreaud63335a2010-02-26 12:56:52 +010013273
Willy Tarreau74ca5042013-06-11 23:12:07 +020013274 Examples :
13275 # delay every incoming request by 2 seconds
13276 tcp-request inspect-delay 2s
13277 tcp-request content accept if WAIT_END
Willy Tarreaud63335a2010-02-26 12:56:52 +010013278
Willy Tarreau74ca5042013-06-11 23:12:07 +020013279 # don't immediately tell bad guys they are rejected
13280 tcp-request inspect-delay 10s
13281 acl goodguys src 10.0.0.0/24
13282 acl badguys src 10.0.1.0/24
13283 tcp-request content accept if goodguys
13284 tcp-request content reject if badguys WAIT_END
13285 tcp-request content reject
13286
13287
Thierry FOURNIER060762e2014-04-23 13:29:15 +0200132887.3.6. Fetching HTTP samples (Layer 7)
Willy Tarreau74ca5042013-06-11 23:12:07 +020013289--------------------------------------
13290
13291It is possible to fetch samples from HTTP contents, requests and responses.
13292This application layer is also called layer 7. It is only possible to fetch the
13293data in this section when a full HTTP request or response has been parsed from
13294its respective request or response buffer. This is always the case with all
13295HTTP specific rules and for sections running with "mode http". When using TCP
13296content inspection, it may be necessary to support an inspection delay in order
13297to let the request or response come in first. These fetches may require a bit
13298more CPU resources than the layer 4 ones, but not much since the request and
13299response are indexed.
13300
13301base : string
13302 This returns the concatenation of the first Host header and the path part of
13303 the request, which starts at the first slash and ends before the question
13304 mark. It can be useful in virtual hosted environments to detect URL abuses as
13305 well as to improve shared caches efficiency. Using this with a limited size
13306 stick table also allows one to collect statistics about most commonly
13307 requested objects by host/path. With ACLs it can allow simple content
13308 switching rules involving the host and the path at the same time, such as
13309 "www.example.com/favicon.ico". See also "path" and "uri".
13310
13311 ACL derivatives :
13312 base : exact string match
13313 base_beg : prefix match
13314 base_dir : subdir match
13315 base_dom : domain match
13316 base_end : suffix match
13317 base_len : length match
13318 base_reg : regex match
13319 base_sub : substring match
13320
13321base32 : integer
13322 This returns a 32-bit hash of the value returned by the "base" fetch method
13323 above. This is useful to track per-URL activity on high traffic sites without
13324 having to store all URLs. Instead a shorter hash is stored, saving a lot of
Willy Tarreau23ec4ca2014-07-15 20:15:37 +020013325 memory. The output type is an unsigned integer. The hash function used is
13326 SDBM with full avalanche on the output. Technically, base32 is exactly equal
13327 to "base,sdbm(1)".
Willy Tarreau74ca5042013-06-11 23:12:07 +020013328
13329base32+src : binary
13330 This returns the concatenation of the base32 fetch above and the src fetch
13331 below. The resulting type is of type binary, with a size of 8 or 20 bytes
13332 depending on the source address family. This can be used to track per-IP,
13333 per-URL counters.
13334
William Lallemand65ad6e12014-01-31 15:08:02 +010013335capture.req.hdr(<idx>) : string
13336 This extracts the content of the header captured by the "capture request
13337 header", idx is the position of the capture keyword in the configuration.
13338 The first entry is an index of 0. See also: "capture request header".
13339
13340capture.req.method : string
13341 This extracts the METHOD of an HTTP request. It can be used in both request
13342 and response. Unlike "method", it can be used in both request and response
13343 because it's allocated.
13344
13345capture.req.uri : string
13346 This extracts the request's URI, which starts at the first slash and ends
13347 before the first space in the request (without the host part). Unlike "path"
13348 and "url", it can be used in both request and response because it's
13349 allocated.
13350
Willy Tarreau3c1b5ec2014-04-24 23:41:57 +020013351capture.req.ver : string
13352 This extracts the request's HTTP version and returns either "HTTP/1.0" or
13353 "HTTP/1.1". Unlike "req.ver", it can be used in both request, response, and
13354 logs because it relies on a persistent flag.
13355
William Lallemand65ad6e12014-01-31 15:08:02 +010013356capture.res.hdr(<idx>) : string
13357 This extracts the content of the header captured by the "capture response
13358 header", idx is the position of the capture keyword in the configuration.
13359 The first entry is an index of 0.
13360 See also: "capture response header"
13361
Willy Tarreau3c1b5ec2014-04-24 23:41:57 +020013362capture.res.ver : string
13363 This extracts the response's HTTP version and returns either "HTTP/1.0" or
13364 "HTTP/1.1". Unlike "res.ver", it can be used in logs because it relies on a
13365 persistent flag.
13366
Willy Tarreaua5910cc2015-05-02 00:46:08 +020013367req.body : binary
13368 This returns the HTTP request's available body as a block of data. It
13369 requires that the request body has been buffered made available using
13370 "option http-buffer-request". In case of chunked-encoded body, currently only
13371 the first chunk is analyzed.
13372
Thierry FOURNIER9826c772015-05-20 15:50:54 +020013373req.body_param([<name>) : string
13374 This fetch assumes that the body of the POST request is url-encoded. The user
13375 can check if the "content-type" contains the value
13376 "application/x-www-form-urlencoded". This extracts the first occurrence of the
13377 parameter <name> in the body, which ends before '&'. The parameter name is
13378 case-sensitive. If no name is given, any parameter will match, and the first
13379 one will be returned. The result is a string corresponding to the value of the
13380 parameter <name> as presented in the request body (no URL decoding is
13381 performed). Note that the ACL version of this fetch iterates over multiple
13382 parameters and will iteratively report all parameters values if no name is
13383 given.
13384
Willy Tarreaua5910cc2015-05-02 00:46:08 +020013385req.body_len : integer
13386 This returns the length of the HTTP request's available body in bytes. It may
13387 be lower than the advertised length if the body is larger than the buffer. It
13388 requires that the request body has been buffered made available using
13389 "option http-buffer-request".
13390
13391req.body_size : integer
13392 This returns the advertised length of the HTTP request's body in bytes. It
13393 will represent the advertised Content-Length header, or the size of the first
13394 chunk in case of chunked encoding. In order to parse the chunks, it requires
13395 that the request body has been buffered made available using
13396 "option http-buffer-request".
13397
Willy Tarreau74ca5042013-06-11 23:12:07 +020013398req.cook([<name>]) : string
13399cook([<name>]) : string (deprecated)
13400 This extracts the last occurrence of the cookie name <name> on a "Cookie"
13401 header line from the request, and returns its value as string. If no name is
13402 specified, the first cookie value is returned. When used with ACLs, all
13403 matching cookies are evaluated. Spaces around the name and the value are
13404 ignored as requested by the Cookie header specification (RFC6265). The cookie
13405 name is case-sensitive. Empty cookies are valid, so an empty cookie may very
13406 well return an empty value if it is present. Use the "found" match to detect
13407 presence. Use the res.cook() variant for response cookies sent by the server.
13408
13409 ACL derivatives :
13410 cook([<name>]) : exact string match
13411 cook_beg([<name>]) : prefix match
13412 cook_dir([<name>]) : subdir match
13413 cook_dom([<name>]) : domain match
13414 cook_end([<name>]) : suffix match
13415 cook_len([<name>]) : length match
13416 cook_reg([<name>]) : regex match
13417 cook_sub([<name>]) : substring match
Willy Tarreaud63335a2010-02-26 12:56:52 +010013418
Willy Tarreau74ca5042013-06-11 23:12:07 +020013419req.cook_cnt([<name>]) : integer
13420cook_cnt([<name>]) : integer (deprecated)
13421 Returns an integer value representing the number of occurrences of the cookie
13422 <name> in the request, or all cookies if <name> is not specified.
Willy Tarreaud63335a2010-02-26 12:56:52 +010013423
Willy Tarreau74ca5042013-06-11 23:12:07 +020013424req.cook_val([<name>]) : integer
13425cook_val([<name>]) : integer (deprecated)
13426 This extracts the last occurrence of the cookie name <name> on a "Cookie"
13427 header line from the request, and converts its value to an integer which is
13428 returned. If no name is specified, the first cookie value is returned. When
13429 used in ACLs, all matching names are iterated over until a value matches.
Willy Tarreau0e698542011-09-16 08:32:32 +020013430
Willy Tarreau74ca5042013-06-11 23:12:07 +020013431cookie([<name>]) : string (deprecated)
13432 This extracts the last occurrence of the cookie name <name> on a "Cookie"
13433 header line from the request, or a "Set-Cookie" header from the response, and
13434 returns its value as a string. A typical use is to get multiple clients
13435 sharing a same profile use the same server. This can be similar to what
Willy Tarreau294d0f02015-08-10 19:40:12 +020013436 "appsession" did with the "request-learn" statement, but with support for
Willy Tarreau74ca5042013-06-11 23:12:07 +020013437 multi-peer synchronization and state keeping across restarts. If no name is
13438 specified, the first cookie value is returned. This fetch should not be used
13439 anymore and should be replaced by req.cook() or res.cook() instead as it
13440 ambiguously uses the direction based on the context where it is used.
Willy Tarreaud63335a2010-02-26 12:56:52 +010013441
Willy Tarreau74ca5042013-06-11 23:12:07 +020013442hdr([<name>[,<occ>]]) : string
13443 This is equivalent to req.hdr() when used on requests, and to res.hdr() when
13444 used on responses. Please refer to these respective fetches for more details.
13445 In case of doubt about the fetch direction, please use the explicit ones.
13446 Note that contrary to the hdr() sample fetch method, the hdr_* ACL keywords
Jarno Huuskonen0e82b922014-04-12 18:22:19 +030013447 unambiguously apply to the request headers.
Willy Tarreaud63335a2010-02-26 12:56:52 +010013448
Willy Tarreau74ca5042013-06-11 23:12:07 +020013449req.fhdr(<name>[,<occ>]) : string
13450 This extracts the last occurrence of header <name> in an HTTP request. When
13451 used from an ACL, all occurrences are iterated over until a match is found.
13452 Optionally, a specific occurrence might be specified as a position number.
13453 Positive values indicate a position from the first occurrence, with 1 being
13454 the first one. Negative values indicate positions relative to the last one,
13455 with -1 being the last one. It differs from req.hdr() in that any commas
13456 present in the value are returned and are not used as delimiters. This is
13457 sometimes useful with headers such as User-Agent.
Willy Tarreaud63335a2010-02-26 12:56:52 +010013458
Willy Tarreau74ca5042013-06-11 23:12:07 +020013459req.fhdr_cnt([<name>]) : integer
13460 Returns an integer value representing the number of occurrences of request
13461 header field name <name>, or the total number of header fields if <name> is
13462 not specified. Contrary to its req.hdr_cnt() cousin, this function returns
13463 the number of full line headers and does not stop on commas.
Willy Tarreaud63335a2010-02-26 12:56:52 +010013464
Willy Tarreau74ca5042013-06-11 23:12:07 +020013465req.hdr([<name>[,<occ>]]) : string
13466 This extracts the last occurrence of header <name> in an HTTP request. When
13467 used from an ACL, all occurrences are iterated over until a match is found.
13468 Optionally, a specific occurrence might be specified as a position number.
13469 Positive values indicate a position from the first occurrence, with 1 being
13470 the first one. Negative values indicate positions relative to the last one,
13471 with -1 being the last one. A typical use is with the X-Forwarded-For header
13472 once converted to IP, associated with an IP stick-table. The function
13473 considers any comma as a delimiter for distinct values. If full-line headers
13474 are desired instead, use req.fhdr(). Please carefully check RFC2616 to know
13475 how certain headers are supposed to be parsed. Also, some of them are case
13476 insensitive (eg: Connection).
Willy Tarreaud63335a2010-02-26 12:56:52 +010013477
Willy Tarreau74ca5042013-06-11 23:12:07 +020013478 ACL derivatives :
13479 hdr([<name>[,<occ>]]) : exact string match
13480 hdr_beg([<name>[,<occ>]]) : prefix match
13481 hdr_dir([<name>[,<occ>]]) : subdir match
13482 hdr_dom([<name>[,<occ>]]) : domain match
13483 hdr_end([<name>[,<occ>]]) : suffix match
13484 hdr_len([<name>[,<occ>]]) : length match
13485 hdr_reg([<name>[,<occ>]]) : regex match
13486 hdr_sub([<name>[,<occ>]]) : substring match
13487
13488req.hdr_cnt([<name>]) : integer
13489hdr_cnt([<header>]) : integer (deprecated)
13490 Returns an integer value representing the number of occurrences of request
13491 header field name <name>, or the total number of header field values if
13492 <name> is not specified. It is important to remember that one header line may
13493 count as several headers if it has several values. The function considers any
13494 comma as a delimiter for distinct values. If full-line headers are desired
13495 instead, req.fhdr_cnt() should be used instead. With ACLs, it can be used to
13496 detect presence, absence or abuse of a specific header, as well as to block
13497 request smuggling attacks by rejecting requests which contain more than one
13498 of certain headers. See "req.hdr" for more information on header matching.
13499
13500req.hdr_ip([<name>[,<occ>]]) : ip
13501hdr_ip([<name>[,<occ>]]) : ip (deprecated)
13502 This extracts the last occurrence of header <name> in an HTTP request,
13503 converts it to an IPv4 or IPv6 address and returns this address. When used
13504 with ACLs, all occurrences are checked, and if <name> is omitted, every value
13505 of every header is checked. Optionally, a specific occurrence might be
13506 specified as a position number. Positive values indicate a position from the
13507 first occurrence, with 1 being the first one. Negative values indicate
13508 positions relative to the last one, with -1 being the last one. A typical use
13509 is with the X-Forwarded-For and X-Client-IP headers.
13510
13511req.hdr_val([<name>[,<occ>]]) : integer
13512hdr_val([<name>[,<occ>]]) : integer (deprecated)
13513 This extracts the last occurrence of header <name> in an HTTP request, and
13514 converts it to an integer value. When used with ACLs, all occurrences are
13515 checked, and if <name> is omitted, every value of every header is checked.
13516 Optionally, a specific occurrence might be specified as a position number.
13517 Positive values indicate a position from the first occurrence, with 1 being
13518 the first one. Negative values indicate positions relative to the last one,
13519 with -1 being the last one. A typical use is with the X-Forwarded-For header.
13520
13521http_auth(<userlist>) : boolean
13522 Returns a boolean indicating whether the authentication data received from
13523 the client match a username & password stored in the specified userlist. This
13524 fetch function is not really useful outside of ACLs. Currently only http
13525 basic auth is supported.
13526
Thierry FOURNIER9eec0a62014-01-22 18:38:02 +010013527http_auth_group(<userlist>) : string
13528 Returns a string corresponding to the user name found in the authentication
13529 data received from the client if both the user name and password are valid
13530 according to the specified userlist. The main purpose is to use it in ACLs
13531 where it is then checked whether the user belongs to any group within a list.
Willy Tarreau74ca5042013-06-11 23:12:07 +020013532 This fetch function is not really useful outside of ACLs. Currently only http
13533 basic auth is supported.
13534
13535 ACL derivatives :
Thierry FOURNIER9eec0a62014-01-22 18:38:02 +010013536 http_auth_group(<userlist>) : group ...
13537 Returns true when the user extracted from the request and whose password is
13538 valid according to the specified userlist belongs to at least one of the
13539 groups.
Willy Tarreau74ca5042013-06-11 23:12:07 +020013540
13541http_first_req : boolean
Willy Tarreau7f18e522010-10-22 20:04:13 +020013542 Returns true when the request being processed is the first one of the
13543 connection. This can be used to add or remove headers that may be missing
Willy Tarreau74ca5042013-06-11 23:12:07 +020013544 from some requests when a request is not the first one, or to help grouping
13545 requests in the logs.
Willy Tarreau7f18e522010-10-22 20:04:13 +020013546
Willy Tarreau74ca5042013-06-11 23:12:07 +020013547method : integer + string
13548 Returns an integer value corresponding to the method in the HTTP request. For
13549 example, "GET" equals 1 (check sources to establish the matching). Value 9
13550 means "other method" and may be converted to a string extracted from the
13551 stream. This should not be used directly as a sample, this is only meant to
13552 be used from ACLs, which transparently convert methods from patterns to these
13553 integer + string values. Some predefined ACL already check for most common
13554 methods.
Willy Tarreau6a06a402007-07-15 20:15:28 +020013555
Willy Tarreau74ca5042013-06-11 23:12:07 +020013556 ACL derivatives :
13557 method : case insensitive method match
Willy Tarreau6a06a402007-07-15 20:15:28 +020013558
Willy Tarreau74ca5042013-06-11 23:12:07 +020013559 Example :
13560 # only accept GET and HEAD requests
13561 acl valid_method method GET HEAD
13562 http-request deny if ! valid_method
Willy Tarreau6a06a402007-07-15 20:15:28 +020013563
Willy Tarreau74ca5042013-06-11 23:12:07 +020013564path : string
13565 This extracts the request's URL path, which starts at the first slash and
13566 ends before the question mark (without the host part). A typical use is with
13567 prefetch-capable caches, and with portals which need to aggregate multiple
13568 information from databases and keep them in caches. Note that with outgoing
13569 caches, it would be wiser to use "url" instead. With ACLs, it's typically
13570 used to match exact file names (eg: "/login.php"), or directory parts using
13571 the derivative forms. See also the "url" and "base" fetch methods.
Willy Tarreau6a06a402007-07-15 20:15:28 +020013572
Willy Tarreau74ca5042013-06-11 23:12:07 +020013573 ACL derivatives :
13574 path : exact string match
13575 path_beg : prefix match
13576 path_dir : subdir match
13577 path_dom : domain match
13578 path_end : suffix match
13579 path_len : length match
13580 path_reg : regex match
13581 path_sub : substring match
Willy Tarreau6a06a402007-07-15 20:15:28 +020013582
Willy Tarreau49ad95c2015-01-19 15:06:26 +010013583query : string
13584 This extracts the request's query string, which starts after the first
13585 question mark. If no question mark is present, this fetch returns nothing. If
13586 a question mark is present but nothing follows, it returns an empty string.
13587 This means it's possible to easily know whether a query string is present
13588 using the "found" matching method. This fetch is the completemnt of "path"
13589 which stops before the question mark.
13590
Willy Tarreaueb27ec72015-02-20 13:55:29 +010013591req.hdr_names([<delim>]) : string
13592 This builds a string made from the concatenation of all header names as they
13593 appear in the request when the rule is evaluated. The default delimiter is
13594 the comma (',') but it may be overridden as an optional argument <delim>. In
13595 this case, only the first character of <delim> is considered.
13596
Willy Tarreau74ca5042013-06-11 23:12:07 +020013597req.ver : string
13598req_ver : string (deprecated)
13599 Returns the version string from the HTTP request, for example "1.1". This can
13600 be useful for logs, but is mostly there for ACL. Some predefined ACL already
13601 check for versions 1.0 and 1.1.
Willy Tarreaud63335a2010-02-26 12:56:52 +010013602
Willy Tarreau74ca5042013-06-11 23:12:07 +020013603 ACL derivatives :
13604 req_ver : exact string match
Willy Tarreau0e698542011-09-16 08:32:32 +020013605
Willy Tarreau74ca5042013-06-11 23:12:07 +020013606res.comp : boolean
13607 Returns the boolean "true" value if the response has been compressed by
13608 HAProxy, otherwise returns boolean "false". This may be used to add
13609 information in the logs.
Willy Tarreau6a06a402007-07-15 20:15:28 +020013610
Willy Tarreau74ca5042013-06-11 23:12:07 +020013611res.comp_algo : string
13612 Returns a string containing the name of the algorithm used if the response
13613 was compressed by HAProxy, for example : "deflate". This may be used to add
13614 some information in the logs.
Willy Tarreaud63335a2010-02-26 12:56:52 +010013615
Willy Tarreau74ca5042013-06-11 23:12:07 +020013616res.cook([<name>]) : string
13617scook([<name>]) : string (deprecated)
13618 This extracts the last occurrence of the cookie name <name> on a "Set-Cookie"
13619 header line from the response, and returns its value as string. If no name is
13620 specified, the first cookie value is returned.
Willy Tarreau0ce3aa02012-04-25 18:46:33 +020013621
Willy Tarreau74ca5042013-06-11 23:12:07 +020013622 ACL derivatives :
13623 scook([<name>] : exact string match
Willy Tarreau0ce3aa02012-04-25 18:46:33 +020013624
Willy Tarreau74ca5042013-06-11 23:12:07 +020013625res.cook_cnt([<name>]) : integer
13626scook_cnt([<name>]) : integer (deprecated)
13627 Returns an integer value representing the number of occurrences of the cookie
13628 <name> in the response, or all cookies if <name> is not specified. This is
13629 mostly useful when combined with ACLs to detect suspicious responses.
Willy Tarreaud63335a2010-02-26 12:56:52 +010013630
Willy Tarreau74ca5042013-06-11 23:12:07 +020013631res.cook_val([<name>]) : integer
13632scook_val([<name>]) : integer (deprecated)
13633 This extracts the last occurrence of the cookie name <name> on a "Set-Cookie"
13634 header line from the response, and converts its value to an integer which is
13635 returned. If no name is specified, the first cookie value is returned.
Willy Tarreaud63335a2010-02-26 12:56:52 +010013636
Willy Tarreau74ca5042013-06-11 23:12:07 +020013637res.fhdr([<name>[,<occ>]]) : string
13638 This extracts the last occurrence of header <name> in an HTTP response, or of
13639 the last header if no <name> is specified. Optionally, a specific occurrence
13640 might be specified as a position number. Positive values indicate a position
13641 from the first occurrence, with 1 being the first one. Negative values
13642 indicate positions relative to the last one, with -1 being the last one. It
13643 differs from res.hdr() in that any commas present in the value are returned
13644 and are not used as delimiters. If this is not desired, the res.hdr() fetch
13645 should be used instead. This is sometimes useful with headers such as Date or
13646 Expires.
Willy Tarreau6a06a402007-07-15 20:15:28 +020013647
Willy Tarreau74ca5042013-06-11 23:12:07 +020013648res.fhdr_cnt([<name>]) : integer
13649 Returns an integer value representing the number of occurrences of response
13650 header field name <name>, or the total number of header fields if <name> is
13651 not specified. Contrary to its res.hdr_cnt() cousin, this function returns
13652 the number of full line headers and does not stop on commas. If this is not
13653 desired, the res.hdr_cnt() fetch should be used instead.
Willy Tarreau6a06a402007-07-15 20:15:28 +020013654
Willy Tarreau74ca5042013-06-11 23:12:07 +020013655res.hdr([<name>[,<occ>]]) : string
13656shdr([<name>[,<occ>]]) : string (deprecated)
13657 This extracts the last occurrence of header <name> in an HTTP response, or of
13658 the last header if no <name> is specified. Optionally, a specific occurrence
13659 might be specified as a position number. Positive values indicate a position
13660 from the first occurrence, with 1 being the first one. Negative values
13661 indicate positions relative to the last one, with -1 being the last one. This
13662 can be useful to learn some data into a stick-table. The function considers
13663 any comma as a delimiter for distinct values. If this is not desired, the
13664 res.fhdr() fetch should be used instead.
Willy Tarreau6a06a402007-07-15 20:15:28 +020013665
Willy Tarreau74ca5042013-06-11 23:12:07 +020013666 ACL derivatives :
13667 shdr([<name>[,<occ>]]) : exact string match
13668 shdr_beg([<name>[,<occ>]]) : prefix match
13669 shdr_dir([<name>[,<occ>]]) : subdir match
13670 shdr_dom([<name>[,<occ>]]) : domain match
13671 shdr_end([<name>[,<occ>]]) : suffix match
13672 shdr_len([<name>[,<occ>]]) : length match
13673 shdr_reg([<name>[,<occ>]]) : regex match
13674 shdr_sub([<name>[,<occ>]]) : substring match
13675
13676res.hdr_cnt([<name>]) : integer
13677shdr_cnt([<name>]) : integer (deprecated)
13678 Returns an integer value representing the number of occurrences of response
13679 header field name <name>, or the total number of header fields if <name> is
13680 not specified. The function considers any comma as a delimiter for distinct
13681 values. If this is not desired, the res.fhdr_cnt() fetch should be used
13682 instead.
Willy Tarreau6a06a402007-07-15 20:15:28 +020013683
Willy Tarreau74ca5042013-06-11 23:12:07 +020013684res.hdr_ip([<name>[,<occ>]]) : ip
13685shdr_ip([<name>[,<occ>]]) : ip (deprecated)
13686 This extracts the last occurrence of header <name> in an HTTP response,
13687 convert it to an IPv4 or IPv6 address and returns this address. Optionally, a
13688 specific occurrence might be specified as a position number. Positive values
13689 indicate a position from the first occurrence, with 1 being the first one.
13690 Negative values indicate positions relative to the last one, with -1 being
13691 the last one. This can be useful to learn some data into a stick table.
Willy Tarreau6a06a402007-07-15 20:15:28 +020013692
Willy Tarreaueb27ec72015-02-20 13:55:29 +010013693res.hdr_names([<delim>]) : string
13694 This builds a string made from the concatenation of all header names as they
13695 appear in the response when the rule is evaluated. The default delimiter is
13696 the comma (',') but it may be overridden as an optional argument <delim>. In
13697 this case, only the first character of <delim> is considered.
13698
Willy Tarreau74ca5042013-06-11 23:12:07 +020013699res.hdr_val([<name>[,<occ>]]) : integer
13700shdr_val([<name>[,<occ>]]) : integer (deprecated)
13701 This extracts the last occurrence of header <name> in an HTTP response, and
13702 converts it to an integer value. Optionally, a specific occurrence might be
13703 specified as a position number. Positive values indicate a position from the
13704 first occurrence, with 1 being the first one. Negative values indicate
13705 positions relative to the last one, with -1 being the last one. This can be
13706 useful to learn some data into a stick table.
Alexandre Cassen5eb1a902007-11-29 15:43:32 +010013707
Willy Tarreau74ca5042013-06-11 23:12:07 +020013708res.ver : string
13709resp_ver : string (deprecated)
13710 Returns the version string from the HTTP response, for example "1.1". This
13711 can be useful for logs, but is mostly there for ACL.
Willy Tarreau0e698542011-09-16 08:32:32 +020013712
Willy Tarreau74ca5042013-06-11 23:12:07 +020013713 ACL derivatives :
13714 resp_ver : exact string match
Alexandre Cassen5eb1a902007-11-29 15:43:32 +010013715
Willy Tarreau74ca5042013-06-11 23:12:07 +020013716set-cookie([<name>]) : string (deprecated)
13717 This extracts the last occurrence of the cookie name <name> on a "Set-Cookie"
13718 header line from the response and uses the corresponding value to match. This
Willy Tarreau294d0f02015-08-10 19:40:12 +020013719 can be comparable to what "appsession" did with default options, but with
Willy Tarreau74ca5042013-06-11 23:12:07 +020013720 support for multi-peer synchronization and state keeping across restarts.
Krzysztof Piotr Oledzki6b35ce12010-02-01 23:35:44 +010013721
Willy Tarreau74ca5042013-06-11 23:12:07 +020013722 This fetch function is deprecated and has been superseded by the "res.cook"
13723 fetch. This keyword will disappear soon.
Krzysztof Piotr Oledzki6b35ce12010-02-01 23:35:44 +010013724
Willy Tarreau74ca5042013-06-11 23:12:07 +020013725status : integer
13726 Returns an integer containing the HTTP status code in the HTTP response, for
13727 example, 302. It is mostly used within ACLs and integer ranges, for example,
13728 to remove any Location header if the response is not a 3xx.
Willy Tarreau25c1ebc2012-04-25 16:21:44 +020013729
Willy Tarreau74ca5042013-06-11 23:12:07 +020013730url : string
13731 This extracts the request's URL as presented in the request. A typical use is
13732 with prefetch-capable caches, and with portals which need to aggregate
13733 multiple information from databases and keep them in caches. With ACLs, using
13734 "path" is preferred over using "url", because clients may send a full URL as
13735 is normally done with proxies. The only real use is to match "*" which does
13736 not match in "path", and for which there is already a predefined ACL. See
13737 also "path" and "base".
Willy Tarreau25c1ebc2012-04-25 16:21:44 +020013738
Willy Tarreau74ca5042013-06-11 23:12:07 +020013739 ACL derivatives :
13740 url : exact string match
13741 url_beg : prefix match
13742 url_dir : subdir match
13743 url_dom : domain match
13744 url_end : suffix match
13745 url_len : length match
13746 url_reg : regex match
13747 url_sub : substring match
Willy Tarreau25c1ebc2012-04-25 16:21:44 +020013748
Willy Tarreau74ca5042013-06-11 23:12:07 +020013749url_ip : ip
13750 This extracts the IP address from the request's URL when the host part is
13751 presented as an IP address. Its use is very limited. For instance, a
13752 monitoring system might use this field as an alternative for the source IP in
13753 order to test what path a given source address would follow, or to force an
13754 entry in a table for a given source address. With ACLs it can be used to
13755 restrict access to certain systems through a proxy, for example when combined
13756 with option "http_proxy".
Willy Tarreau25c1ebc2012-04-25 16:21:44 +020013757
Willy Tarreau74ca5042013-06-11 23:12:07 +020013758url_port : integer
13759 This extracts the port part from the request's URL. Note that if the port is
13760 not specified in the request, port 80 is assumed. With ACLs it can be used to
13761 restrict access to certain systems through a proxy, for example when combined
13762 with option "http_proxy".
Willy Tarreau25c1ebc2012-04-25 16:21:44 +020013763
Willy Tarreau1ede1da2015-05-07 16:06:18 +020013764urlp([<name>[,<delim>]]) : string
13765url_param([<name>[,<delim>]]) : string
Willy Tarreau74ca5042013-06-11 23:12:07 +020013766 This extracts the first occurrence of the parameter <name> in the query
13767 string, which begins after either '?' or <delim>, and which ends before '&',
Willy Tarreau1ede1da2015-05-07 16:06:18 +020013768 ';' or <delim>. The parameter name is case-sensitive. If no name is given,
13769 any parameter will match, and the first one will be returned. The result is
13770 a string corresponding to the value of the parameter <name> as presented in
13771 the request (no URL decoding is performed). This can be used for session
Willy Tarreau74ca5042013-06-11 23:12:07 +020013772 stickiness based on a client ID, to extract an application cookie passed as a
13773 URL parameter, or in ACLs to apply some checks. Note that the ACL version of
Willy Tarreau1ede1da2015-05-07 16:06:18 +020013774 this fetch iterates over multiple parameters and will iteratively report all
13775 parameters values if no name is given
Willy Tarreau25c1ebc2012-04-25 16:21:44 +020013776
Willy Tarreau74ca5042013-06-11 23:12:07 +020013777 ACL derivatives :
13778 urlp(<name>[,<delim>]) : exact string match
13779 urlp_beg(<name>[,<delim>]) : prefix match
13780 urlp_dir(<name>[,<delim>]) : subdir match
13781 urlp_dom(<name>[,<delim>]) : domain match
13782 urlp_end(<name>[,<delim>]) : suffix match
13783 urlp_len(<name>[,<delim>]) : length match
13784 urlp_reg(<name>[,<delim>]) : regex match
13785 urlp_sub(<name>[,<delim>]) : substring match
Willy Tarreau25c1ebc2012-04-25 16:21:44 +020013786
Willy Tarreau25c1ebc2012-04-25 16:21:44 +020013787
Willy Tarreau74ca5042013-06-11 23:12:07 +020013788 Example :
13789 # match http://example.com/foo?PHPSESSIONID=some_id
13790 stick on urlp(PHPSESSIONID)
13791 # match http://example.com/foo;JSESSIONID=some_id
13792 stick on urlp(JSESSIONID,;)
Willy Tarreau25c1ebc2012-04-25 16:21:44 +020013793
Willy Tarreau1ede1da2015-05-07 16:06:18 +020013794urlp_val([<name>[,<delim>])] : integer
Willy Tarreau74ca5042013-06-11 23:12:07 +020013795 See "urlp" above. This one extracts the URL parameter <name> in the request
13796 and converts it to an integer value. This can be used for session stickiness
13797 based on a user ID for example, or with ACLs to match a page number or price.
Willy Tarreaua9fddca2012-07-31 07:51:48 +020013798
Willy Tarreau198a7442008-01-17 12:05:32 +010013799
Willy Tarreau74ca5042013-06-11 23:12:07 +0200138007.4. Pre-defined ACLs
Willy Tarreauc57f0e22009-05-10 13:12:33 +020013801---------------------
Willy Tarreauced27012008-01-17 20:35:34 +010013802
Willy Tarreauc57f0e22009-05-10 13:12:33 +020013803Some predefined ACLs are hard-coded so that they do not have to be declared in
13804every frontend which needs them. They all have their names in upper case in
Patrick Mézard2382ad62010-05-09 10:43:32 +020013805order to avoid confusion. Their equivalence is provided below.
Willy Tarreauced27012008-01-17 20:35:34 +010013806
Willy Tarreauc57f0e22009-05-10 13:12:33 +020013807ACL name Equivalent to Usage
13808---------------+-----------------------------+---------------------------------
Willy Tarreauc57f0e22009-05-10 13:12:33 +020013809FALSE always_false never match
Willy Tarreau2492d5b2009-07-11 00:06:00 +020013810HTTP req_proto_http match if protocol is valid HTTP
Willy Tarreauc57f0e22009-05-10 13:12:33 +020013811HTTP_1.0 req_ver 1.0 match HTTP version 1.0
13812HTTP_1.1 req_ver 1.1 match HTTP version 1.1
Willy Tarreaud63335a2010-02-26 12:56:52 +010013813HTTP_CONTENT hdr_val(content-length) gt 0 match an existing content-length
13814HTTP_URL_ABS url_reg ^[^/:]*:// match absolute URL with scheme
13815HTTP_URL_SLASH url_beg / match URL beginning with "/"
13816HTTP_URL_STAR url * match URL equal to "*"
13817LOCALHOST src 127.0.0.1/8 match connection from local host
Willy Tarreauc57f0e22009-05-10 13:12:33 +020013818METH_CONNECT method CONNECT match HTTP CONNECT method
13819METH_GET method GET HEAD match HTTP GET or HEAD method
13820METH_HEAD method HEAD match HTTP HEAD method
13821METH_OPTIONS method OPTIONS match HTTP OPTIONS method
13822METH_POST method POST match HTTP POST method
13823METH_TRACE method TRACE match HTTP TRACE method
Emeric Brunbede3d02009-06-30 17:54:00 +020013824RDP_COOKIE req_rdp_cookie_cnt gt 0 match presence of an RDP cookie
Willy Tarreauc57f0e22009-05-10 13:12:33 +020013825REQ_CONTENT req_len gt 0 match data in the request buffer
Willy Tarreaud63335a2010-02-26 12:56:52 +010013826TRUE always_true always match
Willy Tarreauc57f0e22009-05-10 13:12:33 +020013827WAIT_END wait_end wait for end of content analysis
13828---------------+-----------------------------+---------------------------------
Willy Tarreauced27012008-01-17 20:35:34 +010013829
Willy Tarreaub937b7e2010-01-12 15:27:54 +010013830
Willy Tarreauc57f0e22009-05-10 13:12:33 +0200138318. Logging
13832----------
Willy Tarreau844e3c52008-01-11 16:28:18 +010013833
Willy Tarreaucc6c8912009-02-22 10:53:55 +010013834One of HAProxy's strong points certainly lies is its precise logs. It probably
13835provides the finest level of information available for such a product, which is
13836very important for troubleshooting complex environments. Standard information
13837provided in logs include client ports, TCP/HTTP state timers, precise session
13838state at termination and precise termination cause, information about decisions
Krzysztof Piotr Oledzkif8645332009-12-13 21:55:50 +010013839to direct traffic to a server, and of course the ability to capture arbitrary
Willy Tarreaucc6c8912009-02-22 10:53:55 +010013840headers.
13841
13842In order to improve administrators reactivity, it offers a great transparency
13843about encountered problems, both internal and external, and it is possible to
13844send logs to different sources at the same time with different level filters :
13845
13846 - global process-level logs (system errors, start/stop, etc..)
13847 - per-instance system and internal errors (lack of resource, bugs, ...)
13848 - per-instance external troubles (servers up/down, max connections)
13849 - per-instance activity (client connections), either at the establishment or
13850 at the termination.
Jim Freeman9e8714b2015-05-26 09:16:34 -060013851 - per-request control of log-level, eg:
13852 http-request set-log-level silent if sensitive_request
Willy Tarreaucc6c8912009-02-22 10:53:55 +010013853
13854The ability to distribute different levels of logs to different log servers
13855allow several production teams to interact and to fix their problems as soon
13856as possible. For example, the system team might monitor system-wide errors,
13857while the application team might be monitoring the up/down for their servers in
13858real time, and the security team might analyze the activity logs with one hour
13859delay.
13860
13861
Willy Tarreauc57f0e22009-05-10 13:12:33 +0200138628.1. Log levels
13863---------------
Willy Tarreaucc6c8912009-02-22 10:53:55 +010013864
Simon Hormandf791f52011-05-29 15:01:10 +090013865TCP and HTTP connections can be logged with information such as the date, time,
Willy Tarreaucc6c8912009-02-22 10:53:55 +010013866source IP address, destination address, connection duration, response times,
Simon Hormandf791f52011-05-29 15:01:10 +090013867HTTP request, HTTP return code, number of bytes transmitted, conditions
13868in which the session ended, and even exchanged cookies values. For example
13869track a particular user's problems. All messages may be sent to up to two
13870syslog servers. Check the "log" keyword in section 4.2 for more information
13871about log facilities.
Willy Tarreaucc6c8912009-02-22 10:53:55 +010013872
13873
Willy Tarreauc57f0e22009-05-10 13:12:33 +0200138748.2. Log formats
13875----------------
Willy Tarreaucc6c8912009-02-22 10:53:55 +010013876
William Lallemand48940402012-01-30 16:47:22 +010013877HAProxy supports 5 log formats. Several fields are common between these formats
Simon Hormandf791f52011-05-29 15:01:10 +090013878and will be detailed in the following sections. A few of them may vary
13879slightly with the configuration, due to indicators specific to certain
13880options. The supported formats are as follows :
Willy Tarreaucc6c8912009-02-22 10:53:55 +010013881
13882 - the default format, which is very basic and very rarely used. It only
13883 provides very basic information about the incoming connection at the moment
13884 it is accepted : source IP:port, destination IP:port, and frontend-name.
13885 This mode will eventually disappear so it will not be described to great
13886 extents.
13887
13888 - the TCP format, which is more advanced. This format is enabled when "option
13889 tcplog" is set on the frontend. HAProxy will then usually wait for the
13890 connection to terminate before logging. This format provides much richer
13891 information, such as timers, connection counts, queue size, etc... This
13892 format is recommended for pure TCP proxies.
13893
13894 - the HTTP format, which is the most advanced for HTTP proxying. This format
13895 is enabled when "option httplog" is set on the frontend. It provides the
13896 same information as the TCP format with some HTTP-specific fields such as
13897 the request, the status code, and captures of headers and cookies. This
13898 format is recommended for HTTP proxies.
13899
Emeric Brun3a058f32009-06-30 18:26:00 +020013900 - the CLF HTTP format, which is equivalent to the HTTP format, but with the
13901 fields arranged in the same order as the CLF format. In this mode, all
13902 timers, captures, flags, etc... appear one per field after the end of the
13903 common fields, in the same order they appear in the standard HTTP format.
13904
William Lallemand48940402012-01-30 16:47:22 +010013905 - the custom log format, allows you to make your own log line.
13906
Willy Tarreaucc6c8912009-02-22 10:53:55 +010013907Next sections will go deeper into details for each of these formats. Format
13908specification will be performed on a "field" basis. Unless stated otherwise, a
13909field is a portion of text delimited by any number of spaces. Since syslog
13910servers are susceptible of inserting fields at the beginning of a line, it is
13911always assumed that the first field is the one containing the process name and
13912identifier.
13913
13914Note : Since log lines may be quite long, the log examples in sections below
13915 might be broken into multiple lines. The example log lines will be
13916 prefixed with 3 closing angle brackets ('>>>') and each time a log is
13917 broken into multiple lines, each non-final line will end with a
13918 backslash ('\') and the next line will start indented by two characters.
13919
13920
Willy Tarreauc57f0e22009-05-10 13:12:33 +0200139218.2.1. Default log format
13922-------------------------
Willy Tarreaucc6c8912009-02-22 10:53:55 +010013923
13924This format is used when no specific option is set. The log is emitted as soon
13925as the connection is accepted. One should note that this currently is the only
13926format which logs the request's destination IP and ports.
13927
13928 Example :
13929 listen www
13930 mode http
13931 log global
13932 server srv1 127.0.0.1:8000
13933
13934 >>> Feb 6 12:12:09 localhost \
13935 haproxy[14385]: Connect from 10.0.1.2:33312 to 10.0.3.31:8012 \
13936 (www/HTTP)
13937
13938 Field Format Extract from the example above
13939 1 process_name '[' pid ']:' haproxy[14385]:
13940 2 'Connect from' Connect from
13941 3 source_ip ':' source_port 10.0.1.2:33312
13942 4 'to' to
13943 5 destination_ip ':' destination_port 10.0.3.31:8012
13944 6 '(' frontend_name '/' mode ')' (www/HTTP)
13945
13946Detailed fields description :
13947 - "source_ip" is the IP address of the client which initiated the connection.
13948 - "source_port" is the TCP port of the client which initiated the connection.
13949 - "destination_ip" is the IP address the client connected to.
13950 - "destination_port" is the TCP port the client connected to.
13951 - "frontend_name" is the name of the frontend (or listener) which received
13952 and processed the connection.
13953 - "mode is the mode the frontend is operating (TCP or HTTP).
13954
Willy Tarreauceb24bc2010-11-09 12:46:41 +010013955In case of a UNIX socket, the source and destination addresses are marked as
13956"unix:" and the ports reflect the internal ID of the socket which accepted the
13957connection (the same ID as reported in the stats).
13958
Willy Tarreaucc6c8912009-02-22 10:53:55 +010013959It is advised not to use this deprecated format for newer installations as it
13960will eventually disappear.
13961
13962
Willy Tarreauc57f0e22009-05-10 13:12:33 +0200139638.2.2. TCP log format
13964---------------------
Willy Tarreaucc6c8912009-02-22 10:53:55 +010013965
13966The TCP format is used when "option tcplog" is specified in the frontend, and
13967is the recommended format for pure TCP proxies. It provides a lot of precious
13968information for troubleshooting. Since this format includes timers and byte
13969counts, the log is normally emitted at the end of the session. It can be
13970emitted earlier if "option logasap" is specified, which makes sense in most
13971environments with long sessions such as remote terminals. Sessions which match
13972the "monitor" rules are never logged. It is also possible not to emit logs for
13973sessions for which no data were exchanged between the client and the server, by
Willy Tarreauc9bd0cc2009-05-10 11:57:02 +020013974specifying "option dontlognull" in the frontend. Successful connections will
13975not be logged if "option dontlog-normal" is specified in the frontend. A few
13976fields may slightly vary depending on some configuration options, those are
13977marked with a star ('*') after the field name below.
Willy Tarreaucc6c8912009-02-22 10:53:55 +010013978
13979 Example :
13980 frontend fnt
13981 mode tcp
13982 option tcplog
13983 log global
13984 default_backend bck
13985
13986 backend bck
13987 server srv1 127.0.0.1:8000
13988
13989 >>> Feb 6 12:12:56 localhost \
13990 haproxy[14387]: 10.0.1.2:33313 [06/Feb/2009:12:12:51.443] fnt \
13991 bck/srv1 0/0/5007 212 -- 0/0/0/0/3 0/0
13992
13993 Field Format Extract from the example above
13994 1 process_name '[' pid ']:' haproxy[14387]:
13995 2 client_ip ':' client_port 10.0.1.2:33313
13996 3 '[' accept_date ']' [06/Feb/2009:12:12:51.443]
13997 4 frontend_name fnt
13998 5 backend_name '/' server_name bck/srv1
13999 6 Tw '/' Tc '/' Tt* 0/0/5007
14000 7 bytes_read* 212
14001 8 termination_state --
14002 9 actconn '/' feconn '/' beconn '/' srv_conn '/' retries* 0/0/0/0/3
14003 10 srv_queue '/' backend_queue 0/0
14004
14005Detailed fields description :
14006 - "client_ip" is the IP address of the client which initiated the TCP
Willy Tarreauceb24bc2010-11-09 12:46:41 +010014007 connection to haproxy. If the connection was accepted on a UNIX socket
14008 instead, the IP address would be replaced with the word "unix". Note that
14009 when the connection is accepted on a socket configured with "accept-proxy"
14010 and the PROXY protocol is correctly used, then the logs will reflect the
14011 forwarded connection's information.
Willy Tarreaucc6c8912009-02-22 10:53:55 +010014012
14013 - "client_port" is the TCP port of the client which initiated the connection.
Willy Tarreauceb24bc2010-11-09 12:46:41 +010014014 If the connection was accepted on a UNIX socket instead, the port would be
14015 replaced with the ID of the accepting socket, which is also reported in the
14016 stats interface.
Willy Tarreaucc6c8912009-02-22 10:53:55 +010014017
14018 - "accept_date" is the exact date when the connection was received by haproxy
14019 (which might be very slightly different from the date observed on the
14020 network if there was some queuing in the system's backlog). This is usually
14021 the same date which may appear in any upstream firewall's log.
14022
14023 - "frontend_name" is the name of the frontend (or listener) which received
14024 and processed the connection.
14025
14026 - "backend_name" is the name of the backend (or listener) which was selected
14027 to manage the connection to the server. This will be the same as the
14028 frontend if no switching rule has been applied, which is common for TCP
14029 applications.
14030
14031 - "server_name" is the name of the last server to which the connection was
14032 sent, which might differ from the first one if there were connection errors
14033 and a redispatch occurred. Note that this server belongs to the backend
14034 which processed the request. If the connection was aborted before reaching
14035 a server, "<NOSRV>" is indicated instead of a server name.
14036
14037 - "Tw" is the total time in milliseconds spent waiting in the various queues.
14038 It can be "-1" if the connection was aborted before reaching the queue.
14039 See "Timers" below for more details.
14040
14041 - "Tc" is the total time in milliseconds spent waiting for the connection to
14042 establish to the final server, including retries. It can be "-1" if the
14043 connection was aborted before a connection could be established. See
14044 "Timers" below for more details.
14045
14046 - "Tt" is the total time in milliseconds elapsed between the accept and the
Jarno Huuskonen0e82b922014-04-12 18:22:19 +030014047 last close. It covers all possible processing. There is one exception, if
Willy Tarreaucc6c8912009-02-22 10:53:55 +010014048 "option logasap" was specified, then the time counting stops at the moment
14049 the log is emitted. In this case, a '+' sign is prepended before the value,
14050 indicating that the final one will be larger. See "Timers" below for more
14051 details.
14052
14053 - "bytes_read" is the total number of bytes transmitted from the server to
14054 the client when the log is emitted. If "option logasap" is specified, the
14055 this value will be prefixed with a '+' sign indicating that the final one
14056 may be larger. Please note that this value is a 64-bit counter, so log
14057 analysis tools must be able to handle it without overflowing.
14058
14059 - "termination_state" is the condition the session was in when the session
14060 ended. This indicates the session state, which side caused the end of
14061 session to happen, and for what reason (timeout, error, ...). The normal
14062 flags should be "--", indicating the session was closed by either end with
14063 no data remaining in buffers. See below "Session state at disconnection"
14064 for more details.
14065
14066 - "actconn" is the total number of concurrent connections on the process when
Jamie Gloudonaaa21002012-08-25 00:18:33 -040014067 the session was logged. It is useful to detect when some per-process system
Willy Tarreaucc6c8912009-02-22 10:53:55 +010014068 limits have been reached. For instance, if actconn is close to 512 when
14069 multiple connection errors occur, chances are high that the system limits
14070 the process to use a maximum of 1024 file descriptors and that all of them
Willy Tarreauc57f0e22009-05-10 13:12:33 +020014071 are used. See section 3 "Global parameters" to find how to tune the system.
Willy Tarreaucc6c8912009-02-22 10:53:55 +010014072
14073 - "feconn" is the total number of concurrent connections on the frontend when
14074 the session was logged. It is useful to estimate the amount of resource
14075 required to sustain high loads, and to detect when the frontend's "maxconn"
14076 has been reached. Most often when this value increases by huge jumps, it is
14077 because there is congestion on the backend servers, but sometimes it can be
14078 caused by a denial of service attack.
14079
14080 - "beconn" is the total number of concurrent connections handled by the
14081 backend when the session was logged. It includes the total number of
14082 concurrent connections active on servers as well as the number of
14083 connections pending in queues. It is useful to estimate the amount of
14084 additional servers needed to support high loads for a given application.
14085 Most often when this value increases by huge jumps, it is because there is
14086 congestion on the backend servers, but sometimes it can be caused by a
14087 denial of service attack.
14088
14089 - "srv_conn" is the total number of concurrent connections still active on
14090 the server when the session was logged. It can never exceed the server's
14091 configured "maxconn" parameter. If this value is very often close or equal
14092 to the server's "maxconn", it means that traffic regulation is involved a
14093 lot, meaning that either the server's maxconn value is too low, or that
14094 there aren't enough servers to process the load with an optimal response
14095 time. When only one of the server's "srv_conn" is high, it usually means
14096 that this server has some trouble causing the connections to take longer to
14097 be processed than on other servers.
14098
14099 - "retries" is the number of connection retries experienced by this session
14100 when trying to connect to the server. It must normally be zero, unless a
14101 server is being stopped at the same moment the connection was attempted.
14102 Frequent retries generally indicate either a network problem between
14103 haproxy and the server, or a misconfigured system backlog on the server
14104 preventing new connections from being queued. This field may optionally be
14105 prefixed with a '+' sign, indicating that the session has experienced a
14106 redispatch after the maximal retry count has been reached on the initial
14107 server. In this case, the server name appearing in the log is the one the
14108 connection was redispatched to, and not the first one, though both may
14109 sometimes be the same in case of hashing for instance. So as a general rule
14110 of thumb, when a '+' is present in front of the retry count, this count
14111 should not be attributed to the logged server.
14112
14113 - "srv_queue" is the total number of requests which were processed before
14114 this one in the server queue. It is zero when the request has not gone
14115 through the server queue. It makes it possible to estimate the approximate
14116 server's response time by dividing the time spent in queue by the number of
14117 requests in the queue. It is worth noting that if a session experiences a
14118 redispatch and passes through two server queues, their positions will be
14119 cumulated. A request should not pass through both the server queue and the
14120 backend queue unless a redispatch occurs.
14121
14122 - "backend_queue" is the total number of requests which were processed before
14123 this one in the backend's global queue. It is zero when the request has not
14124 gone through the global queue. It makes it possible to estimate the average
14125 queue length, which easily translates into a number of missing servers when
14126 divided by a server's "maxconn" parameter. It is worth noting that if a
14127 session experiences a redispatch, it may pass twice in the backend's queue,
14128 and then both positions will be cumulated. A request should not pass
14129 through both the server queue and the backend queue unless a redispatch
14130 occurs.
14131
14132
Willy Tarreauc57f0e22009-05-10 13:12:33 +0200141338.2.3. HTTP log format
14134----------------------
Willy Tarreaucc6c8912009-02-22 10:53:55 +010014135
14136The HTTP format is the most complete and the best suited for HTTP proxies. It
14137is enabled by when "option httplog" is specified in the frontend. It provides
14138the same level of information as the TCP format with additional features which
14139are specific to the HTTP protocol. Just like the TCP format, the log is usually
14140emitted at the end of the session, unless "option logasap" is specified, which
14141generally only makes sense for download sites. A session which matches the
14142"monitor" rules will never logged. It is also possible not to log sessions for
14143which no data were sent by the client by specifying "option dontlognull" in the
Willy Tarreauc9bd0cc2009-05-10 11:57:02 +020014144frontend. Successful connections will not be logged if "option dontlog-normal"
14145is specified in the frontend.
Willy Tarreaucc6c8912009-02-22 10:53:55 +010014146
14147Most fields are shared with the TCP log, some being different. A few fields may
14148slightly vary depending on some configuration options. Those ones are marked
14149with a star ('*') after the field name below.
14150
14151 Example :
14152 frontend http-in
14153 mode http
14154 option httplog
14155 log global
14156 default_backend bck
14157
14158 backend static
14159 server srv1 127.0.0.1:8000
14160
14161 >>> Feb 6 12:14:14 localhost \
14162 haproxy[14389]: 10.0.1.2:33317 [06/Feb/2009:12:14:14.655] http-in \
14163 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 +010014164 {} "GET /index.html HTTP/1.1"
Willy Tarreaucc6c8912009-02-22 10:53:55 +010014165
14166 Field Format Extract from the example above
14167 1 process_name '[' pid ']:' haproxy[14389]:
14168 2 client_ip ':' client_port 10.0.1.2:33317
14169 3 '[' accept_date ']' [06/Feb/2009:12:14:14.655]
14170 4 frontend_name http-in
14171 5 backend_name '/' server_name static/srv1
14172 6 Tq '/' Tw '/' Tc '/' Tr '/' Tt* 10/0/30/69/109
14173 7 status_code 200
14174 8 bytes_read* 2750
14175 9 captured_request_cookie -
14176 10 captured_response_cookie -
14177 11 termination_state ----
14178 12 actconn '/' feconn '/' beconn '/' srv_conn '/' retries* 1/1/1/1/0
14179 13 srv_queue '/' backend_queue 0/0
14180 14 '{' captured_request_headers* '}' {haproxy.1wt.eu}
14181 15 '{' captured_response_headers* '}' {}
14182 16 '"' http_request '"' "GET /index.html HTTP/1.1"
Willy Tarreaud72758d2010-01-12 10:42:19 +010014183
Willy Tarreaucc6c8912009-02-22 10:53:55 +010014184
14185Detailed fields description :
14186 - "client_ip" is the IP address of the client which initiated the TCP
Willy Tarreauceb24bc2010-11-09 12:46:41 +010014187 connection to haproxy. If the connection was accepted on a UNIX socket
14188 instead, the IP address would be replaced with the word "unix". Note that
14189 when the connection is accepted on a socket configured with "accept-proxy"
14190 and the PROXY protocol is correctly used, then the logs will reflect the
14191 forwarded connection's information.
Willy Tarreaucc6c8912009-02-22 10:53:55 +010014192
14193 - "client_port" is the TCP port of the client which initiated the connection.
Willy Tarreauceb24bc2010-11-09 12:46:41 +010014194 If the connection was accepted on a UNIX socket instead, the port would be
14195 replaced with the ID of the accepting socket, which is also reported in the
14196 stats interface.
Willy Tarreaucc6c8912009-02-22 10:53:55 +010014197
14198 - "accept_date" is the exact date when the TCP connection was received by
14199 haproxy (which might be very slightly different from the date observed on
14200 the network if there was some queuing in the system's backlog). This is
14201 usually the same date which may appear in any upstream firewall's log. This
14202 does not depend on the fact that the client has sent the request or not.
14203
14204 - "frontend_name" is the name of the frontend (or listener) which received
14205 and processed the connection.
14206
14207 - "backend_name" is the name of the backend (or listener) which was selected
14208 to manage the connection to the server. This will be the same as the
14209 frontend if no switching rule has been applied.
14210
14211 - "server_name" is the name of the last server to which the connection was
14212 sent, which might differ from the first one if there were connection errors
14213 and a redispatch occurred. Note that this server belongs to the backend
14214 which processed the request. If the request was aborted before reaching a
14215 server, "<NOSRV>" is indicated instead of a server name. If the request was
14216 intercepted by the stats subsystem, "<STATS>" is indicated instead.
14217
14218 - "Tq" is the total time in milliseconds spent waiting for the client to send
14219 a full HTTP request, not counting data. It can be "-1" if the connection
14220 was aborted before a complete request could be received. It should always
14221 be very small because a request generally fits in one single packet. Large
14222 times here generally indicate network trouble between the client and
14223 haproxy. See "Timers" below for more details.
14224
14225 - "Tw" is the total time in milliseconds spent waiting in the various queues.
14226 It can be "-1" if the connection was aborted before reaching the queue.
14227 See "Timers" below for more details.
14228
14229 - "Tc" is the total time in milliseconds spent waiting for the connection to
14230 establish to the final server, including retries. It can be "-1" if the
14231 request was aborted before a connection could be established. See "Timers"
14232 below for more details.
14233
14234 - "Tr" is the total time in milliseconds spent waiting for the server to send
14235 a full HTTP response, not counting data. It can be "-1" if the request was
14236 aborted before a complete response could be received. It generally matches
14237 the server's processing time for the request, though it may be altered by
14238 the amount of data sent by the client to the server. Large times here on
14239 "GET" requests generally indicate an overloaded server. See "Timers" below
14240 for more details.
14241
14242 - "Tt" is the total time in milliseconds elapsed between the accept and the
Jarno Huuskonen0e82b922014-04-12 18:22:19 +030014243 last close. It covers all possible processing. There is one exception, if
Willy Tarreaucc6c8912009-02-22 10:53:55 +010014244 "option logasap" was specified, then the time counting stops at the moment
14245 the log is emitted. In this case, a '+' sign is prepended before the value,
14246 indicating that the final one will be larger. See "Timers" below for more
14247 details.
14248
14249 - "status_code" is the HTTP status code returned to the client. This status
14250 is generally set by the server, but it might also be set by haproxy when
14251 the server cannot be reached or when its response is blocked by haproxy.
14252
14253 - "bytes_read" is the total number of bytes transmitted to the client when
14254 the log is emitted. This does include HTTP headers. If "option logasap" is
14255 specified, the this value will be prefixed with a '+' sign indicating that
14256 the final one may be larger. Please note that this value is a 64-bit
14257 counter, so log analysis tools must be able to handle it without
14258 overflowing.
14259
14260 - "captured_request_cookie" is an optional "name=value" entry indicating that
14261 the client had this cookie in the request. The cookie name and its maximum
14262 length are defined by the "capture cookie" statement in the frontend
14263 configuration. The field is a single dash ('-') when the option is not
14264 set. Only one cookie may be captured, it is generally used to track session
14265 ID exchanges between a client and a server to detect session crossing
14266 between clients due to application bugs. For more details, please consult
14267 the section "Capturing HTTP headers and cookies" below.
14268
14269 - "captured_response_cookie" is an optional "name=value" entry indicating
14270 that the server has returned a cookie with its response. The cookie name
14271 and its maximum length are defined by the "capture cookie" statement in the
14272 frontend configuration. The field is a single dash ('-') when the option is
14273 not set. Only one cookie may be captured, it is generally used to track
14274 session ID exchanges between a client and a server to detect session
14275 crossing between clients due to application bugs. For more details, please
14276 consult the section "Capturing HTTP headers and cookies" below.
14277
14278 - "termination_state" is the condition the session was in when the session
14279 ended. This indicates the session state, which side caused the end of
14280 session to happen, for what reason (timeout, error, ...), just like in TCP
14281 logs, and information about persistence operations on cookies in the last
14282 two characters. The normal flags should begin with "--", indicating the
14283 session was closed by either end with no data remaining in buffers. See
14284 below "Session state at disconnection" for more details.
14285
14286 - "actconn" is the total number of concurrent connections on the process when
Jamie Gloudonaaa21002012-08-25 00:18:33 -040014287 the session was logged. It is useful to detect when some per-process system
Willy Tarreaucc6c8912009-02-22 10:53:55 +010014288 limits have been reached. For instance, if actconn is close to 512 or 1024
14289 when multiple connection errors occur, chances are high that the system
14290 limits the process to use a maximum of 1024 file descriptors and that all
Willy Tarreauc57f0e22009-05-10 13:12:33 +020014291 of them are used. See section 3 "Global parameters" to find how to tune the
Willy Tarreaucc6c8912009-02-22 10:53:55 +010014292 system.
14293
14294 - "feconn" is the total number of concurrent connections on the frontend when
14295 the session was logged. It is useful to estimate the amount of resource
14296 required to sustain high loads, and to detect when the frontend's "maxconn"
14297 has been reached. Most often when this value increases by huge jumps, it is
14298 because there is congestion on the backend servers, but sometimes it can be
14299 caused by a denial of service attack.
14300
14301 - "beconn" is the total number of concurrent connections handled by the
14302 backend when the session was logged. It includes the total number of
14303 concurrent connections active on servers as well as the number of
14304 connections pending in queues. It is useful to estimate the amount of
14305 additional servers needed to support high loads for a given application.
14306 Most often when this value increases by huge jumps, it is because there is
14307 congestion on the backend servers, but sometimes it can be caused by a
14308 denial of service attack.
14309
14310 - "srv_conn" is the total number of concurrent connections still active on
14311 the server when the session was logged. It can never exceed the server's
14312 configured "maxconn" parameter. If this value is very often close or equal
14313 to the server's "maxconn", it means that traffic regulation is involved a
14314 lot, meaning that either the server's maxconn value is too low, or that
14315 there aren't enough servers to process the load with an optimal response
14316 time. When only one of the server's "srv_conn" is high, it usually means
14317 that this server has some trouble causing the requests to take longer to be
14318 processed than on other servers.
14319
14320 - "retries" is the number of connection retries experienced by this session
14321 when trying to connect to the server. It must normally be zero, unless a
14322 server is being stopped at the same moment the connection was attempted.
14323 Frequent retries generally indicate either a network problem between
14324 haproxy and the server, or a misconfigured system backlog on the server
14325 preventing new connections from being queued. This field may optionally be
14326 prefixed with a '+' sign, indicating that the session has experienced a
14327 redispatch after the maximal retry count has been reached on the initial
14328 server. In this case, the server name appearing in the log is the one the
14329 connection was redispatched to, and not the first one, though both may
14330 sometimes be the same in case of hashing for instance. So as a general rule
14331 of thumb, when a '+' is present in front of the retry count, this count
14332 should not be attributed to the logged server.
14333
14334 - "srv_queue" is the total number of requests which were processed before
14335 this one in the server queue. It is zero when the request has not gone
14336 through the server queue. It makes it possible to estimate the approximate
14337 server's response time by dividing the time spent in queue by the number of
14338 requests in the queue. It is worth noting that if a session experiences a
14339 redispatch and passes through two server queues, their positions will be
14340 cumulated. A request should not pass through both the server queue and the
14341 backend queue unless a redispatch occurs.
14342
14343 - "backend_queue" is the total number of requests which were processed before
14344 this one in the backend's global queue. It is zero when the request has not
14345 gone through the global queue. It makes it possible to estimate the average
14346 queue length, which easily translates into a number of missing servers when
14347 divided by a server's "maxconn" parameter. It is worth noting that if a
14348 session experiences a redispatch, it may pass twice in the backend's queue,
14349 and then both positions will be cumulated. A request should not pass
14350 through both the server queue and the backend queue unless a redispatch
14351 occurs.
14352
14353 - "captured_request_headers" is a list of headers captured in the request due
14354 to the presence of the "capture request header" statement in the frontend.
14355 Multiple headers can be captured, they will be delimited by a vertical bar
14356 ('|'). When no capture is enabled, the braces do not appear, causing a
14357 shift of remaining fields. It is important to note that this field may
14358 contain spaces, and that using it requires a smarter log parser than when
14359 it's not used. Please consult the section "Capturing HTTP headers and
14360 cookies" below for more details.
14361
14362 - "captured_response_headers" is a list of headers captured in the response
14363 due to the presence of the "capture response header" statement in the
14364 frontend. Multiple headers can be captured, they will be delimited by a
14365 vertical bar ('|'). When no capture is enabled, the braces do not appear,
14366 causing a shift of remaining fields. It is important to note that this
14367 field may contain spaces, and that using it requires a smarter log parser
14368 than when it's not used. Please consult the section "Capturing HTTP headers
14369 and cookies" below for more details.
14370
14371 - "http_request" is the complete HTTP request line, including the method,
14372 request and HTTP version string. Non-printable characters are encoded (see
14373 below the section "Non-printable characters"). This is always the last
14374 field, and it is always delimited by quotes and is the only one which can
14375 contain quotes. If new fields are added to the log format, they will be
14376 added before this field. This field might be truncated if the request is
14377 huge and does not fit in the standard syslog buffer (1024 characters). This
14378 is the reason why this field must always remain the last one.
14379
14380
Cyril Bontédc4d9032012-04-08 21:57:39 +0200143818.2.4. Custom log format
14382------------------------
William Lallemand48940402012-01-30 16:47:22 +010014383
Willy Tarreau2beef582012-12-20 17:22:52 +010014384The directive log-format allows you to customize the logs in http mode and tcp
William Lallemandbddd4fd2012-02-27 11:23:10 +010014385mode. It takes a string as argument.
William Lallemand48940402012-01-30 16:47:22 +010014386
14387HAproxy understands some log format variables. % precedes log format variables.
14388Variables can take arguments using braces ('{}'), and multiple arguments are
14389separated by commas within the braces. Flags may be added or removed by
14390prefixing them with a '+' or '-' sign.
14391
14392Special variable "%o" may be used to propagate its flags to all other
14393variables on the same format string. This is particularly handy with quoted
14394string formats ("Q").
14395
Willy Tarreauc8368452012-12-21 00:09:23 +010014396If a variable is named between square brackets ('[' .. ']') then it is used
Willy Tarreaube722a22014-06-13 16:31:59 +020014397as a sample expression rule (see section 7.3). This it useful to add some
Willy Tarreauc8368452012-12-21 00:09:23 +010014398less common information such as the client's SSL certificate's DN, or to log
14399the key that would be used to store an entry into a stick table.
14400
William Lallemand48940402012-01-30 16:47:22 +010014401Note: spaces must be escaped. A space character is considered as a separator.
Jarno Huuskonen0e82b922014-04-12 18:22:19 +030014402In order to emit a verbatim '%', it must be preceded by another '%' resulting
Willy Tarreau06d97f92013-12-02 17:45:48 +010014403in '%%'. HAProxy will automatically merge consecutive separators.
William Lallemand48940402012-01-30 16:47:22 +010014404
14405Flags are :
14406 * Q: quote a string
Jamie Gloudonaaa21002012-08-25 00:18:33 -040014407 * X: hexadecimal representation (IPs, Ports, %Ts, %rt, %pid)
William Lallemand48940402012-01-30 16:47:22 +010014408
14409 Example:
14410
14411 log-format %T\ %t\ Some\ Text
14412 log-format %{+Q}o\ %t\ %s\ %{-Q}r
14413
14414At the moment, the default HTTP format is defined this way :
14415
Willy Tarreau2beef582012-12-20 17:22:52 +010014416 log-format %ci:%cp\ [%t]\ %ft\ %b/%s\ %Tq/%Tw/%Tc/%Tr/%Tt\ %ST\ %B\ %CC\ \
14417 %CS\ %tsc\ %ac/%fc/%bc/%sc/%rc\ %sq/%bq\ %hr\ %hs\ %{+Q}r
William Lallemand48940402012-01-30 16:47:22 +010014418
William Lallemandbddd4fd2012-02-27 11:23:10 +010014419the default CLF format is defined this way :
William Lallemand48940402012-01-30 16:47:22 +010014420
Willy Tarreau2beef582012-12-20 17:22:52 +010014421 log-format %{+Q}o\ %{-Q}ci\ -\ -\ [%T]\ %r\ %ST\ %B\ \"\"\ \"\"\ %cp\ \
Willy Tarreau773d65f2012-10-12 14:56:11 +020014422 %ms\ %ft\ %b\ %s\ \%Tq\ %Tw\ %Tc\ %Tr\ %Tt\ %tsc\ %ac\ %fc\ \
Willy Tarreau2beef582012-12-20 17:22:52 +010014423 %bc\ %sc\ %rc\ %sq\ %bq\ %CC\ %CS\ \%hrl\ %hsl
William Lallemand48940402012-01-30 16:47:22 +010014424
William Lallemandbddd4fd2012-02-27 11:23:10 +010014425and the default TCP format is defined this way :
14426
Willy Tarreau2beef582012-12-20 17:22:52 +010014427 log-format %ci:%cp\ [%t]\ %ft\ %b/%s\ %Tw/%Tc/%Tt\ %B\ %ts\ \
William Lallemandbddd4fd2012-02-27 11:23:10 +010014428 %ac/%fc/%bc/%sc/%rc\ %sq/%bq
14429
William Lallemand48940402012-01-30 16:47:22 +010014430Please refer to the table below for currently defined variables :
14431
William Lallemandbddd4fd2012-02-27 11:23:10 +010014432 +---+------+-----------------------------------------------+-------------+
Willy Tarreauffc3fcd2012-10-12 20:17:54 +020014433 | R | var | field name (8.2.2 and 8.2.3 for description) | type |
William Lallemandbddd4fd2012-02-27 11:23:10 +010014434 +---+------+-----------------------------------------------+-------------+
14435 | | %o | special variable, apply flags on all next var | |
14436 +---+------+-----------------------------------------------+-------------+
Willy Tarreau2beef582012-12-20 17:22:52 +010014437 | | %B | bytes_read (from server to client) | numeric |
14438 | H | %CC | captured_request_cookie | string |
14439 | H | %CS | captured_response_cookie | string |
William Lallemand5f232402012-04-05 18:02:55 +020014440 | | %H | hostname | string |
Andrew Hayworth0ebc55f2015-04-27 21:37:03 +000014441 | H | %HM | HTTP method (ex: POST) | string |
14442 | H | %HP | HTTP request URI without query string (path) | string |
Andrew Hayworthe63ac872015-07-31 16:14:16 +000014443 | H | %HQ | HTTP request URI query string (ex: ?bar=baz) | string |
Andrew Hayworth0ebc55f2015-04-27 21:37:03 +000014444 | H | %HU | HTTP request URI (ex: /foo?bar=baz) | string |
14445 | H | %HV | HTTP version (ex: HTTP/1.0) | string |
William Lallemanda73203e2012-03-12 12:48:57 +010014446 | | %ID | unique-id | string |
Willy Tarreau4bf99632014-06-13 12:21:40 +020014447 | | %ST | status_code | numeric |
William Lallemand5f232402012-04-05 18:02:55 +020014448 | | %T | gmt_date_time | date |
William Lallemandbddd4fd2012-02-27 11:23:10 +010014449 | | %Tc | Tc | numeric |
Yuxans Yao4e25b012012-10-19 10:36:09 +080014450 | | %Tl | local_date_time | date |
Willy Tarreauffc3fcd2012-10-12 20:17:54 +020014451 | H | %Tq | Tq | numeric |
14452 | H | %Tr | Tr | numeric |
William Lallemand5f232402012-04-05 18:02:55 +020014453 | | %Ts | timestamp | numeric |
William Lallemandbddd4fd2012-02-27 11:23:10 +010014454 | | %Tt | Tt | numeric |
14455 | | %Tw | Tw | numeric |
Willy Tarreau2beef582012-12-20 17:22:52 +010014456 | | %U | bytes_uploaded (from client to server) | numeric |
William Lallemandbddd4fd2012-02-27 11:23:10 +010014457 | | %ac | actconn | numeric |
14458 | | %b | backend_name | string |
Willy Tarreau2beef582012-12-20 17:22:52 +010014459 | | %bc | beconn (backend concurrent connections) | numeric |
14460 | | %bi | backend_source_ip (connecting address) | IP |
14461 | | %bp | backend_source_port (connecting address) | numeric |
William Lallemandbddd4fd2012-02-27 11:23:10 +010014462 | | %bq | backend_queue | numeric |
Willy Tarreau2beef582012-12-20 17:22:52 +010014463 | | %ci | client_ip (accepted address) | IP |
14464 | | %cp | client_port (accepted address) | numeric |
William Lallemandbddd4fd2012-02-27 11:23:10 +010014465 | | %f | frontend_name | string |
Willy Tarreau2beef582012-12-20 17:22:52 +010014466 | | %fc | feconn (frontend concurrent connections) | numeric |
14467 | | %fi | frontend_ip (accepting address) | IP |
14468 | | %fp | frontend_port (accepting address) | numeric |
Willy Tarreau773d65f2012-10-12 14:56:11 +020014469 | | %ft | frontend_name_transport ('~' suffix for SSL) | string |
Willy Tarreau7346acb2014-08-28 15:03:15 +020014470 | | %lc | frontend_log_counter | numeric |
Willy Tarreaud9ed3d22014-06-13 12:23:06 +020014471 | | %hr | captured_request_headers default style | string |
14472 | | %hrl | captured_request_headers CLF style | string list |
14473 | | %hs | captured_response_headers default style | string |
14474 | | %hsl | captured_response_headers CLF style | string list |
Willy Tarreau812c88e2015-08-09 10:56:35 +020014475 | | %ms | accept date milliseconds (left-padded with 0) | numeric |
William Lallemand5f232402012-04-05 18:02:55 +020014476 | | %pid | PID | numeric |
Willy Tarreauffc3fcd2012-10-12 20:17:54 +020014477 | H | %r | http_request | string |
William Lallemandbddd4fd2012-02-27 11:23:10 +010014478 | | %rc | retries | numeric |
Willy Tarreau1f0da242014-01-25 11:01:50 +010014479 | | %rt | request_counter (HTTP req or TCP session) | numeric |
William Lallemandbddd4fd2012-02-27 11:23:10 +010014480 | | %s | server_name | string |
Willy Tarreau2beef582012-12-20 17:22:52 +010014481 | | %sc | srv_conn (server concurrent connections) | numeric |
14482 | | %si | server_IP (target address) | IP |
14483 | | %sp | server_port (target address) | numeric |
William Lallemandbddd4fd2012-02-27 11:23:10 +010014484 | | %sq | srv_queue | numeric |
Willy Tarreauffc3fcd2012-10-12 20:17:54 +020014485 | S | %sslc| ssl_ciphers (ex: AES-SHA) | string |
14486 | S | %sslv| ssl_version (ex: TLSv1) | string |
Willy Tarreau2beef582012-12-20 17:22:52 +010014487 | | %t | date_time (with millisecond resolution) | date |
William Lallemandbddd4fd2012-02-27 11:23:10 +010014488 | | %ts | termination_state | string |
Willy Tarreauffc3fcd2012-10-12 20:17:54 +020014489 | H | %tsc | termination_state with cookie status | string |
William Lallemandbddd4fd2012-02-27 11:23:10 +010014490 +---+------+-----------------------------------------------+-------------+
William Lallemand48940402012-01-30 16:47:22 +010014491
Willy Tarreauffc3fcd2012-10-12 20:17:54 +020014492 R = Restrictions : H = mode http only ; S = SSL only
William Lallemand48940402012-01-30 16:47:22 +010014493
Willy Tarreau5f51e1a2012-12-03 18:40:10 +010014494
144958.2.5. Error log format
14496-----------------------
14497
14498When an incoming connection fails due to an SSL handshake or an invalid PROXY
14499protocol header, haproxy will log the event using a shorter, fixed line format.
14500By default, logs are emitted at the LOG_INFO level, unless the option
14501"log-separate-errors" is set in the backend, in which case the LOG_ERR level
14502will be used. Connections on which no data are exchanged (eg: probes) are not
14503logged if the "dontlognull" option is set.
14504
14505The format looks like this :
14506
14507 >>> Dec 3 18:27:14 localhost \
14508 haproxy[6103]: 127.0.0.1:56059 [03/Dec/2012:17:35:10.380] frt/f1: \
14509 Connection error during SSL handshake
14510
14511 Field Format Extract from the example above
14512 1 process_name '[' pid ']:' haproxy[6103]:
14513 2 client_ip ':' client_port 127.0.0.1:56059
14514 3 '[' accept_date ']' [03/Dec/2012:17:35:10.380]
14515 4 frontend_name "/" bind_name ":" frt/f1:
14516 5 message Connection error during SSL handshake
14517
14518These fields just provide minimal information to help debugging connection
14519failures.
14520
14521
Willy Tarreauc57f0e22009-05-10 13:12:33 +0200145228.3. Advanced logging options
14523-----------------------------
Willy Tarreaucc6c8912009-02-22 10:53:55 +010014524
14525Some advanced logging options are often looked for but are not easy to find out
14526just by looking at the various options. Here is an entry point for the few
14527options which can enable better logging. Please refer to the keywords reference
14528for more information about their usage.
14529
14530
Willy Tarreauc57f0e22009-05-10 13:12:33 +0200145318.3.1. Disabling logging of external tests
14532------------------------------------------
Willy Tarreaucc6c8912009-02-22 10:53:55 +010014533
14534It is quite common to have some monitoring tools perform health checks on
14535haproxy. Sometimes it will be a layer 3 load-balancer such as LVS or any
14536commercial load-balancer, and sometimes it will simply be a more complete
14537monitoring system such as Nagios. When the tests are very frequent, users often
14538ask how to disable logging for those checks. There are three possibilities :
14539
14540 - if connections come from everywhere and are just TCP probes, it is often
14541 desired to simply disable logging of connections without data exchange, by
14542 setting "option dontlognull" in the frontend. It also disables logging of
14543 port scans, which may or may not be desired.
14544
14545 - if the connection come from a known source network, use "monitor-net" to
14546 declare this network as monitoring only. Any host in this network will then
14547 only be able to perform health checks, and their requests will not be
Jarno Huuskonen0e82b922014-04-12 18:22:19 +030014548 logged. This is generally appropriate to designate a list of equipment
Willy Tarreaucc6c8912009-02-22 10:53:55 +010014549 such as other load-balancers.
14550
14551 - if the tests are performed on a known URI, use "monitor-uri" to declare
14552 this URI as dedicated to monitoring. Any host sending this request will
14553 only get the result of a health-check, and the request will not be logged.
14554
14555
Willy Tarreauc57f0e22009-05-10 13:12:33 +0200145568.3.2. Logging before waiting for the session to terminate
14557----------------------------------------------------------
Willy Tarreaucc6c8912009-02-22 10:53:55 +010014558
14559The problem with logging at end of connection is that you have no clue about
14560what is happening during very long sessions, such as remote terminal sessions
14561or large file downloads. This problem can be worked around by specifying
14562"option logasap" in the frontend. Haproxy will then log as soon as possible,
14563just before data transfer begins. This means that in case of TCP, it will still
14564log the connection status to the server, and in case of HTTP, it will log just
14565after processing the server headers. In this case, the number of bytes reported
14566is the number of header bytes sent to the client. In order to avoid confusion
14567with normal logs, the total time field and the number of bytes are prefixed
14568with a '+' sign which means that real numbers are certainly larger.
14569
14570
Willy Tarreauc57f0e22009-05-10 13:12:33 +0200145718.3.3. Raising log level upon errors
14572------------------------------------
Willy Tarreauc9bd0cc2009-05-10 11:57:02 +020014573
14574Sometimes it is more convenient to separate normal traffic from errors logs,
14575for instance in order to ease error monitoring from log files. When the option
14576"log-separate-errors" is used, connections which experience errors, timeouts,
14577retries, redispatches or HTTP status codes 5xx will see their syslog level
14578raised from "info" to "err". This will help a syslog daemon store the log in
14579a separate file. It is very important to keep the errors in the normal traffic
14580file too, so that log ordering is not altered. You should also be careful if
14581you already have configured your syslog daemon to store all logs higher than
14582"notice" in an "admin" file, because the "err" level is higher than "notice".
14583
14584
Willy Tarreauc57f0e22009-05-10 13:12:33 +0200145858.3.4. Disabling logging of successful connections
14586--------------------------------------------------
Willy Tarreauc9bd0cc2009-05-10 11:57:02 +020014587
14588Although this may sound strange at first, some large sites have to deal with
14589multiple thousands of logs per second and are experiencing difficulties keeping
14590them intact for a long time or detecting errors within them. If the option
14591"dontlog-normal" is set on the frontend, all normal connections will not be
14592logged. In this regard, a normal connection is defined as one without any
14593error, timeout, retry nor redispatch. In HTTP, the status code is checked too,
14594and a response with a status 5xx is not considered normal and will be logged
14595too. Of course, doing is is really discouraged as it will remove most of the
14596useful information from the logs. Do this only if you have no other
14597alternative.
14598
14599
Willy Tarreauc57f0e22009-05-10 13:12:33 +0200146008.4. Timing events
14601------------------
Willy Tarreaucc6c8912009-02-22 10:53:55 +010014602
14603Timers provide a great help in troubleshooting network problems. All values are
14604reported in milliseconds (ms). These timers should be used in conjunction with
14605the session termination flags. In TCP mode with "option tcplog" set on the
14606frontend, 3 control points are reported under the form "Tw/Tc/Tt", and in HTTP
14607mode, 5 control points are reported under the form "Tq/Tw/Tc/Tr/Tt" :
14608
14609 - Tq: total time to get the client request (HTTP mode only). It's the time
14610 elapsed between the moment the client connection was accepted and the
14611 moment the proxy received the last HTTP header. The value "-1" indicates
14612 that the end of headers (empty line) has never been seen. This happens when
14613 the client closes prematurely or times out.
14614
14615 - Tw: total time spent in the queues waiting for a connection slot. It
14616 accounts for backend queue as well as the server queues, and depends on the
14617 queue size, and the time needed for the server to complete previous
14618 requests. The value "-1" means that the request was killed before reaching
14619 the queue, which is generally what happens with invalid or denied requests.
14620
14621 - Tc: total time to establish the TCP connection to the server. It's the time
14622 elapsed between the moment the proxy sent the connection request, and the
14623 moment it was acknowledged by the server, or between the TCP SYN packet and
14624 the matching SYN/ACK packet in return. The value "-1" means that the
14625 connection never established.
14626
14627 - Tr: server response time (HTTP mode only). It's the time elapsed between
14628 the moment the TCP connection was established to the server and the moment
14629 the server sent its complete response headers. It purely shows its request
14630 processing time, without the network overhead due to the data transmission.
14631 It is worth noting that when the client has data to send to the server, for
14632 instance during a POST request, the time already runs, and this can distort
14633 apparent response time. For this reason, it's generally wise not to trust
14634 too much this field for POST requests initiated from clients behind an
14635 untrusted network. A value of "-1" here means that the last the response
14636 header (empty line) was never seen, most likely because the server timeout
14637 stroke before the server managed to process the request.
14638
14639 - Tt: total session duration time, between the moment the proxy accepted it
14640 and the moment both ends were closed. The exception is when the "logasap"
14641 option is specified. In this case, it only equals (Tq+Tw+Tc+Tr), and is
14642 prefixed with a '+' sign. From this field, we can deduce "Td", the data
Jarno Huuskonen0e82b922014-04-12 18:22:19 +030014643 transmission time, by subtracting other timers when valid :
Willy Tarreaucc6c8912009-02-22 10:53:55 +010014644
14645 Td = Tt - (Tq + Tw + Tc + Tr)
14646
14647 Timers with "-1" values have to be excluded from this equation. In TCP
14648 mode, "Tq" and "Tr" have to be excluded too. Note that "Tt" can never be
14649 negative.
14650
14651These timers provide precious indications on trouble causes. Since the TCP
14652protocol defines retransmit delays of 3, 6, 12... seconds, we know for sure
14653that timers close to multiples of 3s are nearly always related to lost packets
Krzysztof Piotr Oledzkif8645332009-12-13 21:55:50 +010014654due to network problems (wires, negotiation, congestion). Moreover, if "Tt" is
Willy Tarreaucc6c8912009-02-22 10:53:55 +010014655close to a timeout value specified in the configuration, it often means that a
14656session has been aborted on timeout.
14657
14658Most common cases :
14659
14660 - If "Tq" is close to 3000, a packet has probably been lost between the
14661 client and the proxy. This is very rare on local networks but might happen
14662 when clients are on far remote networks and send large requests. It may
14663 happen that values larger than usual appear here without any network cause.
14664 Sometimes, during an attack or just after a resource starvation has ended,
14665 haproxy may accept thousands of connections in a few milliseconds. The time
14666 spent accepting these connections will inevitably slightly delay processing
14667 of other connections, and it can happen that request times in the order of
14668 a few tens of milliseconds are measured after a few thousands of new
Patrick Mezard105faca2010-06-12 17:02:46 +020014669 connections have been accepted at once. Setting "option http-server-close"
14670 may display larger request times since "Tq" also measures the time spent
14671 waiting for additional requests.
Willy Tarreaucc6c8912009-02-22 10:53:55 +010014672
14673 - If "Tc" is close to 3000, a packet has probably been lost between the
14674 server and the proxy during the server connection phase. This value should
14675 always be very low, such as 1 ms on local networks and less than a few tens
14676 of ms on remote networks.
14677
Willy Tarreau55165fe2009-05-10 12:02:55 +020014678 - If "Tr" is nearly always lower than 3000 except some rare values which seem
14679 to be the average majored by 3000, there are probably some packets lost
14680 between the proxy and the server.
Willy Tarreaucc6c8912009-02-22 10:53:55 +010014681
14682 - If "Tt" is large even for small byte counts, it generally is because
14683 neither the client nor the server decides to close the connection, for
14684 instance because both have agreed on a keep-alive connection mode. In order
14685 to solve this issue, it will be needed to specify "option httpclose" on
14686 either the frontend or the backend. If the problem persists, it means that
14687 the server ignores the "close" connection mode and expects the client to
14688 close. Then it will be required to use "option forceclose". Having the
14689 smallest possible 'Tt' is important when connection regulation is used with
14690 the "maxconn" option on the servers, since no new connection will be sent
14691 to the server until another one is released.
14692
14693Other noticeable HTTP log cases ('xx' means any value to be ignored) :
14694
14695 Tq/Tw/Tc/Tr/+Tt The "option logasap" is present on the frontend and the log
14696 was emitted before the data phase. All the timers are valid
14697 except "Tt" which is shorter than reality.
14698
14699 -1/xx/xx/xx/Tt The client was not able to send a complete request in time
14700 or it aborted too early. Check the session termination flags
14701 then "timeout http-request" and "timeout client" settings.
14702
14703 Tq/-1/xx/xx/Tt It was not possible to process the request, maybe because
14704 servers were out of order, because the request was invalid
14705 or forbidden by ACL rules. Check the session termination
14706 flags.
14707
14708 Tq/Tw/-1/xx/Tt The connection could not establish on the server. Either it
14709 actively refused it or it timed out after Tt-(Tq+Tw) ms.
14710 Check the session termination flags, then check the
14711 "timeout connect" setting. Note that the tarpit action might
14712 return similar-looking patterns, with "Tw" equal to the time
14713 the client connection was maintained open.
14714
14715 Tq/Tw/Tc/-1/Tt The server has accepted the connection but did not return
Jarno Huuskonen0e82b922014-04-12 18:22:19 +030014716 a complete response in time, or it closed its connection
Willy Tarreaucc6c8912009-02-22 10:53:55 +010014717 unexpectedly after Tt-(Tq+Tw+Tc) ms. Check the session
14718 termination flags, then check the "timeout server" setting.
14719
14720
Willy Tarreauc57f0e22009-05-10 13:12:33 +0200147218.5. Session state at disconnection
14722-----------------------------------
Willy Tarreaucc6c8912009-02-22 10:53:55 +010014723
14724TCP and HTTP logs provide a session termination indicator in the
14725"termination_state" field, just before the number of active connections. It is
147262-characters long in TCP mode, and is extended to 4 characters in HTTP mode,
14727each of which has a special meaning :
14728
14729 - On the first character, a code reporting the first event which caused the
14730 session to terminate :
14731
14732 C : the TCP session was unexpectedly aborted by the client.
14733
14734 S : the TCP session was unexpectedly aborted by the server, or the
14735 server explicitly refused it.
14736
14737 P : the session was prematurely aborted by the proxy, because of a
14738 connection limit enforcement, because a DENY filter was matched,
14739 because of a security check which detected and blocked a dangerous
14740 error in server response which might have caused information leak
Willy Tarreau570f2212013-06-10 16:42:09 +020014741 (eg: cacheable cookie).
14742
14743 L : the session was locally processed by haproxy and was not passed to
14744 a server. This is what happens for stats and redirects.
Willy Tarreaucc6c8912009-02-22 10:53:55 +010014745
14746 R : a resource on the proxy has been exhausted (memory, sockets, source
14747 ports, ...). Usually, this appears during the connection phase, and
14748 system logs should contain a copy of the precise error. If this
14749 happens, it must be considered as a very serious anomaly which
14750 should be fixed as soon as possible by any means.
14751
14752 I : an internal error was identified by the proxy during a self-check.
14753 This should NEVER happen, and you are encouraged to report any log
14754 containing this, because this would almost certainly be a bug. It
14755 would be wise to preventively restart the process after such an
14756 event too, in case it would be caused by memory corruption.
14757
Simon Horman752dc4a2011-06-21 14:34:59 +090014758 D : the session was killed by haproxy because the server was detected
14759 as down and was configured to kill all connections when going down.
14760
Justin Karnegeseb2c24a2012-05-24 15:28:52 -070014761 U : the session was killed by haproxy on this backup server because an
14762 active server was detected as up and was configured to kill all
14763 backup connections when going up.
14764
Willy Tarreaua2a64e92011-09-07 23:01:56 +020014765 K : the session was actively killed by an admin operating on haproxy.
14766
Willy Tarreaucc6c8912009-02-22 10:53:55 +010014767 c : the client-side timeout expired while waiting for the client to
14768 send or receive data.
14769
14770 s : the server-side timeout expired while waiting for the server to
14771 send or receive data.
14772
14773 - : normal session completion, both the client and the server closed
14774 with nothing left in the buffers.
14775
14776 - on the second character, the TCP or HTTP session state when it was closed :
14777
Willy Tarreauf7b30a92010-12-06 22:59:17 +010014778 R : the proxy was waiting for a complete, valid REQUEST from the client
Willy Tarreaucc6c8912009-02-22 10:53:55 +010014779 (HTTP mode only). Nothing was sent to any server.
14780
14781 Q : the proxy was waiting in the QUEUE for a connection slot. This can
14782 only happen when servers have a 'maxconn' parameter set. It can
14783 also happen in the global queue after a redispatch consecutive to
14784 a failed attempt to connect to a dying server. If no redispatch is
14785 reported, then no connection attempt was made to any server.
14786
14787 C : the proxy was waiting for the CONNECTION to establish on the
14788 server. The server might at most have noticed a connection attempt.
14789
14790 H : the proxy was waiting for complete, valid response HEADERS from the
14791 server (HTTP only).
14792
14793 D : the session was in the DATA phase.
14794
14795 L : the proxy was still transmitting LAST data to the client while the
14796 server had already finished. This one is very rare as it can only
14797 happen when the client dies while receiving the last packets.
14798
14799 T : the request was tarpitted. It has been held open with the client
14800 during the whole "timeout tarpit" duration or until the client
14801 closed, both of which will be reported in the "Tw" timer.
14802
14803 - : normal session completion after end of data transfer.
14804
14805 - the third character tells whether the persistence cookie was provided by
14806 the client (only in HTTP mode) :
14807
14808 N : the client provided NO cookie. This is usually the case for new
14809 visitors, so counting the number of occurrences of this flag in the
14810 logs generally indicate a valid trend for the site frequentation.
14811
14812 I : the client provided an INVALID cookie matching no known server.
14813 This might be caused by a recent configuration change, mixed
Cyril Bontéa8e7bbc2010-04-25 22:29:29 +020014814 cookies between HTTP/HTTPS sites, persistence conditionally
14815 ignored, or an attack.
Willy Tarreaucc6c8912009-02-22 10:53:55 +010014816
14817 D : the client provided a cookie designating a server which was DOWN,
14818 so either "option persist" was used and the client was sent to
14819 this server, or it was not set and the client was redispatched to
14820 another server.
14821
Willy Tarreau996a92c2010-10-13 19:30:47 +020014822 V : the client provided a VALID cookie, and was sent to the associated
Willy Tarreaucc6c8912009-02-22 10:53:55 +010014823 server.
14824
Willy Tarreau996a92c2010-10-13 19:30:47 +020014825 E : the client provided a valid cookie, but with a last date which was
14826 older than what is allowed by the "maxidle" cookie parameter, so
14827 the cookie is consider EXPIRED and is ignored. The request will be
14828 redispatched just as if there was no cookie.
14829
14830 O : the client provided a valid cookie, but with a first date which was
14831 older than what is allowed by the "maxlife" cookie parameter, so
14832 the cookie is consider too OLD and is ignored. The request will be
14833 redispatched just as if there was no cookie.
14834
Willy Tarreauc89ccb62012-04-05 21:18:22 +020014835 U : a cookie was present but was not used to select the server because
14836 some other server selection mechanism was used instead (typically a
14837 "use-server" rule).
14838
Willy Tarreaucc6c8912009-02-22 10:53:55 +010014839 - : does not apply (no cookie set in configuration).
14840
14841 - the last character reports what operations were performed on the persistence
14842 cookie returned by the server (only in HTTP mode) :
14843
14844 N : NO cookie was provided by the server, and none was inserted either.
14845
14846 I : no cookie was provided by the server, and the proxy INSERTED one.
14847 Note that in "cookie insert" mode, if the server provides a cookie,
14848 it will still be overwritten and reported as "I" here.
14849
Willy Tarreau996a92c2010-10-13 19:30:47 +020014850 U : the proxy UPDATED the last date in the cookie that was presented by
14851 the client. This can only happen in insert mode with "maxidle". It
Jarno Huuskonen0e82b922014-04-12 18:22:19 +030014852 happens every time there is activity at a different date than the
Willy Tarreau996a92c2010-10-13 19:30:47 +020014853 date indicated in the cookie. If any other change happens, such as
14854 a redispatch, then the cookie will be marked as inserted instead.
14855
Willy Tarreaucc6c8912009-02-22 10:53:55 +010014856 P : a cookie was PROVIDED by the server and transmitted as-is.
14857
14858 R : the cookie provided by the server was REWRITTEN by the proxy, which
14859 happens in "cookie rewrite" or "cookie prefix" modes.
14860
14861 D : the cookie provided by the server was DELETED by the proxy.
14862
14863 - : does not apply (no cookie set in configuration).
14864
Willy Tarreau996a92c2010-10-13 19:30:47 +020014865The combination of the two first flags gives a lot of information about what
14866was happening when the session terminated, and why it did terminate. It can be
Willy Tarreaucc6c8912009-02-22 10:53:55 +010014867helpful to detect server saturation, network troubles, local system resource
14868starvation, attacks, etc...
14869
14870The most common termination flags combinations are indicated below. They are
14871alphabetically sorted, with the lowercase set just after the upper case for
14872easier finding and understanding.
14873
14874 Flags Reason
14875
14876 -- Normal termination.
14877
14878 CC The client aborted before the connection could be established to the
14879 server. This can happen when haproxy tries to connect to a recently
14880 dead (or unchecked) server, and the client aborts while haproxy is
14881 waiting for the server to respond or for "timeout connect" to expire.
14882
14883 CD The client unexpectedly aborted during data transfer. This can be
14884 caused by a browser crash, by an intermediate equipment between the
14885 client and haproxy which decided to actively break the connection,
14886 by network routing issues between the client and haproxy, or by a
14887 keep-alive session between the server and the client terminated first
14888 by the client.
Willy Tarreaud72758d2010-01-12 10:42:19 +010014889
Willy Tarreaucc6c8912009-02-22 10:53:55 +010014890 cD The client did not send nor acknowledge any data for as long as the
14891 "timeout client" delay. This is often caused by network failures on
Cyril Bontédc4d9032012-04-08 21:57:39 +020014892 the client side, or the client simply leaving the net uncleanly.
Willy Tarreaucc6c8912009-02-22 10:53:55 +010014893
14894 CH The client aborted while waiting for the server to start responding.
14895 It might be the server taking too long to respond or the client
14896 clicking the 'Stop' button too fast.
14897
14898 cH The "timeout client" stroke while waiting for client data during a
14899 POST request. This is sometimes caused by too large TCP MSS values
14900 for PPPoE networks which cannot transport full-sized packets. It can
14901 also happen when client timeout is smaller than server timeout and
14902 the server takes too long to respond.
14903
14904 CQ The client aborted while its session was queued, waiting for a server
14905 with enough empty slots to accept it. It might be that either all the
14906 servers were saturated or that the assigned server was taking too
14907 long a time to respond.
14908
14909 CR The client aborted before sending a full HTTP request. Most likely
14910 the request was typed by hand using a telnet client, and aborted
14911 too early. The HTTP status code is likely a 400 here. Sometimes this
14912 might also be caused by an IDS killing the connection between haproxy
Willy Tarreau0f228a02015-05-01 15:37:53 +020014913 and the client. "option http-ignore-probes" can be used to ignore
14914 connections without any data transfer.
Willy Tarreaucc6c8912009-02-22 10:53:55 +010014915
14916 cR The "timeout http-request" stroke before the client sent a full HTTP
14917 request. This is sometimes caused by too large TCP MSS values on the
14918 client side for PPPoE networks which cannot transport full-sized
14919 packets, or by clients sending requests by hand and not typing fast
14920 enough, or forgetting to enter the empty line at the end of the
Willy Tarreau2705a612014-05-23 17:38:34 +020014921 request. The HTTP status code is likely a 408 here. Note: recently,
Willy Tarreau0f228a02015-05-01 15:37:53 +020014922 some browsers started to implement a "pre-connect" feature consisting
14923 in speculatively connecting to some recently visited web sites just
14924 in case the user would like to visit them. This results in many
14925 connections being established to web sites, which end up in 408
14926 Request Timeout if the timeout strikes first, or 400 Bad Request when
14927 the browser decides to close them first. These ones pollute the log
14928 and feed the error counters. Some versions of some browsers have even
14929 been reported to display the error code. It is possible to work
14930 around the undesirable effects of this behaviour by adding "option
14931 http-ignore-probes" in the frontend, resulting in connections with
14932 zero data transfer to be totally ignored. This will definitely hide
14933 the errors of people experiencing connectivity issues though.
Willy Tarreaucc6c8912009-02-22 10:53:55 +010014934
14935 CT The client aborted while its session was tarpitted. It is important to
14936 check if this happens on valid requests, in order to be sure that no
Willy Tarreau55165fe2009-05-10 12:02:55 +020014937 wrong tarpit rules have been written. If a lot of them happen, it
14938 might make sense to lower the "timeout tarpit" value to something
14939 closer to the average reported "Tw" timer, in order not to consume
14940 resources for just a few attackers.
Willy Tarreaucc6c8912009-02-22 10:53:55 +010014941
Willy Tarreau570f2212013-06-10 16:42:09 +020014942 LR The request was intercepted and locally handled by haproxy. Generally
14943 it means that this was a redirect or a stats request.
14944
Krzysztof Piotr Oledzkif8645332009-12-13 21:55:50 +010014945 SC The server or an equipment between it and haproxy explicitly refused
Willy Tarreaucc6c8912009-02-22 10:53:55 +010014946 the TCP connection (the proxy received a TCP RST or an ICMP message
14947 in return). Under some circumstances, it can also be the network
14948 stack telling the proxy that the server is unreachable (eg: no route,
14949 or no ARP response on local network). When this happens in HTTP mode,
14950 the status code is likely a 502 or 503 here.
14951
14952 sC The "timeout connect" stroke before a connection to the server could
14953 complete. When this happens in HTTP mode, the status code is likely a
14954 503 or 504 here.
14955
14956 SD The connection to the server died with an error during the data
14957 transfer. This usually means that haproxy has received an RST from
14958 the server or an ICMP message from an intermediate equipment while
14959 exchanging data with the server. This can be caused by a server crash
14960 or by a network issue on an intermediate equipment.
14961
14962 sD The server did not send nor acknowledge any data for as long as the
14963 "timeout server" setting during the data phase. This is often caused
Krzysztof Piotr Oledzkif8645332009-12-13 21:55:50 +010014964 by too short timeouts on L4 equipments before the server (firewalls,
Willy Tarreaucc6c8912009-02-22 10:53:55 +010014965 load-balancers, ...), as well as keep-alive sessions maintained
14966 between the client and the server expiring first on haproxy.
14967
14968 SH The server aborted before sending its full HTTP response headers, or
14969 it crashed while processing the request. Since a server aborting at
14970 this moment is very rare, it would be wise to inspect its logs to
14971 control whether it crashed and why. The logged request may indicate a
14972 small set of faulty requests, demonstrating bugs in the application.
14973 Sometimes this might also be caused by an IDS killing the connection
14974 between haproxy and the server.
14975
14976 sH The "timeout server" stroke before the server could return its
14977 response headers. This is the most common anomaly, indicating too
14978 long transactions, probably caused by server or database saturation.
14979 The immediate workaround consists in increasing the "timeout server"
14980 setting, but it is important to keep in mind that the user experience
14981 will suffer from these long response times. The only long term
14982 solution is to fix the application.
14983
14984 sQ The session spent too much time in queue and has been expired. See
14985 the "timeout queue" and "timeout connect" settings to find out how to
14986 fix this if it happens too often. If it often happens massively in
14987 short periods, it may indicate general problems on the affected
14988 servers due to I/O or database congestion, or saturation caused by
14989 external attacks.
14990
14991 PC The proxy refused to establish a connection to the server because the
14992 process' socket limit has been reached while attempting to connect.
Cyril Bontédc4d9032012-04-08 21:57:39 +020014993 The global "maxconn" parameter may be increased in the configuration
Willy Tarreaucc6c8912009-02-22 10:53:55 +010014994 so that it does not happen anymore. This status is very rare and
14995 might happen when the global "ulimit-n" parameter is forced by hand.
14996
Willy Tarreaued2fd2d2010-12-29 11:23:27 +010014997 PD The proxy blocked an incorrectly formatted chunked encoded message in
14998 a request or a response, after the server has emitted its headers. In
14999 most cases, this will indicate an invalid message from the server to
Willy Tarreauf3a3e132013-08-31 08:16:26 +020015000 the client. Haproxy supports chunk sizes of up to 2GB - 1 (2147483647
15001 bytes). Any larger size will be considered as an error.
Willy Tarreaued2fd2d2010-12-29 11:23:27 +010015002
Willy Tarreaucc6c8912009-02-22 10:53:55 +010015003 PH The proxy blocked the server's response, because it was invalid,
15004 incomplete, dangerous (cache control), or matched a security filter.
15005 In any case, an HTTP 502 error is sent to the client. One possible
15006 cause for this error is an invalid syntax in an HTTP header name
Willy Tarreaued2fd2d2010-12-29 11:23:27 +010015007 containing unauthorized characters. It is also possible but quite
15008 rare, that the proxy blocked a chunked-encoding request from the
15009 client due to an invalid syntax, before the server responded. In this
15010 case, an HTTP 400 error is sent to the client and reported in the
15011 logs.
Willy Tarreaucc6c8912009-02-22 10:53:55 +010015012
15013 PR The proxy blocked the client's HTTP request, either because of an
15014 invalid HTTP syntax, in which case it returned an HTTP 400 error to
15015 the client, or because a deny filter matched, in which case it
15016 returned an HTTP 403 error.
15017
15018 PT The proxy blocked the client's request and has tarpitted its
15019 connection before returning it a 500 server error. Nothing was sent
15020 to the server. The connection was maintained open for as long as
15021 reported by the "Tw" timer field.
15022
15023 RC A local resource has been exhausted (memory, sockets, source ports)
15024 preventing the connection to the server from establishing. The error
15025 logs will tell precisely what was missing. This is very rare and can
15026 only be solved by proper system tuning.
15027
Willy Tarreau996a92c2010-10-13 19:30:47 +020015028The combination of the two last flags gives a lot of information about how
15029persistence was handled by the client, the server and by haproxy. This is very
15030important to troubleshoot disconnections, when users complain they have to
15031re-authenticate. The commonly encountered flags are :
15032
15033 -- Persistence cookie is not enabled.
15034
15035 NN No cookie was provided by the client, none was inserted in the
15036 response. For instance, this can be in insert mode with "postonly"
15037 set on a GET request.
15038
15039 II A cookie designating an invalid server was provided by the client,
15040 a valid one was inserted in the response. This typically happens when
Jamie Gloudonaaa21002012-08-25 00:18:33 -040015041 a "server" entry is removed from the configuration, since its cookie
Willy Tarreau996a92c2010-10-13 19:30:47 +020015042 value can be presented by a client when no other server knows it.
15043
15044 NI No cookie was provided by the client, one was inserted in the
15045 response. This typically happens for first requests from every user
15046 in "insert" mode, which makes it an easy way to count real users.
15047
15048 VN A cookie was provided by the client, none was inserted in the
15049 response. This happens for most responses for which the client has
15050 already got a cookie.
15051
15052 VU A cookie was provided by the client, with a last visit date which is
15053 not completely up-to-date, so an updated cookie was provided in
15054 response. This can also happen if there was no date at all, or if
15055 there was a date but the "maxidle" parameter was not set, so that the
15056 cookie can be switched to unlimited time.
15057
15058 EI A cookie was provided by the client, with a last visit date which is
15059 too old for the "maxidle" parameter, so the cookie was ignored and a
15060 new cookie was inserted in the response.
15061
15062 OI A cookie was provided by the client, with a first visit date which is
15063 too old for the "maxlife" parameter, so the cookie was ignored and a
15064 new cookie was inserted in the response.
15065
15066 DI The server designated by the cookie was down, a new server was
15067 selected and a new cookie was emitted in the response.
15068
15069 VI The server designated by the cookie was not marked dead but could not
15070 be reached. A redispatch happened and selected another one, which was
15071 then advertised in the response.
15072
Willy Tarreaucc6c8912009-02-22 10:53:55 +010015073
Willy Tarreauc57f0e22009-05-10 13:12:33 +0200150748.6. Non-printable characters
15075-----------------------------
Willy Tarreaucc6c8912009-02-22 10:53:55 +010015076
15077In order not to cause trouble to log analysis tools or terminals during log
15078consulting, non-printable characters are not sent as-is into log files, but are
15079converted to the two-digits hexadecimal representation of their ASCII code,
15080prefixed by the character '#'. The only characters that can be logged without
15081being escaped are comprised between 32 and 126 (inclusive). Obviously, the
15082escape character '#' itself is also encoded to avoid any ambiguity ("#23"). It
15083is the same for the character '"' which becomes "#22", as well as '{', '|' and
15084'}' when logging headers.
15085
15086Note that the space character (' ') is not encoded in headers, which can cause
15087issues for tools relying on space count to locate fields. A typical header
15088containing spaces is "User-Agent".
15089
15090Last, it has been observed that some syslog daemons such as syslog-ng escape
15091the quote ('"') with a backslash ('\'). The reverse operation can safely be
15092performed since no quote may appear anywhere else in the logs.
15093
15094
Willy Tarreauc57f0e22009-05-10 13:12:33 +0200150958.7. Capturing HTTP cookies
15096---------------------------
Willy Tarreaucc6c8912009-02-22 10:53:55 +010015097
15098Cookie capture simplifies the tracking a complete user session. This can be
15099achieved using the "capture cookie" statement in the frontend. Please refer to
Willy Tarreauc57f0e22009-05-10 13:12:33 +020015100section 4.2 for more details. Only one cookie can be captured, and the same
Willy Tarreaucc6c8912009-02-22 10:53:55 +010015101cookie will simultaneously be checked in the request ("Cookie:" header) and in
15102the response ("Set-Cookie:" header). The respective values will be reported in
15103the HTTP logs at the "captured_request_cookie" and "captured_response_cookie"
Willy Tarreauc57f0e22009-05-10 13:12:33 +020015104locations (see section 8.2.3 about HTTP log format). When either cookie is
Willy Tarreaucc6c8912009-02-22 10:53:55 +010015105not seen, a dash ('-') replaces the value. This way, it's easy to detect when a
15106user switches to a new session for example, because the server will reassign it
15107a new cookie. It is also possible to detect if a server unexpectedly sets a
15108wrong cookie to a client, leading to session crossing.
15109
15110 Examples :
15111 # capture the first cookie whose name starts with "ASPSESSION"
15112 capture cookie ASPSESSION len 32
15113
15114 # capture the first cookie whose name is exactly "vgnvisitor"
15115 capture cookie vgnvisitor= len 32
15116
15117
Willy Tarreauc57f0e22009-05-10 13:12:33 +0200151188.8. Capturing HTTP headers
15119---------------------------
Willy Tarreaucc6c8912009-02-22 10:53:55 +010015120
15121Header captures are useful to track unique request identifiers set by an upper
15122proxy, virtual host names, user-agents, POST content-length, referrers, etc. In
15123the response, one can search for information about the response length, how the
15124server asked the cache to behave, or an object location during a redirection.
15125
15126Header captures are performed using the "capture request header" and "capture
15127response header" statements in the frontend. Please consult their definition in
Willy Tarreauc57f0e22009-05-10 13:12:33 +020015128section 4.2 for more details.
Willy Tarreaucc6c8912009-02-22 10:53:55 +010015129
15130It is possible to include both request headers and response headers at the same
Krzysztof Piotr Oledzkif8645332009-12-13 21:55:50 +010015131time. Non-existent headers are logged as empty strings, and if one header
15132appears more than once, only its last occurrence will be logged. Request headers
Willy Tarreaucc6c8912009-02-22 10:53:55 +010015133are grouped within braces '{' and '}' in the same order as they were declared,
15134and delimited with a vertical bar '|' without any space. Response headers
15135follow the same representation, but are displayed after a space following the
15136request headers block. These blocks are displayed just before the HTTP request
15137in the logs.
15138
Willy Tarreaud9ed3d22014-06-13 12:23:06 +020015139As a special case, it is possible to specify an HTTP header capture in a TCP
15140frontend. The purpose is to enable logging of headers which will be parsed in
15141an HTTP backend if the request is then switched to this HTTP backend.
15142
Willy Tarreaucc6c8912009-02-22 10:53:55 +010015143 Example :
15144 # This instance chains to the outgoing proxy
15145 listen proxy-out
15146 mode http
15147 option httplog
15148 option logasap
15149 log global
15150 server cache1 192.168.1.1:3128
15151
15152 # log the name of the virtual server
15153 capture request header Host len 20
15154
15155 # log the amount of data uploaded during a POST
15156 capture request header Content-Length len 10
15157
15158 # log the beginning of the referrer
15159 capture request header Referer len 20
15160
15161 # server name (useful for outgoing proxies only)
15162 capture response header Server len 20
15163
15164 # logging the content-length is useful with "option logasap"
15165 capture response header Content-Length len 10
15166
15167 # log the expected cache behaviour on the response
15168 capture response header Cache-Control len 8
15169
15170 # the Via header will report the next proxy's name
15171 capture response header Via len 20
15172
15173 # log the URL location during a redirection
15174 capture response header Location len 20
15175
15176 >>> Aug 9 20:26:09 localhost \
15177 haproxy[2022]: 127.0.0.1:34014 [09/Aug/2004:20:26:09] proxy-out \
15178 proxy-out/cache1 0/0/0/162/+162 200 +350 - - ---- 0/0/0/0/0 0/0 \
15179 {fr.adserver.yahoo.co||http://fr.f416.mail.} {|864|private||} \
15180 "GET http://fr.adserver.yahoo.com/"
15181
15182 >>> Aug 9 20:30:46 localhost \
15183 haproxy[2022]: 127.0.0.1:34020 [09/Aug/2004:20:30:46] proxy-out \
15184 proxy-out/cache1 0/0/0/182/+182 200 +279 - - ---- 0/0/0/0/0 0/0 \
15185 {w.ods.org||} {Formilux/0.1.8|3495|||} \
Willy Tarreaud72758d2010-01-12 10:42:19 +010015186 "GET http://trafic.1wt.eu/ HTTP/1.1"
Willy Tarreaucc6c8912009-02-22 10:53:55 +010015187
15188 >>> Aug 9 20:30:46 localhost \
15189 haproxy[2022]: 127.0.0.1:34028 [09/Aug/2004:20:30:46] proxy-out \
15190 proxy-out/cache1 0/0/2/126/+128 301 +223 - - ---- 0/0/0/0/0 0/0 \
15191 {www.sytadin.equipement.gouv.fr||http://trafic.1wt.eu/} \
15192 {Apache|230|||http://www.sytadin.} \
Willy Tarreaud72758d2010-01-12 10:42:19 +010015193 "GET http://www.sytadin.equipement.gouv.fr/ HTTP/1.1"
Willy Tarreaucc6c8912009-02-22 10:53:55 +010015194
15195
Willy Tarreauc57f0e22009-05-10 13:12:33 +0200151968.9. Examples of logs
15197---------------------
Willy Tarreaucc6c8912009-02-22 10:53:55 +010015198
15199These are real-world examples of logs accompanied with an explanation. Some of
15200them have been made up by hand. The syslog part has been removed for better
15201reading. Their sole purpose is to explain how to decipher them.
15202
15203 >>> haproxy[674]: 127.0.0.1:33318 [15/Oct/2003:08:31:57.130] px-http \
15204 px-http/srv1 6559/0/7/147/6723 200 243 - - ---- 5/3/3/1/0 0/0 \
15205 "HEAD / HTTP/1.0"
15206
15207 => long request (6.5s) entered by hand through 'telnet'. The server replied
15208 in 147 ms, and the session ended normally ('----')
15209
15210 >>> haproxy[674]: 127.0.0.1:33319 [15/Oct/2003:08:31:57.149] px-http \
15211 px-http/srv1 6559/1230/7/147/6870 200 243 - - ---- 324/239/239/99/0 \
15212 0/9 "HEAD / HTTP/1.0"
15213
15214 => Idem, but the request was queued in the global queue behind 9 other
15215 requests, and waited there for 1230 ms.
15216
15217 >>> haproxy[674]: 127.0.0.1:33320 [15/Oct/2003:08:32:17.654] px-http \
15218 px-http/srv1 9/0/7/14/+30 200 +243 - - ---- 3/3/3/1/0 0/0 \
15219 "GET /image.iso HTTP/1.0"
15220
15221 => request for a long data transfer. The "logasap" option was specified, so
Krzysztof Piotr Oledzkif8645332009-12-13 21:55:50 +010015222 the log was produced just before transferring data. The server replied in
Willy Tarreaucc6c8912009-02-22 10:53:55 +010015223 14 ms, 243 bytes of headers were sent to the client, and total time from
15224 accept to first data byte is 30 ms.
15225
15226 >>> haproxy[674]: 127.0.0.1:33320 [15/Oct/2003:08:32:17.925] px-http \
15227 px-http/srv1 9/0/7/14/30 502 243 - - PH-- 3/2/2/0/0 0/0 \
15228 "GET /cgi-bin/bug.cgi? HTTP/1.0"
15229
15230 => the proxy blocked a server response either because of an "rspdeny" or
15231 "rspideny" filter, or because the response was improperly formatted and
Willy Tarreau3c92c5f2011-08-28 09:45:47 +020015232 not HTTP-compliant, or because it blocked sensitive information which
Willy Tarreaucc6c8912009-02-22 10:53:55 +010015233 risked being cached. In this case, the response is replaced with a "502
15234 bad gateway". The flags ("PH--") tell us that it was haproxy who decided
15235 to return the 502 and not the server.
15236
15237 >>> haproxy[18113]: 127.0.0.1:34548 [15/Oct/2003:15:18:55.798] px-http \
Willy Tarreaud72758d2010-01-12 10:42:19 +010015238 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 +010015239
15240 => the client never completed its request and aborted itself ("C---") after
15241 8.5s, while the proxy was waiting for the request headers ("-R--").
15242 Nothing was sent to any server.
15243
15244 >>> haproxy[18113]: 127.0.0.1:34549 [15/Oct/2003:15:19:06.103] px-http \
15245 px-http/<NOSRV> -1/-1/-1/-1/50001 408 0 - - cR-- 2/2/2/0/0 0/0 ""
15246
15247 => The client never completed its request, which was aborted by the
15248 time-out ("c---") after 50s, while the proxy was waiting for the request
15249 headers ("-R--"). Nothing was sent to any server, but the proxy could
15250 send a 408 return code to the client.
15251
15252 >>> haproxy[18989]: 127.0.0.1:34550 [15/Oct/2003:15:24:28.312] px-tcp \
15253 px-tcp/srv1 0/0/5007 0 cD 0/0/0/0/0 0/0
15254
15255 => This log was produced with "option tcplog". The client timed out after
15256 5 seconds ("c----").
15257
15258 >>> haproxy[18989]: 10.0.0.1:34552 [15/Oct/2003:15:26:31.462] px-http \
15259 px-http/srv1 3183/-1/-1/-1/11215 503 0 - - SC-- 205/202/202/115/3 \
Willy Tarreaud72758d2010-01-12 10:42:19 +010015260 0/0 "HEAD / HTTP/1.0"
Willy Tarreaucc6c8912009-02-22 10:53:55 +010015261
15262 => The request took 3s to complete (probably a network problem), and the
Willy Tarreauc57f0e22009-05-10 13:12:33 +020015263 connection to the server failed ('SC--') after 4 attempts of 2 seconds
Willy Tarreaucc6c8912009-02-22 10:53:55 +010015264 (config says 'retries 3'), and no redispatch (otherwise we would have
15265 seen "/+3"). Status code 503 was returned to the client. There were 115
15266 connections on this server, 202 connections on this proxy, and 205 on
15267 the global process. It is possible that the server refused the
15268 connection because of too many already established.
Willy Tarreau844e3c52008-01-11 16:28:18 +010015269
Willy Tarreau3dfe6cd2008-12-07 22:29:48 +010015270
Willy Tarreauc57f0e22009-05-10 13:12:33 +0200152719. Statistics and monitoring
15272----------------------------
15273
15274It is possible to query HAProxy about its status. The most commonly used
15275mechanism is the HTTP statistics page. This page also exposes an alternative
15276CSV output format for monitoring tools. The same format is provided on the
15277Unix socket.
15278
15279
152809.1. CSV format
Willy Tarreau3dfe6cd2008-12-07 22:29:48 +010015281---------------
Krzysztof Piotr Oledzkif58a9622008-02-23 01:19:10 +010015282
Willy Tarreau7f062c42009-03-05 18:43:00 +010015283The statistics may be consulted either from the unix socket or from the HTTP
Willy Tarreaua3310dc2014-06-16 15:43:21 +020015284page. Both means provide a CSV format whose fields follow. The first line
15285begins with a sharp ('#') and has one word per comma-delimited field which
15286represents the title of the column. All other lines starting at the second one
15287use a classical CSV format using a comma as the delimiter, and the double quote
15288('"') as an optional text delimiter, but only if the enclosed text is ambiguous
15289(if it contains a quote or a comma). The double-quote character ('"') in the
15290text is doubled ('""'), which is the format that most tools recognize. Please
15291do not insert any column before these ones in order not to break tools which
15292use hard-coded column positions.
Willy Tarreau7f062c42009-03-05 18:43:00 +010015293
James Westbyebe62d62014-07-08 10:14:57 -040015294In brackets after each field name are the types which may have a value for
15295that field. The types are L (Listeners), F (Frontends), B (Backends), and
15296S (Servers).
15297
15298 0. pxname [LFBS]: proxy name
15299 1. svname [LFBS]: service name (FRONTEND for frontend, BACKEND for backend,
15300 any name for server/listener)
15301 2. qcur [..BS]: current queued requests. For the backend this reports the
15302 number queued without a server assigned.
15303 3. qmax [..BS]: max value of qcur
15304 4. scur [LFBS]: current sessions
15305 5. smax [LFBS]: max sessions
15306 6. slim [LFBS]: configured session limit
15307 7. stot [LFBS]: cumulative number of connections
15308 8. bin [LFBS]: bytes in
15309 9. bout [LFBS]: bytes out
15310 10. dreq [LFB.]: requests denied because of security concerns.
15311 - For tcp this is because of a matched tcp-request content rule.
15312 - For http this is because of a matched http-request or tarpit rule.
15313 11. dresp [LFBS]: responses denied because of security concerns.
15314 - For http this is because of a matched http-request rule, or
15315 "option checkcache".
15316 12. ereq [LF..]: request errors. Some of the possible causes are:
15317 - early termination from the client, before the request has been sent.
15318 - read error from the client
15319 - client timeout
15320 - client closed connection
15321 - various bad requests from the client.
15322 - request was tarpitted.
15323 13. econ [..BS]: number of requests that encountered an error trying to
15324 connect to a backend server. The backend stat is the sum of the stat
15325 for all servers of that backend, plus any connection errors not
15326 associated with a particular server (such as the backend having no
15327 active servers).
15328 14. eresp [..BS]: response errors. srv_abrt will be counted here also.
15329 Some other errors are:
15330 - write error on the client socket (won't be counted for the server stat)
15331 - failure applying filters to the response.
15332 15. wretr [..BS]: number of times a connection to a server was retried.
15333 16. wredis [..BS]: number of times a request was redispatched to another
15334 server. The server value counts the number of times that server was
15335 switched away from.
15336 17. status [LFBS]: status (UP/DOWN/NOLB/MAINT/MAINT(via)...)
Pavlos Parissis1f673c72015-05-02 20:30:44 +020015337 18. weight [..BS]: total weight (backend), server weight (server)
15338 19. act [..BS]: number of active servers (backend), server is active (server)
15339 20. bck [..BS]: number of backup servers (backend), server is backup (server)
James Westbyebe62d62014-07-08 10:14:57 -040015340 21. chkfail [...S]: number of failed checks. (Only counts checks failed when
15341 the server is up.)
15342 22. chkdown [..BS]: number of UP->DOWN transitions. The backend counter counts
15343 transitions to the whole backend being down, rather than the sum of the
15344 counters for each server.
15345 23. lastchg [..BS]: number of seconds since the last UP<->DOWN transition
15346 24. downtime [..BS]: total downtime (in seconds). The value for the backend
15347 is the downtime for the whole backend, not the sum of the server downtime.
15348 25. qlimit [...S]: configured maxqueue for the server, or nothing in the
15349 value is 0 (default, meaning no limit)
15350 26. pid [LFBS]: process id (0 for first instance, 1 for second, ...)
15351 27. iid [LFBS]: unique proxy id
15352 28. sid [L..S]: server id (unique inside a proxy)
15353 29. throttle [...S]: current throttle percentage for the server, when
15354 slowstart is active, or no value if not in slowstart.
15355 30. lbtot [..BS]: total number of times a server was selected, either for new
15356 sessions, or when re-dispatching. The server counter is the number
15357 of times that server was selected.
15358 31. tracked [...S]: id of proxy/server if tracking is enabled.
15359 32. type [LFBS]: (0=frontend, 1=backend, 2=server, 3=socket/listener)
15360 33. rate [.FBS]: number of sessions per second over last elapsed second
15361 34. rate_lim [.F..]: configured limit on new sessions per second
15362 35. rate_max [.FBS]: max number of new sessions per second
15363 36. check_status [...S]: status of last health check, one of:
Cyril Bontéf0c60612010-02-06 14:44:47 +010015364 UNK -> unknown
15365 INI -> initializing
15366 SOCKERR -> socket error
15367 L4OK -> check passed on layer 4, no upper layers testing enabled
Jason Harvey83104802015-04-16 11:13:21 -080015368 L4TOUT -> layer 1-4 timeout
Cyril Bontéf0c60612010-02-06 14:44:47 +010015369 L4CON -> layer 1-4 connection problem, for example
15370 "Connection refused" (tcp rst) or "No route to host" (icmp)
15371 L6OK -> check passed on layer 6
15372 L6TOUT -> layer 6 (SSL) timeout
15373 L6RSP -> layer 6 invalid response - protocol error
15374 L7OK -> check passed on layer 7
15375 L7OKC -> check conditionally passed on layer 7, for example 404 with
15376 disable-on-404
15377 L7TOUT -> layer 7 (HTTP/SMTP) timeout
15378 L7RSP -> layer 7 invalid response - protocol error
15379 L7STS -> layer 7 response error, for example HTTP 5xx
James Westbyebe62d62014-07-08 10:14:57 -040015380 37. check_code [...S]: layer5-7 code, if available
15381 38. check_duration [...S]: time in ms took to finish last health check
15382 39. hrsp_1xx [.FBS]: http responses with 1xx code
15383 40. hrsp_2xx [.FBS]: http responses with 2xx code
15384 41. hrsp_3xx [.FBS]: http responses with 3xx code
15385 42. hrsp_4xx [.FBS]: http responses with 4xx code
15386 43. hrsp_5xx [.FBS]: http responses with 5xx code
15387 44. hrsp_other [.FBS]: http responses with other codes (protocol error)
15388 45. hanafail [...S]: failed health checks details
15389 46. req_rate [.F..]: HTTP requests per second over last elapsed second
15390 47. req_rate_max [.F..]: max number of HTTP requests per second observed
15391 48. req_tot [.F..]: total number of HTTP requests received
15392 49. cli_abrt [..BS]: number of data transfers aborted by the client
15393 50. srv_abrt [..BS]: number of data transfers aborted by the server
15394 (inc. in eresp)
15395 51. comp_in [.FB.]: number of HTTP response bytes fed to the compressor
15396 52. comp_out [.FB.]: number of HTTP response bytes emitted by the compressor
15397 53. comp_byp [.FB.]: number of bytes that bypassed the HTTP compressor
15398 (CPU/BW limit)
15399 54. comp_rsp [.FB.]: number of HTTP responses that were compressed
15400 55. lastsess [..BS]: number of seconds since last session assigned to
15401 server/backend
15402 56. last_chk [...S]: last health check contents or textual error
15403 57. last_agt [...S]: last agent check contents or textual error
15404 58. qtime [..BS]: the average queue time in ms over the 1024 last requests
15405 59. ctime [..BS]: the average connect time in ms over the 1024 last requests
15406 60. rtime [..BS]: the average response time in ms over the 1024 last requests
15407 (0 for TCP)
15408 61. ttime [..BS]: the average total session time in ms over the 1024 last
15409 requests
Willy Tarreau844e3c52008-01-11 16:28:18 +010015410
Willy Tarreau3dfe6cd2008-12-07 22:29:48 +010015411
Willy Tarreauc57f0e22009-05-10 13:12:33 +0200154129.2. Unix Socket commands
Willy Tarreau3dfe6cd2008-12-07 22:29:48 +010015413-------------------------
Krzysztof Piotr Oledzki2c6962c2008-03-02 02:42:14 +010015414
Willy Tarreau468f4932013-08-01 16:50:16 +020015415The stats socket is not enabled by default. In order to enable it, it is
15416necessary to add one line in the global section of the haproxy configuration.
15417A second line is recommended to set a larger timeout, always appreciated when
15418issuing commands by hand :
15419
15420 global
15421 stats socket /var/run/haproxy.sock mode 600 level admin
15422 stats timeout 2m
15423
15424It is also possible to add multiple instances of the stats socket by repeating
15425the line, and make them listen to a TCP port instead of a UNIX socket. This is
15426never done by default because this is dangerous, but can be handy in some
15427situations :
15428
15429 global
15430 stats socket /var/run/haproxy.sock mode 600 level admin
15431 stats socket ipv4@192.168.0.1:9999 level admin
15432 stats timeout 2m
15433
Cyril Bonté307ee1e2015-09-28 23:16:06 +020015434To access the socket, an external utility such as "socat" is required. Socat is
15435a swiss-army knife to connect anything to anything. We use it to connect
15436terminals to the socket, or a couple of stdin/stdout pipes to it for scripts.
15437The two main syntaxes we'll use are the following :
Willy Tarreau468f4932013-08-01 16:50:16 +020015438
15439 # socat /var/run/haproxy.sock stdio
15440 # socat /var/run/haproxy.sock readline
15441
15442The first one is used with scripts. It is possible to send the output of a
15443script to haproxy, and pass haproxy's output to another script. That's useful
15444for retrieving counters or attack traces for example.
15445
15446The second one is only useful for issuing commands by hand. It has the benefit
15447that the terminal is handled by the readline library which supports line
15448editing and history, which is very convenient when issuing repeated commands
15449(eg: watch a counter).
15450
15451The socket supports two operation modes :
15452 - interactive
15453 - non-interactive
15454
15455The non-interactive mode is the default when socat connects to the socket. In
15456this mode, a single line may be sent. It is processed as a whole, responses are
15457sent back, and the connection closes after the end of the response. This is the
15458mode that scripts and monitoring tools use. It is possible to send multiple
15459commands in this mode, they need to be delimited by a semi-colon (';'). For
15460example :
15461
15462 # echo "show info;show stat;show table" | socat /var/run/haproxy stdio
15463
15464The interactive mode displays a prompt ('>') and waits for commands to be
15465entered on the line, then processes them, and displays the prompt again to wait
15466for a new command. This mode is entered via the "prompt" command which must be
15467sent on the first line in non-interactive mode. The mode is a flip switch, if
15468"prompt" is sent in interactive mode, it is disabled and the connection closes
15469after processing the last command of the same line.
15470
15471For this reason, when debugging by hand, it's quite common to start with the
15472"prompt" command :
15473
15474 # socat /var/run/haproxy readline
15475 prompt
15476 > show info
15477 ...
15478 >
15479
15480Since multiple commands may be issued at once, haproxy uses the empty line as a
15481delimiter to mark an end of output for each command, and takes care of ensuring
15482that no command can emit an empty line on output. A script can thus easily
15483parse the output even when multiple commands were pipelined on a single line.
Willy Tarreau3dfe6cd2008-12-07 22:29:48 +010015484
Willy Tarreau9a42c0d2009-09-22 19:31:03 +020015485It is important to understand that when multiple haproxy processes are started
15486on the same sockets, any process may pick up the request and will output its
15487own stats.
Willy Tarreau3dfe6cd2008-12-07 22:29:48 +010015488
Willy Tarreau468f4932013-08-01 16:50:16 +020015489The list of commands currently supported on the stats socket is provided below.
15490If an unknown command is sent, haproxy displays the usage message which reminds
15491all supported commands. Some commands support a more complex syntax, generally
15492it will explain what part of the command is invalid when this happens.
15493
Thierry FOURNIERd32079e2014-01-29 20:02:04 +010015494add acl <acl> <pattern>
Thierry FOURNIER65ce6132014-03-20 11:42:45 +010015495 Add an entry into the acl <acl>. <acl> is the #<id> or the <file> returned by
15496 "show acl". This command does not verify if the entry already exists. This
15497 command cannot be used if the reference <acl> is a file also used with a map.
15498 In this case, you must use the command "add map" in place of "add acl".
Thierry FOURNIERd32079e2014-01-29 20:02:04 +010015499
Thierry FOURNIERc0e0d7b2013-12-11 16:55:52 +010015500add map <map> <key> <value>
15501 Add an entry into the map <map> to associate the value <value> to the key
15502 <key>. This command does not verify if the entry already exists. It is
Thierry FOURNIERd32079e2014-01-29 20:02:04 +010015503 mainly used to fill a map after a clear operation. Note that if the reference
15504 <map> is a file and is shared with a map, this map will contain also a new
15505 pattern entry.
Thierry FOURNIERc0e0d7b2013-12-11 16:55:52 +010015506
Willy Tarreaud63335a2010-02-26 12:56:52 +010015507clear counters
15508 Clear the max values of the statistics counters in each proxy (frontend &
15509 backend) and in each server. The cumulated counters are not affected. This
15510 can be used to get clean counters after an incident, without having to
15511 restart nor to clear traffic counters. This command is restricted and can
15512 only be issued on sockets configured for levels "operator" or "admin".
15513
15514clear counters all
15515 Clear all statistics counters in each proxy (frontend & backend) and in each
15516 server. This has the same effect as restarting. This command is restricted
15517 and can only be issued on sockets configured for level "admin".
15518
Thierry FOURNIERd32079e2014-01-29 20:02:04 +010015519clear acl <acl>
Thierry FOURNIER65ce6132014-03-20 11:42:45 +010015520 Remove all entries from the acl <acl>. <acl> is the #<id> or the <file>
15521 returned by "show acl". Note that if the reference <acl> is a file and is
15522 shared with a map, this map will be also cleared.
Thierry FOURNIERd32079e2014-01-29 20:02:04 +010015523
Thierry FOURNIERc0e0d7b2013-12-11 16:55:52 +010015524clear map <map>
Thierry FOURNIER65ce6132014-03-20 11:42:45 +010015525 Remove all entries from the map <map>. <map> is the #<id> or the <file>
15526 returned by "show map". Note that if the reference <map> is a file and is
15527 shared with a acl, this acl will be also cleared.
Thierry FOURNIERc0e0d7b2013-12-11 16:55:52 +010015528
Simon Hormanc88b8872011-06-15 15:18:49 +090015529clear table <table> [ data.<type> <operator> <value> ] | [ key <key> ]
15530 Remove entries from the stick-table <table>.
15531
15532 This is typically used to unblock some users complaining they have been
15533 abusively denied access to a service, but this can also be used to clear some
15534 stickiness entries matching a server that is going to be replaced (see "show
15535 table" below for details). Note that sometimes, removal of an entry will be
15536 refused because it is currently tracked by a session. Retrying a few seconds
15537 later after the session ends is usual enough.
15538
15539 In the case where no options arguments are given all entries will be removed.
15540
15541 When the "data." form is used entries matching a filter applied using the
15542 stored data (see "stick-table" in section 4.2) are removed. A stored data
15543 type must be specified in <type>, and this data type must be stored in the
15544 table otherwise an error is reported. The data is compared according to
15545 <operator> with the 64-bit integer <value>. Operators are the same as with
15546 the ACLs :
15547
15548 - eq : match entries whose data is equal to this value
15549 - ne : match entries whose data is not equal to this value
15550 - le : match entries whose data is less than or equal to this value
15551 - ge : match entries whose data is greater than or equal to this value
15552 - lt : match entries whose data is less than this value
15553 - gt : match entries whose data is greater than this value
15554
15555 When the key form is used the entry <key> is removed. The key must be of the
Simon Horman619e3cc2011-06-15 15:18:52 +090015556 same type as the table, which currently is limited to IPv4, IPv6, integer and
15557 string.
Willy Tarreau88bc4ec2010-08-01 07:58:48 +020015558
15559 Example :
Willy Tarreau62a36c42010-08-17 15:53:10 +020015560 $ echo "show table http_proxy" | socat stdio /tmp/sock1
Emeric Brun7c6b82e2010-09-24 16:34:28 +020015561 >>> # table: http_proxy, type: ip, size:204800, used:2
Willy Tarreau62a36c42010-08-17 15:53:10 +020015562 >>> 0x80e6a4c: key=127.0.0.1 use=0 exp=3594729 gpc0=0 conn_rate(30000)=1 \
15563 bytes_out_rate(60000)=187
15564 >>> 0x80e6a80: key=127.0.0.2 use=0 exp=3594740 gpc0=1 conn_rate(30000)=10 \
15565 bytes_out_rate(60000)=191
Willy Tarreau88bc4ec2010-08-01 07:58:48 +020015566
15567 $ echo "clear table http_proxy key 127.0.0.1" | socat stdio /tmp/sock1
15568
15569 $ echo "show table http_proxy" | socat stdio /tmp/sock1
Emeric Brun7c6b82e2010-09-24 16:34:28 +020015570 >>> # table: http_proxy, type: ip, size:204800, used:1
Willy Tarreau62a36c42010-08-17 15:53:10 +020015571 >>> 0x80e6a80: key=127.0.0.2 use=0 exp=3594740 gpc0=1 conn_rate(30000)=10 \
15572 bytes_out_rate(60000)=191
Simon Hormanc88b8872011-06-15 15:18:49 +090015573 $ echo "clear table http_proxy data.gpc0 eq 1" | socat stdio /tmp/sock1
15574 $ echo "show table http_proxy" | socat stdio /tmp/sock1
15575 >>> # table: http_proxy, type: ip, size:204800, used:1
Willy Tarreau88bc4ec2010-08-01 07:58:48 +020015576
Thierry FOURNIERd32079e2014-01-29 20:02:04 +010015577del acl <acl> [<key>|#<ref>]
15578 Delete all the acl entries from the acl <acl> corresponding to the key <key>.
Thierry FOURNIER65ce6132014-03-20 11:42:45 +010015579 <acl> is the #<id> or the <file> returned by "show acl". If the <ref> is used,
15580 this command delete only the listed reference. The reference can be found with
15581 listing the content of the acl. Note that if the reference <acl> is a file and
15582 is shared with a map, the entry will be also deleted in the map.
Thierry FOURNIERd32079e2014-01-29 20:02:04 +010015583
15584del map <map> [<key>|#<ref>]
Thierry FOURNIER0b90f312014-01-29 20:40:18 +010015585 Delete all the map entries from the map <map> corresponding to the key <key>.
Thierry FOURNIER65ce6132014-03-20 11:42:45 +010015586 <map> is the #<id> or the <file> returned by "show map". If the <ref> is used,
15587 this command delete only the listed reference. The reference can be found with
15588 listing the content of the map. Note that if the reference <map> is a file and
15589 is shared with a acl, the entry will be also deleted in the map.
Thierry FOURNIER0b90f312014-01-29 20:40:18 +010015590
15591disable agent <backend>/<server>
Simon Horman671b6f02013-11-25 10:46:39 +090015592 Mark the auxiliary agent check as temporarily stopped.
15593
15594 In the case where an agent check is being run as a auxiliary check, due
15595 to the agent-check parameter of a server directive, new checks are only
15596 initialised when the agent is in the enabled. Thus, disable agent will
15597 prevent any new agent checks from begin initiated until the agent
15598 re-enabled using enable agent.
15599
15600 When an agent is disabled the processing of an auxiliary agent check that
15601 was initiated while the agent was set as enabled is as follows: All
15602 results that would alter the weight, specifically "drain" or a weight
15603 returned by the agent, are ignored. The processing of agent check is
15604 otherwise unchanged.
15605
15606 The motivation for this feature is to allow the weight changing effects
15607 of the agent checks to be paused to allow the weight of a server to be
15608 configured using set weight without being overridden by the agent.
15609
15610 This command is restricted and can only be issued on sockets configured for
15611 level "admin".
15612
Willy Tarreau532a4502011-09-07 22:37:44 +020015613disable frontend <frontend>
15614 Mark the frontend as temporarily stopped. This corresponds to the mode which
15615 is used during a soft restart : the frontend releases the port but can be
15616 enabled again if needed. This should be used with care as some non-Linux OSes
15617 are unable to enable it back. This is intended to be used in environments
15618 where stopping a proxy is not even imaginable but a misconfigured proxy must
15619 be fixed. That way it's possible to release the port and bind it into another
15620 process to restore operations. The frontend will appear with status "STOP"
15621 on the stats page.
15622
15623 The frontend may be specified either by its name or by its numeric ID,
15624 prefixed with a sharp ('#').
15625
15626 This command is restricted and can only be issued on sockets configured for
15627 level "admin".
15628
Willy Tarreau9b5aecd2014-05-23 11:53:10 +020015629disable health <backend>/<server>
15630 Mark the primary health check as temporarily stopped. This will disable
15631 sending of health checks, and the last health check result will be ignored.
15632 The server will be in unchecked state and considered UP unless an auxiliary
15633 agent check forces it down.
15634
15635 This command is restricted and can only be issued on sockets configured for
15636 level "admin".
15637
Willy Tarreaud63335a2010-02-26 12:56:52 +010015638disable server <backend>/<server>
15639 Mark the server DOWN for maintenance. In this mode, no more checks will be
15640 performed on the server until it leaves maintenance.
15641 If the server is tracked by other servers, those servers will be set to DOWN
15642 during the maintenance.
15643
15644 In the statistics page, a server DOWN for maintenance will appear with a
15645 "MAINT" status, its tracking servers with the "MAINT(via)" one.
15646
15647 Both the backend and the server may be specified either by their name or by
Willy Tarreauf5f31922011-08-02 11:32:07 +020015648 their numeric ID, prefixed with a sharp ('#').
Willy Tarreaud63335a2010-02-26 12:56:52 +010015649
15650 This command is restricted and can only be issued on sockets configured for
15651 level "admin".
15652
Simon Horman671b6f02013-11-25 10:46:39 +090015653enable agent <backend>/<server>
15654 Resume auxiliary agent check that was temporarily stopped.
15655
15656 See "disable agent" for details of the effect of temporarily starting
15657 and stopping an auxiliary agent.
15658
15659 This command is restricted and can only be issued on sockets configured for
15660 level "admin".
15661
Willy Tarreau532a4502011-09-07 22:37:44 +020015662enable frontend <frontend>
15663 Resume a frontend which was temporarily stopped. It is possible that some of
15664 the listening ports won't be able to bind anymore (eg: if another process
15665 took them since the 'disable frontend' operation). If this happens, an error
15666 is displayed. Some operating systems might not be able to resume a frontend
15667 which was disabled.
15668
15669 The frontend may be specified either by its name or by its numeric ID,
15670 prefixed with a sharp ('#').
15671
15672 This command is restricted and can only be issued on sockets configured for
15673 level "admin".
15674
Willy Tarreau9b5aecd2014-05-23 11:53:10 +020015675enable health <backend>/<server>
15676 Resume a primary health check that was temporarily stopped. This will enable
15677 sending of health checks again. Please see "disable health" for details.
15678
15679 This command is restricted and can only be issued on sockets configured for
15680 level "admin".
15681
Willy Tarreaud63335a2010-02-26 12:56:52 +010015682enable server <backend>/<server>
15683 If the server was previously marked as DOWN for maintenance, this marks the
15684 server UP and checks are re-enabled.
15685
15686 Both the backend and the server may be specified either by their name or by
Willy Tarreauf5f31922011-08-02 11:32:07 +020015687 their numeric ID, prefixed with a sharp ('#').
Willy Tarreaud63335a2010-02-26 12:56:52 +010015688
15689 This command is restricted and can only be issued on sockets configured for
15690 level "admin".
15691
Thierry FOURNIER5b16df72014-02-26 18:07:38 +010015692get map <map> <value>
Thierry FOURNIER65ce6132014-03-20 11:42:45 +010015693get acl <acl> <value>
15694 Lookup the value <value> in the map <map> or in the ACL <acl>. <map> or <acl>
15695 are the #<id> or the <file> returned by "show map" or "show acl". This command
15696 returns all the matching patterns associated with this map. This is useful for
15697 debugging maps and ACLs. The output format is composed by one line par
15698 matching type. Each line is composed by space-delimited series of words.
Thierry FOURNIER5b16df72014-02-26 18:07:38 +010015699
15700 The first two words are:
15701
15702 <match method>: The match method applied. It can be "found", "bool",
15703 "int", "ip", "bin", "len", "str", "beg", "sub", "dir",
15704 "dom", "end" or "reg".
15705
15706 <match result>: The result. Can be "match" or "no-match".
15707
15708 The following words are returned only if the pattern matches an entry.
15709
15710 <index type>: "tree" or "list". The internal lookup algorithm.
15711
15712 <case>: "case-insensitive" or "case-sensitive". The
15713 interpretation of the case.
15714
15715 <entry matched>: match="<entry>". Return the matched pattern. It is
15716 useful with regular expressions.
15717
15718 The two last word are used to show the returned value and its type. With the
15719 "acl" case, the pattern doesn't exist.
15720
15721 return=nothing: No return because there are no "map".
15722 return="<value>": The value returned in the string format.
15723 return=cannot-display: The value cannot be converted as string.
15724
15725 type="<type>": The type of the returned sample.
15726
Willy Tarreaud63335a2010-02-26 12:56:52 +010015727get weight <backend>/<server>
15728 Report the current weight and the initial weight of server <server> in
15729 backend <backend> or an error if either doesn't exist. The initial weight is
15730 the one that appears in the configuration file. Both are normally equal
15731 unless the current weight has been changed. Both the backend and the server
15732 may be specified either by their name or by their numeric ID, prefixed with a
Willy Tarreauf5f31922011-08-02 11:32:07 +020015733 sharp ('#').
Willy Tarreaud63335a2010-02-26 12:56:52 +010015734
Willy Tarreau9a42c0d2009-09-22 19:31:03 +020015735help
15736 Print the list of known keywords and their basic usage. The same help screen
15737 is also displayed for unknown commands.
Willy Tarreau3dfe6cd2008-12-07 22:29:48 +010015738
Willy Tarreau9a42c0d2009-09-22 19:31:03 +020015739prompt
15740 Toggle the prompt at the beginning of the line and enter or leave interactive
15741 mode. In interactive mode, the connection is not closed after a command
15742 completes. Instead, the prompt will appear again, indicating the user that
15743 the interpreter is waiting for a new command. The prompt consists in a right
15744 angle bracket followed by a space "> ". This mode is particularly convenient
15745 when one wants to periodically check information such as stats or errors.
15746 It is also a good idea to enter interactive mode before issuing a "help"
15747 command.
15748
15749quit
15750 Close the connection when in interactive mode.
Krzysztof Piotr Oledzki2c6962c2008-03-02 02:42:14 +010015751
Thierry FOURNIERd32079e2014-01-29 20:02:04 +010015752set map <map> [<key>|#<ref>] <value>
Thierry FOURNIER65ce6132014-03-20 11:42:45 +010015753 Modify the value corresponding to each key <key> in a map <map>. <map> is the
15754 #<id> or <file> returned by "show map". If the <ref> is used in place of
15755 <key>, only the entry pointed by <ref> is changed. The new value is <value>.
Thierry FOURNIERc0e0d7b2013-12-11 16:55:52 +010015756
Willy Tarreau2a0f4d22011-08-02 11:49:05 +020015757set maxconn frontend <frontend> <value>
Willy Tarreau3c7a79d2012-09-26 21:07:15 +020015758 Dynamically change the specified frontend's maxconn setting. Any positive
15759 value is allowed including zero, but setting values larger than the global
15760 maxconn does not make much sense. If the limit is increased and connections
15761 were pending, they will immediately be accepted. If it is lowered to a value
15762 below the current number of connections, new connections acceptation will be
Willy Tarreau2a0f4d22011-08-02 11:49:05 +020015763 delayed until the threshold is reached. The frontend might be specified by
15764 either its name or its numeric ID prefixed with a sharp ('#').
15765
Willy Tarreau91886b62011-09-07 14:38:31 +020015766set maxconn global <maxconn>
15767 Dynamically change the global maxconn setting within the range defined by the
15768 initial global maxconn setting. If it is increased and connections were
15769 pending, they will immediately be accepted. If it is lowered to a value below
15770 the current number of connections, new connections acceptation will be
15771 delayed until the threshold is reached. A value of zero restores the initial
15772 setting.
15773
Willy Tarreauf5b22872011-09-07 16:13:44 +020015774set rate-limit connections global <value>
15775 Change the process-wide connection rate limit, which is set by the global
15776 'maxconnrate' setting. A value of zero disables the limitation. This limit
15777 applies to all frontends and the change has an immediate effect. The value
15778 is passed in number of connections per second.
15779
William Lallemandd85f9172012-11-09 17:05:39 +010015780set rate-limit http-compression global <value>
15781 Change the maximum input compression rate, which is set by the global
15782 'maxcomprate' setting. A value of zero disables the limitation. The value is
William Lallemand096f5542012-11-19 17:26:05 +010015783 passed in number of kilobytes per second. The value is available in the "show
15784 info" on the line "CompressBpsRateLim" in bytes.
William Lallemandd85f9172012-11-09 17:05:39 +010015785
Willy Tarreau93e7c002013-10-07 18:51:07 +020015786set rate-limit sessions global <value>
15787 Change the process-wide session rate limit, which is set by the global
15788 'maxsessrate' setting. A value of zero disables the limitation. This limit
15789 applies to all frontends and the change has an immediate effect. The value
15790 is passed in number of sessions per second.
15791
Willy Tarreaue43d5322013-10-07 20:01:52 +020015792set rate-limit ssl-sessions global <value>
15793 Change the process-wide SSL session rate limit, which is set by the global
15794 'maxsslrate' setting. A value of zero disables the limitation. This limit
15795 applies to all frontends and the change has an immediate effect. The value
15796 is passed in number of sessions per second sent to the SSL stack. It applies
15797 before the handshake in order to protect the stack against handshake abuses.
15798
Baptiste Assmann3d8f8312015-04-13 22:54:33 +020015799set server <backend>/<server> addr <ip4 or ip6 address>
15800 Replace the current IP address of a server by the one provided.
15801
Willy Tarreau2a4b70f2014-05-22 18:42:35 +020015802set server <backend>/<server> agent [ up | down ]
15803 Force a server's agent to a new state. This can be useful to immediately
15804 switch a server's state regardless of some slow agent checks for example.
15805 Note that the change is propagated to tracking servers if any.
15806
15807set server <backend>/<server> health [ up | stopping | down ]
15808 Force a server's health to a new state. This can be useful to immediately
15809 switch a server's state regardless of some slow health checks for example.
15810 Note that the change is propagated to tracking servers if any.
15811
15812set server <backend>/<server> state [ ready | drain | maint ]
15813 Force a server's administrative state to a new state. This can be useful to
15814 disable load balancing and/or any traffic to a server. Setting the state to
15815 "ready" puts the server in normal mode, and the command is the equivalent of
15816 the "enable server" command. Setting the state to "maint" disables any traffic
15817 to the server as well as any health checks. This is the equivalent of the
15818 "disable server" command. Setting the mode to "drain" only removes the server
15819 from load balancing but still allows it to be checked and to accept new
15820 persistent connections. Changes are propagated to tracking servers if any.
15821
15822set server <backend>/<server> weight <weight>[%]
15823 Change a server's weight to the value passed in argument. This is the exact
15824 equivalent of the "set weight" command below.
15825
Emeric Brun4147b2e2014-06-16 18:36:30 +020015826set ssl ocsp-response <response>
15827 This command is used to update an OCSP Response for a certificate (see "crt"
15828 on "bind" lines). Same controls are performed as during the initial loading of
15829 the response. The <response> must be passed as a base64 encoded string of the
15830 DER encoded response from the OCSP server.
15831
15832 Example:
15833 openssl ocsp -issuer issuer.pem -cert server.pem \
15834 -host ocsp.issuer.com:80 -respout resp.der
15835 echo "set ssl ocsp-response $(base64 -w 10000 resp.der)" | \
15836 socat stdio /var/run/haproxy.stat
15837
Nenad Merdanovicc6985f02015-05-09 08:46:02 +020015838set ssl tls-key <id> <tlskey>
15839 Set the next TLS key for the <id> listener to <tlskey>. This key becomes the
15840 ultimate key, while the penultimate one is used for encryption (others just
15841 decrypt). The oldest TLS key present is overwritten. <id> is either a numeric
15842 #<id> or <file> returned by "show tls-keys". <tlskey> is a base64 encoded 48
15843 bit TLS ticket key (ex. openssl rand -base64 48).
15844
Willy Tarreau47060b62013-08-01 21:11:42 +020015845set table <table> key <key> [data.<data_type> <value>]*
Willy Tarreau654694e2012-06-07 01:03:16 +020015846 Create or update a stick-table entry in the table. If the key is not present,
15847 an entry is inserted. See stick-table in section 4.2 to find all possible
15848 values for <data_type>. The most likely use consists in dynamically entering
15849 entries for source IP addresses, with a flag in gpc0 to dynamically block an
Willy Tarreau47060b62013-08-01 21:11:42 +020015850 IP address or affect its quality of service. It is possible to pass multiple
15851 data_types in a single call.
Willy Tarreau654694e2012-06-07 01:03:16 +020015852
Willy Tarreaud63335a2010-02-26 12:56:52 +010015853set timeout cli <delay>
15854 Change the CLI interface timeout for current connection. This can be useful
15855 during long debugging sessions where the user needs to constantly inspect
15856 some indicators without being disconnected. The delay is passed in seconds.
15857
15858set weight <backend>/<server> <weight>[%]
15859 Change a server's weight to the value passed in argument. If the value ends
15860 with the '%' sign, then the new weight will be relative to the initially
Simon Horman58b5d292013-02-12 10:45:52 +090015861 configured weight. Absolute weights are permitted between 0 and 256.
15862 Relative weights must be positive with the resulting absolute weight is
15863 capped at 256. Servers which are part of a farm running a static
15864 load-balancing algorithm have stricter limitations because the weight
15865 cannot change once set. Thus for these servers, the only accepted values
15866 are 0 and 100% (or 0 and the initial weight). Changes take effect
15867 immediately, though certain LB algorithms require a certain amount of
15868 requests to consider changes. A typical usage of this command is to
15869 disable a server during an update by setting its weight to zero, then to
15870 enable it again after the update by setting it back to 100%. This command
15871 is restricted and can only be issued on sockets configured for level
15872 "admin". Both the backend and the server may be specified either by their
15873 name or by their numeric ID, prefixed with a sharp ('#').
Willy Tarreaud63335a2010-02-26 12:56:52 +010015874
Willy Tarreaue0c8a1a2009-03-04 16:33:10 +010015875show errors [<iid>]
15876 Dump last known request and response errors collected by frontends and
15877 backends. If <iid> is specified, the limit the dump to errors concerning
Willy Tarreau6162db22009-10-10 17:13:00 +020015878 either frontend or backend whose ID is <iid>. This command is restricted
15879 and can only be issued on sockets configured for levels "operator" or
15880 "admin".
Willy Tarreaue0c8a1a2009-03-04 16:33:10 +010015881
15882 The errors which may be collected are the last request and response errors
15883 caused by protocol violations, often due to invalid characters in header
15884 names. The report precisely indicates what exact character violated the
15885 protocol. Other important information such as the exact date the error was
15886 detected, frontend and backend names, the server name (when known), the
15887 internal session ID and the source address which has initiated the session
15888 are reported too.
15889
15890 All characters are returned, and non-printable characters are encoded. The
15891 most common ones (\t = 9, \n = 10, \r = 13 and \e = 27) are encoded as one
15892 letter following a backslash. The backslash itself is encoded as '\\' to
15893 avoid confusion. Other non-printable characters are encoded '\xNN' where
15894 NN is the two-digits hexadecimal representation of the character's ASCII
15895 code.
15896
15897 Lines are prefixed with the position of their first character, starting at 0
15898 for the beginning of the buffer. At most one input line is printed per line,
15899 and large lines will be broken into multiple consecutive output lines so that
15900 the output never goes beyond 79 characters wide. It is easy to detect if a
15901 line was broken, because it will not end with '\n' and the next line's offset
15902 will be followed by a '+' sign, indicating it is a continuation of previous
15903 line.
15904
15905 Example :
Willy Tarreau62a36c42010-08-17 15:53:10 +020015906 $ echo "show errors" | socat stdio /tmp/sock1
15907 >>> [04/Mar/2009:15:46:56.081] backend http-in (#2) : invalid response
Willy Tarreaue0c8a1a2009-03-04 16:33:10 +010015908 src 127.0.0.1, session #54, frontend fe-eth0 (#1), server s2 (#1)
15909 response length 213 bytes, error at position 23:
15910
15911 00000 HTTP/1.0 200 OK\r\n
15912 00017 header/bizarre:blah\r\n
15913 00038 Location: blah\r\n
15914 00054 Long-line: this is a very long line which should b
15915 00104+ e broken into multiple lines on the output buffer,
15916 00154+ otherwise it would be too large to print in a ter
15917 00204+ minal\r\n
15918 00211 \r\n
15919
Willy Tarreauc57f0e22009-05-10 13:12:33 +020015920 In the example above, we see that the backend "http-in" which has internal
Willy Tarreaue0c8a1a2009-03-04 16:33:10 +010015921 ID 2 has blocked an invalid response from its server s2 which has internal
15922 ID 1. The request was on session 54 initiated by source 127.0.0.1 and
15923 received by frontend fe-eth0 whose ID is 1. The total response length was
15924 213 bytes when the error was detected, and the error was at byte 23. This
15925 is the slash ('/') in header name "header/bizarre", which is not a valid
15926 HTTP character for a header name.
Krzysztof Piotr Oledzki2c6962c2008-03-02 02:42:14 +010015927
Baptiste Assmann9b6857e2015-09-18 14:49:12 +020015928show backend
15929 Dump the list of backends available in the running process
15930
Willy Tarreau9a42c0d2009-09-22 19:31:03 +020015931show info
15932 Dump info about haproxy status on current process.
15933
Thierry FOURNIERc0e0d7b2013-12-11 16:55:52 +010015934show map [<map>]
15935 Dump info about map converters. Without argument, the list of all available
Thierry FOURNIER65ce6132014-03-20 11:42:45 +010015936 maps is returned. If a <map> is specified, its contents are dumped. <map> is
15937 the #<id> or <file>. The first column is a unique identifier. It can be used
15938 as reference for the operation "del map" and "set map". The second column is
15939 the pattern and the third column is the sample if available. The data returned
15940 are not directly a list of available maps, but are the list of all patterns
15941 composing any map. Many of these patterns can be shared with ACL.
Thierry FOURNIERd32079e2014-01-29 20:02:04 +010015942
15943show acl [<acl>]
15944 Dump info about acl converters. Without argument, the list of all available
Thierry FOURNIER65ce6132014-03-20 11:42:45 +010015945 acls is returned. If a <acl> is specified, its contents are dumped. <acl> if
15946 the #<id> or <file>. The dump format is the same than the map even for the
15947 sample value. The data returned are not a list of available ACL, but are the
15948 list of all patterns composing any ACL. Many of these patterns can be shared
15949 with maps.
Thierry FOURNIERc0e0d7b2013-12-11 16:55:52 +010015950
Willy Tarreau12833bb2014-01-28 16:49:56 +010015951show pools
15952 Dump the status of internal memory pools. This is useful to track memory
15953 usage when suspecting a memory leak for example. It does exactly the same
15954 as the SIGQUIT when running in foreground except that it does not flush
15955 the pools.
15956
Baptiste Assmann6f9225a2015-05-08 19:35:08 +020015957show servers state [<backend>]
15958 Dump the state of the servers found in the running configuration. A backend
15959 name or identifier may be provided to limit the output to this backend only.
15960
15961 The dump has the following format:
15962 - first line contains the format version (1 in this specification);
15963 - second line contains the column headers, prefixed by a sharp ('#');
15964 - third line and next ones contain data;
15965 - each line starting by a sharp ('#') is considered as a comment.
15966
15967 Since multiple versions of the ouptput may co-exist, below is the list of
15968 fields and their order per file format version :
15969 1:
15970 be_id: Backend unique id.
15971 be_name: Backend label.
15972 srv_id: Server unique id (in the backend).
15973 srv_name: Server label.
15974 srv_addr: Server IP address.
15975 srv_op_state: Server operational state (UP/DOWN/...).
15976 In source code: SRV_ST_*.
15977 srv_admin_state: Server administrative state (MAINT/DRAIN/...).
15978 In source code: SRV_ADMF_*.
15979 srv_uweight: User visible server's weight.
15980 srv_iweight: Server's initial weight.
15981 srv_time_since_last_change: Time since last operational change.
15982 srv_check_status: Last health check status.
15983 srv_check_result: Last check result (FAILED/PASSED/...).
15984 In source code: CHK_RES_*.
15985 srv_check_health: Checks rise / fall current counter.
15986 srv_check_state: State of the check (ENABLED/PAUSED/...).
15987 In source code: CHK_ST_*.
15988 srv_agent_state: State of the agent check (ENABLED/PAUSED/...).
15989 In source code: CHK_ST_*.
15990 bk_f_forced_id: Flag to know if the backend ID is forced by
15991 configuration.
15992 srv_f_forced_id: Flag to know if the server's ID is forced by
15993 configuration.
15994
Willy Tarreau9a42c0d2009-09-22 19:31:03 +020015995show sess
15996 Dump all known sessions. Avoid doing this on slow connections as this can
Willy Tarreau6162db22009-10-10 17:13:00 +020015997 be huge. This command is restricted and can only be issued on sockets
15998 configured for levels "operator" or "admin".
15999
Willy Tarreau66dc20a2010-03-05 17:53:32 +010016000show sess <id>
16001 Display a lot of internal information about the specified session identifier.
16002 This identifier is the first field at the beginning of the lines in the dumps
16003 of "show sess" (it corresponds to the session pointer). Those information are
16004 useless to most users but may be used by haproxy developers to troubleshoot a
16005 complex bug. The output format is intentionally not documented so that it can
Olivierce31e6e2014-09-05 18:49:10 +020016006 freely evolve depending on demands. You may find a description of all fields
16007 returned in src/dumpstats.c
16008
16009 The special id "all" dumps the states of all sessions, which must be avoided
16010 as much as possible as it is highly CPU intensive and can take a lot of time.
Willy Tarreau9a42c0d2009-09-22 19:31:03 +020016011
16012show stat [<iid> <type> <sid>]
16013 Dump statistics in the CSV format. By passing <id>, <type> and <sid>, it is
16014 possible to dump only selected items :
16015 - <iid> is a proxy ID, -1 to dump everything
16016 - <type> selects the type of dumpable objects : 1 for frontends, 2 for
16017 backends, 4 for servers, -1 for everything. These values can be ORed,
16018 for example:
16019 1 + 2 = 3 -> frontend + backend.
16020 1 + 2 + 4 = 7 -> frontend + backend + server.
16021 - <sid> is a server ID, -1 to dump everything from the selected proxy.
16022
16023 Example :
Willy Tarreau62a36c42010-08-17 15:53:10 +020016024 $ echo "show info;show stat" | socat stdio unix-connect:/tmp/sock1
16025 >>> Name: HAProxy
Willy Tarreau9a42c0d2009-09-22 19:31:03 +020016026 Version: 1.4-dev2-49
16027 Release_date: 2009/09/23
16028 Nbproc: 1
16029 Process_num: 1
16030 (...)
16031
16032 # pxname,svname,qcur,qmax,scur,smax,slim,stot,bin,bout,dreq, (...)
16033 stats,FRONTEND,,,0,0,1000,0,0,0,0,0,0,,,,,OPEN,,,,,,,,,1,1,0, (...)
16034 stats,BACKEND,0,0,0,0,1000,0,0,0,0,0,,0,0,0,0,UP,0,0,0,,0,250,(...)
16035 (...)
16036 www1,BACKEND,0,0,0,0,1000,0,0,0,0,0,,0,0,0,0,UP,1,1,0,,0,250, (...)
16037
16038 $
16039
16040 Here, two commands have been issued at once. That way it's easy to find
16041 which process the stats apply to in multi-process mode. Notice the empty
16042 line after the information output which marks the end of the first block.
16043 A similar empty line appears at the end of the second block (stats) so that
Krzysztof Piotr Oledzkif8645332009-12-13 21:55:50 +010016044 the reader knows the output has not been truncated.
Willy Tarreau9a42c0d2009-09-22 19:31:03 +020016045
Baptiste Assmann3863f972015-05-17 00:33:24 +020016046show stat resolvers <resolvers section id>
16047 Dump statistics for the given resolvers section.
16048 For each name server, the following counters are reported:
16049 sent: number of DNS requests sent to this server
16050 valid: number of DNS valid responses received from this server
16051 update: number of DNS responses used to update the server's IP address
16052 cname: number of CNAME responses
16053 cname_error: CNAME errors encountered with this server
16054 any_err: number of empty response (IE: server does not support ANY type)
16055 nx: non existent domain response received from this server
16056 timeout: how many time this server did not answer in time
16057 refused: number of requests refused by this server
16058 other: any other DNS errors
16059 invalid: invalid DNS response (from a protocol point of view)
16060 too_big: too big response
16061 outdated: number of response arrived too late (after an other name server)
16062
Willy Tarreau88bc4ec2010-08-01 07:58:48 +020016063show table
16064 Dump general information on all known stick-tables. Their name is returned
16065 (the name of the proxy which holds them), their type (currently zero, always
16066 IP), their size in maximum possible number of entries, and the number of
16067 entries currently in use.
16068
16069 Example :
Willy Tarreau62a36c42010-08-17 15:53:10 +020016070 $ echo "show table" | socat stdio /tmp/sock1
Simon Horman64b28d02011-08-13 08:03:50 +090016071 >>> # table: front_pub, type: ip, size:204800, used:171454
16072 >>> # table: back_rdp, type: ip, size:204800, used:0
Willy Tarreau88bc4ec2010-08-01 07:58:48 +020016073
Simon Horman17bce342011-06-15 15:18:47 +090016074show table <name> [ data.<type> <operator> <value> ] | [ key <key> ]
Willy Tarreau88bc4ec2010-08-01 07:58:48 +020016075 Dump contents of stick-table <name>. In this mode, a first line of generic
16076 information about the table is reported as with "show table", then all
16077 entries are dumped. Since this can be quite heavy, it is possible to specify
Simon Horman17bce342011-06-15 15:18:47 +090016078 a filter in order to specify what entries to display.
16079
16080 When the "data." form is used the filter applies to the stored data (see
16081 "stick-table" in section 4.2). A stored data type must be specified
16082 in <type>, and this data type must be stored in the table otherwise an
16083 error is reported. The data is compared according to <operator> with the
16084 64-bit integer <value>. Operators are the same as with the ACLs :
16085
Willy Tarreau88bc4ec2010-08-01 07:58:48 +020016086 - eq : match entries whose data is equal to this value
16087 - ne : match entries whose data is not equal to this value
16088 - le : match entries whose data is less than or equal to this value
16089 - ge : match entries whose data is greater than or equal to this value
16090 - lt : match entries whose data is less than this value
16091 - gt : match entries whose data is greater than this value
16092
Simon Hormanc88b8872011-06-15 15:18:49 +090016093
16094 When the key form is used the entry <key> is shown. The key must be of the
Simon Horman619e3cc2011-06-15 15:18:52 +090016095 same type as the table, which currently is limited to IPv4, IPv6, integer,
16096 and string.
Simon Horman17bce342011-06-15 15:18:47 +090016097
Willy Tarreau88bc4ec2010-08-01 07:58:48 +020016098 Example :
Willy Tarreau62a36c42010-08-17 15:53:10 +020016099 $ echo "show table http_proxy" | 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 >>> 0x80e6a4c: key=127.0.0.1 use=0 exp=3594729 gpc0=0 conn_rate(30000)=1 \
16102 bytes_out_rate(60000)=187
16103 >>> 0x80e6a80: key=127.0.0.2 use=0 exp=3594740 gpc0=1 conn_rate(30000)=10 \
16104 bytes_out_rate(60000)=191
Willy Tarreau88bc4ec2010-08-01 07:58:48 +020016105
Willy Tarreau62a36c42010-08-17 15:53:10 +020016106 $ echo "show table http_proxy data.gpc0 gt 0" | socat stdio /tmp/sock1
Simon Horman64b28d02011-08-13 08:03:50 +090016107 >>> # table: http_proxy, type: ip, size:204800, used:2
Willy Tarreau62a36c42010-08-17 15:53:10 +020016108 >>> 0x80e6a80: key=127.0.0.2 use=0 exp=3594740 gpc0=1 conn_rate(30000)=10 \
16109 bytes_out_rate(60000)=191
Willy Tarreau88bc4ec2010-08-01 07:58:48 +020016110
Willy Tarreau62a36c42010-08-17 15:53:10 +020016111 $ echo "show table http_proxy data.conn_rate gt 5" | \
16112 socat stdio /tmp/sock1
Simon Horman64b28d02011-08-13 08:03:50 +090016113 >>> # table: http_proxy, type: ip, size:204800, used:2
Willy Tarreau62a36c42010-08-17 15:53:10 +020016114 >>> 0x80e6a80: key=127.0.0.2 use=0 exp=3594740 gpc0=1 conn_rate(30000)=10 \
16115 bytes_out_rate(60000)=191
Willy Tarreau88bc4ec2010-08-01 07:58:48 +020016116
Simon Horman17bce342011-06-15 15:18:47 +090016117 $ echo "show table http_proxy key 127.0.0.2" | \
16118 socat stdio /tmp/sock1
Simon Horman64b28d02011-08-13 08:03:50 +090016119 >>> # table: http_proxy, type: ip, size:204800, used:2
Simon Horman17bce342011-06-15 15:18:47 +090016120 >>> 0x80e6a80: key=127.0.0.2 use=0 exp=3594740 gpc0=1 conn_rate(30000)=10 \
16121 bytes_out_rate(60000)=191
16122
Willy Tarreau88bc4ec2010-08-01 07:58:48 +020016123 When the data criterion applies to a dynamic value dependent on time such as
16124 a bytes rate, the value is dynamically computed during the evaluation of the
16125 entry in order to decide whether it has to be dumped or not. This means that
16126 such a filter could match for some time then not match anymore because as
16127 time goes, the average event rate drops.
16128
16129 It is possible to use this to extract lists of IP addresses abusing the
16130 service, in order to monitor them or even blacklist them in a firewall.
16131 Example :
Willy Tarreau62a36c42010-08-17 15:53:10 +020016132 $ echo "show table http_proxy data.gpc0 gt 0" \
16133 | socat stdio /tmp/sock1 \
Willy Tarreau88bc4ec2010-08-01 07:58:48 +020016134 | fgrep 'key=' | cut -d' ' -f2 | cut -d= -f2 > abusers-ip.txt
16135 ( or | awk '/key/{ print a[split($2,a,"=")]; }' )
Krzysztof Piotr Oledzki719e7262009-10-04 15:02:46 +020016136
Nenad Merdanovicc6985f02015-05-09 08:46:02 +020016137show tls-keys
16138 Dump all loaded TLS ticket keys. The TLS ticket key reference ID and the
16139 file from which the keys have been loaded is shown. Both of those can be
16140 used to update the TLS keys using "set ssl tls-key".
16141
Willy Tarreau532a4502011-09-07 22:37:44 +020016142shutdown frontend <frontend>
16143 Completely delete the specified frontend. All the ports it was bound to will
16144 be released. It will not be possible to enable the frontend anymore after
16145 this operation. This is intended to be used in environments where stopping a
16146 proxy is not even imaginable but a misconfigured proxy must be fixed. That
16147 way it's possible to release the port and bind it into another process to
16148 restore operations. The frontend will not appear at all on the stats page
16149 once it is terminated.
16150
16151 The frontend may be specified either by its name or by its numeric ID,
16152 prefixed with a sharp ('#').
16153
16154 This command is restricted and can only be issued on sockets configured for
16155 level "admin".
16156
Willy Tarreaua295edc2011-09-07 23:21:03 +020016157shutdown session <id>
16158 Immediately terminate the session matching the specified session identifier.
16159 This identifier is the first field at the beginning of the lines in the dumps
16160 of "show sess" (it corresponds to the session pointer). This can be used to
16161 terminate a long-running session without waiting for a timeout or when an
16162 endless transfer is ongoing. Such terminated sessions are reported with a 'K'
16163 flag in the logs.
16164
Cyril Bontée63a1eb2014-07-12 18:22:42 +020016165shutdown sessions server <backend>/<server>
Willy Tarreau52b2d222011-09-07 23:48:48 +020016166 Immediately terminate all the sessions attached to the specified server. This
16167 can be used to terminate long-running sessions after a server is put into
16168 maintenance mode, for instance. Such terminated sessions are reported with a
16169 'K' flag in the logs.
16170
Willy Tarreau0ba27502007-12-24 16:55:16 +010016171/*
16172 * Local variables:
16173 * fill-column: 79
16174 * End:
16175 */