blob: 7c87dc82ff546c7485f0f3e8fd00a6fa54259c56 [file] [log] [blame]
Willy Tarreau6a06a402007-07-15 20:15:28 +02001 ----------------------
2 HAProxy
3 Configuration Manual
4 ----------------------
Willy Tarreau79158882009-06-09 11:59:08 +02005 version 1.4
Willy Tarreau6a06a402007-07-15 20:15:28 +02006 willy tarreau
Willy Tarreau6939b552010-01-25 01:54:37 +01007 2010/01/25
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 :
17 This document is formated with 80 columns per line, with even number of
18 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
21 ('\') and continue on next line. If you add sections, please update the
22 summary below for easier searching.
23
24
25Summary
26-------
27
281. Quick reminder about HTTP
291.1. The HTTP transaction model
301.2. HTTP request
311.2.1. The Request line
321.2.2. The request headers
331.3. HTTP response
341.3.1. The Response line
351.3.2. The response headers
36
372. Configuring HAProxy
382.1. Configuration file format
392.2. Time format
40
413. Global parameters
423.1. Process management and security
433.2. Performance tuning
443.3. Debugging
45
464. Proxies
474.1. Proxy keywords matrix
484.2. Alphabetically sorted keywords reference
49
Krzysztof Piotr Oledzkic6df0662010-01-05 16:38:49 +0100505. Server and default-server options
Willy Tarreauc57f0e22009-05-10 13:12:33 +020051
526. HTTP header manipulation
53
547. Using ACLs
557.1. Matching integers
567.2. Matching strings
577.3. Matching regular expressions (regexes)
587.4. Matching IPv4 addresses
597.5. Available matching criteria
607.5.1. Matching at Layer 4 and below
617.5.2. Matching contents at Layer 4
627.5.3. Matching at Layer 7
637.6. Pre-defined ACLs
647.7. Using ACLs to form conditions
65
668. Logging
678.1. Log levels
688.2. Log formats
698.2.1. Default log format
708.2.2. TCP log format
718.2.3. HTTP log format
728.3. Advanced logging options
738.3.1. Disabling logging of external tests
748.3.2. Logging before waiting for the session to terminate
758.3.3. Raising log level upon errors
768.3.4. Disabling logging of successful connections
778.4. Timing events
788.5. Session state at disconnection
798.6. Non-printable characters
808.7. Capturing HTTP cookies
818.8. Capturing HTTP headers
828.9. Examples of logs
83
849. Statistics and monitoring
859.1. CSV format
869.2. Unix Socket commands
87
88
891. Quick reminder about HTTP
90----------------------------
91
92When haproxy is running in HTTP mode, both the request and the response are
93fully analyzed and indexed, thus it becomes possible to build matching criteria
94on almost anything found in the contents.
95
96However, it is important to understand how HTTP requests and responses are
97formed, and how HAProxy decomposes them. It will then become easier to write
98correct rules and to debug existing configurations.
99
100
1011.1. The HTTP transaction model
102-------------------------------
103
104The HTTP protocol is transaction-driven. This means that each request will lead
Krzysztof Piotr Oledzkif8645332009-12-13 21:55:50 +0100105to one and only one response. Traditionally, a TCP connection is established
Willy Tarreauc57f0e22009-05-10 13:12:33 +0200106from the client to the server, a request is sent by the client on the
107connection, the server responds and the connection is closed. A new request
108will involve a new connection :
109
110 [CON1] [REQ1] ... [RESP1] [CLO1] [CON2] [REQ2] ... [RESP2] [CLO2] ...
111
112In this mode, called the "HTTP close" mode, there are as many connection
113establishments as there are HTTP transactions. Since the connection is closed
114by the server after the response, the client does not need to know the content
115length.
116
117Due to the transactional nature of the protocol, it was possible to improve it
118to avoid closing a connection between two subsequent transactions. In this mode
119however, it is mandatory that the server indicates the content length for each
120response so that the client does not wait indefinitely. For this, a special
121header is used: "Content-length". This mode is called the "keep-alive" mode :
122
123 [CON] [REQ1] ... [RESP1] [REQ2] ... [RESP2] [CLO] ...
124
125Its advantages are a reduced latency between transactions, and less processing
126power required on the server side. It is generally better than the close mode,
127but not always because the clients often limit their concurrent connections to
128a smaller value. HAProxy currently does not support the HTTP keep-alive mode,
129but knows how to transform it to the close mode.
130
131A last improvement in the communications is the pipelining mode. It still uses
132keep-alive, but the client does not wait for the first response to send the
133second request. This is useful for fetching large number of images composing a
134page :
135
136 [CON] [REQ1] [REQ2] ... [RESP1] [RESP2] [CLO] ...
137
138This can obviously have a tremendous benefit on performance because the network
139latency is eliminated between subsequent requests. Many HTTP agents do not
140correctly support pipelining since there is no way to associate a response with
141the corresponding request in HTTP. For this reason, it is mandatory for the
142server to reply in the exact same order as the requests were received.
143
144Right now, HAProxy only supports the first mode (HTTP close) if it needs to
145process the request. This means that for each request, there will be one TCP
146connection. If keep-alive or pipelining are required, HAProxy will still
147support them, but will only see the first request and the first response of
148each transaction. While this is generally problematic with regards to logs,
149content switching or filtering, it most often causes no problem for persistence
150with cookie insertion.
151
152
1531.2. HTTP request
154-----------------
155
156First, let's consider this HTTP request :
157
158 Line Contents
Willy Tarreaud72758d2010-01-12 10:42:19 +0100159 number
Willy Tarreauc57f0e22009-05-10 13:12:33 +0200160 1 GET /serv/login.php?lang=en&profile=2 HTTP/1.1
161 2 Host: www.mydomain.com
162 3 User-agent: my small browser
163 4 Accept: image/jpeg, image/gif
164 5 Accept: image/png
165
166
1671.2.1. The Request line
168-----------------------
169
170Line 1 is the "request line". It is always composed of 3 fields :
171
172 - a METHOD : GET
173 - a URI : /serv/login.php?lang=en&profile=2
174 - a version tag : HTTP/1.1
175
176All of them are delimited by what the standard calls LWS (linear white spaces),
177which are commonly spaces, but can also be tabs or line feeds/carriage returns
178followed by spaces/tabs. The method itself cannot contain any colon (':') and
179is limited to alphabetic letters. All those various combinations make it
180desirable that HAProxy performs the splitting itself rather than leaving it to
181the user to write a complex or inaccurate regular expression.
182
183The URI itself can have several forms :
184
185 - A "relative URI" :
186
187 /serv/login.php?lang=en&profile=2
188
189 It is a complete URL without the host part. This is generally what is
190 received by servers, reverse proxies and transparent proxies.
191
192 - An "absolute URI", also called a "URL" :
193
194 http://192.168.0.12:8080/serv/login.php?lang=en&profile=2
195
196 It is composed of a "scheme" (the protocol name followed by '://'), a host
197 name or address, optionally a colon (':') followed by a port number, then
198 a relative URI beginning at the first slash ('/') after the address part.
199 This is generally what proxies receive, but a server supporting HTTP/1.1
200 must accept this form too.
201
202 - a star ('*') : this form is only accepted in association with the OPTIONS
203 method and is not relayable. It is used to inquiry a next hop's
204 capabilities.
Willy Tarreaud72758d2010-01-12 10:42:19 +0100205
Willy Tarreauc57f0e22009-05-10 13:12:33 +0200206 - an address:port combination : 192.168.0.12:80
207 This is used with the CONNECT method, which is used to establish TCP
208 tunnels through HTTP proxies, generally for HTTPS, but sometimes for
209 other protocols too.
210
211In a relative URI, two sub-parts are identified. The part before the question
212mark is called the "path". It is typically the relative path to static objects
213on the server. The part after the question mark is called the "query string".
214It is mostly used with GET requests sent to dynamic scripts and is very
215specific to the language, framework or application in use.
216
217
2181.2.2. The request headers
219--------------------------
220
221The headers start at the second line. They are composed of a name at the
222beginning of the line, immediately followed by a colon (':'). Traditionally,
223an LWS is added after the colon but that's not required. Then come the values.
224Multiple identical headers may be folded into one single line, delimiting the
225values with commas, provided that their order is respected. This is commonly
226encountered in the "Cookie:" field. A header may span over multiple lines if
227the subsequent lines begin with an LWS. In the example in 1.2, lines 4 and 5
228define a total of 3 values for the "Accept:" header.
229
230Contrary to a common mis-conception, header names are not case-sensitive, and
231their values are not either if they refer to other header names (such as the
232"Connection:" header).
233
234The end of the headers is indicated by the first empty line. People often say
235that it's a double line feed, which is not exact, even if a double line feed
236is one valid form of empty line.
237
238Fortunately, HAProxy takes care of all these complex combinations when indexing
239headers, checking values and counting them, so there is no reason to worry
240about the way they could be written, but it is important not to accuse an
241application of being buggy if it does unusual, valid things.
242
243Important note:
244 As suggested by RFC2616, HAProxy normalizes headers by replacing line breaks
245 in the middle of headers by LWS in order to join multi-line headers. This
246 is necessary for proper analysis and helps less capable HTTP parsers to work
247 correctly and not to be fooled by such complex constructs.
248
249
2501.3. HTTP response
251------------------
252
253An HTTP response looks very much like an HTTP request. Both are called HTTP
254messages. Let's consider this HTTP response :
255
256 Line Contents
Willy Tarreaud72758d2010-01-12 10:42:19 +0100257 number
Willy Tarreauc57f0e22009-05-10 13:12:33 +0200258 1 HTTP/1.1 200 OK
259 2 Content-length: 350
260 3 Content-Type: text/html
261
Willy Tarreau816b9792009-09-15 21:25:21 +0200262As a special case, HTTP supports so called "Informational responses" as status
263codes 1xx. These messages are special in that they don't convey any part of the
264response, they're just used as sort of a signaling message to ask a client to
265continue to post its request for instance. The requested information will be
266carried by the next non-1xx response message following the informational one.
267This implies that multiple responses may be sent to a single request, and that
268this only works when keep-alive is enabled (1xx messages are HTTP/1.1 only).
269HAProxy handles these messages and is able to correctly forward and skip them,
270and only process the next non-1xx response. As such, these messages are neither
271logged nor transformed, unless explicitly state otherwise.
272
Willy Tarreauc57f0e22009-05-10 13:12:33 +0200273
2741.3.1. The Response line
275------------------------
276
277Line 1 is the "response line". It is always composed of 3 fields :
278
279 - a version tag : HTTP/1.1
280 - a status code : 200
281 - a reason : OK
282
283The status code is always 3-digit. The first digit indicates a general status :
Willy Tarreau816b9792009-09-15 21:25:21 +0200284 - 1xx = informational message to be skipped (eg: 100, 101)
Willy Tarreauc57f0e22009-05-10 13:12:33 +0200285 - 2xx = OK, content is following (eg: 200, 206)
286 - 3xx = OK, no content following (eg: 302, 304)
287 - 4xx = error caused by the client (eg: 401, 403, 404)
288 - 5xx = error caused by the server (eg: 500, 502, 503)
289
290Please refer to RFC2616 for the detailed meaning of all such codes. The
Willy Tarreaud72758d2010-01-12 10:42:19 +0100291"reason" field is just a hint, but is not parsed by clients. Anything can be
Willy Tarreauc57f0e22009-05-10 13:12:33 +0200292found there, but it's a common practice to respect the well-established
293messages. It can be composed of one or multiple words, such as "OK", "Found",
294or "Authentication Required".
295
296Haproxy may emit the following status codes by itself :
297
298 Code When / reason
299 200 access to stats page, and when replying to monitoring requests
300 301 when performing a redirection, depending on the configured code
301 302 when performing a redirection, depending on the configured code
302 303 when performing a redirection, depending on the configured code
303 400 for an invalid or too large request
304 401 when an authentication is required to perform the action (when
305 accessing the stats page)
306 403 when a request is forbidden by a "block" ACL or "reqdeny" filter
307 408 when the request timeout strikes before the request is complete
308 500 when haproxy encounters an unrecoverable internal error, such as a
309 memory allocation failure, which should never happen
310 502 when the server returns an empty, invalid or incomplete response, or
311 when an "rspdeny" filter blocks the response.
312 503 when no server was available to handle the request, or in response to
313 monitoring requests which match the "monitor fail" condition
314 504 when the response timeout strikes before the server responds
315
316The error 4xx and 5xx codes above may be customized (see "errorloc" in section
3174.2).
318
319
3201.3.2. The response headers
321---------------------------
322
323Response headers work exactly like request headers, and as such, HAProxy uses
324the same parsing function for both. Please refer to paragraph 1.2.2 for more
325details.
326
327
3282. Configuring HAProxy
329----------------------
330
3312.1. Configuration file format
332------------------------------
Willy Tarreau6a06a402007-07-15 20:15:28 +0200333
334HAProxy's configuration process involves 3 major sources of parameters :
335
336 - the arguments from the command-line, which always take precedence
337 - the "global" section, which sets process-wide parameters
338 - the proxies sections which can take form of "defaults", "listen",
339 "frontend" and "backend".
340
Willy Tarreau0ba27502007-12-24 16:55:16 +0100341The configuration file syntax consists in lines beginning with a keyword
342referenced in this manual, optionally followed by one or several parameters
343delimited by spaces. If spaces have to be entered in strings, then they must be
Krzysztof Piotr Oledzkif8645332009-12-13 21:55:50 +0100344preceded by a backslash ('\') to be escaped. Backslashes also have to be
Willy Tarreau0ba27502007-12-24 16:55:16 +0100345escaped by doubling them.
346
Willy Tarreauc57f0e22009-05-10 13:12:33 +0200347
3482.2. Time format
349----------------
350
Krzysztof Piotr Oledzkif8645332009-12-13 21:55:50 +0100351Some parameters involve values representing time, such as timeouts. These
Willy Tarreau0ba27502007-12-24 16:55:16 +0100352values are generally expressed in milliseconds (unless explicitly stated
353otherwise) but may be expressed in any other unit by suffixing the unit to the
354numeric value. It is important to consider this because it will not be repeated
355for every keyword. Supported units are :
356
357 - us : microseconds. 1 microsecond = 1/1000000 second
358 - ms : milliseconds. 1 millisecond = 1/1000 second. This is the default.
359 - s : seconds. 1s = 1000ms
360 - m : minutes. 1m = 60s = 60000ms
361 - h : hours. 1h = 60m = 3600s = 3600000ms
362 - d : days. 1d = 24h = 1440m = 86400s = 86400000ms
363
364
Willy Tarreauc57f0e22009-05-10 13:12:33 +02003653. Global parameters
Willy Tarreau6a06a402007-07-15 20:15:28 +0200366--------------------
367
368Parameters in the "global" section are process-wide and often OS-specific. They
369are generally set once for all and do not need being changed once correct. Some
370of them have command-line equivalents.
371
372The following keywords are supported in the "global" section :
373
374 * Process management and security
375 - chroot
376 - daemon
377 - gid
378 - group
379 - log
380 - nbproc
381 - pidfile
382 - uid
383 - ulimit-n
384 - user
Willy Tarreaufbee7132007-10-18 13:53:22 +0200385 - stats
Krzysztof Piotr Oledzki48cb2ae2009-10-02 22:51:14 +0200386 - node
387 - description
Willy Tarreaud72758d2010-01-12 10:42:19 +0100388
Willy Tarreau6a06a402007-07-15 20:15:28 +0200389 * Performance tuning
390 - maxconn
Willy Tarreauff4f82d2009-02-06 11:28:13 +0100391 - maxpipes
Willy Tarreau6a06a402007-07-15 20:15:28 +0200392 - noepoll
393 - nokqueue
394 - nopoll
395 - nosepoll
Willy Tarreauff4f82d2009-02-06 11:28:13 +0100396 - nosplice
Willy Tarreaufe255b72007-10-14 23:09:26 +0200397 - spread-checks
Willy Tarreau27a674e2009-08-17 07:23:33 +0200398 - tune.bufsize
Willy Tarreaua0250ba2008-01-06 11:22:57 +0100399 - tune.maxaccept
400 - tune.maxpollevents
Willy Tarreau27a674e2009-08-17 07:23:33 +0200401 - tune.maxrewrite
Willy Tarreaue803de22010-01-21 17:43:04 +0100402 - tune.rcvbuf.client
403 - tune.rcvbuf.server
404 - tune.sndbuf.client
405 - tune.sndbuf.server
Willy Tarreaud72758d2010-01-12 10:42:19 +0100406
Willy Tarreau6a06a402007-07-15 20:15:28 +0200407 * Debugging
408 - debug
409 - quiet
Willy Tarreau6a06a402007-07-15 20:15:28 +0200410
411
Willy Tarreauc57f0e22009-05-10 13:12:33 +02004123.1. Process management and security
Willy Tarreau6a06a402007-07-15 20:15:28 +0200413------------------------------------
414
415chroot <jail dir>
416 Changes current directory to <jail dir> and performs a chroot() there before
417 dropping privileges. This increases the security level in case an unknown
418 vulnerability would be exploited, since it would make it very hard for the
419 attacker to exploit the system. This only works when the process is started
420 with superuser privileges. It is important to ensure that <jail_dir> is both
421 empty and unwritable to anyone.
Willy Tarreaud72758d2010-01-12 10:42:19 +0100422
Willy Tarreau6a06a402007-07-15 20:15:28 +0200423daemon
424 Makes the process fork into background. This is the recommended mode of
425 operation. It is equivalent to the command line "-D" argument. It can be
426 disabled by the command line "-db" argument.
427
428gid <number>
429 Changes the process' group ID to <number>. It is recommended that the group
430 ID is dedicated to HAProxy or to a small set of similar daemons. HAProxy must
431 be started with a user belonging to this group, or with superuser privileges.
432 See also "group" and "uid".
Willy Tarreaud72758d2010-01-12 10:42:19 +0100433
Willy Tarreau6a06a402007-07-15 20:15:28 +0200434group <group name>
435 Similar to "gid" but uses the GID of group name <group name> from /etc/group.
436 See also "gid" and "user".
Willy Tarreaud72758d2010-01-12 10:42:19 +0100437
Willy Tarreauf7edefa2009-05-10 17:20:05 +0200438log <address> <facility> [max level [min level]]
Willy Tarreau6a06a402007-07-15 20:15:28 +0200439 Adds a global syslog server. Up to two global servers can be defined. They
440 will receive logs for startups and exits, as well as all logs from proxies
Robert Tsai81ae1952007-12-05 10:47:29 +0100441 configured with "log global".
442
443 <address> can be one of:
444
Willy Tarreau2769aa02007-12-27 18:26:09 +0100445 - An IPv4 address optionally followed by a colon and a UDP port. If
Robert Tsai81ae1952007-12-05 10:47:29 +0100446 no port is specified, 514 is used by default (the standard syslog
447 port).
448
449 - A filesystem path to a UNIX domain socket, keeping in mind
450 considerations for chroot (be sure the path is accessible inside
451 the chroot) and uid/gid (be sure the path is appropriately
452 writeable).
453
454 <facility> must be one of the 24 standard syslog facilities :
Willy Tarreau6a06a402007-07-15 20:15:28 +0200455
456 kern user mail daemon auth syslog lpr news
457 uucp cron auth2 ftp ntp audit alert cron2
458 local0 local1 local2 local3 local4 local5 local6 local7
459
460 An optional level can be specified to filter outgoing messages. By default,
Willy Tarreauf7edefa2009-05-10 17:20:05 +0200461 all messages are sent. If a maximum level is specified, only messages with a
462 severity at least as important as this level will be sent. An optional minimum
463 level can be specified. If it is set, logs emitted with a more severe level
464 than this one will be capped to this level. This is used to avoid sending
465 "emerg" messages on all terminals on some default syslog configurations.
466 Eight levels are known :
Willy Tarreau6a06a402007-07-15 20:15:28 +0200467
468 emerg alert crit err warning notice info debug
469
470nbproc <number>
471 Creates <number> processes when going daemon. This requires the "daemon"
472 mode. By default, only one process is created, which is the recommended mode
473 of operation. For systems limited to small sets of file descriptors per
474 process, it may be needed to fork multiple daemons. USING MULTIPLE PROCESSES
475 IS HARDER TO DEBUG AND IS REALLY DISCOURAGED. See also "daemon".
476
477pidfile <pidfile>
478 Writes pids of all daemons into file <pidfile>. This option is equivalent to
479 the "-p" command line argument. The file must be accessible to the user
480 starting the process. See also "daemon".
481
Willy Tarreaufbee7132007-10-18 13:53:22 +0200482stats socket <path> [{uid | user} <uid>] [{gid | group} <gid>] [mode <mode>]
Willy Tarreau6162db22009-10-10 17:13:00 +0200483 [level <level>]
484
Willy Tarreaufbee7132007-10-18 13:53:22 +0200485 Creates a UNIX socket in stream mode at location <path>. Any previously
486 existing socket will be backed up then replaced. Connections to this socket
Krzysztof Piotr Oledzkif8645332009-12-13 21:55:50 +0100487 will return various statistics outputs and even allow some commands to be
Willy Tarreau6162db22009-10-10 17:13:00 +0200488 issued. Please consult section 9.2 "Unix Socket commands" for more details.
489
490 An optional "level" parameter can be specified to restrict the nature of
491 the commands that can be issued on the socket :
492 - "user" is the least privileged level ; only non-sensitive stats can be
493 read, and no change is allowed. It would make sense on systems where it
494 is not easy to restrict access to the socket.
495
496 - "operator" is the default level and fits most common uses. All data can
497 be read, and only non-sensible changes are permitted (eg: clear max
498 counters).
499
500 - "admin" should be used with care, as everything is permitted (eg: clear
501 all counters).
Willy Tarreaua8efd362008-01-03 10:19:15 +0100502
503 On platforms which support it, it is possible to restrict access to this
504 socket by specifying numerical IDs after "uid" and "gid", or valid user and
505 group names after the "user" and "group" keywords. It is also possible to
506 restrict permissions on the socket by passing an octal value after the "mode"
507 keyword (same syntax as chmod). Depending on the platform, the permissions on
508 the socket will be inherited from the directory which hosts it, or from the
509 user the process is started with.
Willy Tarreaufbee7132007-10-18 13:53:22 +0200510
511stats timeout <timeout, in milliseconds>
512 The default timeout on the stats socket is set to 10 seconds. It is possible
513 to change this value with "stats timeout". The value must be passed in
Willy Tarreaubefdff12007-12-02 22:27:38 +0100514 milliseconds, or be suffixed by a time unit among { us, ms, s, m, h, d }.
Willy Tarreaufbee7132007-10-18 13:53:22 +0200515
516stats maxconn <connections>
517 By default, the stats socket is limited to 10 concurrent connections. It is
518 possible to change this value with "stats maxconn".
519
Willy Tarreau6a06a402007-07-15 20:15:28 +0200520uid <number>
521 Changes the process' user ID to <number>. It is recommended that the user ID
522 is dedicated to HAProxy or to a small set of similar daemons. HAProxy must
523 be started with superuser privileges in order to be able to switch to another
524 one. See also "gid" and "user".
525
526ulimit-n <number>
527 Sets the maximum number of per-process file-descriptors to <number>. By
528 default, it is automatically computed, so it is recommended not to use this
529 option.
530
531user <user name>
532 Similar to "uid" but uses the UID of user name <user name> from /etc/passwd.
533 See also "uid" and "group".
534
Krzysztof Piotr Oledzki48cb2ae2009-10-02 22:51:14 +0200535node <name>
536 Only letters, digits, hyphen and underscore are allowed, like in DNS names.
537
538 This statement is useful in HA configurations where two or more processes or
539 servers share the same IP address. By setting a different node-name on all
540 nodes, it becomes easy to immediately spot what server is handling the
541 traffic.
542
543description <text>
544 Add a text that describes the instance.
545
546 Please note that it is required to escape certain characters (# for example)
547 and this text is inserted into a html page so you should avoid using
548 "<" and ">" characters.
549
Willy Tarreau6a06a402007-07-15 20:15:28 +0200550
Willy Tarreauc57f0e22009-05-10 13:12:33 +02005513.2. Performance tuning
Willy Tarreau6a06a402007-07-15 20:15:28 +0200552-----------------------
553
554maxconn <number>
555 Sets the maximum per-process number of concurrent connections to <number>. It
556 is equivalent to the command-line argument "-n". Proxies will stop accepting
557 connections when this limit is reached. The "ulimit-n" parameter is
558 automatically adjusted according to this value. See also "ulimit-n".
559
Willy Tarreauff4f82d2009-02-06 11:28:13 +0100560maxpipes <number>
561 Sets the maximum per-process number of pipes to <number>. Currently, pipes
562 are only used by kernel-based tcp splicing. Since a pipe contains two file
563 descriptors, the "ulimit-n" value will be increased accordingly. The default
564 value is maxconn/4, which seems to be more than enough for most heavy usages.
565 The splice code dynamically allocates and releases pipes, and can fall back
566 to standard copy, so setting this value too low may only impact performance.
567
Willy Tarreau6a06a402007-07-15 20:15:28 +0200568noepoll
569 Disables the use of the "epoll" event polling system on Linux. It is
570 equivalent to the command-line argument "-de". The next polling system
571 used will generally be "poll". See also "nosepoll", and "nopoll".
572
573nokqueue
574 Disables the use of the "kqueue" event polling system on BSD. It is
575 equivalent to the command-line argument "-dk". The next polling system
576 used will generally be "poll". See also "nopoll".
577
578nopoll
579 Disables the use of the "poll" event polling system. It is equivalent to the
580 command-line argument "-dp". The next polling system used will be "select".
Willy Tarreau0ba27502007-12-24 16:55:16 +0100581 It should never be needed to disable "poll" since it's available on all
Willy Tarreau6a06a402007-07-15 20:15:28 +0200582 platforms supported by HAProxy. See also "nosepoll", and "nopoll" and
583 "nokqueue".
584
585nosepoll
586 Disables the use of the "speculative epoll" event polling system on Linux. It
587 is equivalent to the command-line argument "-ds". The next polling system
588 used will generally be "epoll". See also "nosepoll", and "nopoll".
589
Willy Tarreauff4f82d2009-02-06 11:28:13 +0100590nosplice
591 Disables the use of kernel tcp splicing between sockets on Linux. It is
592 equivalent to the command line argument "-dS". Data will then be copied
593 using conventional and more portable recv/send calls. Kernel tcp splicing is
Krzysztof Piotr Oledzkif8645332009-12-13 21:55:50 +0100594 limited to some very recent instances of kernel 2.6. Most versions between
Willy Tarreauff4f82d2009-02-06 11:28:13 +0100595 2.6.25 and 2.6.28 are buggy and will forward corrupted data, so they must not
596 be used. This option makes it easier to globally disable kernel splicing in
597 case of doubt. See also "option splice-auto", "option splice-request" and
598 "option splice-response".
599
Willy Tarreaufe255b72007-10-14 23:09:26 +0200600spread-checks <0..50, in percent>
601 Sometimes it is desirable to avoid sending health checks to servers at exact
602 intervals, for instance when many logical servers are located on the same
603 physical server. With the help of this parameter, it becomes possible to add
604 some randomness in the check interval between 0 and +/- 50%. A value between
605 2 and 5 seems to show good results. The default value remains at 0.
606
Willy Tarreau27a674e2009-08-17 07:23:33 +0200607tune.bufsize <number>
608 Sets the buffer size to this size (in bytes). Lower values allow more
609 sessions to coexist in the same amount of RAM, and higher values allow some
610 applications with very large cookies to work. The default value is 16384 and
611 can be changed at build time. It is strongly recommended not to change this
612 from the default value, as very low values will break some services such as
613 statistics, and values larger than default size will increase memory usage,
614 possibly causing the system to run out of memory. At least the global maxconn
615 parameter should be decreased by the same factor as this one is increased.
616
Willy Tarreaua0250ba2008-01-06 11:22:57 +0100617tune.maxaccept <number>
618 Sets the maximum number of consecutive accepts that a process may perform on
619 a single wake up. High values give higher priority to high connection rates,
620 while lower values give higher priority to already established connections.
Willy Tarreauf49d1df2009-03-01 08:35:41 +0100621 This value is limited to 100 by default in single process mode. However, in
Willy Tarreaua0250ba2008-01-06 11:22:57 +0100622 multi-process mode (nbproc > 1), it defaults to 8 so that when one process
623 wakes up, it does not take all incoming connections for itself and leaves a
Willy Tarreauf49d1df2009-03-01 08:35:41 +0100624 part of them to other processes. Setting this value to -1 completely disables
Willy Tarreaua0250ba2008-01-06 11:22:57 +0100625 the limitation. It should normally not be needed to tweak this value.
626
627tune.maxpollevents <number>
628 Sets the maximum amount of events that can be processed at once in a call to
629 the polling system. The default value is adapted to the operating system. It
630 has been noticed that reducing it below 200 tends to slightly decrease
631 latency at the expense of network bandwidth, and increasing it above 200
632 tends to trade latency for slightly increased bandwidth.
633
Willy Tarreau27a674e2009-08-17 07:23:33 +0200634tune.maxrewrite <number>
635 Sets the reserved buffer space to this size in bytes. The reserved space is
636 used for header rewriting or appending. The first reads on sockets will never
637 fill more than bufsize-maxrewrite. Historically it has defaulted to half of
638 bufsize, though that does not make much sense since there are rarely large
639 numbers of headers to add. Setting it too high prevents processing of large
640 requests or responses. Setting it too low prevents addition of new headers
641 to already large requests or to POST requests. It is generally wise to set it
642 to about 1024. It is automatically readjusted to half of bufsize if it is
643 larger than that. This means you don't have to worry about it when changing
644 bufsize.
645
Willy Tarreaue803de22010-01-21 17:43:04 +0100646tune.rcvbuf.client <number>
647tune.rcvbuf.server <number>
648 Forces the kernel socket receive buffer size on the client or the server side
649 to the specified value in bytes. This value applies to all TCP/HTTP frontends
650 and backends. It should normally never be set, and the default size (0) lets
651 the kernel autotune this value depending on the amount of available memory.
652 However it can sometimes help to set it to very low values (eg: 4096) in
653 order to save kernel memory by preventing it from buffering too large amounts
654 of received data. Lower values will significantly increase CPU usage though.
655
656tune.sndbuf.client <number>
657tune.sndbuf.server <number>
658 Forces the kernel socket send buffer size on the client or the server side to
659 the specified value in bytes. This value applies to all TCP/HTTP frontends
660 and backends. It should normally never be set, and the default size (0) lets
661 the kernel autotune this value depending on the amount of available memory.
662 However it can sometimes help to set it to very low values (eg: 4096) in
663 order to save kernel memory by preventing it from buffering too large amounts
664 of received data. Lower values will significantly increase CPU usage though.
665 Another use case is to prevent write timeouts with extremely slow clients due
666 to the kernel waiting for a large part of the buffer to be read before
667 notifying haproxy again.
668
Willy Tarreau6a06a402007-07-15 20:15:28 +0200669
Willy Tarreauc57f0e22009-05-10 13:12:33 +02006703.3. Debugging
671--------------
Willy Tarreau6a06a402007-07-15 20:15:28 +0200672
673debug
674 Enables debug mode which dumps to stdout all exchanges, and disables forking
675 into background. It is the equivalent of the command-line argument "-d". It
676 should never be used in a production configuration since it may prevent full
677 system startup.
678
679quiet
680 Do not display any message during startup. It is equivalent to the command-
681 line argument "-q".
682
Willy Tarreau6a06a402007-07-15 20:15:28 +0200683
Willy Tarreauc57f0e22009-05-10 13:12:33 +02006844. Proxies
Willy Tarreau6a06a402007-07-15 20:15:28 +0200685----------
Willy Tarreau0ba27502007-12-24 16:55:16 +0100686
Willy Tarreau6a06a402007-07-15 20:15:28 +0200687Proxy configuration can be located in a set of sections :
688 - defaults <name>
689 - frontend <name>
690 - backend <name>
691 - listen <name>
692
693A "defaults" section sets default parameters for all other sections following
694its declaration. Those default parameters are reset by the next "defaults"
695section. See below for the list of parameters which can be set in a "defaults"
Willy Tarreau0ba27502007-12-24 16:55:16 +0100696section. The name is optional but its use is encouraged for better readability.
Willy Tarreau6a06a402007-07-15 20:15:28 +0200697
698A "frontend" section describes a set of listening sockets accepting client
699connections.
700
701A "backend" section describes a set of servers to which the proxy will connect
702to forward incoming connections.
703
704A "listen" section defines a complete proxy with its frontend and backend
705parts combined in one section. It is generally useful for TCP-only traffic.
706
Willy Tarreau0ba27502007-12-24 16:55:16 +0100707All proxy names must be formed from upper and lower case letters, digits,
708'-' (dash), '_' (underscore) , '.' (dot) and ':' (colon). ACL names are
709case-sensitive, which means that "www" and "WWW" are two different proxies.
710
711Historically, all proxy names could overlap, it just caused troubles in the
712logs. Since the introduction of content switching, it is mandatory that two
713proxies with overlapping capabilities (frontend/backend) have different names.
714However, it is still permitted that a frontend and a backend share the same
715name, as this configuration seems to be commonly encountered.
716
717Right now, two major proxy modes are supported : "tcp", also known as layer 4,
718and "http", also known as layer 7. In layer 4 mode, HAProxy simply forwards
Krzysztof Piotr Oledzkif8645332009-12-13 21:55:50 +0100719bidirectional traffic between two sides. In layer 7 mode, HAProxy analyzes the
Willy Tarreau0ba27502007-12-24 16:55:16 +0100720protocol, and can interact with it by allowing, blocking, switching, adding,
721modifying, or removing arbitrary contents in requests or responses, based on
722arbitrary criteria.
723
Willy Tarreau0ba27502007-12-24 16:55:16 +0100724
Willy Tarreauc57f0e22009-05-10 13:12:33 +02007254.1. Proxy keywords matrix
726--------------------------
Willy Tarreau0ba27502007-12-24 16:55:16 +0100727
Willy Tarreauc57f0e22009-05-10 13:12:33 +0200728The following list of keywords is supported. Most of them may only be used in a
729limited set of section types. Some of them are marked as "deprecated" because
730they are inherited from an old syntax which may be confusing or functionally
731limited, and there are new recommended keywords to replace them. Keywords
Willy Tarreau3842f002009-06-14 11:39:52 +0200732listed with [no] can be optionally inverted using the "no" prefix, eg. "no
Willy Tarreauc57f0e22009-05-10 13:12:33 +0200733option contstats". This makes sense when the option has been enabled by default
Willy Tarreau3842f002009-06-14 11:39:52 +0200734and must be disabled for a specific instance. Such options may also be prefixed
735with "default" in order to restore default settings regardless of what has been
736specified in a previous "defaults" section.
Willy Tarreau0ba27502007-12-24 16:55:16 +0100737
Willy Tarreau6a06a402007-07-15 20:15:28 +0200738
739keyword defaults frontend listen backend
740----------------------+----------+----------+---------+---------
Willy Tarreaud72758d2010-01-12 10:42:19 +0100741acl - X X X
742appsession - - X X
Willy Tarreauc73ce2b2008-01-06 10:55:10 +0100743backlog X X X -
Willy Tarreaud72758d2010-01-12 10:42:19 +0100744balance X - X X
745bind - X X -
746bind-process X X X X
Willy Tarreau6a06a402007-07-15 20:15:28 +0200747block - X X X
Willy Tarreau0ba27502007-12-24 16:55:16 +0100748capture cookie - X X -
749capture request header - X X -
750capture response header - X X -
Willy Tarreaue219db72007-12-03 01:30:13 +0100751clitimeout X X X - (deprecated)
Willy Tarreau0ba27502007-12-24 16:55:16 +0100752contimeout X - X X (deprecated)
Willy Tarreau6a06a402007-07-15 20:15:28 +0200753cookie X - X X
Krzysztof Piotr Oledzkic53601c2010-01-06 10:50:42 +0100754default-server X - X X
Willy Tarreau6a06a402007-07-15 20:15:28 +0200755default_backend - X X -
Krzysztof Piotr Oledzki48cb2ae2009-10-02 22:51:14 +0200756description - X X X
Willy Tarreau0ba27502007-12-24 16:55:16 +0100757disabled X X X X
Willy Tarreau6a06a402007-07-15 20:15:28 +0200758dispatch - - X X
Willy Tarreau0ba27502007-12-24 16:55:16 +0100759enabled X X X X
Willy Tarreau6a06a402007-07-15 20:15:28 +0200760errorfile X X X X
761errorloc X X X X
762errorloc302 X X X X
763errorloc303 X X X X
764fullconn X - X X
765grace - X X X
Willy Tarreau6b2e11b2009-10-01 07:52:15 +0200766hash-type X - X X
Willy Tarreaudbc36f62007-11-30 12:29:11 +0100767http-check disable-on-404 X - X X
Willy Tarreau53fb4ae2009-10-04 23:04:08 +0200768id - X X X
Willy Tarreau6a06a402007-07-15 20:15:28 +0200769log X X X X
770maxconn X X X -
771mode X X X X
Willy Tarreauc7246fc2007-12-02 17:31:20 +0100772monitor fail - X X -
Willy Tarreau6a06a402007-07-15 20:15:28 +0200773monitor-net X X X -
774monitor-uri X X X -
Krzysztof Oledzki336d4752007-12-25 02:40:22 +0100775[no] option abortonclose X - X X
Willy Tarreau4076a152009-04-02 15:18:36 +0200776[no] option accept-invalid-
777 http-request X X X -
778[no] option accept-invalid-
779 http-response X - X X
Krzysztof Oledzki336d4752007-12-25 02:40:22 +0100780[no] option allbackups X - X X
781[no] option checkcache X - X X
782[no] option clitcpka X X X -
783[no] option contstats X X X -
Willy Tarreauc9bd0cc2009-05-10 11:57:02 +0200784[no] option dontlog-normal X X X -
Krzysztof Oledzki336d4752007-12-25 02:40:22 +0100785[no] option dontlognull X X X -
Willy Tarreaua31e5df2009-12-30 01:10:35 +0100786[no] option forceclose X X X X
Willy Tarreau6a06a402007-07-15 20:15:28 +0200787option forwardfor X X X X
788option httpchk X - X X
Willy Tarreaub608feb2010-01-02 22:47:18 +0100789[no] option http-server-
790 close X X X X
Krzysztof Oledzki336d4752007-12-25 02:40:22 +0100791[no] option httpclose X X X X
Willy Tarreau6a06a402007-07-15 20:15:28 +0200792option httplog X X X X
Willy Tarreau55165fe2009-05-10 12:02:55 +0200793[no] option http_proxy X X X X
Willy Tarreauf27b5ea2009-10-03 22:01:18 +0200794[no] option independant-
795 streams X X X X
Krzysztof Piotr Oledzki213014e2009-09-27 15:50:02 +0200796[no] option log-health- X - X X
797 checks
Willy Tarreau211ad242009-10-03 21:45:07 +0200798[no] option log-separate-
799 errors X X X -
Krzysztof Oledzki336d4752007-12-25 02:40:22 +0100800[no] option logasap X X X -
Hervé COMMOWICK698ae002010-01-12 09:25:13 +0100801option mysql-check X - X X
Krzysztof Oledzki336d4752007-12-25 02:40:22 +0100802[no] option nolinger X X X X
Willy Tarreau55165fe2009-05-10 12:02:55 +0200803option originalto X X X X
Krzysztof Oledzki336d4752007-12-25 02:40:22 +0100804[no] option persist X - X X
805[no] option redispatch X - X X
Willy Tarreau6a06a402007-07-15 20:15:28 +0200806option smtpchk X - X X
Krzysztof Piotr Oledzkiaeebf9b2009-10-04 15:43:17 +0200807[no] option socket-stats X X X -
Willy Tarreauff4f82d2009-02-06 11:28:13 +0100808[no] option splice-auto X X X X
809[no] option splice-request X X X X
810[no] option splice-response X X X X
Krzysztof Oledzki336d4752007-12-25 02:40:22 +0100811[no] option srvtcpka X - X X
Willy Tarreau6a06a402007-07-15 20:15:28 +0200812option ssl-hello-chk X - X X
Willy Tarreau9ea05a72009-06-14 12:07:01 +0200813[no] option tcp-smart-
814 accept X X X -
Willy Tarreau39bb9be2009-10-17 16:04:09 +0200815[no] option tcp-smart-
816 connect X - X X
Willy Tarreau6a06a402007-07-15 20:15:28 +0200817option tcpka X X X X
818option tcplog X X X X
Willy Tarreau4b1f8592008-12-23 23:13:55 +0100819[no] option transparent X - X X
Emeric Brun647caf12009-06-30 17:57:00 +0200820persist rdp-cookie X - X X
Willy Tarreau3a7d2072009-03-05 23:48:25 +0100821rate-limit sessions X X X -
Willy Tarreaub463dfb2008-06-07 23:08:56 +0200822redirect - X X X
Krzysztof Oledzki336d4752007-12-25 02:40:22 +0100823redisp X - X X (deprecated)
824redispatch X - X X (deprecated)
Willy Tarreau6a06a402007-07-15 20:15:28 +0200825reqadd - X X X
826reqallow - X X X
827reqdel - X X X
828reqdeny - X X X
829reqiallow - X X X
830reqidel - X X X
831reqideny - X X X
832reqipass - X X X
833reqirep - X X X
834reqisetbe - X X X
835reqitarpit - X X X
836reqpass - X X X
837reqrep - X X X
838reqsetbe - X X X
839reqtarpit - X X X
840retries X - X X
841rspadd - X X X
842rspdel - X X X
843rspdeny - X X X
844rspidel - X X X
845rspideny - X X X
846rspirep - X X X
847rsprep - X X X
848server - - X X
849source X - X X
Willy Tarreaue219db72007-12-03 01:30:13 +0100850srvtimeout X - X X (deprecated)
Willy Tarreau24e779b2007-07-24 23:43:37 +0200851stats auth X - X X
852stats enable X - X X
853stats realm X - X X
Willy Tarreaubbd42122007-07-25 07:26:38 +0200854stats refresh X - X X
Willy Tarreau24e779b2007-07-24 23:43:37 +0200855stats scope X - X X
856stats uri X - X X
Krzysztof Oledzkid9db9272007-10-15 10:05:11 +0200857stats hide-version X - X X
Willy Tarreau62644772008-07-16 18:36:06 +0200858tcp-request content accept - X X -
859tcp-request content reject - X X -
860tcp-request inspect-delay - X X -
Krzysztof Piotr Oledzki5259dfe2008-01-21 01:54:06 +0100861timeout check X - X X
Willy Tarreaue219db72007-12-03 01:30:13 +0100862timeout client X X X -
863timeout clitimeout X X X - (deprecated)
864timeout connect X - X X
865timeout contimeout X - X X (deprecated)
Willy Tarreaub16a5742010-01-10 14:46:16 +0100866timeout http-keep-alive X X X X
Willy Tarreaucd7afc02009-07-12 10:03:17 +0200867timeout http-request X X X X
Willy Tarreaue219db72007-12-03 01:30:13 +0100868timeout queue X - X X
869timeout server X - X X
870timeout srvtimeout X - X X (deprecated)
Willy Tarreau51c9bde2008-01-06 13:40:03 +0100871timeout tarpit X X X X
Willy Tarreau4b1f8592008-12-23 23:13:55 +0100872transparent X - X X (deprecated)
Willy Tarreau6a06a402007-07-15 20:15:28 +0200873use_backend - X X -
Willy Tarreau6a06a402007-07-15 20:15:28 +0200874----------------------+----------+----------+---------+---------
875keyword defaults frontend listen backend
876
Willy Tarreau0ba27502007-12-24 16:55:16 +0100877
Willy Tarreauc57f0e22009-05-10 13:12:33 +02008784.2. Alphabetically sorted keywords reference
879---------------------------------------------
Willy Tarreau0ba27502007-12-24 16:55:16 +0100880
881This section provides a description of each keyword and its usage.
882
883
884acl <aclname> <criterion> [flags] [operator] <value> ...
885 Declare or complete an access list.
886 May be used in sections : defaults | frontend | listen | backend
887 no | yes | yes | yes
888 Example:
889 acl invalid_src src 0.0.0.0/7 224.0.0.0/3
890 acl invalid_src src_port 0:1023
891 acl local_dst hdr(host) -i localhost
892
Willy Tarreauc57f0e22009-05-10 13:12:33 +0200893 See section 7 about ACL usage.
Willy Tarreau0ba27502007-12-24 16:55:16 +0100894
895
Cyril Bontéb21570a2009-11-29 20:04:48 +0100896appsession <cookie> len <length> timeout <holdtime>
897 [request-learn] [prefix] [mode <path-parameters|query-string>]
Willy Tarreau0ba27502007-12-24 16:55:16 +0100898 Define session stickiness on an existing application cookie.
899 May be used in sections : defaults | frontend | listen | backend
900 no | no | yes | yes
901 Arguments :
902 <cookie> this is the name of the cookie used by the application and which
903 HAProxy will have to learn for each new session.
904
Cyril Bontéb21570a2009-11-29 20:04:48 +0100905 <length> this is the max number of characters that will be memorized and
Willy Tarreau0ba27502007-12-24 16:55:16 +0100906 checked in each cookie value.
907
908 <holdtime> this is the time after which the cookie will be removed from
909 memory if unused. If no unit is specified, this time is in
910 milliseconds.
911
Cyril Bontébf47aeb2009-10-15 00:15:40 +0200912 request-learn
913 If this option is specified, then haproxy will be able to learn
914 the cookie found in the request in case the server does not
915 specify any in response. This is typically what happens with
916 PHPSESSID cookies, or when haproxy's session expires before
917 the application's session and the correct server is selected.
918 It is recommended to specify this option to improve reliability.
919
Cyril Bontéb21570a2009-11-29 20:04:48 +0100920 prefix When this option is specified, haproxy will match on the cookie
921 prefix (or URL parameter prefix). The appsession value is the
922 data following this prefix.
923
924 Example :
925 appsession ASPSESSIONID len 64 timeout 3h prefix
926
927 This will match the cookie ASPSESSIONIDXXXX=XXXXX,
928 the appsession value will be XXXX=XXXXX.
929
930 mode This option allows to change the URL parser mode.
931 2 modes are currently supported :
932 - path-parameters :
933 The parser looks for the appsession in the path parameters
934 part (each parameter is separated by a semi-colon), which is
935 convenient for JSESSIONID for example.
936 This is the default mode if the option is not set.
937 - query-string :
938 In this mode, the parser will look for the appsession in the
939 query string.
940
Willy Tarreau0ba27502007-12-24 16:55:16 +0100941 When an application cookie is defined in a backend, HAProxy will check when
942 the server sets such a cookie, and will store its value in a table, and
943 associate it with the server's identifier. Up to <length> characters from
944 the value will be retained. On each connection, haproxy will look for this
Cyril Bontéb21570a2009-11-29 20:04:48 +0100945 cookie both in the "Cookie:" headers, and as a URL parameter (depending on
946 the mode used). If a known value is found, the client will be directed to the
947 server associated with this value. Otherwise, the load balancing algorithm is
Willy Tarreau0ba27502007-12-24 16:55:16 +0100948 applied. Cookies are automatically removed from memory when they have been
949 unused for a duration longer than <holdtime>.
950
951 The definition of an application cookie is limited to one per backend.
952
953 Example :
954 appsession JSESSIONID len 52 timeout 3h
955
Willy Tarreaub937b7e2010-01-12 15:27:54 +0100956 See also : "cookie", "capture cookie", "balance", "stick" and "stick-table".
Willy Tarreau0ba27502007-12-24 16:55:16 +0100957
958
Willy Tarreauc73ce2b2008-01-06 10:55:10 +0100959backlog <conns>
960 Give hints to the system about the approximate listen backlog desired size
961 May be used in sections : defaults | frontend | listen | backend
962 yes | yes | yes | no
963 Arguments :
964 <conns> is the number of pending connections. Depending on the operating
965 system, it may represent the number of already acknowledged
966 connections, of non-acknowledged ones, or both.
967
968 In order to protect against SYN flood attacks, one solution is to increase
969 the system's SYN backlog size. Depending on the system, sometimes it is just
970 tunable via a system parameter, sometimes it is not adjustable at all, and
971 sometimes the system relies on hints given by the application at the time of
972 the listen() syscall. By default, HAProxy passes the frontend's maxconn value
973 to the listen() syscall. On systems which can make use of this value, it can
974 sometimes be useful to be able to specify a different value, hence this
975 backlog parameter.
976
977 On Linux 2.4, the parameter is ignored by the system. On Linux 2.6, it is
978 used as a hint and the system accepts up to the smallest greater power of
979 two, and never more than some limits (usually 32768).
980
981 See also : "maxconn" and the target operating system's tuning guide.
982
983
Willy Tarreau0ba27502007-12-24 16:55:16 +0100984balance <algorithm> [ <arguments> ]
matt.farnsworth@nokia.com1c2ab962008-04-14 20:47:37 +0200985balance url_param <param> [check_post [<max_wait>]]
Willy Tarreau0ba27502007-12-24 16:55:16 +0100986 Define the load balancing algorithm to be used in a backend.
987 May be used in sections : defaults | frontend | listen | backend
988 yes | no | yes | yes
989 Arguments :
990 <algorithm> is the algorithm used to select a server when doing load
991 balancing. This only applies when no persistence information
992 is available, or when a connection is redispatched to another
993 server. <algorithm> may be one of the following :
994
995 roundrobin Each server is used in turns, according to their weights.
996 This is the smoothest and fairest algorithm when the server's
997 processing time remains equally distributed. This algorithm
998 is dynamic, which means that server weights may be adjusted
Willy Tarreau9757a382009-10-03 12:56:50 +0200999 on the fly for slow starts for instance. It is limited by
1000 design to 4128 active servers per backend. Note that in some
1001 large farms, when a server becomes up after having been down
1002 for a very short time, it may sometimes take a few hundreds
1003 requests for it to be re-integrated into the farm and start
1004 receiving traffic. This is normal, though very rare. It is
1005 indicated here in case you would have the chance to observe
1006 it, so that you don't worry.
1007
1008 static-rr Each server is used in turns, according to their weights.
1009 This algorithm is as similar to roundrobin except that it is
1010 static, which means that changing a server's weight on the
1011 fly will have no effect. On the other hand, it has no design
1012 limitation on the number of servers, and when a server goes
1013 up, it is always immediately reintroduced into the farm, once
1014 the full map is recomputed. It also uses slightly less CPU to
1015 run (around -1%).
Willy Tarreau0ba27502007-12-24 16:55:16 +01001016
Willy Tarreau2d2a7f82008-03-17 12:07:56 +01001017 leastconn The server with the lowest number of connections receives the
1018 connection. Round-robin is performed within groups of servers
1019 of the same load to ensure that all servers will be used. Use
1020 of this algorithm is recommended where very long sessions are
1021 expected, such as LDAP, SQL, TSE, etc... but is not very well
1022 suited for protocols using short sessions such as HTTP. This
1023 algorithm is dynamic, which means that server weights may be
1024 adjusted on the fly for slow starts for instance.
1025
Willy Tarreau0ba27502007-12-24 16:55:16 +01001026 source The source IP address is hashed and divided by the total
1027 weight of the running servers to designate which server will
1028 receive the request. This ensures that the same client IP
1029 address will always reach the same server as long as no
1030 server goes down or up. If the hash result changes due to the
1031 number of running servers changing, many clients will be
1032 directed to a different server. This algorithm is generally
1033 used in TCP mode where no cookie may be inserted. It may also
Krzysztof Piotr Oledzkif8645332009-12-13 21:55:50 +01001034 be used on the Internet to provide a best-effort stickiness
Willy Tarreau0ba27502007-12-24 16:55:16 +01001035 to clients which refuse session cookies. This algorithm is
Willy Tarreau6b2e11b2009-10-01 07:52:15 +02001036 static by default, which means that changing a server's
1037 weight on the fly will have no effect, but this can be
1038 changed using "hash-type".
Willy Tarreau0ba27502007-12-24 16:55:16 +01001039
1040 uri The left part of the URI (before the question mark) is hashed
1041 and divided by the total weight of the running servers. The
1042 result designates which server will receive the request. This
1043 ensures that a same URI will always be directed to the same
1044 server as long as no server goes up or down. This is used
1045 with proxy caches and anti-virus proxies in order to maximize
1046 the cache hit rate. Note that this algorithm may only be used
Willy Tarreau6b2e11b2009-10-01 07:52:15 +02001047 in an HTTP backend. This algorithm is static by default,
1048 which means that changing a server's weight on the fly will
1049 have no effect, but this can be changed using "hash-type".
Willy Tarreau0ba27502007-12-24 16:55:16 +01001050
Marek Majkowski9c30fc12008-04-27 23:25:55 +02001051 This algorithm support two optional parameters "len" and
1052 "depth", both followed by a positive integer number. These
1053 options may be helpful when it is needed to balance servers
1054 based on the beginning of the URI only. The "len" parameter
1055 indicates that the algorithm should only consider that many
1056 characters at the beginning of the URI to compute the hash.
1057 Note that having "len" set to 1 rarely makes sense since most
1058 URIs start with a leading "/".
1059
1060 The "depth" parameter indicates the maximum directory depth
1061 to be used to compute the hash. One level is counted for each
1062 slash in the request. If both parameters are specified, the
1063 evaluation stops when either is reached.
1064
Willy Tarreau0ba27502007-12-24 16:55:16 +01001065 url_param The URL parameter specified in argument will be looked up in
matt.farnsworth@nokia.com1c2ab962008-04-14 20:47:37 +02001066 the query string of each HTTP GET request.
1067
1068 If the modifier "check_post" is used, then an HTTP POST
1069 request entity will be searched for the parameter argument,
1070 when the question mark indicating a query string ('?') is not
1071 present in the URL. Optionally, specify a number of octets to
1072 wait for before attempting to search the message body. If the
1073 entity can not be searched, then round robin is used for each
1074 request. For instance, if your clients always send the LB
1075 parameter in the first 128 bytes, then specify that. The
1076 default is 48. The entity data will not be scanned until the
1077 required number of octets have arrived at the gateway, this
1078 is the minimum of: (default/max_wait, Content-Length or first
1079 chunk length). If Content-Length is missing or zero, it does
1080 not need to wait for more data than the client promised to
1081 send. When Content-Length is present and larger than
1082 <max_wait>, then waiting is limited to <max_wait> and it is
1083 assumed that this will be enough data to search for the
1084 presence of the parameter. In the unlikely event that
1085 Transfer-Encoding: chunked is used, only the first chunk is
1086 scanned. Parameter values separated by a chunk boundary, may
1087 be randomly balanced if at all.
1088
1089 If the parameter is found followed by an equal sign ('=') and
1090 a value, then the value is hashed and divided by the total
1091 weight of the running servers. The result designates which
1092 server will receive the request.
1093
1094 This is used to track user identifiers in requests and ensure
1095 that a same user ID will always be sent to the same server as
1096 long as no server goes up or down. If no value is found or if
1097 the parameter is not found, then a round robin algorithm is
1098 applied. Note that this algorithm may only be used in an HTTP
Willy Tarreau6b2e11b2009-10-01 07:52:15 +02001099 backend. This algorithm is static by default, which means
1100 that changing a server's weight on the fly will have no
1101 effect, but this can be changed using "hash-type".
Willy Tarreau0ba27502007-12-24 16:55:16 +01001102
Benoitaffb4812009-03-25 13:02:10 +01001103 hdr(name) The HTTP header <name> will be looked up in each HTTP request.
1104 Just as with the equivalent ACL 'hdr()' function, the header
1105 name in parenthesis is not case sensitive. If the header is
Krzysztof Piotr Oledzkif8645332009-12-13 21:55:50 +01001106 absent or if it does not contain any value, the roundrobin
Benoitaffb4812009-03-25 13:02:10 +01001107 algorithm is applied instead.
1108
Krzysztof Piotr Oledzkif8645332009-12-13 21:55:50 +01001109 An optional 'use_domain_only' parameter is available, for
Benoitaffb4812009-03-25 13:02:10 +01001110 reducing the hash algorithm to the main domain part with some
1111 specific headers such as 'Host'. For instance, in the Host
1112 value "haproxy.1wt.eu", only "1wt" will be considered.
1113
Willy Tarreau6b2e11b2009-10-01 07:52:15 +02001114 This algorithm is static by default, which means that
1115 changing a server's weight on the fly will have no effect,
1116 but this can be changed using "hash-type".
1117
Emeric Brun736aa232009-06-30 17:56:00 +02001118 rdp-cookie
1119 rdp-cookie(name)
1120 The RDP cookie <name> (or "mstshash" if omitted) will be
1121 looked up and hashed for each incoming TCP request. Just as
1122 with the equivalent ACL 'req_rdp_cookie()' function, the name
1123 is not case-sensitive. This mechanism is useful as a degraded
1124 persistence mode, as it makes it possible to always send the
1125 same user (or the same session ID) to the same server. If the
Krzysztof Piotr Oledzkif8645332009-12-13 21:55:50 +01001126 cookie is not found, the normal roundrobin algorithm is
Emeric Brun736aa232009-06-30 17:56:00 +02001127 used instead.
1128
1129 Note that for this to work, the frontend must ensure that an
1130 RDP cookie is already present in the request buffer. For this
1131 you must use 'tcp-request content accept' rule combined with
1132 a 'req_rdp_cookie_cnt' ACL.
1133
Willy Tarreau6b2e11b2009-10-01 07:52:15 +02001134 This algorithm is static by default, which means that
1135 changing a server's weight on the fly will have no effect,
1136 but this can be changed using "hash-type".
1137
Willy Tarreau0ba27502007-12-24 16:55:16 +01001138 <arguments> is an optional list of arguments which may be needed by some
Marek Majkowski9c30fc12008-04-27 23:25:55 +02001139 algorithms. Right now, only "url_param" and "uri" support an
1140 optional argument.
matt.farnsworth@nokia.com1c2ab962008-04-14 20:47:37 +02001141
Marek Majkowski9c30fc12008-04-27 23:25:55 +02001142 balance uri [len <len>] [depth <depth>]
matt.farnsworth@nokia.com1c2ab962008-04-14 20:47:37 +02001143 balance url_param <param> [check_post [<max_wait>]]
Willy Tarreau0ba27502007-12-24 16:55:16 +01001144
Willy Tarreau3cd9af22009-03-15 14:06:41 +01001145 The load balancing algorithm of a backend is set to roundrobin when no other
1146 algorithm, mode nor option have been set. The algorithm may only be set once
1147 for each backend.
Willy Tarreau0ba27502007-12-24 16:55:16 +01001148
1149 Examples :
1150 balance roundrobin
1151 balance url_param userid
matt.farnsworth@nokia.com1c2ab962008-04-14 20:47:37 +02001152 balance url_param session_id check_post 64
Benoitaffb4812009-03-25 13:02:10 +01001153 balance hdr(User-Agent)
1154 balance hdr(host)
1155 balance hdr(Host) use_domain_only
matt.farnsworth@nokia.com1c2ab962008-04-14 20:47:37 +02001156
1157 Note: the following caveats and limitations on using the "check_post"
1158 extension with "url_param" must be considered :
1159
Krzysztof Piotr Oledzkif8645332009-12-13 21:55:50 +01001160 - all POST requests are eligible for consideration, because there is no way
matt.farnsworth@nokia.com1c2ab962008-04-14 20:47:37 +02001161 to determine if the parameters will be found in the body or entity which
1162 may contain binary data. Therefore another method may be required to
1163 restrict consideration of POST requests that have no URL parameters in
1164 the body. (see acl reqideny http_end)
1165
1166 - using a <max_wait> value larger than the request buffer size does not
1167 make sense and is useless. The buffer size is set at build time, and
1168 defaults to 16 kB.
1169
1170 - Content-Encoding is not supported, the parameter search will probably
1171 fail; and load balancing will fall back to Round Robin.
1172
1173 - Expect: 100-continue is not supported, load balancing will fall back to
1174 Round Robin.
1175
1176 - Transfer-Encoding (RFC2616 3.6.1) is only supported in the first chunk.
1177 If the entire parameter value is not present in the first chunk, the
1178 selection of server is undefined (actually, defined by how little
1179 actually appeared in the first chunk).
1180
1181 - This feature does not support generation of a 100, 411 or 501 response.
1182
1183 - In some cases, requesting "check_post" MAY attempt to scan the entire
Krzysztof Piotr Oledzkif8645332009-12-13 21:55:50 +01001184 contents of a message body. Scanning normally terminates when linear
matt.farnsworth@nokia.com1c2ab962008-04-14 20:47:37 +02001185 white space or control characters are found, indicating the end of what
1186 might be a URL parameter list. This is probably not a concern with SGML
1187 type message bodies.
Willy Tarreau0ba27502007-12-24 16:55:16 +01001188
Willy Tarreau6b2e11b2009-10-01 07:52:15 +02001189 See also : "dispatch", "cookie", "appsession", "transparent", "hash-type" and
1190 "http_proxy".
Willy Tarreau0ba27502007-12-24 16:55:16 +01001191
1192
1193bind [<address>]:<port> [, ...]
Willy Tarreau5e6e2042009-02-04 17:19:29 +01001194bind [<address>]:<port> [, ...] interface <interface>
Willy Tarreaube1b9182009-06-14 18:48:19 +02001195bind [<address>]:<port> [, ...] mss <maxseg>
Willy Tarreaub1e52e82008-01-13 14:49:51 +01001196bind [<address>]:<port> [, ...] transparent
Krzysztof Piotr Oledzkiaeebf9b2009-10-04 15:43:17 +02001197bind [<address>]:<port> [, ...] id <id>
1198bind [<address>]:<port> [, ...] name <name>
Willy Tarreau53319c92009-11-28 08:21:29 +01001199bind [<address>]:<port> [, ...] defer-accept
Willy Tarreau0ba27502007-12-24 16:55:16 +01001200 Define one or several listening addresses and/or ports in a frontend.
1201 May be used in sections : defaults | frontend | listen | backend
1202 no | yes | yes | no
1203 Arguments :
Willy Tarreaub1e52e82008-01-13 14:49:51 +01001204 <address> is optional and can be a host name, an IPv4 address, an IPv6
1205 address, or '*'. It designates the address the frontend will
1206 listen on. If unset, all IPv4 addresses of the system will be
1207 listened on. The same will apply for '*' or the system's
1208 special address "0.0.0.0".
1209
1210 <port> is the TCP port number the proxy will listen on. The port is
1211 mandatory. Note that in the case of an IPv6 address, the port
1212 is always the number after the last colon (':').
Willy Tarreau0ba27502007-12-24 16:55:16 +01001213
Willy Tarreau5e6e2042009-02-04 17:19:29 +01001214 <interface> is an optional physical interface name. This is currently
1215 only supported on Linux. The interface must be a physical
1216 interface, not an aliased interface. When specified, all
1217 addresses on the same line will only be accepted if the
1218 incoming packet physically come through the designated
1219 interface. It is also possible to bind multiple frontends to
1220 the same address if they are bound to different interfaces.
1221 Note that binding to a physical interface requires root
1222 privileges.
1223
Willy Tarreaube1b9182009-06-14 18:48:19 +02001224 <maxseg> is an optional TCP Maximum Segment Size (MSS) value to be
1225 advertised on incoming connections. This can be used to force
1226 a lower MSS for certain specific ports, for instance for
1227 connections passing through a VPN. Note that this relies on a
1228 kernel feature which is theorically supported under Linux but
1229 was buggy in all versions prior to 2.6.28. It may or may not
1230 work on other operating systems. The commonly advertised
1231 value on Ethernet networks is 1460 = 1500(MTU) - 40(IP+TCP).
1232
Willy Tarreau53fb4ae2009-10-04 23:04:08 +02001233 <id> is a persistent value for socket ID. Must be positive and
1234 unique in the proxy. An unused value will automatically be
1235 assigned if unset. Can only be used when defining only a
1236 single socket.
Krzysztof Piotr Oledzkiaeebf9b2009-10-04 15:43:17 +02001237
1238 <name> is an optional name provided for stats
1239
Willy Tarreaub1e52e82008-01-13 14:49:51 +01001240 transparent is an optional keyword which is supported only on certain
1241 Linux kernels. It indicates that the addresses will be bound
1242 even if they do not belong to the local machine. Any packet
Krzysztof Piotr Oledzkif8645332009-12-13 21:55:50 +01001243 targeting any of these addresses will be caught just as if
Willy Tarreaub1e52e82008-01-13 14:49:51 +01001244 the address was locally configured. This normally requires
1245 that IP forwarding is enabled. Caution! do not use this with
1246 the default address '*', as it would redirect any traffic for
1247 the specified port. This keyword is available only when
1248 HAProxy is built with USE_LINUX_TPROXY=1.
Willy Tarreau0ba27502007-12-24 16:55:16 +01001249
Willy Tarreaucb6cd432009-10-13 07:34:14 +02001250 defer_accept is an optional keyword which is supported only on certain
1251 Linux kernels. It states that a connection will only be
1252 accepted once some data arrive on it, or at worst after the
1253 first retransmit. This should be used only on protocols for
1254 which the client talks first (eg: HTTP). It can slightly
1255 improve performance by ensuring that most of the request is
1256 already available when the connection is accepted. On the
1257 other hand, it will not be able to detect connections which
1258 don't talk. It is important to note that this option is
1259 broken in all kernels up to 2.6.31, as the connection is
1260 never accepted until the client talks. This can cause issues
1261 with front firewalls which would see an established
1262 connection while the proxy will only see it in SYN_RECV.
1263
Willy Tarreau0ba27502007-12-24 16:55:16 +01001264 It is possible to specify a list of address:port combinations delimited by
1265 commas. The frontend will then listen on all of these addresses. There is no
1266 fixed limit to the number of addresses and ports which can be listened on in
1267 a frontend, as well as there is no limit to the number of "bind" statements
1268 in a frontend.
1269
1270 Example :
1271 listen http_proxy
1272 bind :80,:443
1273 bind 10.0.0.1:10080,10.0.0.1:10443
1274
1275 See also : "source".
1276
1277
Willy Tarreau0b9c02c2009-02-04 22:05:05 +01001278bind-process [ all | odd | even | <number 1-32> ] ...
1279 Limit visibility of an instance to a certain set of processes numbers.
1280 May be used in sections : defaults | frontend | listen | backend
1281 yes | yes | yes | yes
1282 Arguments :
1283 all All process will see this instance. This is the default. It
1284 may be used to override a default value.
1285
1286 odd This instance will be enabled on processes 1,3,5,...31. This
1287 option may be combined with other numbers.
1288
1289 even This instance will be enabled on processes 2,4,6,...32. This
1290 option may be combined with other numbers. Do not use it
1291 with less than 2 processes otherwise some instances might be
1292 missing from all processes.
1293
1294 number The instance will be enabled on this process number, between
1295 1 and 32. You must be careful not to reference a process
1296 number greater than the configured global.nbproc, otherwise
1297 some instances might be missing from all processes.
1298
1299 This keyword limits binding of certain instances to certain processes. This
1300 is useful in order not to have too many processes listening to the same
1301 ports. For instance, on a dual-core machine, it might make sense to set
1302 'nbproc 2' in the global section, then distributes the listeners among 'odd'
1303 and 'even' instances.
1304
1305 At the moment, it is not possible to reference more than 32 processes using
1306 this keyword, but this should be more than enough for most setups. Please
1307 note that 'all' really means all processes and is not limited to the first
1308 32.
1309
1310 If some backends are referenced by frontends bound to other processes, the
1311 backend automatically inherits the frontend's processes.
1312
1313 Example :
1314 listen app_ip1
1315 bind 10.0.0.1:80
1316 bind_process odd
1317
1318 listen app_ip2
1319 bind 10.0.0.2:80
1320 bind_process even
1321
1322 listen management
1323 bind 10.0.0.3:80
1324 bind_process 1 2 3 4
1325
1326 See also : "nbproc" in global section.
1327
1328
Willy Tarreau0ba27502007-12-24 16:55:16 +01001329block { if | unless } <condition>
1330 Block a layer 7 request if/unless a condition is matched
1331 May be used in sections : defaults | frontend | listen | backend
1332 no | yes | yes | yes
1333
1334 The HTTP request will be blocked very early in the layer 7 processing
1335 if/unless <condition> is matched. A 403 error will be returned if the request
Willy Tarreauc57f0e22009-05-10 13:12:33 +02001336 is blocked. The condition has to reference ACLs (see section 7). This is
Willy Tarreau0ba27502007-12-24 16:55:16 +01001337 typically used to deny access to certain sensible resources if some
1338 conditions are met or not met. There is no fixed limit to the number of
1339 "block" statements per instance.
1340
1341 Example:
1342 acl invalid_src src 0.0.0.0/7 224.0.0.0/3
1343 acl invalid_src src_port 0:1023
1344 acl local_dst hdr(host) -i localhost
1345 block if invalid_src || local_dst
1346
Willy Tarreauc57f0e22009-05-10 13:12:33 +02001347 See section 7 about ACL usage.
Willy Tarreau0ba27502007-12-24 16:55:16 +01001348
1349
1350capture cookie <name> len <length>
1351 Capture and log a cookie in the request and in the response.
1352 May be used in sections : defaults | frontend | listen | backend
1353 no | yes | yes | no
1354 Arguments :
1355 <name> is the beginning of the name of the cookie to capture. In order
1356 to match the exact name, simply suffix the name with an equal
1357 sign ('='). The full name will appear in the logs, which is
1358 useful with application servers which adjust both the cookie name
1359 and value (eg: ASPSESSIONXXXXX).
1360
1361 <length> is the maximum number of characters to report in the logs, which
1362 include the cookie name, the equal sign and the value, all in the
1363 standard "name=value" form. The string will be truncated on the
1364 right if it exceeds <length>.
1365
1366 Only the first cookie is captured. Both the "cookie" request headers and the
1367 "set-cookie" response headers are monitored. This is particularly useful to
1368 check for application bugs causing session crossing or stealing between
1369 users, because generally the user's cookies can only change on a login page.
1370
1371 When the cookie was not presented by the client, the associated log column
1372 will report "-". When a request does not cause a cookie to be assigned by the
1373 server, a "-" is reported in the response column.
1374
1375 The capture is performed in the frontend only because it is necessary that
1376 the log format does not change for a given frontend depending on the
1377 backends. This may change in the future. Note that there can be only one
1378 "capture cookie" statement in a frontend. The maximum capture length is
Krzysztof Piotr Oledzkif8645332009-12-13 21:55:50 +01001379 configured in the sources by default to 64 characters. It is not possible to
Willy Tarreau0ba27502007-12-24 16:55:16 +01001380 specify a capture in a "defaults" section.
1381
1382 Example:
1383 capture cookie ASPSESSION len 32
1384
1385 See also : "capture request header", "capture response header" as well as
Willy Tarreauc57f0e22009-05-10 13:12:33 +02001386 section 8 about logging.
Willy Tarreau0ba27502007-12-24 16:55:16 +01001387
1388
1389capture request header <name> len <length>
1390 Capture and log the first occurrence of the specified request header.
1391 May be used in sections : defaults | frontend | listen | backend
1392 no | yes | yes | no
1393 Arguments :
1394 <name> is the name of the header to capture. The header names are not
Willy Tarreaud2a4aa22008-01-31 15:28:22 +01001395 case-sensitive, but it is a common practice to write them as they
Willy Tarreau0ba27502007-12-24 16:55:16 +01001396 appear in the requests, with the first letter of each word in
1397 upper case. The header name will not appear in the logs, only the
1398 value is reported, but the position in the logs is respected.
1399
1400 <length> is the maximum number of characters to extract from the value and
1401 report in the logs. The string will be truncated on the right if
1402 it exceeds <length>.
1403
Willy Tarreaucc6c8912009-02-22 10:53:55 +01001404 Only the first value of the last occurrence of the header is captured. The
Willy Tarreau0ba27502007-12-24 16:55:16 +01001405 value will be added to the logs between braces ('{}'). If multiple headers
1406 are captured, they will be delimited by a vertical bar ('|') and will appear
Willy Tarreaucc6c8912009-02-22 10:53:55 +01001407 in the same order they were declared in the configuration. Non-existent
1408 headers will be logged just as an empty string. Common uses for request
1409 header captures include the "Host" field in virtual hosting environments, the
1410 "Content-length" when uploads are supported, "User-agent" to quickly
Krzysztof Piotr Oledzkif8645332009-12-13 21:55:50 +01001411 differentiate between real users and robots, and "X-Forwarded-For" in proxied
Willy Tarreaucc6c8912009-02-22 10:53:55 +01001412 environments to find where the request came from.
1413
1414 Note that when capturing headers such as "User-agent", some spaces may be
1415 logged, making the log analysis more difficult. Thus be careful about what
1416 you log if you know your log parser is not smart enough to rely on the
1417 braces.
Willy Tarreau0ba27502007-12-24 16:55:16 +01001418
1419 There is no limit to the number of captured request headers, but each capture
1420 is limited to 64 characters. In order to keep log format consistent for a
1421 same frontend, header captures can only be declared in a frontend. It is not
1422 possible to specify a capture in a "defaults" section.
1423
1424 Example:
1425 capture request header Host len 15
1426 capture request header X-Forwarded-For len 15
1427 capture request header Referrer len 15
1428
Willy Tarreauc57f0e22009-05-10 13:12:33 +02001429 See also : "capture cookie", "capture response header" as well as section 8
Willy Tarreau0ba27502007-12-24 16:55:16 +01001430 about logging.
1431
1432
1433capture response header <name> len <length>
1434 Capture and log the first occurrence of the specified response header.
1435 May be used in sections : defaults | frontend | listen | backend
1436 no | yes | yes | no
1437 Arguments :
1438 <name> is the name of the header to capture. The header names are not
Willy Tarreaud2a4aa22008-01-31 15:28:22 +01001439 case-sensitive, but it is a common practice to write them as they
Willy Tarreau0ba27502007-12-24 16:55:16 +01001440 appear in the response, with the first letter of each word in
1441 upper case. The header name will not appear in the logs, only the
1442 value is reported, but the position in the logs is respected.
1443
1444 <length> is the maximum number of characters to extract from the value and
1445 report in the logs. The string will be truncated on the right if
1446 it exceeds <length>.
1447
Willy Tarreaucc6c8912009-02-22 10:53:55 +01001448 Only the first value of the last occurrence of the header is captured. The
Willy Tarreau0ba27502007-12-24 16:55:16 +01001449 result will be added to the logs between braces ('{}') after the captured
1450 request headers. If multiple headers are captured, they will be delimited by
1451 a vertical bar ('|') and will appear in the same order they were declared in
Willy Tarreaucc6c8912009-02-22 10:53:55 +01001452 the configuration. Non-existent headers will be logged just as an empty
1453 string. Common uses for response header captures include the "Content-length"
1454 header which indicates how many bytes are expected to be returned, the
1455 "Location" header to track redirections.
Willy Tarreau0ba27502007-12-24 16:55:16 +01001456
1457 There is no limit to the number of captured response headers, but each
1458 capture is limited to 64 characters. In order to keep log format consistent
1459 for a same frontend, header captures can only be declared in a frontend. It
1460 is not possible to specify a capture in a "defaults" section.
1461
1462 Example:
1463 capture response header Content-length len 9
1464 capture response header Location len 15
1465
Willy Tarreauc57f0e22009-05-10 13:12:33 +02001466 See also : "capture cookie", "capture request header" as well as section 8
Willy Tarreau0ba27502007-12-24 16:55:16 +01001467 about logging.
1468
1469
1470clitimeout <timeout>
1471 Set the maximum inactivity time on the client side.
1472 May be used in sections : defaults | frontend | listen | backend
1473 yes | yes | yes | no
1474 Arguments :
1475 <timeout> is the timeout value is specified in milliseconds by default, but
1476 can be in any other unit if the number is suffixed by the unit,
1477 as explained at the top of this document.
1478
1479 The inactivity timeout applies when the client is expected to acknowledge or
1480 send data. In HTTP mode, this timeout is particularly important to consider
1481 during the first phase, when the client sends the request, and during the
1482 response while it is reading data sent by the server. The value is specified
1483 in milliseconds by default, but can be in any other unit if the number is
1484 suffixed by the unit, as specified at the top of this document. In TCP mode
1485 (and to a lesser extent, in HTTP mode), it is highly recommended that the
1486 client timeout remains equal to the server timeout in order to avoid complex
Willy Tarreaud2a4aa22008-01-31 15:28:22 +01001487 situations to debug. It is a good practice to cover one or several TCP packet
Willy Tarreau0ba27502007-12-24 16:55:16 +01001488 losses by specifying timeouts that are slightly above multiples of 3 seconds
1489 (eg: 4 or 5 seconds).
1490
1491 This parameter is specific to frontends, but can be specified once for all in
1492 "defaults" sections. This is in fact one of the easiest solutions not to
1493 forget about it. An unspecified timeout results in an infinite timeout, which
1494 is not recommended. Such a usage is accepted and works but reports a warning
1495 during startup because it may results in accumulation of expired sessions in
1496 the system if the system's timeouts are not configured either.
1497
1498 This parameter is provided for compatibility but is currently deprecated.
1499 Please use "timeout client" instead.
1500
Willy Tarreau036fae02008-01-06 13:24:40 +01001501 See also : "timeout client", "timeout http-request", "timeout server", and
1502 "srvtimeout".
Willy Tarreau0ba27502007-12-24 16:55:16 +01001503
1504
1505contimeout <timeout>
1506 Set the maximum time to wait for a connection attempt to a server to succeed.
1507 May be used in sections : defaults | frontend | listen | backend
1508 yes | no | yes | yes
1509 Arguments :
1510 <timeout> is the timeout value is specified in milliseconds by default, but
1511 can be in any other unit if the number is suffixed by the unit,
1512 as explained at the top of this document.
1513
1514 If the server is located on the same LAN as haproxy, the connection should be
Willy Tarreaud2a4aa22008-01-31 15:28:22 +01001515 immediate (less than a few milliseconds). Anyway, it is a good practice to
Willy Tarreaud72758d2010-01-12 10:42:19 +01001516 cover one or several TCP packet losses by specifying timeouts that are
Willy Tarreau0ba27502007-12-24 16:55:16 +01001517 slightly above multiples of 3 seconds (eg: 4 or 5 seconds). By default, the
1518 connect timeout also presets the queue timeout to the same value if this one
1519 has not been specified. Historically, the contimeout was also used to set the
1520 tarpit timeout in a listen section, which is not possible in a pure frontend.
1521
1522 This parameter is specific to backends, but can be specified once for all in
1523 "defaults" sections. This is in fact one of the easiest solutions not to
1524 forget about it. An unspecified timeout results in an infinite timeout, which
1525 is not recommended. Such a usage is accepted and works but reports a warning
1526 during startup because it may results in accumulation of failed sessions in
1527 the system if the system's timeouts are not configured either.
1528
1529 This parameter is provided for backwards compatibility but is currently
1530 deprecated. Please use "timeout connect", "timeout queue" or "timeout tarpit"
1531 instead.
1532
1533 See also : "timeout connect", "timeout queue", "timeout tarpit",
1534 "timeout server", "contimeout".
1535
1536
Willy Tarreau55165fe2009-05-10 12:02:55 +02001537cookie <name> [ rewrite | insert | prefix ] [ indirect ] [ nocache ]
Willy Tarreau68a897b2009-12-03 23:28:34 +01001538 [ postonly ] [ domain <domain> ]*
Willy Tarreau0ba27502007-12-24 16:55:16 +01001539 Enable cookie-based persistence in a backend.
1540 May be used in sections : defaults | frontend | listen | backend
1541 yes | no | yes | yes
1542 Arguments :
1543 <name> is the name of the cookie which will be monitored, modified or
1544 inserted in order to bring persistence. This cookie is sent to
1545 the client via a "Set-Cookie" header in the response, and is
1546 brought back by the client in a "Cookie" header in all requests.
1547 Special care should be taken to choose a name which does not
1548 conflict with any likely application cookie. Also, if the same
1549 backends are subject to be used by the same clients (eg:
1550 HTTP/HTTPS), care should be taken to use different cookie names
1551 between all backends if persistence between them is not desired.
1552
1553 rewrite This keyword indicates that the cookie will be provided by the
1554 server and that haproxy will have to modify its value to set the
1555 server's identifier in it. This mode is handy when the management
1556 of complex combinations of "Set-cookie" and "Cache-control"
1557 headers is left to the application. The application can then
1558 decide whether or not it is appropriate to emit a persistence
1559 cookie. Since all responses should be monitored, this mode only
1560 works in HTTP close mode. Unless the application behaviour is
1561 very complex and/or broken, it is advised not to start with this
1562 mode for new deployments. This keyword is incompatible with
1563 "insert" and "prefix".
1564
1565 insert This keyword indicates that the persistence cookie will have to
1566 be inserted by haproxy in the responses. If the server emits a
1567 cookie with the same name, it will be replaced anyway. For this
1568 reason, this mode can be used to upgrade existing configurations
1569 running in the "rewrite" mode. The cookie will only be a session
1570 cookie and will not be stored on the client's disk. Due to
1571 caching effects, it is generally wise to add the "indirect" and
1572 "nocache" or "postonly" keywords (see below). The "insert"
1573 keyword is not compatible with "rewrite" and "prefix".
1574
1575 prefix This keyword indicates that instead of relying on a dedicated
1576 cookie for the persistence, an existing one will be completed.
1577 This may be needed in some specific environments where the client
1578 does not support more than one single cookie and the application
1579 already needs it. In this case, whenever the server sets a cookie
1580 named <name>, it will be prefixed with the server's identifier
1581 and a delimiter. The prefix will be removed from all client
1582 requests so that the server still finds the cookie it emitted.
1583 Since all requests and responses are subject to being modified,
1584 this mode requires the HTTP close mode. The "prefix" keyword is
1585 not compatible with "rewrite" and "insert".
1586
1587 indirect When this option is specified in insert mode, cookies will only
1588 be added when the server was not reached after a direct access,
1589 which means that only when a server is elected after applying a
1590 load-balancing algorithm, or after a redispatch, then the cookie
1591 will be inserted. If the client has all the required information
1592 to connect to the same server next time, no further cookie will
1593 be inserted. In all cases, when the "indirect" option is used in
1594 insert mode, the cookie is always removed from the requests
1595 transmitted to the server. The persistence mechanism then becomes
1596 totally transparent from the application point of view.
1597
1598 nocache This option is recommended in conjunction with the insert mode
1599 when there is a cache between the client and HAProxy, as it
1600 ensures that a cacheable response will be tagged non-cacheable if
1601 a cookie needs to be inserted. This is important because if all
1602 persistence cookies are added on a cacheable home page for
1603 instance, then all customers will then fetch the page from an
1604 outer cache and will all share the same persistence cookie,
1605 leading to one server receiving much more traffic than others.
1606 See also the "insert" and "postonly" options.
1607
1608 postonly This option ensures that cookie insertion will only be performed
1609 on responses to POST requests. It is an alternative to the
1610 "nocache" option, because POST responses are not cacheable, so
1611 this ensures that the persistence cookie will never get cached.
1612 Since most sites do not need any sort of persistence before the
1613 first POST which generally is a login request, this is a very
1614 efficient method to optimize caching without risking to find a
1615 persistence cookie in the cache.
1616 See also the "insert" and "nocache" options.
1617
Krzysztof Piotr Oledzkiefe3b6f2008-05-23 23:49:32 +02001618 domain This option allows to specify the domain at which a cookie is
Krzysztof Piotr Oledzkif8645332009-12-13 21:55:50 +01001619 inserted. It requires exactly one parameter: a valid domain
Willy Tarreau68a897b2009-12-03 23:28:34 +01001620 name. If the domain begins with a dot, the browser is allowed to
1621 use it for any host ending with that name. It is also possible to
1622 specify several domain names by invoking this option multiple
1623 times. Some browsers might have small limits on the number of
1624 domains, so be careful when doing that. For the record, sending
1625 10 domains to MSIE 6 or Firefox 2 works as expected.
Krzysztof Piotr Oledzkiefe3b6f2008-05-23 23:49:32 +02001626
Willy Tarreau0ba27502007-12-24 16:55:16 +01001627 There can be only one persistence cookie per HTTP backend, and it can be
1628 declared in a defaults section. The value of the cookie will be the value
1629 indicated after the "cookie" keyword in a "server" statement. If no cookie
1630 is declared for a given server, the cookie is not set.
Willy Tarreau6a06a402007-07-15 20:15:28 +02001631
Willy Tarreau0ba27502007-12-24 16:55:16 +01001632 Examples :
1633 cookie JSESSIONID prefix
1634 cookie SRV insert indirect nocache
1635 cookie SRV insert postonly indirect
1636
1637 See also : "appsession", "balance source", "capture cookie", "server".
1638
Willy Tarreau983e01e2010-01-11 18:42:06 +01001639
Krzysztof Piotr Oledzkic6df0662010-01-05 16:38:49 +01001640default-server [param*]
1641 Change default options for a server in a backend
1642 May be used in sections : defaults | frontend | listen | backend
1643 yes | no | yes | yes
1644 Arguments:
Willy Tarreau983e01e2010-01-11 18:42:06 +01001645 <param*> is a list of parameters for this server. The "default-server"
1646 keyword accepts an important number of options and has a complete
1647 section dedicated to it. Please refer to section 5 for more
1648 details.
Krzysztof Piotr Oledzkic6df0662010-01-05 16:38:49 +01001649
Willy Tarreau983e01e2010-01-11 18:42:06 +01001650 Example :
Krzysztof Piotr Oledzkic6df0662010-01-05 16:38:49 +01001651 default-server inter 1000 weight 13
1652
1653 See also: "server" and section 5 about server options
Willy Tarreau0ba27502007-12-24 16:55:16 +01001654
Willy Tarreau983e01e2010-01-11 18:42:06 +01001655
Willy Tarreau0ba27502007-12-24 16:55:16 +01001656default_backend <backend>
1657 Specify the backend to use when no "use_backend" rule has been matched.
1658 May be used in sections : defaults | frontend | listen | backend
1659 yes | yes | yes | no
1660 Arguments :
1661 <backend> is the name of the backend to use.
1662
1663 When doing content-switching between frontend and backends using the
1664 "use_backend" keyword, it is often useful to indicate which backend will be
1665 used when no rule has matched. It generally is the dynamic backend which
1666 will catch all undetermined requests.
1667
Willy Tarreau0ba27502007-12-24 16:55:16 +01001668 Example :
1669
1670 use_backend dynamic if url_dyn
1671 use_backend static if url_css url_img extension_img
1672 default_backend dynamic
1673
Willy Tarreau2769aa02007-12-27 18:26:09 +01001674 See also : "use_backend", "reqsetbe", "reqisetbe"
1675
Willy Tarreau0ba27502007-12-24 16:55:16 +01001676
1677disabled
1678 Disable a proxy, frontend or backend.
1679 May be used in sections : defaults | frontend | listen | backend
1680 yes | yes | yes | yes
1681 Arguments : none
1682
1683 The "disabled" keyword is used to disable an instance, mainly in order to
1684 liberate a listening port or to temporarily disable a service. The instance
1685 will still be created and its configuration will be checked, but it will be
1686 created in the "stopped" state and will appear as such in the statistics. It
1687 will not receive any traffic nor will it send any health-checks or logs. It
1688 is possible to disable many instances at once by adding the "disabled"
1689 keyword in a "defaults" section.
1690
1691 See also : "enabled"
1692
1693
1694enabled
1695 Enable a proxy, frontend or backend.
1696 May be used in sections : defaults | frontend | listen | backend
1697 yes | yes | yes | yes
1698 Arguments : none
1699
1700 The "enabled" keyword is used to explicitly enable an instance, when the
1701 defaults has been set to "disabled". This is very rarely used.
1702
1703 See also : "disabled"
1704
1705
1706errorfile <code> <file>
1707 Return a file contents instead of errors generated by HAProxy
1708 May be used in sections : defaults | frontend | listen | backend
1709 yes | yes | yes | yes
1710 Arguments :
1711 <code> is the HTTP status code. Currently, HAProxy is capable of
1712 generating codes 400, 403, 408, 500, 502, 503, and 504.
1713
1714 <file> designates a file containing the full HTTP response. It is
Willy Tarreaud2a4aa22008-01-31 15:28:22 +01001715 recommended to follow the common practice of appending ".http" to
Willy Tarreau0ba27502007-12-24 16:55:16 +01001716 the filename so that people do not confuse the response with HTML
Willy Tarreau59140a22009-02-22 12:02:30 +01001717 error pages, and to use absolute paths, since files are read
1718 before any chroot is performed.
Willy Tarreau0ba27502007-12-24 16:55:16 +01001719
1720 It is important to understand that this keyword is not meant to rewrite
1721 errors returned by the server, but errors detected and returned by HAProxy.
1722 This is why the list of supported errors is limited to a small set.
1723
1724 The files are returned verbatim on the TCP socket. This allows any trick such
1725 as redirections to another URL or site, as well as tricks to clean cookies,
1726 force enable or disable caching, etc... The package provides default error
1727 files returning the same contents as default errors.
1728
Willy Tarreau59140a22009-02-22 12:02:30 +01001729 The files should not exceed the configured buffer size (BUFSIZE), which
1730 generally is 8 or 16 kB, otherwise they will be truncated. It is also wise
1731 not to put any reference to local contents (eg: images) in order to avoid
1732 loops between the client and HAProxy when all servers are down, causing an
1733 error to be returned instead of an image. For better HTTP compliance, it is
1734 recommended that all header lines end with CR-LF and not LF alone.
1735
Willy Tarreau0ba27502007-12-24 16:55:16 +01001736 The files are read at the same time as the configuration and kept in memory.
1737 For this reason, the errors continue to be returned even when the process is
1738 chrooted, and no file change is considered while the process is running. A
Willy Tarreauc27debf2008-01-06 08:57:02 +01001739 simple method for developing those files consists in associating them to the
Willy Tarreau0ba27502007-12-24 16:55:16 +01001740 403 status code and interrogating a blocked URL.
1741
1742 See also : "errorloc", "errorloc302", "errorloc303"
1743
Willy Tarreau59140a22009-02-22 12:02:30 +01001744 Example :
1745 errorfile 400 /etc/haproxy/errorfiles/400badreq.http
1746 errorfile 403 /etc/haproxy/errorfiles/403forbid.http
1747 errorfile 503 /etc/haproxy/errorfiles/503sorry.http
1748
Willy Tarreau2769aa02007-12-27 18:26:09 +01001749
1750errorloc <code> <url>
1751errorloc302 <code> <url>
1752 Return an HTTP redirection to a URL instead of errors generated by HAProxy
1753 May be used in sections : defaults | frontend | listen | backend
1754 yes | yes | yes | yes
1755 Arguments :
1756 <code> is the HTTP status code. Currently, HAProxy is capable of
1757 generating codes 400, 403, 408, 500, 502, 503, and 504.
1758
1759 <url> it is the exact contents of the "Location" header. It may contain
1760 either a relative URI to an error page hosted on the same site,
1761 or an absolute URI designating an error page on another site.
1762 Special care should be given to relative URIs to avoid redirect
1763 loops if the URI itself may generate the same error (eg: 500).
1764
1765 It is important to understand that this keyword is not meant to rewrite
1766 errors returned by the server, but errors detected and returned by HAProxy.
1767 This is why the list of supported errors is limited to a small set.
1768
1769 Note that both keyword return the HTTP 302 status code, which tells the
1770 client to fetch the designated URL using the same HTTP method. This can be
1771 quite problematic in case of non-GET methods such as POST, because the URL
1772 sent to the client might not be allowed for something other than GET. To
1773 workaround this problem, please use "errorloc303" which send the HTTP 303
1774 status code, indicating to the client that the URL must be fetched with a GET
1775 request.
1776
1777 See also : "errorfile", "errorloc303"
1778
1779
1780errorloc303 <code> <url>
1781 Return an HTTP redirection to a URL instead of errors generated by HAProxy
1782 May be used in sections : defaults | frontend | listen | backend
1783 yes | yes | yes | yes
1784 Arguments :
1785 <code> is the HTTP status code. Currently, HAProxy is capable of
1786 generating codes 400, 403, 408, 500, 502, 503, and 504.
1787
1788 <url> it is the exact contents of the "Location" header. It may contain
1789 either a relative URI to an error page hosted on the same site,
1790 or an absolute URI designating an error page on another site.
1791 Special care should be given to relative URIs to avoid redirect
1792 loops if the URI itself may generate the same error (eg: 500).
1793
1794 It is important to understand that this keyword is not meant to rewrite
1795 errors returned by the server, but errors detected and returned by HAProxy.
1796 This is why the list of supported errors is limited to a small set.
1797
1798 Note that both keyword return the HTTP 303 status code, which tells the
1799 client to fetch the designated URL using the same HTTP GET method. This
1800 solves the usual problems associated with "errorloc" and the 302 code. It is
1801 possible that some very old browsers designed before HTTP/1.1 do not support
Willy Tarreaud2a4aa22008-01-31 15:28:22 +01001802 it, but no such problem has been reported till now.
Willy Tarreau2769aa02007-12-27 18:26:09 +01001803
1804 See also : "errorfile", "errorloc", "errorloc302"
1805
1806
Willy Tarreau4de91492010-01-22 19:10:05 +01001807force-persist { if | unless } <condition>
1808 Declare a condition to force persistence on down servers
1809 May be used in sections: defaults | frontend | listen | backend
1810 no | yes | yes | yes
1811
1812 By default, requests are not dispatched to down servers. It is possible to
1813 force this using "option persist", but it is unconditional and redispatches
1814 to a valid server if "option redispatch" is set. That leaves with very little
1815 possibilities to force some requests to reach a server which is artificially
1816 marked down for maintenance operations.
1817
1818 The "force-persist" statement allows one to declare various ACL-based
1819 conditions which, when met, will cause a request to ignore the down status of
1820 a server and still try to connect to it. That makes it possible to start a
1821 server, still replying an error to the health checks, and run a specially
1822 configured browser to test the service. Among the handy methods, one could
1823 use a specific source IP address, or a specific cookie. The cookie also has
1824 the advantage that it can easily be added/removed on the browser from a test
1825 page. Once the service is validated, it is then possible to open the service
1826 to the world by returning a valid response to health checks.
1827
1828 The forced persistence is enabled when an "if" condition is met, or unless an
1829 "unless" condition is met. The final redispatch is always disabled when this
1830 is used.
1831
1832 See also : "option redispatch", "persist", and section 7 about ACL usage.
1833
1834
Willy Tarreau2769aa02007-12-27 18:26:09 +01001835fullconn <conns>
1836 Specify at what backend load the servers will reach their maxconn
1837 May be used in sections : defaults | frontend | listen | backend
1838 yes | no | yes | yes
1839 Arguments :
1840 <conns> is the number of connections on the backend which will make the
1841 servers use the maximal number of connections.
1842
Willy Tarreau198a7442008-01-17 12:05:32 +01001843 When a server has a "maxconn" parameter specified, it means that its number
Willy Tarreau2769aa02007-12-27 18:26:09 +01001844 of concurrent connections will never go higher. Additionally, if it has a
Willy Tarreau198a7442008-01-17 12:05:32 +01001845 "minconn" parameter, it indicates a dynamic limit following the backend's
Willy Tarreau2769aa02007-12-27 18:26:09 +01001846 load. The server will then always accept at least <minconn> connections,
1847 never more than <maxconn>, and the limit will be on the ramp between both
1848 values when the backend has less than <conns> concurrent connections. This
1849 makes it possible to limit the load on the servers during normal loads, but
1850 push it further for important loads without overloading the servers during
Krzysztof Piotr Oledzkif8645332009-12-13 21:55:50 +01001851 exceptional loads.
Willy Tarreau2769aa02007-12-27 18:26:09 +01001852
1853 Example :
1854 # The servers will accept between 100 and 1000 concurrent connections each
1855 # and the maximum of 1000 will be reached when the backend reaches 10000
1856 # connections.
1857 backend dynamic
1858 fullconn 10000
1859 server srv1 dyn1:80 minconn 100 maxconn 1000
1860 server srv2 dyn2:80 minconn 100 maxconn 1000
1861
1862 See also : "maxconn", "server"
1863
1864
1865grace <time>
1866 Maintain a proxy operational for some time after a soft stop
1867 May be used in sections : defaults | frontend | listen | backend
1868 no | yes | yes | yes
1869 Arguments :
1870 <time> is the time (by default in milliseconds) for which the instance
1871 will remain operational with the frontend sockets still listening
1872 when a soft-stop is received via the SIGUSR1 signal.
1873
1874 This may be used to ensure that the services disappear in a certain order.
1875 This was designed so that frontends which are dedicated to monitoring by an
Krzysztof Piotr Oledzkif8645332009-12-13 21:55:50 +01001876 external equipment fail immediately while other ones remain up for the time
Willy Tarreau2769aa02007-12-27 18:26:09 +01001877 needed by the equipment to detect the failure.
1878
1879 Note that currently, there is very little benefit in using this parameter,
1880 and it may in fact complicate the soft-reconfiguration process more than
1881 simplify it.
1882
Willy Tarreau0ba27502007-12-24 16:55:16 +01001883
Willy Tarreau6b2e11b2009-10-01 07:52:15 +02001884hash-type <method>
1885 Specify a method to use for mapping hashes to servers
1886 May be used in sections : defaults | frontend | listen | backend
1887 yes | no | yes | yes
1888 Arguments :
1889 map-based the hash table is a static array containing all alive servers.
1890 The hashes will be very smooth, will consider weights, but will
1891 be static in that weight changes while a server is up will be
1892 ignored. This means that there will be no slow start. Also,
1893 since a server is selected by its position in the array, most
1894 mappings are changed when the server count changes. This means
1895 that when a server goes up or down, or when a server is added
1896 to a farm, most connections will be redistributed to different
1897 servers. This can be inconvenient with caches for instance.
1898
1899 consistent the hash table is a tree filled with many occurrences of each
1900 server. The hash key is looked up in the tree and the closest
1901 server is chosen. This hash is dynamic, it supports changing
1902 weights while the servers are up, so it is compatible with the
1903 slow start feature. It has the advantage that when a server
1904 goes up or down, only its associations are moved. When a server
1905 is added to the farm, only a few part of the mappings are
1906 redistributed, making it an ideal algorithm for caches.
1907 However, due to its principle, the algorithm will never be very
1908 smooth and it may sometimes be necessary to adjust a server's
1909 weight or its ID to get a more balanced distribution. In order
1910 to get the same distribution on multiple load balancers, it is
1911 important that all servers have the same IDs.
1912
1913 The default hash type is "map-based" and is recommended for most usages.
1914
1915 See also : "balance", "server"
1916
1917
Willy Tarreau0ba27502007-12-24 16:55:16 +01001918http-check disable-on-404
1919 Enable a maintenance mode upon HTTP/404 response to health-checks
1920 May be used in sections : defaults | frontend | listen | backend
Willy Tarreau2769aa02007-12-27 18:26:09 +01001921 yes | no | yes | yes
Willy Tarreau0ba27502007-12-24 16:55:16 +01001922 Arguments : none
1923
1924 When this option is set, a server which returns an HTTP code 404 will be
1925 excluded from further load-balancing, but will still receive persistent
1926 connections. This provides a very convenient method for Web administrators
1927 to perform a graceful shutdown of their servers. It is also important to note
1928 that a server which is detected as failed while it was in this mode will not
1929 generate an alert, just a notice. If the server responds 2xx or 3xx again, it
1930 will immediately be reinserted into the farm. The status on the stats page
1931 reports "NOLB" for a server in this mode. It is important to note that this
1932 option only works in conjunction with the "httpchk" option.
1933
Willy Tarreau2769aa02007-12-27 18:26:09 +01001934 See also : "option httpchk"
1935
1936
Krzysztof Piotr Oledzkif58a9622008-02-23 01:19:10 +01001937id <value>
Willy Tarreau53fb4ae2009-10-04 23:04:08 +02001938 Set a persistent ID to a proxy.
1939 May be used in sections : defaults | frontend | listen | backend
1940 no | yes | yes | yes
1941 Arguments : none
1942
1943 Set a persistent ID for the proxy. This ID must be unique and positive.
1944 An unused ID will automatically be assigned if unset. The first assigned
1945 value will be 1. This ID is currently only returned in statistics.
Krzysztof Piotr Oledzkif58a9622008-02-23 01:19:10 +01001946
1947
Willy Tarreau2769aa02007-12-27 18:26:09 +01001948log global
Willy Tarreauf7edefa2009-05-10 17:20:05 +02001949log <address> <facility> [<level> [<minlevel>]]
Willy Tarreau2769aa02007-12-27 18:26:09 +01001950 Enable per-instance logging of events and traffic.
1951 May be used in sections : defaults | frontend | listen | backend
1952 yes | yes | yes | yes
1953 Arguments :
1954 global should be used when the instance's logging parameters are the
1955 same as the global ones. This is the most common usage. "global"
1956 replaces <address>, <facility> and <level> with those of the log
1957 entries found in the "global" section. Only one "log global"
1958 statement may be used per instance, and this form takes no other
1959 parameter.
1960
1961 <address> indicates where to send the logs. It takes the same format as
1962 for the "global" section's logs, and can be one of :
1963
1964 - An IPv4 address optionally followed by a colon (':') and a UDP
1965 port. If no port is specified, 514 is used by default (the
1966 standard syslog port).
1967
1968 - A filesystem path to a UNIX domain socket, keeping in mind
1969 considerations for chroot (be sure the path is accessible
1970 inside the chroot) and uid/gid (be sure the path is
1971 appropriately writeable).
1972
1973 <facility> must be one of the 24 standard syslog facilities :
1974
1975 kern user mail daemon auth syslog lpr news
1976 uucp cron auth2 ftp ntp audit alert cron2
1977 local0 local1 local2 local3 local4 local5 local6 local7
1978
1979 <level> is optional and can be specified to filter outgoing messages. By
1980 default, all messages are sent. If a level is specified, only
1981 messages with a severity at least as important as this level
Willy Tarreauf7edefa2009-05-10 17:20:05 +02001982 will be sent. An optional minimum level can be specified. If it
1983 is set, logs emitted with a more severe level than this one will
1984 be capped to this level. This is used to avoid sending "emerg"
1985 messages on all terminals on some default syslog configurations.
1986 Eight levels are known :
Willy Tarreau2769aa02007-12-27 18:26:09 +01001987
1988 emerg alert crit err warning notice info debug
1989
1990 Note that up to two "log" entries may be specified per instance. However, if
1991 "log global" is used and if the "global" section already contains 2 log
1992 entries, then additional log entries will be ignored.
1993
1994 Also, it is important to keep in mind that it is the frontend which decides
Willy Tarreaucc6c8912009-02-22 10:53:55 +01001995 what to log from a connection, and that in case of content switching, the log
1996 entries from the backend will be ignored. Connections are logged at level
1997 "info".
1998
1999 However, backend log declaration define how and where servers status changes
2000 will be logged. Level "notice" will be used to indicate a server going up,
2001 "warning" will be used for termination signals and definitive service
2002 termination, and "alert" will be used for when a server goes down.
2003
2004 Note : According to RFC3164, messages are truncated to 1024 bytes before
2005 being emitted.
Willy Tarreau2769aa02007-12-27 18:26:09 +01002006
2007 Example :
2008 log global
Willy Tarreauf7edefa2009-05-10 17:20:05 +02002009 log 127.0.0.1:514 local0 notice # only send important events
2010 log 127.0.0.1:514 local0 notice notice # same but limit output level
Willy Tarreau2769aa02007-12-27 18:26:09 +01002011
2012
2013maxconn <conns>
2014 Fix the maximum number of concurrent connections on a frontend
2015 May be used in sections : defaults | frontend | listen | backend
2016 yes | yes | yes | no
2017 Arguments :
2018 <conns> is the maximum number of concurrent connections the frontend will
2019 accept to serve. Excess connections will be queued by the system
2020 in the socket's listen queue and will be served once a connection
2021 closes.
2022
2023 If the system supports it, it can be useful on big sites to raise this limit
2024 very high so that haproxy manages connection queues, instead of leaving the
2025 clients with unanswered connection attempts. This value should not exceed the
2026 global maxconn. Also, keep in mind that a connection contains two buffers
2027 of 8kB each, as well as some other data resulting in about 17 kB of RAM being
2028 consumed per established connection. That means that a medium system equipped
2029 with 1GB of RAM can withstand around 40000-50000 concurrent connections if
2030 properly tuned.
2031
2032 Also, when <conns> is set to large values, it is possible that the servers
2033 are not sized to accept such loads, and for this reason it is generally wise
2034 to assign them some reasonable connection limits.
2035
2036 See also : "server", global section's "maxconn", "fullconn"
2037
2038
2039mode { tcp|http|health }
2040 Set the running mode or protocol of the instance
2041 May be used in sections : defaults | frontend | listen | backend
2042 yes | yes | yes | yes
2043 Arguments :
2044 tcp The instance will work in pure TCP mode. A full-duplex connection
2045 will be established between clients and servers, and no layer 7
2046 examination will be performed. This is the default mode. It
2047 should be used for SSL, SSH, SMTP, ...
2048
2049 http The instance will work in HTTP mode. The client request will be
2050 analyzed in depth before connecting to any server. Any request
2051 which is not RFC-compliant will be rejected. Layer 7 filtering,
2052 processing and switching will be possible. This is the mode which
2053 brings HAProxy most of its value.
2054
2055 health The instance will work in "health" mode. It will just reply "OK"
2056 to incoming connections and close the connection. Nothing will be
2057 logged. This mode is used to reply to external components health
2058 checks. This mode is deprecated and should not be used anymore as
2059 it is possible to do the same and even better by combining TCP or
2060 HTTP modes with the "monitor" keyword.
2061
2062 When doing content switching, it is mandatory that the frontend and the
2063 backend are in the same mode (generally HTTP), otherwise the configuration
2064 will be refused.
2065
2066 Example :
2067 defaults http_instances
2068 mode http
2069
2070 See also : "monitor", "monitor-net"
2071
Willy Tarreau0ba27502007-12-24 16:55:16 +01002072
2073monitor fail [if | unless] <condition>
Willy Tarreau2769aa02007-12-27 18:26:09 +01002074 Add a condition to report a failure to a monitor HTTP request.
Willy Tarreau0ba27502007-12-24 16:55:16 +01002075 May be used in sections : defaults | frontend | listen | backend
2076 no | yes | yes | no
Willy Tarreau0ba27502007-12-24 16:55:16 +01002077 Arguments :
2078 if <cond> the monitor request will fail if the condition is satisfied,
2079 and will succeed otherwise. The condition should describe a
Krzysztof Piotr Oledzkif8645332009-12-13 21:55:50 +01002080 combined test which must induce a failure if all conditions
Willy Tarreau0ba27502007-12-24 16:55:16 +01002081 are met, for instance a low number of servers both in a
2082 backend and its backup.
2083
2084 unless <cond> the monitor request will succeed only if the condition is
2085 satisfied, and will fail otherwise. Such a condition may be
2086 based on a test on the presence of a minimum number of active
2087 servers in a list of backends.
2088
2089 This statement adds a condition which can force the response to a monitor
2090 request to report a failure. By default, when an external component queries
2091 the URI dedicated to monitoring, a 200 response is returned. When one of the
2092 conditions above is met, haproxy will return 503 instead of 200. This is
2093 very useful to report a site failure to an external component which may base
2094 routing advertisements between multiple sites on the availability reported by
2095 haproxy. In this case, one would rely on an ACL involving the "nbsrv"
Willy Tarreau2769aa02007-12-27 18:26:09 +01002096 criterion. Note that "monitor fail" only works in HTTP mode.
Willy Tarreau0ba27502007-12-24 16:55:16 +01002097
2098 Example:
2099 frontend www
Willy Tarreau2769aa02007-12-27 18:26:09 +01002100 mode http
Willy Tarreau0ba27502007-12-24 16:55:16 +01002101 acl site_dead nbsrv(dynamic) lt 2
2102 acl site_dead nbsrv(static) lt 2
2103 monitor-uri /site_alive
2104 monitor fail if site_dead
2105
Willy Tarreau2769aa02007-12-27 18:26:09 +01002106 See also : "monitor-net", "monitor-uri"
2107
2108
2109monitor-net <source>
2110 Declare a source network which is limited to monitor requests
2111 May be used in sections : defaults | frontend | listen | backend
2112 yes | yes | yes | no
2113 Arguments :
2114 <source> is the source IPv4 address or network which will only be able to
2115 get monitor responses to any request. It can be either an IPv4
2116 address, a host name, or an address followed by a slash ('/')
2117 followed by a mask.
2118
2119 In TCP mode, any connection coming from a source matching <source> will cause
2120 the connection to be immediately closed without any log. This allows another
Krzysztof Piotr Oledzkif8645332009-12-13 21:55:50 +01002121 equipment to probe the port and verify that it is still listening, without
Willy Tarreau2769aa02007-12-27 18:26:09 +01002122 forwarding the connection to a remote server.
2123
2124 In HTTP mode, a connection coming from a source matching <source> will be
2125 accepted, the following response will be sent without waiting for a request,
2126 then the connection will be closed : "HTTP/1.0 200 OK". This is normally
2127 enough for any front-end HTTP probe to detect that the service is UP and
2128 running without forwarding the request to a backend server.
2129
2130 Monitor requests are processed very early. It is not possible to block nor
2131 divert them using ACLs. They cannot be logged either, and it is the intended
2132 purpose. They are only used to report HAProxy's health to an upper component,
2133 nothing more. Right now, it is not possible to set failure conditions on
2134 requests caught by "monitor-net".
2135
2136 Example :
2137 # addresses .252 and .253 are just probing us.
2138 frontend www
2139 monitor-net 192.168.0.252/31
2140
2141 See also : "monitor fail", "monitor-uri"
2142
2143
2144monitor-uri <uri>
2145 Intercept a URI used by external components' monitor requests
2146 May be used in sections : defaults | frontend | listen | backend
2147 yes | yes | yes | no
2148 Arguments :
2149 <uri> is the exact URI which we want to intercept to return HAProxy's
2150 health status instead of forwarding the request.
2151
2152 When an HTTP request referencing <uri> will be received on a frontend,
2153 HAProxy will not forward it nor log it, but instead will return either
2154 "HTTP/1.0 200 OK" or "HTTP/1.0 503 Service unavailable", depending on failure
2155 conditions defined with "monitor fail". This is normally enough for any
2156 front-end HTTP probe to detect that the service is UP and running without
2157 forwarding the request to a backend server. Note that the HTTP method, the
2158 version and all headers are ignored, but the request must at least be valid
2159 at the HTTP level. This keyword may only be used with an HTTP-mode frontend.
2160
2161 Monitor requests are processed very early. It is not possible to block nor
2162 divert them using ACLs. They cannot be logged either, and it is the intended
2163 purpose. They are only used to report HAProxy's health to an upper component,
2164 nothing more. However, it is possible to add any number of conditions using
2165 "monitor fail" and ACLs so that the result can be adjusted to whatever check
2166 can be imagined (most often the number of available servers in a backend).
2167
2168 Example :
2169 # Use /haproxy_test to report haproxy's status
2170 frontend www
2171 mode http
2172 monitor-uri /haproxy_test
2173
2174 See also : "monitor fail", "monitor-net"
2175
Willy Tarreau0ba27502007-12-24 16:55:16 +01002176
Willy Tarreaubf1f8162007-12-28 17:42:56 +01002177option abortonclose
2178no option abortonclose
2179 Enable or disable early dropping of aborted requests pending in queues.
2180 May be used in sections : defaults | frontend | listen | backend
2181 yes | no | yes | yes
2182 Arguments : none
2183
2184 In presence of very high loads, the servers will take some time to respond.
2185 The per-instance connection queue will inflate, and the response time will
2186 increase respective to the size of the queue times the average per-session
2187 response time. When clients will wait for more than a few seconds, they will
Willy Tarreau198a7442008-01-17 12:05:32 +01002188 often hit the "STOP" button on their browser, leaving a useless request in
Willy Tarreaubf1f8162007-12-28 17:42:56 +01002189 the queue, and slowing down other users, and the servers as well, because the
2190 request will eventually be served, then aborted at the first error
2191 encountered while delivering the response.
2192
2193 As there is no way to distinguish between a full STOP and a simple output
2194 close on the client side, HTTP agents should be conservative and consider
2195 that the client might only have closed its output channel while waiting for
2196 the response. However, this introduces risks of congestion when lots of users
2197 do the same, and is completely useless nowadays because probably no client at
2198 all will close the session while waiting for the response. Some HTTP agents
Willy Tarreaud72758d2010-01-12 10:42:19 +01002199 support this behaviour (Squid, Apache, HAProxy), and others do not (TUX, most
Willy Tarreaubf1f8162007-12-28 17:42:56 +01002200 hardware-based load balancers). So the probability for a closed input channel
Willy Tarreau198a7442008-01-17 12:05:32 +01002201 to represent a user hitting the "STOP" button is close to 100%, and the risk
Willy Tarreaubf1f8162007-12-28 17:42:56 +01002202 of being the single component to break rare but valid traffic is extremely
2203 low, which adds to the temptation to be able to abort a session early while
2204 still not served and not pollute the servers.
2205
2206 In HAProxy, the user can choose the desired behaviour using the option
2207 "abortonclose". By default (without the option) the behaviour is HTTP
2208 compliant and aborted requests will be served. But when the option is
2209 specified, a session with an incoming channel closed will be aborted while
2210 it is still possible, either pending in the queue for a connection slot, or
2211 during the connection establishment if the server has not yet acknowledged
2212 the connection request. This considerably reduces the queue size and the load
2213 on saturated servers when users are tempted to click on STOP, which in turn
Willy Tarreaud72758d2010-01-12 10:42:19 +01002214 reduces the response time for other users.
Willy Tarreaubf1f8162007-12-28 17:42:56 +01002215
2216 If this option has been enabled in a "defaults" section, it can be disabled
2217 in a specific instance by prepending the "no" keyword before it.
2218
2219 See also : "timeout queue" and server's "maxconn" and "maxqueue" parameters
2220
2221
Willy Tarreau4076a152009-04-02 15:18:36 +02002222option accept-invalid-http-request
2223no option accept-invalid-http-request
2224 Enable or disable relaxing of HTTP request parsing
2225 May be used in sections : defaults | frontend | listen | backend
2226 yes | yes | yes | no
2227 Arguments : none
2228
2229 By default, HAProxy complies with RFC2616 in terms of message parsing. This
2230 means that invalid characters in header names are not permitted and cause an
2231 error to be returned to the client. This is the desired behaviour as such
2232 forbidden characters are essentially used to build attacks exploiting server
2233 weaknesses, and bypass security filtering. Sometimes, a buggy browser or
2234 server will emit invalid header names for whatever reason (configuration,
2235 implementation) and the issue will not be immediately fixed. In such a case,
2236 it is possible to relax HAProxy's header name parser to accept any character
2237 even if that does not make sense, by specifying this option.
2238
2239 This option should never be enabled by default as it hides application bugs
2240 and open security breaches. It should only be deployed after a problem has
2241 been confirmed.
2242
2243 When this option is enabled, erroneous header names will still be accepted in
2244 requests, but the complete request will be captured in order to permit later
2245 analysis using the "show errors" request on the UNIX stats socket. Doing this
2246 also helps confirming that the issue has been solved.
2247
2248 If this option has been enabled in a "defaults" section, it can be disabled
2249 in a specific instance by prepending the "no" keyword before it.
2250
2251 See also : "option accept-invalid-http-response" and "show errors" on the
2252 stats socket.
2253
2254
2255option accept-invalid-http-response
2256no option accept-invalid-http-response
2257 Enable or disable relaxing of HTTP response parsing
2258 May be used in sections : defaults | frontend | listen | backend
2259 yes | no | yes | yes
2260 Arguments : none
2261
2262 By default, HAProxy complies with RFC2616 in terms of message parsing. This
2263 means that invalid characters in header names are not permitted and cause an
2264 error to be returned to the client. This is the desired behaviour as such
2265 forbidden characters are essentially used to build attacks exploiting server
2266 weaknesses, and bypass security filtering. Sometimes, a buggy browser or
2267 server will emit invalid header names for whatever reason (configuration,
2268 implementation) and the issue will not be immediately fixed. In such a case,
2269 it is possible to relax HAProxy's header name parser to accept any character
2270 even if that does not make sense, by specifying this option.
2271
2272 This option should never be enabled by default as it hides application bugs
2273 and open security breaches. It should only be deployed after a problem has
2274 been confirmed.
2275
2276 When this option is enabled, erroneous header names will still be accepted in
2277 responses, but the complete response will be captured in order to permit
2278 later analysis using the "show errors" request on the UNIX stats socket.
2279 Doing this also helps confirming that the issue has been solved.
2280
2281 If this option has been enabled in a "defaults" section, it can be disabled
2282 in a specific instance by prepending the "no" keyword before it.
2283
2284 See also : "option accept-invalid-http-request" and "show errors" on the
2285 stats socket.
2286
2287
Willy Tarreaubf1f8162007-12-28 17:42:56 +01002288option allbackups
2289no option allbackups
2290 Use either all backup servers at a time or only the first one
2291 May be used in sections : defaults | frontend | listen | backend
2292 yes | no | yes | yes
2293 Arguments : none
2294
2295 By default, the first operational backup server gets all traffic when normal
2296 servers are all down. Sometimes, it may be preferred to use multiple backups
2297 at once, because one will not be enough. When "option allbackups" is enabled,
2298 the load balancing will be performed among all backup servers when all normal
2299 ones are unavailable. The same load balancing algorithm will be used and the
2300 servers' weights will be respected. Thus, there will not be any priority
2301 order between the backup servers anymore.
2302
2303 This option is mostly used with static server farms dedicated to return a
2304 "sorry" page when an application is completely offline.
2305
2306 If this option has been enabled in a "defaults" section, it can be disabled
2307 in a specific instance by prepending the "no" keyword before it.
2308
2309
2310option checkcache
2311no option checkcache
Krzysztof Piotr Oledzkif8645332009-12-13 21:55:50 +01002312 Analyze all server responses and block requests with cacheable cookies
Willy Tarreaubf1f8162007-12-28 17:42:56 +01002313 May be used in sections : defaults | frontend | listen | backend
2314 yes | no | yes | yes
2315 Arguments : none
2316
2317 Some high-level frameworks set application cookies everywhere and do not
2318 always let enough control to the developer to manage how the responses should
Krzysztof Piotr Oledzkif8645332009-12-13 21:55:50 +01002319 be cached. When a session cookie is returned on a cacheable object, there is a
Willy Tarreaubf1f8162007-12-28 17:42:56 +01002320 high risk of session crossing or stealing between users traversing the same
2321 caches. In some situations, it is better to block the response than to let
2322 some sensible session information go in the wild.
2323
2324 The option "checkcache" enables deep inspection of all server responses for
Krzysztof Piotr Oledzkif8645332009-12-13 21:55:50 +01002325 strict compliance with HTTP specification in terms of cacheability. It
Willy Tarreau198a7442008-01-17 12:05:32 +01002326 carefully checks "Cache-control", "Pragma" and "Set-cookie" headers in server
Willy Tarreaubf1f8162007-12-28 17:42:56 +01002327 response to check if there's a risk of caching a cookie on a client-side
2328 proxy. When this option is enabled, the only responses which can be delivered
Willy Tarreau198a7442008-01-17 12:05:32 +01002329 to the client are :
2330 - all those without "Set-Cookie" header ;
Willy Tarreaubf1f8162007-12-28 17:42:56 +01002331 - all those with a return code other than 200, 203, 206, 300, 301, 410,
Willy Tarreau198a7442008-01-17 12:05:32 +01002332 provided that the server has not set a "Cache-control: public" header ;
Willy Tarreaubf1f8162007-12-28 17:42:56 +01002333 - all those that come from a POST request, provided that the server has not
2334 set a 'Cache-Control: public' header ;
2335 - those with a 'Pragma: no-cache' header
2336 - those with a 'Cache-control: private' header
2337 - those with a 'Cache-control: no-store' header
2338 - those with a 'Cache-control: max-age=0' header
2339 - those with a 'Cache-control: s-maxage=0' header
2340 - those with a 'Cache-control: no-cache' header
2341 - those with a 'Cache-control: no-cache="set-cookie"' header
2342 - those with a 'Cache-control: no-cache="set-cookie,' header
2343 (allowing other fields after set-cookie)
2344
2345 If a response doesn't respect these requirements, then it will be blocked
Willy Tarreau198a7442008-01-17 12:05:32 +01002346 just as if it was from an "rspdeny" filter, with an "HTTP 502 bad gateway".
Willy Tarreaubf1f8162007-12-28 17:42:56 +01002347 The session state shows "PH--" meaning that the proxy blocked the response
Krzysztof Piotr Oledzkif8645332009-12-13 21:55:50 +01002348 during headers processing. Additionally, an alert will be sent in the logs so
Willy Tarreaubf1f8162007-12-28 17:42:56 +01002349 that admins are informed that there's something to be fixed.
2350
2351 Due to the high impact on the application, the application should be tested
2352 in depth with the option enabled before going to production. It is also a
Willy Tarreaud2a4aa22008-01-31 15:28:22 +01002353 good practice to always activate it during tests, even if it is not used in
Willy Tarreaubf1f8162007-12-28 17:42:56 +01002354 production, as it will report potentially dangerous application behaviours.
2355
2356 If this option has been enabled in a "defaults" section, it can be disabled
2357 in a specific instance by prepending the "no" keyword before it.
2358
2359
2360option clitcpka
2361no option clitcpka
2362 Enable or disable the sending of TCP keepalive packets on the client side
2363 May be used in sections : defaults | frontend | listen | backend
2364 yes | yes | yes | no
2365 Arguments : none
2366
2367 When there is a firewall or any session-aware component between a client and
2368 a server, and when the protocol involves very long sessions with long idle
2369 periods (eg: remote desktops), there is a risk that one of the intermediate
2370 components decides to expire a session which has remained idle for too long.
2371
2372 Enabling socket-level TCP keep-alives makes the system regularly send packets
2373 to the other end of the connection, leaving it active. The delay between
2374 keep-alive probes is controlled by the system only and depends both on the
2375 operating system and its tuning parameters.
2376
2377 It is important to understand that keep-alive packets are neither emitted nor
2378 received at the application level. It is only the network stacks which sees
2379 them. For this reason, even if one side of the proxy already uses keep-alives
2380 to maintain its connection alive, those keep-alive packets will not be
2381 forwarded to the other side of the proxy.
2382
2383 Please note that this has nothing to do with HTTP keep-alive.
2384
2385 Using option "clitcpka" enables the emission of TCP keep-alive probes on the
2386 client side of a connection, which should help when session expirations are
2387 noticed between HAProxy and a client.
2388
2389 If this option has been enabled in a "defaults" section, it can be disabled
2390 in a specific instance by prepending the "no" keyword before it.
2391
2392 See also : "option srvtcpka", "option tcpka"
2393
2394
Willy Tarreau0ba27502007-12-24 16:55:16 +01002395option contstats
2396 Enable continuous traffic statistics updates
2397 May be used in sections : defaults | frontend | listen | backend
2398 yes | yes | yes | no
2399 Arguments : none
2400
2401 By default, counters used for statistics calculation are incremented
2402 only when a session finishes. It works quite well when serving small
2403 objects, but with big ones (for example large images or archives) or
2404 with A/V streaming, a graph generated from haproxy counters looks like
2405 a hedgehog. With this option enabled counters get incremented continuously,
2406 during a whole session. Recounting touches a hotpath directly so
2407 it is not enabled by default, as it has small performance impact (~0.5%).
2408
2409
Willy Tarreauc9bd0cc2009-05-10 11:57:02 +02002410option dontlog-normal
2411no option dontlog-normal
2412 Enable or disable logging of normal, successful connections
2413 May be used in sections : defaults | frontend | listen | backend
2414 yes | yes | yes | no
2415 Arguments : none
2416
2417 There are large sites dealing with several thousand connections per second
2418 and for which logging is a major pain. Some of them are even forced to turn
2419 logs off and cannot debug production issues. Setting this option ensures that
2420 normal connections, those which experience no error, no timeout, no retry nor
2421 redispatch, will not be logged. This leaves disk space for anomalies. In HTTP
2422 mode, the response status code is checked and return codes 5xx will still be
2423 logged.
2424
2425 It is strongly discouraged to use this option as most of the time, the key to
2426 complex issues is in the normal logs which will not be logged here. If you
2427 need to separate logs, see the "log-separate-errors" option instead.
2428
Willy Tarreauc57f0e22009-05-10 13:12:33 +02002429 See also : "log", "dontlognull", "log-separate-errors" and section 8 about
Willy Tarreauc9bd0cc2009-05-10 11:57:02 +02002430 logging.
2431
2432
Willy Tarreaubf1f8162007-12-28 17:42:56 +01002433option dontlognull
2434no option dontlognull
2435 Enable or disable logging of null connections
2436 May be used in sections : defaults | frontend | listen | backend
2437 yes | yes | yes | no
2438 Arguments : none
2439
2440 In certain environments, there are components which will regularly connect to
2441 various systems to ensure that they are still alive. It can be the case from
2442 another load balancer as well as from monitoring systems. By default, even a
2443 simple port probe or scan will produce a log. If those connections pollute
2444 the logs too much, it is possible to enable option "dontlognull" to indicate
2445 that a connection on which no data has been transferred will not be logged,
2446 which typically corresponds to those probes.
2447
2448 It is generally recommended not to use this option in uncontrolled
2449 environments (eg: internet), otherwise scans and other malicious activities
2450 would not be logged.
2451
2452 If this option has been enabled in a "defaults" section, it can be disabled
2453 in a specific instance by prepending the "no" keyword before it.
2454
Willy Tarreauc57f0e22009-05-10 13:12:33 +02002455 See also : "log", "monitor-net", "monitor-uri" and section 8 about logging.
Willy Tarreaubf1f8162007-12-28 17:42:56 +01002456
2457
2458option forceclose
2459no option forceclose
2460 Enable or disable active connection closing after response is transferred.
2461 May be used in sections : defaults | frontend | listen | backend
Willy Tarreaua31e5df2009-12-30 01:10:35 +01002462 yes | yes | yes | yes
Willy Tarreaubf1f8162007-12-28 17:42:56 +01002463 Arguments : none
2464
2465 Some HTTP servers do not necessarily close the connections when they receive
2466 the "Connection: close" set by "option httpclose", and if the client does not
2467 close either, then the connection remains open till the timeout expires. This
2468 causes high number of simultaneous connections on the servers and shows high
2469 global session times in the logs.
2470
2471 When this happens, it is possible to use "option forceclose". It will
Willy Tarreau82eeaf22009-12-29 12:09:05 +01002472 actively close the outgoing server channel as soon as the server has finished
Willy Tarreau0dfdf192010-01-05 11:33:11 +01002473 to respond. This option implicitly enables the "httpclose" option. Note that
2474 this option also enables the parsing of the full request and response, which
2475 means we can close the connection to the server very quickly, releasing some
2476 resources earlier than with httpclose.
Willy Tarreaubf1f8162007-12-28 17:42:56 +01002477
2478 If this option has been enabled in a "defaults" section, it can be disabled
2479 in a specific instance by prepending the "no" keyword before it.
2480
2481 See also : "option httpclose"
2482
2483
Ross Westaf72a1d2008-08-03 10:51:45 +02002484option forwardfor [ except <network> ] [ header <name> ]
Willy Tarreauc27debf2008-01-06 08:57:02 +01002485 Enable insertion of the X-Forwarded-For header to requests sent to servers
2486 May be used in sections : defaults | frontend | listen | backend
2487 yes | yes | yes | yes
2488 Arguments :
2489 <network> is an optional argument used to disable this option for sources
2490 matching <network>
Ross Westaf72a1d2008-08-03 10:51:45 +02002491 <name> an optional argument to specify a different "X-Forwarded-For"
Willy Tarreaud72758d2010-01-12 10:42:19 +01002492 header name.
Willy Tarreauc27debf2008-01-06 08:57:02 +01002493
2494 Since HAProxy works in reverse-proxy mode, the servers see its IP address as
2495 their client address. This is sometimes annoying when the client's IP address
2496 is expected in server logs. To solve this problem, the well-known HTTP header
2497 "X-Forwarded-For" may be added by HAProxy to all requests sent to the server.
2498 This header contains a value representing the client's IP address. Since this
2499 header is always appended at the end of the existing header list, the server
2500 must be configured to always use the last occurrence of this header only. See
Ross Westaf72a1d2008-08-03 10:51:45 +02002501 the server's manual to find how to enable use of this standard header. Note
2502 that only the last occurrence of the header must be used, since it is really
2503 possible that the client has already brought one.
2504
Willy Tarreaud72758d2010-01-12 10:42:19 +01002505 The keyword "header" may be used to supply a different header name to replace
Ross Westaf72a1d2008-08-03 10:51:45 +02002506 the default "X-Forwarded-For". This can be useful where you might already
Willy Tarreaud72758d2010-01-12 10:42:19 +01002507 have a "X-Forwarded-For" header from a different application (eg: stunnel),
2508 and you need preserve it. Also if your backend server doesn't use the
Ross Westaf72a1d2008-08-03 10:51:45 +02002509 "X-Forwarded-For" header and requires different one (eg: Zeus Web Servers
2510 require "X-Cluster-Client-IP").
Willy Tarreauc27debf2008-01-06 08:57:02 +01002511
2512 Sometimes, a same HAProxy instance may be shared between a direct client
2513 access and a reverse-proxy access (for instance when an SSL reverse-proxy is
2514 used to decrypt HTTPS traffic). It is possible to disable the addition of the
2515 header for a known source address or network by adding the "except" keyword
2516 followed by the network address. In this case, any source IP matching the
2517 network will not cause an addition of this header. Most common uses are with
2518 private networks or 127.0.0.1.
2519
2520 This option may be specified either in the frontend or in the backend. If at
Ross Westaf72a1d2008-08-03 10:51:45 +02002521 least one of them uses it, the header will be added. Note that the backend's
2522 setting of the header subargument takes precedence over the frontend's if
2523 both are defined.
Willy Tarreauc27debf2008-01-06 08:57:02 +01002524
2525 It is important to note that as long as HAProxy does not support keep-alive
2526 connections, only the first request of a connection will receive the header.
2527 For this reason, it is important to ensure that "option httpclose" is set
2528 when using this option.
2529
Ross Westaf72a1d2008-08-03 10:51:45 +02002530 Examples :
Willy Tarreauc27debf2008-01-06 08:57:02 +01002531 # Public HTTP address also used by stunnel on the same machine
2532 frontend www
2533 mode http
2534 option forwardfor except 127.0.0.1 # stunnel already adds the header
2535
Ross Westaf72a1d2008-08-03 10:51:45 +02002536 # Those servers want the IP Address in X-Client
2537 backend www
2538 mode http
2539 option forwardfor header X-Client
2540
Willy Tarreauc27debf2008-01-06 08:57:02 +01002541 See also : "option httpclose"
2542
2543
Willy Tarreauc27debf2008-01-06 08:57:02 +01002544option httpchk
2545option httpchk <uri>
2546option httpchk <method> <uri>
2547option httpchk <method> <uri> <version>
2548 Enable HTTP protocol to check on the servers health
2549 May be used in sections : defaults | frontend | listen | backend
2550 yes | no | yes | yes
2551 Arguments :
2552 <method> is the optional HTTP method used with the requests. When not set,
2553 the "OPTIONS" method is used, as it generally requires low server
2554 processing and is easy to filter out from the logs. Any method
2555 may be used, though it is not recommended to invent non-standard
2556 ones.
2557
2558 <uri> is the URI referenced in the HTTP requests. It defaults to " / "
2559 which is accessible by default on almost any server, but may be
2560 changed to any other URI. Query strings are permitted.
2561
2562 <version> is the optional HTTP version string. It defaults to "HTTP/1.0"
2563 but some servers might behave incorrectly in HTTP 1.0, so turning
2564 it to HTTP/1.1 may sometimes help. Note that the Host field is
2565 mandatory in HTTP/1.1, and as a trick, it is possible to pass it
2566 after "\r\n" following the version string.
2567
2568 By default, server health checks only consist in trying to establish a TCP
2569 connection. When "option httpchk" is specified, a complete HTTP request is
2570 sent once the TCP connection is established, and responses 2xx and 3xx are
2571 considered valid, while all other ones indicate a server failure, including
2572 the lack of any response.
2573
2574 The port and interval are specified in the server configuration.
2575
2576 This option does not necessarily require an HTTP backend, it also works with
2577 plain TCP backends. This is particularly useful to check simple scripts bound
2578 to some dedicated ports using the inetd daemon.
2579
2580 Examples :
2581 # Relay HTTPS traffic to Apache instance and check service availability
2582 # using HTTP request "OPTIONS * HTTP/1.1" on port 80.
2583 backend https_relay
2584 mode tcp
Willy Tarreauebaf21a2008-03-21 20:17:14 +01002585 option httpchk OPTIONS * HTTP/1.1\r\nHost:\ www
Willy Tarreauc27debf2008-01-06 08:57:02 +01002586 server apache1 192.168.1.1:443 check port 80
2587
Hervé COMMOWICK698ae002010-01-12 09:25:13 +01002588 See also : "option ssl-hello-chk", "option smtpchk", "option mysql-check",
2589 "http-check" and the "check", "port" and "interval" server options.
Willy Tarreauc27debf2008-01-06 08:57:02 +01002590
2591
Willy Tarreaub608feb2010-01-02 22:47:18 +01002592option http-server-close
2593no option http-server-close
2594 Enable or disable HTTP connection closing on the server side
2595 May be used in sections : defaults | frontend | listen | backend
2596 yes | yes | yes | yes
2597 Arguments : none
2598
2599 This mode enables HTTP connection-close mode on the server side while keeping
2600 the ability to support HTTP keep-alive and pipelining on the client side.
2601 This provides the lowest latency on the client side (slow network) and the
2602 fastest session reuse on the server side to save server resources, similarly
2603 to "option forceclose". It also permits non-keepalive capable servers to be
2604 served in keep-alive mode to the clients if they conform to the requirements
2605 of RFC2616.
2606
2607 At the moment, logs will not indicate whether requests came from the same
2608 session or not. The accept date reported in the logs corresponds to the end
2609 of the previous request, and the request time corresponds to the time spent
2610 waiting for a new request. The keep-alive request time is still bound to the
Willy Tarreaub16a5742010-01-10 14:46:16 +01002611 timeout defined by "timeout http-keep-alive" or "timeout http-request" if
2612 not set.
Willy Tarreaub608feb2010-01-02 22:47:18 +01002613
2614 This option may be set both in a frontend and in a backend. It is enabled if
2615 at least one of the frontend or backend holding a connection has it enabled.
Willy Tarreau0dfdf192010-01-05 11:33:11 +01002616 It is worth noting that "option forceclose" has precedence over "option
2617 http-server-close" and that combining "http-server-close" with "httpclose"
2618 basically achieve the same result as "forceclose".
Willy Tarreaub608feb2010-01-02 22:47:18 +01002619
2620 If this option has been enabled in a "defaults" section, it can be disabled
2621 in a specific instance by prepending the "no" keyword before it.
2622
2623 See also : "option forceclose" and "option httpclose"
2624
2625
Willy Tarreauc27debf2008-01-06 08:57:02 +01002626option httpclose
2627no option httpclose
2628 Enable or disable passive HTTP connection closing
2629 May be used in sections : defaults | frontend | listen | backend
2630 yes | yes | yes | yes
2631 Arguments : none
2632
Willy Tarreauc57f0e22009-05-10 13:12:33 +02002633 As stated in section 1, HAProxy does not yes support the HTTP keep-alive
Willy Tarreauc27debf2008-01-06 08:57:02 +01002634 mode. So by default, if a client communicates with a server in this mode, it
2635 will only analyze, log, and process the first request of each connection. To
2636 workaround this limitation, it is possible to specify "option httpclose". It
2637 will check if a "Connection: close" header is already set in each direction,
2638 and will add one if missing. Each end should react to this by actively
2639 closing the TCP connection after each transfer, thus resulting in a switch to
2640 the HTTP close mode. Any "Connection" header different from "close" will also
2641 be removed.
2642
2643 It seldom happens that some servers incorrectly ignore this header and do not
Willy Tarreau0dfdf192010-01-05 11:33:11 +01002644 close the connection eventhough they reply "Connection: close". For this
2645 reason, they are not compatible with older HTTP 1.0 browsers. If this happens
2646 it is possible to use the "option forceclose" which actively closes the
2647 request connection once the server responds. Option "forceclose" also
2648 releases the server connection earlier because it does not have to wait for
2649 the client to acknowledge it.
Willy Tarreauc27debf2008-01-06 08:57:02 +01002650
2651 This option may be set both in a frontend and in a backend. It is enabled if
2652 at least one of the frontend or backend holding a connection has it enabled.
2653 If "option forceclose" is specified too, it has precedence over "httpclose".
Willy Tarreau0dfdf192010-01-05 11:33:11 +01002654 If "option http-server-close" is enabled at the same time as "httpclose", it
2655 basically achieves the same result as "option forceclose".
Willy Tarreauc27debf2008-01-06 08:57:02 +01002656
2657 If this option has been enabled in a "defaults" section, it can be disabled
2658 in a specific instance by prepending the "no" keyword before it.
2659
Willy Tarreaub608feb2010-01-02 22:47:18 +01002660 See also : "option forceclose" and "option http-server-close"
Willy Tarreauc27debf2008-01-06 08:57:02 +01002661
2662
Emeric Brun3a058f32009-06-30 18:26:00 +02002663option httplog [ clf ]
Willy Tarreauc27debf2008-01-06 08:57:02 +01002664 Enable logging of HTTP request, session state and timers
2665 May be used in sections : defaults | frontend | listen | backend
2666 yes | yes | yes | yes
Emeric Brun3a058f32009-06-30 18:26:00 +02002667 Arguments :
2668 clf if the "clf" argument is added, then the output format will be
2669 the CLF format instead of HAProxy's default HTTP format. You can
2670 use this when you need to feed HAProxy's logs through a specific
2671 log analyser which only support the CLF format and which is not
2672 extensible.
Willy Tarreauc27debf2008-01-06 08:57:02 +01002673
2674 By default, the log output format is very poor, as it only contains the
2675 source and destination addresses, and the instance name. By specifying
2676 "option httplog", each log line turns into a much richer format including,
2677 but not limited to, the HTTP request, the connection timers, the session
2678 status, the connections numbers, the captured headers and cookies, the
2679 frontend, backend and server name, and of course the source address and
2680 ports.
2681
2682 This option may be set either in the frontend or the backend.
2683
Emeric Brun3a058f32009-06-30 18:26:00 +02002684 If this option has been enabled in a "defaults" section, it can be disabled
2685 in a specific instance by prepending the "no" keyword before it. Specifying
2686 only "option httplog" will automatically clear the 'clf' mode if it was set
2687 by default.
2688
Willy Tarreauc57f0e22009-05-10 13:12:33 +02002689 See also : section 8 about logging.
Willy Tarreauc27debf2008-01-06 08:57:02 +01002690
Willy Tarreau55165fe2009-05-10 12:02:55 +02002691
2692option http_proxy
2693no option http_proxy
2694 Enable or disable plain HTTP proxy mode
2695 May be used in sections : defaults | frontend | listen | backend
2696 yes | yes | yes | yes
2697 Arguments : none
2698
2699 It sometimes happens that people need a pure HTTP proxy which understands
2700 basic proxy requests without caching nor any fancy feature. In this case,
2701 it may be worth setting up an HAProxy instance with the "option http_proxy"
2702 set. In this mode, no server is declared, and the connection is forwarded to
2703 the IP address and port found in the URL after the "http://" scheme.
2704
2705 No host address resolution is performed, so this only works when pure IP
2706 addresses are passed. Since this option's usage perimeter is rather limited,
2707 it will probably be used only by experts who know they need exactly it. Last,
2708 if the clients are susceptible of sending keep-alive requests, it will be
2709 needed to add "option http_close" to ensure that all requests will correctly
2710 be analyzed.
2711
2712 If this option has been enabled in a "defaults" section, it can be disabled
2713 in a specific instance by prepending the "no" keyword before it.
2714
2715 Example :
2716 # this backend understands HTTP proxy requests and forwards them directly.
2717 backend direct_forward
2718 option httpclose
2719 option http_proxy
2720
2721 See also : "option httpclose"
2722
Willy Tarreau211ad242009-10-03 21:45:07 +02002723
Willy Tarreauf27b5ea2009-10-03 22:01:18 +02002724option independant-streams
2725no option independant-streams
2726 Enable or disable independant timeout processing for both directions
2727 May be used in sections : defaults | frontend | listen | backend
2728 yes | yes | yes | yes
2729 Arguments : none
2730
2731 By default, when data is sent over a socket, both the write timeout and the
2732 read timeout for that socket are refreshed, because we consider that there is
2733 activity on that socket, and we have no other means of guessing if we should
2734 receive data or not.
2735
2736 While this default behaviour is desirable for almost all applications, there
2737 exists a situation where it is desirable to disable it, and only refresh the
2738 read timeout if there are incoming data. This happens on sessions with large
2739 timeouts and low amounts of exchanged data such as telnet session. If the
2740 server suddenly disappears, the output data accumulates in the system's
2741 socket buffers, both timeouts are correctly refreshed, and there is no way
2742 to know the server does not receive them, so we don't timeout. However, when
2743 the underlying protocol always echoes sent data, it would be enough by itself
2744 to detect the issue using the read timeout. Note that this problem does not
2745 happen with more verbose protocols because data won't accumulate long in the
2746 socket buffers.
2747
2748 When this option is set on the frontend, it will disable read timeout updates
2749 on data sent to the client. There probably is little use of this case. When
2750 the option is set on the backend, it will disable read timeout updates on
2751 data sent to the server. Doing so will typically break large HTTP posts from
2752 slow lines, so use it with caution.
2753
2754 See also : "timeout client" and "timeout server"
2755
2756
Willy Tarreau211ad242009-10-03 21:45:07 +02002757option log-health-checks
2758no option log-health-checks
2759 Enable or disable logging of health checks
2760 May be used in sections : defaults | frontend | listen | backend
2761 yes | no | yes | yes
2762 Arguments : none
2763
2764 Enable health checks logging so it possible to check for example what
2765 was happening before a server crash. Failed health check are logged if
2766 server is UP and succeeded health checks if server is DOWN, so the amount
2767 of additional information is limited.
2768
2769 If health check logging is enabled no health check status is printed
2770 when servers is set up UP/DOWN/ENABLED/DISABLED.
2771
2772 See also: "log" and section 8 about logging.
2773
Willy Tarreauc9bd0cc2009-05-10 11:57:02 +02002774
2775option log-separate-errors
2776no option log-separate-errors
2777 Change log level for non-completely successful connections
2778 May be used in sections : defaults | frontend | listen | backend
2779 yes | yes | yes | no
2780 Arguments : none
2781
2782 Sometimes looking for errors in logs is not easy. This option makes haproxy
2783 raise the level of logs containing potentially interesting information such
2784 as errors, timeouts, retries, redispatches, or HTTP status codes 5xx. The
2785 level changes from "info" to "err". This makes it possible to log them
2786 separately to a different file with most syslog daemons. Be careful not to
2787 remove them from the original file, otherwise you would lose ordering which
2788 provides very important information.
2789
2790 Using this option, large sites dealing with several thousand connections per
2791 second may log normal traffic to a rotating buffer and only archive smaller
2792 error logs.
2793
Willy Tarreauc57f0e22009-05-10 13:12:33 +02002794 See also : "log", "dontlognull", "dontlog-normal" and section 8 about
Willy Tarreauc9bd0cc2009-05-10 11:57:02 +02002795 logging.
2796
Willy Tarreauc27debf2008-01-06 08:57:02 +01002797
2798option logasap
2799no option logasap
2800 Enable or disable early logging of HTTP requests
2801 May be used in sections : defaults | frontend | listen | backend
2802 yes | yes | yes | no
2803 Arguments : none
2804
2805 By default, HTTP requests are logged upon termination so that the total
2806 transfer time and the number of bytes appear in the logs. When large objects
2807 are being transferred, it may take a while before the request appears in the
2808 logs. Using "option logasap", the request gets logged as soon as the server
2809 sends the complete headers. The only missing information in the logs will be
2810 the total number of bytes which will indicate everything except the amount
2811 of data transferred, and the total time which will not take the transfer
Willy Tarreaud2a4aa22008-01-31 15:28:22 +01002812 time into account. In such a situation, it's a good practice to capture the
Willy Tarreauc27debf2008-01-06 08:57:02 +01002813 "Content-Length" response header so that the logs at least indicate how many
2814 bytes are expected to be transferred.
2815
Willy Tarreaucc6c8912009-02-22 10:53:55 +01002816 Examples :
2817 listen http_proxy 0.0.0.0:80
2818 mode http
2819 option httplog
2820 option logasap
2821 log 192.168.2.200 local3
2822
2823 >>> Feb 6 12:14:14 localhost \
2824 haproxy[14389]: 10.0.1.2:33317 [06/Feb/2009:12:14:14.655] http-in \
2825 static/srv1 9/10/7/14/+30 200 +243 - - ---- 3/1/1/1/0 1/0 \
2826 "GET /image.iso HTTP/1.0"
2827
Willy Tarreauc57f0e22009-05-10 13:12:33 +02002828 See also : "option httplog", "capture response header", and section 8 about
Willy Tarreauc27debf2008-01-06 08:57:02 +01002829 logging.
2830
2831
Hervé COMMOWICK698ae002010-01-12 09:25:13 +01002832option mysql-check
2833 Use Mysql health checks for server testing
2834 May be used in sections : defaults | frontend | listen | backend
2835 yes | no | yes | yes
2836 Arguments : none
2837
2838 The check consists in parsing Mysql Handshake Initialisation packet or Error
2839 packet, which is sent by MySQL server on connect. It is a basic but useful
2840 test which does not produce any logging on the server. However, it does not
2841 check database presence nor database consistency, nor user permission to
2842 access. To do this, you can use an external check with xinetd for example.
2843
2844 Most often, an incoming MySQL server needs to see the client's IP address for
2845 various purposes, including IP privilege matching and connection logging.
2846 When possible, it is often wise to masquerade the client's IP address when
2847 connecting to the server using the "usesrc" argument of the "source" keyword,
2848 which requires the cttproxy feature to be compiled in, and the MySQL server
2849 to route the client via the machine hosting haproxy.
2850
2851 See also: "option httpchk"
2852
2853
Willy Tarreaua453bdd2008-01-08 19:50:52 +01002854option nolinger
2855no option nolinger
Krzysztof Piotr Oledzkif8645332009-12-13 21:55:50 +01002856 Enable or disable immediate session resource cleaning after close
Willy Tarreaua453bdd2008-01-08 19:50:52 +01002857 May be used in sections: defaults | frontend | listen | backend
2858 yes | yes | yes | yes
Willy Tarreaueabeafa2008-01-16 16:17:06 +01002859 Arguments : none
Willy Tarreaua453bdd2008-01-08 19:50:52 +01002860
2861 When clients or servers abort connections in a dirty way (eg: they are
2862 physically disconnected), the session timeouts triggers and the session is
2863 closed. But it will remain in FIN_WAIT1 state for some time in the system,
2864 using some resources and possibly limiting the ability to establish newer
2865 connections.
2866
2867 When this happens, it is possible to activate "option nolinger" which forces
2868 the system to immediately remove any socket's pending data on close. Thus,
2869 the session is instantly purged from the system's tables. This usually has
2870 side effects such as increased number of TCP resets due to old retransmits
2871 getting immediately rejected. Some firewalls may sometimes complain about
2872 this too.
2873
2874 For this reason, it is not recommended to use this option when not absolutely
2875 needed. You know that you need it when you have thousands of FIN_WAIT1
2876 sessions on your system (TIME_WAIT ones do not count).
2877
2878 This option may be used both on frontends and backends, depending on the side
2879 where it is required. Use it on the frontend for clients, and on the backend
2880 for servers.
2881
2882 If this option has been enabled in a "defaults" section, it can be disabled
2883 in a specific instance by prepending the "no" keyword before it.
2884
2885
Willy Tarreau55165fe2009-05-10 12:02:55 +02002886option originalto [ except <network> ] [ header <name> ]
2887 Enable insertion of the X-Original-To header to requests sent to servers
2888 May be used in sections : defaults | frontend | listen | backend
2889 yes | yes | yes | yes
2890 Arguments :
2891 <network> is an optional argument used to disable this option for sources
2892 matching <network>
2893 <name> an optional argument to specify a different "X-Original-To"
2894 header name.
2895
2896 Since HAProxy can work in transparent mode, every request from a client can
2897 be redirected to the proxy and HAProxy itself can proxy every request to a
2898 complex SQUID environment and the destination host from SO_ORIGINAL_DST will
2899 be lost. This is annoying when you want access rules based on destination ip
2900 addresses. To solve this problem, a new HTTP header "X-Original-To" may be
2901 added by HAProxy to all requests sent to the server. This header contains a
2902 value representing the original destination IP address. Since this must be
2903 configured to always use the last occurrence of this header only. Note that
2904 only the last occurrence of the header must be used, since it is really
2905 possible that the client has already brought one.
2906
2907 The keyword "header" may be used to supply a different header name to replace
2908 the default "X-Original-To". This can be useful where you might already
2909 have a "X-Original-To" header from a different application, and you need
2910 preserve it. Also if your backend server doesn't use the "X-Original-To"
2911 header and requires different one.
2912
2913 Sometimes, a same HAProxy instance may be shared between a direct client
2914 access and a reverse-proxy access (for instance when an SSL reverse-proxy is
2915 used to decrypt HTTPS traffic). It is possible to disable the addition of the
2916 header for a known source address or network by adding the "except" keyword
2917 followed by the network address. In this case, any source IP matching the
2918 network will not cause an addition of this header. Most common uses are with
2919 private networks or 127.0.0.1.
2920
2921 This option may be specified either in the frontend or in the backend. If at
2922 least one of them uses it, the header will be added. Note that the backend's
2923 setting of the header subargument takes precedence over the frontend's if
2924 both are defined.
2925
2926 It is important to note that as long as HAProxy does not support keep-alive
2927 connections, only the first request of a connection will receive the header.
2928 For this reason, it is important to ensure that "option httpclose" is set
2929 when using this option.
2930
2931 Examples :
2932 # Original Destination address
2933 frontend www
2934 mode http
2935 option originalto except 127.0.0.1
2936
2937 # Those servers want the IP Address in X-Client-Dst
2938 backend www
2939 mode http
2940 option originalto header X-Client-Dst
2941
2942 See also : "option httpclose"
2943
2944
Willy Tarreaua453bdd2008-01-08 19:50:52 +01002945option persist
2946no option persist
2947 Enable or disable forced persistence on down servers
2948 May be used in sections: defaults | frontend | listen | backend
2949 yes | no | yes | yes
Willy Tarreaueabeafa2008-01-16 16:17:06 +01002950 Arguments : none
Willy Tarreaua453bdd2008-01-08 19:50:52 +01002951
2952 When an HTTP request reaches a backend with a cookie which references a dead
2953 server, by default it is redispatched to another server. It is possible to
2954 force the request to be sent to the dead server first using "option persist"
2955 if absolutely needed. A common use case is when servers are under extreme
2956 load and spend their time flapping. In this case, the users would still be
2957 directed to the server they opened the session on, in the hope they would be
2958 correctly served. It is recommended to use "option redispatch" in conjunction
2959 with this option so that in the event it would not be possible to connect to
2960 the server at all (server definitely dead), the client would finally be
2961 redirected to another valid server.
2962
2963 If this option has been enabled in a "defaults" section, it can be disabled
2964 in a specific instance by prepending the "no" keyword before it.
2965
Willy Tarreau4de91492010-01-22 19:10:05 +01002966 See also : "option redispatch", "retries", "force-persist"
Willy Tarreaua453bdd2008-01-08 19:50:52 +01002967
2968
Krzysztof Piotr Oledzki25b501a2008-01-06 16:36:16 +01002969option redispatch
2970no option redispatch
2971 Enable or disable session redistribution in case of connection failure
2972 May be used in sections: defaults | frontend | listen | backend
2973 yes | no | yes | yes
Willy Tarreaueabeafa2008-01-16 16:17:06 +01002974 Arguments : none
Krzysztof Piotr Oledzki25b501a2008-01-06 16:36:16 +01002975
2976 In HTTP mode, if a server designated by a cookie is down, clients may
2977 definitely stick to it because they cannot flush the cookie, so they will not
2978 be able to access the service anymore.
2979
2980 Specifying "option redispatch" will allow the proxy to break their
2981 persistence and redistribute them to a working server.
2982
2983 It also allows to retry last connection to another server in case of multiple
2984 connection failures. Of course, it requires having "retries" set to a nonzero
2985 value.
Willy Tarreaud72758d2010-01-12 10:42:19 +01002986
Krzysztof Piotr Oledzki25b501a2008-01-06 16:36:16 +01002987 This form is the preferred form, which replaces both the "redispatch" and
2988 "redisp" keywords.
2989
2990 If this option has been enabled in a "defaults" section, it can be disabled
2991 in a specific instance by prepending the "no" keyword before it.
2992
Willy Tarreau4de91492010-01-22 19:10:05 +01002993 See also : "redispatch", "retries", "force-persist"
Krzysztof Piotr Oledzki25b501a2008-01-06 16:36:16 +01002994
Willy Tarreaua453bdd2008-01-08 19:50:52 +01002995
2996option smtpchk
2997option smtpchk <hello> <domain>
2998 Use SMTP health checks for server testing
2999 May be used in sections : defaults | frontend | listen | backend
3000 yes | no | yes | yes
Willy Tarreaud72758d2010-01-12 10:42:19 +01003001 Arguments :
Willy Tarreaua453bdd2008-01-08 19:50:52 +01003002 <hello> is an optional argument. It is the "hello" command to use. It can
3003 be either "HELO" (for SMTP) or "EHLO" (for ESTMP). All other
3004 values will be turned into the default command ("HELO").
3005
3006 <domain> is the domain name to present to the server. It may only be
3007 specified (and is mandatory) if the hello command has been
3008 specified. By default, "localhost" is used.
3009
3010 When "option smtpchk" is set, the health checks will consist in TCP
3011 connections followed by an SMTP command. By default, this command is
3012 "HELO localhost". The server's return code is analyzed and only return codes
3013 starting with a "2" will be considered as valid. All other responses,
3014 including a lack of response will constitute an error and will indicate a
3015 dead server.
3016
3017 This test is meant to be used with SMTP servers or relays. Depending on the
3018 request, it is possible that some servers do not log each connection attempt,
3019 so you may want to experiment to improve the behaviour. Using telnet on port
3020 25 is often easier than adjusting the configuration.
3021
3022 Most often, an incoming SMTP server needs to see the client's IP address for
3023 various purposes, including spam filtering, anti-spoofing and logging. When
3024 possible, it is often wise to masquerade the client's IP address when
3025 connecting to the server using the "usesrc" argument of the "source" keyword,
3026 which requires the cttproxy feature to be compiled in.
3027
3028 Example :
3029 option smtpchk HELO mydomain.org
3030
3031 See also : "option httpchk", "source"
3032
Krzysztof Piotr Oledzki25b501a2008-01-06 16:36:16 +01003033
Krzysztof Piotr Oledzkiaeebf9b2009-10-04 15:43:17 +02003034option socket-stats
3035no option socket-stats
3036
3037 Enable or disable collecting & providing separate statistics for each socket.
3038 May be used in sections : defaults | frontend | listen | backend
3039 yes | yes | yes | no
3040
3041 Arguments : none
3042
3043
Willy Tarreauff4f82d2009-02-06 11:28:13 +01003044option splice-auto
3045no option splice-auto
3046 Enable or disable automatic kernel acceleration on sockets in both directions
3047 May be used in sections : defaults | frontend | listen | backend
3048 yes | yes | yes | yes
3049 Arguments : none
3050
3051 When this option is enabled either on a frontend or on a backend, haproxy
3052 will automatically evaluate the opportunity to use kernel tcp splicing to
3053 forward data between the client and the server, in either direction. Haproxy
3054 uses heuristics to estimate if kernel splicing might improve performance or
Krzysztof Piotr Oledzkif8645332009-12-13 21:55:50 +01003055 not. Both directions are handled independently. Note that the heuristics used
Willy Tarreauff4f82d2009-02-06 11:28:13 +01003056 are not much aggressive in order to limit excessive use of splicing. This
3057 option requires splicing to be enabled at compile time, and may be globally
3058 disabled with the global option "nosplice". Since splice uses pipes, using it
3059 requires that there are enough spare pipes.
3060
3061 Important note: kernel-based TCP splicing is a Linux-specific feature which
3062 first appeared in kernel 2.6.25. It offers kernel-based acceleration to
3063 transfer data between sockets without copying these data to user-space, thus
3064 providing noticeable performance gains and CPU cycles savings. Since many
3065 early implementations are buggy, corrupt data and/or are inefficient, this
3066 feature is not enabled by default, and it should be used with extreme care.
3067 While it is not possible to detect the correctness of an implementation,
3068 2.6.29 is the first version offering a properly working implementation. In
3069 case of doubt, splicing may be globally disabled using the global "nosplice"
3070 keyword.
3071
3072 Example :
3073 option splice-auto
3074
3075 If this option has been enabled in a "defaults" section, it can be disabled
3076 in a specific instance by prepending the "no" keyword before it.
3077
3078 See also : "option splice-request", "option splice-response", and global
3079 options "nosplice" and "maxpipes"
3080
3081
3082option splice-request
3083no option splice-request
3084 Enable or disable automatic kernel acceleration on sockets for requests
3085 May be used in sections : defaults | frontend | listen | backend
3086 yes | yes | yes | yes
3087 Arguments : none
3088
3089 When this option is enabled either on a frontend or on a backend, haproxy
3090 will user kernel tcp splicing whenever possible to forward data going from
3091 the client to the server. It might still use the recv/send scheme if there
3092 are no spare pipes left. This option requires splicing to be enabled at
3093 compile time, and may be globally disabled with the global option "nosplice".
3094 Since splice uses pipes, using it requires that there are enough spare pipes.
3095
3096 Important note: see "option splice-auto" for usage limitations.
3097
3098 Example :
3099 option splice-request
3100
3101 If this option has been enabled in a "defaults" section, it can be disabled
3102 in a specific instance by prepending the "no" keyword before it.
3103
3104 See also : "option splice-auto", "option splice-response", and global options
3105 "nosplice" and "maxpipes"
3106
3107
3108option splice-response
3109no option splice-response
3110 Enable or disable automatic kernel acceleration on sockets for responses
3111 May be used in sections : defaults | frontend | listen | backend
3112 yes | yes | yes | yes
3113 Arguments : none
3114
3115 When this option is enabled either on a frontend or on a backend, haproxy
3116 will user kernel tcp splicing whenever possible to forward data going from
3117 the server to the client. It might still use the recv/send scheme if there
3118 are no spare pipes left. This option requires splicing to be enabled at
3119 compile time, and may be globally disabled with the global option "nosplice".
3120 Since splice uses pipes, using it requires that there are enough spare pipes.
3121
3122 Important note: see "option splice-auto" for usage limitations.
3123
3124 Example :
3125 option splice-response
3126
3127 If this option has been enabled in a "defaults" section, it can be disabled
3128 in a specific instance by prepending the "no" keyword before it.
3129
3130 See also : "option splice-auto", "option splice-request", and global options
3131 "nosplice" and "maxpipes"
3132
3133
Willy Tarreaubf1f8162007-12-28 17:42:56 +01003134option srvtcpka
3135no option srvtcpka
3136 Enable or disable the sending of TCP keepalive packets on the server side
3137 May be used in sections : defaults | frontend | listen | backend
3138 yes | no | yes | yes
3139 Arguments : none
3140
3141 When there is a firewall or any session-aware component between a client and
3142 a server, and when the protocol involves very long sessions with long idle
3143 periods (eg: remote desktops), there is a risk that one of the intermediate
3144 components decides to expire a session which has remained idle for too long.
3145
3146 Enabling socket-level TCP keep-alives makes the system regularly send packets
3147 to the other end of the connection, leaving it active. The delay between
3148 keep-alive probes is controlled by the system only and depends both on the
3149 operating system and its tuning parameters.
3150
3151 It is important to understand that keep-alive packets are neither emitted nor
3152 received at the application level. It is only the network stacks which sees
3153 them. For this reason, even if one side of the proxy already uses keep-alives
3154 to maintain its connection alive, those keep-alive packets will not be
3155 forwarded to the other side of the proxy.
3156
3157 Please note that this has nothing to do with HTTP keep-alive.
3158
3159 Using option "srvtcpka" enables the emission of TCP keep-alive probes on the
3160 server side of a connection, which should help when session expirations are
3161 noticed between HAProxy and a server.
3162
3163 If this option has been enabled in a "defaults" section, it can be disabled
3164 in a specific instance by prepending the "no" keyword before it.
3165
3166 See also : "option clitcpka", "option tcpka"
3167
3168
Willy Tarreaua453bdd2008-01-08 19:50:52 +01003169option ssl-hello-chk
3170 Use SSLv3 client hello health checks for server testing
3171 May be used in sections : defaults | frontend | listen | backend
3172 yes | no | yes | yes
3173 Arguments : none
3174
3175 When some SSL-based protocols are relayed in TCP mode through HAProxy, it is
3176 possible to test that the server correctly talks SSL instead of just testing
3177 that it accepts the TCP connection. When "option ssl-hello-chk" is set, pure
3178 SSLv3 client hello messages are sent once the connection is established to
3179 the server, and the response is analyzed to find an SSL server hello message.
3180 The server is considered valid only when the response contains this server
3181 hello message.
3182
3183 All servers tested till there correctly reply to SSLv3 client hello messages,
3184 and most servers tested do not even log the requests containing only hello
3185 messages, which is appreciable.
3186
3187 See also: "option httpchk"
3188
3189
Willy Tarreau9ea05a72009-06-14 12:07:01 +02003190option tcp-smart-accept
3191no option tcp-smart-accept
3192 Enable or disable the saving of one ACK packet during the accept sequence
3193 May be used in sections : defaults | frontend | listen | backend
3194 yes | yes | yes | no
3195 Arguments : none
3196
3197 When an HTTP connection request comes in, the system acknowledges it on
3198 behalf of HAProxy, then the client immediately sends its request, and the
3199 system acknowledges it too while it is notifying HAProxy about the new
3200 connection. HAProxy then reads the request and responds. This means that we
3201 have one TCP ACK sent by the system for nothing, because the request could
3202 very well be acknowledged by HAProxy when it sends its response.
3203
3204 For this reason, in HTTP mode, HAProxy automatically asks the system to avoid
3205 sending this useless ACK on platforms which support it (currently at least
3206 Linux). It must not cause any problem, because the system will send it anyway
3207 after 40 ms if the response takes more time than expected to come.
3208
3209 During complex network debugging sessions, it may be desirable to disable
3210 this optimization because delayed ACKs can make troubleshooting more complex
3211 when trying to identify where packets are delayed. It is then possible to
3212 fall back to normal behaviour by specifying "no option tcp-smart-accept".
3213
3214 It is also possible to force it for non-HTTP proxies by simply specifying
3215 "option tcp-smart-accept". For instance, it can make sense with some services
3216 such as SMTP where the server speaks first.
3217
3218 It is recommended to avoid forcing this option in a defaults section. In case
3219 of doubt, consider setting it back to automatic values by prepending the
3220 "default" keyword before it, or disabling it using the "no" keyword.
3221
Willy Tarreaud88edf22009-06-14 15:48:17 +02003222 See also : "option tcp-smart-connect"
3223
3224
3225option tcp-smart-connect
3226no option tcp-smart-connect
3227 Enable or disable the saving of one ACK packet during the connect sequence
3228 May be used in sections : defaults | frontend | listen | backend
3229 yes | no | yes | yes
3230 Arguments : none
3231
3232 On certain systems (at least Linux), HAProxy can ask the kernel not to
3233 immediately send an empty ACK upon a connection request, but to directly
3234 send the buffer request instead. This saves one packet on the network and
3235 thus boosts performance. It can also be useful for some servers, because they
3236 immediately get the request along with the incoming connection.
3237
3238 This feature is enabled when "option tcp-smart-connect" is set in a backend.
3239 It is not enabled by default because it makes network troubleshooting more
3240 complex.
3241
3242 It only makes sense to enable it with protocols where the client speaks first
3243 such as HTTP. In other situations, if there is no data to send in place of
3244 the ACK, a normal ACK is sent.
3245
3246 If this option has been enabled in a "defaults" section, it can be disabled
3247 in a specific instance by prepending the "no" keyword before it.
3248
3249 See also : "option tcp-smart-accept"
3250
Willy Tarreau9ea05a72009-06-14 12:07:01 +02003251
Willy Tarreaubf1f8162007-12-28 17:42:56 +01003252option tcpka
3253 Enable or disable the sending of TCP keepalive packets on both sides
3254 May be used in sections : defaults | frontend | listen | backend
3255 yes | yes | yes | yes
3256 Arguments : none
3257
3258 When there is a firewall or any session-aware component between a client and
3259 a server, and when the protocol involves very long sessions with long idle
3260 periods (eg: remote desktops), there is a risk that one of the intermediate
3261 components decides to expire a session which has remained idle for too long.
3262
3263 Enabling socket-level TCP keep-alives makes the system regularly send packets
3264 to the other end of the connection, leaving it active. The delay between
3265 keep-alive probes is controlled by the system only and depends both on the
3266 operating system and its tuning parameters.
3267
3268 It is important to understand that keep-alive packets are neither emitted nor
3269 received at the application level. It is only the network stacks which sees
3270 them. For this reason, even if one side of the proxy already uses keep-alives
3271 to maintain its connection alive, those keep-alive packets will not be
3272 forwarded to the other side of the proxy.
3273
3274 Please note that this has nothing to do with HTTP keep-alive.
3275
3276 Using option "tcpka" enables the emission of TCP keep-alive probes on both
3277 the client and server sides of a connection. Note that this is meaningful
3278 only in "defaults" or "listen" sections. If this option is used in a
3279 frontend, only the client side will get keep-alives, and if this option is
3280 used in a backend, only the server side will get keep-alives. For this
3281 reason, it is strongly recommended to explicitly use "option clitcpka" and
3282 "option srvtcpka" when the configuration is split between frontends and
3283 backends.
3284
3285 See also : "option clitcpka", "option srvtcpka"
3286
Willy Tarreau844e3c52008-01-11 16:28:18 +01003287
3288option tcplog
3289 Enable advanced logging of TCP connections with session state and timers
3290 May be used in sections : defaults | frontend | listen | backend
3291 yes | yes | yes | yes
3292 Arguments : none
3293
3294 By default, the log output format is very poor, as it only contains the
3295 source and destination addresses, and the instance name. By specifying
3296 "option tcplog", each log line turns into a much richer format including, but
3297 not limited to, the connection timers, the session status, the connections
3298 numbers, the frontend, backend and server name, and of course the source
3299 address and ports. This option is useful for pure TCP proxies in order to
3300 find which of the client or server disconnects or times out. For normal HTTP
3301 proxies, it's better to use "option httplog" which is even more complete.
3302
3303 This option may be set either in the frontend or the backend.
3304
Willy Tarreauc57f0e22009-05-10 13:12:33 +02003305 See also : "option httplog", and section 8 about logging.
Willy Tarreau844e3c52008-01-11 16:28:18 +01003306
3307
Willy Tarreau844e3c52008-01-11 16:28:18 +01003308option transparent
3309no option transparent
3310 Enable client-side transparent proxying
3311 May be used in sections : defaults | frontend | listen | backend
Willy Tarreau4b1f8592008-12-23 23:13:55 +01003312 yes | no | yes | yes
Willy Tarreau844e3c52008-01-11 16:28:18 +01003313 Arguments : none
3314
3315 This option was introduced in order to provide layer 7 persistence to layer 3
3316 load balancers. The idea is to use the OS's ability to redirect an incoming
3317 connection for a remote address to a local process (here HAProxy), and let
3318 this process know what address was initially requested. When this option is
3319 used, sessions without cookies will be forwarded to the original destination
3320 IP address of the incoming request (which should match that of another
3321 equipment), while requests with cookies will still be forwarded to the
3322 appropriate server.
3323
3324 Note that contrary to a common belief, this option does NOT make HAProxy
3325 present the client's IP to the server when establishing the connection.
3326
Willy Tarreaueabeafa2008-01-16 16:17:06 +01003327 See also: the "usersrc" argument of the "source" keyword, and the
3328 "transparent" option of the "bind" keyword.
Willy Tarreau844e3c52008-01-11 16:28:18 +01003329
Willy Tarreaubf1f8162007-12-28 17:42:56 +01003330
Emeric Brun647caf12009-06-30 17:57:00 +02003331persist rdp-cookie
3332persist rdp-cookie(name)
3333 Enable RDP cookie-based persistence
3334 May be used in sections : defaults | frontend | listen | backend
3335 yes | no | yes | yes
3336 Arguments :
3337 <name> is the optional name of the RDP cookie to check. If omitted, the
3338 default cookie name "mstshash" will be used. There currently is
3339 no valid reason to change this name.
3340
3341 This statement enables persistence based on an RDP cookie. The RDP cookie
3342 contains all information required to find the server in the list of known
3343 servers. So when this option is set in the backend, the request is analysed
3344 and if an RDP cookie is found, it is decoded. If it matches a known server
3345 which is still UP (or if "option persist" is set), then the connection is
3346 forwarded to this server.
3347
3348 Note that this only makes sense in a TCP backend, but for this to work, the
3349 frontend must have waited long enough to ensure that an RDP cookie is present
3350 in the request buffer. This is the same requirement as with the "rdp-cookie"
Krzysztof Piotr Oledzkif8645332009-12-13 21:55:50 +01003351 load-balancing method. Thus it is highly recommended to put all statements in
Emeric Brun647caf12009-06-30 17:57:00 +02003352 a single "listen" section.
3353
3354 Example :
3355 listen tse-farm
3356 bind :3389
3357 # wait up to 5s for an RDP cookie in the request
3358 tcp-request inspect-delay 5s
3359 tcp-request content accept if RDP_COOKIE
3360 # apply RDP cookie persistence
3361 persist rdp-cookie
3362 # if server is unknown, let's balance on the same cookie.
3363 # alternatively, "balance leastconn" may be useful too.
3364 balance rdp-cookie
3365 server srv1 1.1.1.1:3389
3366 server srv2 1.1.1.2:3389
3367
3368 See also : "balance rdp-cookie", "tcp-request" and the "req_rdp_cookie" ACL.
3369
3370
Willy Tarreau3a7d2072009-03-05 23:48:25 +01003371rate-limit sessions <rate>
3372 Set a limit on the number of new sessions accepted per second on a frontend
3373 May be used in sections : defaults | frontend | listen | backend
3374 yes | yes | yes | no
3375 Arguments :
3376 <rate> The <rate> parameter is an integer designating the maximum number
3377 of new sessions per second to accept on the frontend.
3378
3379 When the frontend reaches the specified number of new sessions per second, it
3380 stops accepting new connections until the rate drops below the limit again.
3381 During this time, the pending sessions will be kept in the socket's backlog
3382 (in system buffers) and haproxy will not even be aware that sessions are
3383 pending. When applying very low limit on a highly loaded service, it may make
3384 sense to increase the socket's backlog using the "backlog" keyword.
3385
3386 This feature is particularly efficient at blocking connection-based attacks
3387 or service abuse on fragile servers. Since the session rate is measured every
3388 millisecond, it is extremely accurate. Also, the limit applies immediately,
3389 no delay is needed at all to detect the threshold.
3390
3391 Example : limit the connection rate on SMTP to 10 per second max
3392 listen smtp
3393 mode tcp
3394 bind :25
3395 rate-limit sessions 10
3396 server 127.0.0.1:1025
3397
3398 Note : when the maximum rate is reached, the frontend's status appears as
3399 "FULL" in the statistics, exactly as when it is saturated.
3400
3401 See also : the "backlog" keyword and the "fe_sess_rate" ACL criterion.
3402
3403
Willy Tarreauf285f542010-01-03 20:03:03 +01003404redirect location <to> [code <code>] <option> [{if | unless} <condition>]
3405redirect prefix <to> [code <code>] <option> [{if | unless} <condition>]
Willy Tarreaub463dfb2008-06-07 23:08:56 +02003406 Return an HTTP redirection if/unless a condition is matched
3407 May be used in sections : defaults | frontend | listen | backend
3408 no | yes | yes | yes
3409
3410 If/unless the condition is matched, the HTTP request will lead to a redirect
Willy Tarreauf285f542010-01-03 20:03:03 +01003411 response. If no condition is specified, the redirect applies unconditionally.
Willy Tarreaub463dfb2008-06-07 23:08:56 +02003412
Willy Tarreau0140f252008-11-19 21:07:09 +01003413 Arguments :
3414 <to> With "redirect location", the exact value in <to> is placed into
3415 the HTTP "Location" header. In case of "redirect prefix", the
3416 "Location" header is built from the concatenation of <to> and the
3417 complete URI, including the query string, unless the "drop-query"
Willy Tarreaufe651a52008-11-19 21:15:17 +01003418 option is specified (see below). As a special case, if <to>
3419 equals exactly "/" in prefix mode, then nothing is inserted
3420 before the original URI. It allows one to redirect to the same
3421 URL.
Willy Tarreau0140f252008-11-19 21:07:09 +01003422
3423 <code> The code is optional. It indicates which type of HTTP redirection
3424 is desired. Only codes 301, 302 and 303 are supported, and 302 is
3425 used if no code is specified. 301 means "Moved permanently", and
3426 a browser may cache the Location. 302 means "Moved permanently"
3427 and means that the browser should not cache the redirection. 303
3428 is equivalent to 302 except that the browser will fetch the
3429 location with a GET method.
3430
3431 <option> There are several options which can be specified to adjust the
3432 expected behaviour of a redirection :
3433
3434 - "drop-query"
3435 When this keyword is used in a prefix-based redirection, then the
3436 location will be set without any possible query-string, which is useful
3437 for directing users to a non-secure page for instance. It has no effect
3438 with a location-type redirect.
3439
Willy Tarreau81e3b4f2010-01-10 00:42:19 +01003440 - "append-slash"
3441 This keyword may be used in conjunction with "drop-query" to redirect
3442 users who use a URL not ending with a '/' to the same one with the '/'.
3443 It can be useful to ensure that search engines will only see one URL.
3444 For this, a return code 301 is preferred.
3445
Willy Tarreau0140f252008-11-19 21:07:09 +01003446 - "set-cookie NAME[=value]"
3447 A "Set-Cookie" header will be added with NAME (and optionally "=value")
3448 to the response. This is sometimes used to indicate that a user has
3449 been seen, for instance to protect against some types of DoS. No other
3450 cookie option is added, so the cookie will be a session cookie. Note
3451 that for a browser, a sole cookie name without an equal sign is
3452 different from a cookie with an equal sign.
3453
3454 - "clear-cookie NAME[=]"
3455 A "Set-Cookie" header will be added with NAME (and optionally "="), but
3456 with the "Max-Age" attribute set to zero. This will tell the browser to
3457 delete this cookie. It is useful for instance on logout pages. It is
3458 important to note that clearing the cookie "NAME" will not remove a
3459 cookie set with "NAME=value". You have to clear the cookie "NAME=" for
3460 that, because the browser makes the difference.
Willy Tarreaub463dfb2008-06-07 23:08:56 +02003461
3462 Example: move the login URL only to HTTPS.
3463 acl clear dst_port 80
3464 acl secure dst_port 8080
3465 acl login_page url_beg /login
Willy Tarreau0140f252008-11-19 21:07:09 +01003466 acl logout url_beg /logout
Willy Tarreau79da4692008-11-19 20:03:04 +01003467 acl uid_given url_reg /login?userid=[^&]+
Willy Tarreau0140f252008-11-19 21:07:09 +01003468 acl cookie_set hdr_sub(cookie) SEEN=1
3469
3470 redirect prefix https://mysite.com set-cookie SEEN=1 if !cookie_set
Willy Tarreau79da4692008-11-19 20:03:04 +01003471 redirect prefix https://mysite.com if login_page !secure
3472 redirect prefix http://mysite.com drop-query if login_page !uid_given
3473 redirect location http://mysite.com/ if !login_page secure
Willy Tarreau0140f252008-11-19 21:07:09 +01003474 redirect location / clear-cookie USERID= if logout
Willy Tarreaub463dfb2008-06-07 23:08:56 +02003475
Willy Tarreau81e3b4f2010-01-10 00:42:19 +01003476 Example: send redirects for request for articles without a '/'.
3477 acl missing_slash path_reg ^/article/[^/]*$
3478 redirect code 301 prefix / drop-query append-slash if missing_slash
3479
Willy Tarreauc57f0e22009-05-10 13:12:33 +02003480 See section 7 about ACL usage.
Willy Tarreaub463dfb2008-06-07 23:08:56 +02003481
3482
Krzysztof Piotr Oledzki25b501a2008-01-06 16:36:16 +01003483redisp (deprecated)
3484redispatch (deprecated)
3485 Enable or disable session redistribution in case of connection failure
3486 May be used in sections: defaults | frontend | listen | backend
3487 yes | no | yes | yes
Willy Tarreaueabeafa2008-01-16 16:17:06 +01003488 Arguments : none
Krzysztof Piotr Oledzki25b501a2008-01-06 16:36:16 +01003489
3490 In HTTP mode, if a server designated by a cookie is down, clients may
3491 definitely stick to it because they cannot flush the cookie, so they will not
3492 be able to access the service anymore.
3493
3494 Specifying "redispatch" will allow the proxy to break their persistence and
3495 redistribute them to a working server.
3496
3497 It also allows to retry last connection to another server in case of multiple
3498 connection failures. Of course, it requires having "retries" set to a nonzero
3499 value.
Willy Tarreaud72758d2010-01-12 10:42:19 +01003500
Krzysztof Piotr Oledzki25b501a2008-01-06 16:36:16 +01003501 This form is deprecated, do not use it in any new configuration, use the new
3502 "option redispatch" instead.
3503
3504 See also : "option redispatch"
3505
Willy Tarreaueabeafa2008-01-16 16:17:06 +01003506
Willy Tarreau303c0352008-01-17 19:01:39 +01003507reqadd <string>
3508 Add a header at the end of the HTTP request
3509 May be used in sections : defaults | frontend | listen | backend
3510 no | yes | yes | yes
3511 Arguments :
3512 <string> is the complete line to be added. Any space or known delimiter
3513 must be escaped using a backslash ('\'). Please refer to section
Willy Tarreauc57f0e22009-05-10 13:12:33 +02003514 6 about HTTP header manipulation for more information.
Willy Tarreau303c0352008-01-17 19:01:39 +01003515
3516 A new line consisting in <string> followed by a line feed will be added after
3517 the last header of an HTTP request.
3518
3519 Header transformations only apply to traffic which passes through HAProxy,
3520 and not to traffic generated by HAProxy, such as health-checks or error
3521 responses.
3522
Willy Tarreauc57f0e22009-05-10 13:12:33 +02003523 See also: "rspadd" and section 6 about HTTP header manipulation
Willy Tarreau303c0352008-01-17 19:01:39 +01003524
3525
3526reqallow <search>
3527reqiallow <search> (ignore case)
3528 Definitely allow an HTTP request if a line matches a regular expression
3529 May be used in sections : defaults | frontend | listen | backend
3530 no | yes | yes | yes
3531 Arguments :
3532 <search> is the regular expression applied to HTTP headers and to the
3533 request line. This is an extended regular expression. Parenthesis
3534 grouping is supported and no preliminary backslash is required.
3535 Any space or known delimiter must be escaped using a backslash
3536 ('\'). The pattern applies to a full line at a time. The
3537 "reqallow" keyword strictly matches case while "reqiallow"
3538 ignores case.
3539
3540 A request containing any line which matches extended regular expression
3541 <search> will mark the request as allowed, even if any later test would
3542 result in a deny. The test applies both to the request line and to request
3543 headers. Keep in mind that URLs in request line are case-sensitive while
Willy Tarreaud72758d2010-01-12 10:42:19 +01003544 header names are not.
Willy Tarreau303c0352008-01-17 19:01:39 +01003545
3546 It is easier, faster and more powerful to use ACLs to write access policies.
3547 Reqdeny, reqallow and reqpass should be avoided in new designs.
3548
3549 Example :
3550 # allow www.* but refuse *.local
3551 reqiallow ^Host:\ www\.
3552 reqideny ^Host:\ .*\.local
3553
Willy Tarreauc57f0e22009-05-10 13:12:33 +02003554 See also: "reqdeny", "acl", "block" and section 6 about HTTP header
Willy Tarreau303c0352008-01-17 19:01:39 +01003555 manipulation
3556
3557
3558reqdel <search>
3559reqidel <search> (ignore case)
3560 Delete all headers matching a regular expression in an HTTP request
3561 May be used in sections : defaults | frontend | listen | backend
3562 no | yes | yes | yes
3563 Arguments :
3564 <search> is the regular expression applied to HTTP headers and to the
3565 request line. This is an extended regular expression. Parenthesis
3566 grouping is supported and no preliminary backslash is required.
3567 Any space or known delimiter must be escaped using a backslash
3568 ('\'). The pattern applies to a full line at a time. The "reqdel"
3569 keyword strictly matches case while "reqidel" ignores case.
3570
3571 Any header line matching extended regular expression <search> in the request
3572 will be completely deleted. Most common use of this is to remove unwanted
3573 and/or dangerous headers or cookies from a request before passing it to the
3574 next servers.
3575
3576 Header transformations only apply to traffic which passes through HAProxy,
3577 and not to traffic generated by HAProxy, such as health-checks or error
3578 responses. Keep in mind that header names are not case-sensitive.
3579
3580 Example :
3581 # remove X-Forwarded-For header and SERVER cookie
3582 reqidel ^X-Forwarded-For:.*
3583 reqidel ^Cookie:.*SERVER=
3584
Willy Tarreauc57f0e22009-05-10 13:12:33 +02003585 See also: "reqadd", "reqrep", "rspdel" and section 6 about HTTP header
Willy Tarreau303c0352008-01-17 19:01:39 +01003586 manipulation
3587
3588
3589reqdeny <search>
3590reqideny <search> (ignore case)
3591 Deny an HTTP request if a line matches a regular expression
3592 May be used in sections : defaults | frontend | listen | backend
3593 no | yes | yes | yes
3594 Arguments :
3595 <search> is the regular expression applied to HTTP headers and to the
3596 request line. This is an extended regular expression. Parenthesis
3597 grouping is supported and no preliminary backslash is required.
3598 Any space or known delimiter must be escaped using a backslash
3599 ('\'). The pattern applies to a full line at a time. The
3600 "reqdeny" keyword strictly matches case while "reqideny" ignores
3601 case.
3602
3603 A request containing any line which matches extended regular expression
3604 <search> will mark the request as denied, even if any later test would
3605 result in an allow. The test applies both to the request line and to request
3606 headers. Keep in mind that URLs in request line are case-sensitive while
Willy Tarreaud72758d2010-01-12 10:42:19 +01003607 header names are not.
Willy Tarreau303c0352008-01-17 19:01:39 +01003608
Willy Tarreauced27012008-01-17 20:35:34 +01003609 A denied request will generate an "HTTP 403 forbidden" response once the
Willy Tarreaud2a4aa22008-01-31 15:28:22 +01003610 complete request has been parsed. This is consistent with what is practiced
Willy Tarreaud72758d2010-01-12 10:42:19 +01003611 using ACLs.
Willy Tarreauced27012008-01-17 20:35:34 +01003612
Willy Tarreau303c0352008-01-17 19:01:39 +01003613 It is easier, faster and more powerful to use ACLs to write access policies.
3614 Reqdeny, reqallow and reqpass should be avoided in new designs.
3615
3616 Example :
3617 # refuse *.local, then allow www.*
3618 reqideny ^Host:\ .*\.local
3619 reqiallow ^Host:\ www\.
3620
Willy Tarreauc57f0e22009-05-10 13:12:33 +02003621 See also: "reqallow", "rspdeny", "acl", "block" and section 6 about HTTP
Willy Tarreau303c0352008-01-17 19:01:39 +01003622 header manipulation
3623
3624
3625reqpass <search>
3626reqipass <search> (ignore case)
3627 Ignore any HTTP request line matching a regular expression in next rules
3628 May be used in sections : defaults | frontend | listen | backend
3629 no | yes | yes | yes
3630 Arguments :
3631 <search> is the regular expression applied to HTTP headers and to the
3632 request line. This is an extended regular expression. Parenthesis
3633 grouping is supported and no preliminary backslash is required.
3634 Any space or known delimiter must be escaped using a backslash
3635 ('\'). The pattern applies to a full line at a time. The
3636 "reqpass" keyword strictly matches case while "reqipass" ignores
3637 case.
3638
3639 A request containing any line which matches extended regular expression
3640 <search> will skip next rules, without assigning any deny or allow verdict.
3641 The test applies both to the request line and to request headers. Keep in
3642 mind that URLs in request line are case-sensitive while header names are not.
3643
3644 It is easier, faster and more powerful to use ACLs to write access policies.
3645 Reqdeny, reqallow and reqpass should be avoided in new designs.
3646
3647 Example :
3648 # refuse *.local, then allow www.*, but ignore "www.private.local"
3649 reqipass ^Host:\ www.private\.local
3650 reqideny ^Host:\ .*\.local
3651 reqiallow ^Host:\ www\.
3652
Willy Tarreauc57f0e22009-05-10 13:12:33 +02003653 See also: "reqallow", "reqdeny", "acl", "block" and section 6 about HTTP
Willy Tarreau303c0352008-01-17 19:01:39 +01003654 header manipulation
3655
3656
3657reqrep <search> <string>
3658reqirep <search> <string> (ignore case)
3659 Replace a regular expression with a string in an HTTP request line
3660 May be used in sections : defaults | frontend | listen | backend
3661 no | yes | yes | yes
3662 Arguments :
3663 <search> is the regular expression applied to HTTP headers and to the
3664 request line. This is an extended regular expression. Parenthesis
3665 grouping is supported and no preliminary backslash is required.
3666 Any space or known delimiter must be escaped using a backslash
3667 ('\'). The pattern applies to a full line at a time. The "reqrep"
3668 keyword strictly matches case while "reqirep" ignores case.
3669
3670 <string> is the complete line to be added. Any space or known delimiter
3671 must be escaped using a backslash ('\'). References to matched
3672 pattern groups are possible using the common \N form, with N
3673 being a single digit between 0 and 9. Please refer to section
Willy Tarreauc57f0e22009-05-10 13:12:33 +02003674 6 about HTTP header manipulation for more information.
Willy Tarreau303c0352008-01-17 19:01:39 +01003675
3676 Any line matching extended regular expression <search> in the request (both
3677 the request line and header lines) will be completely replaced with <string>.
3678 Most common use of this is to rewrite URLs or domain names in "Host" headers.
3679
3680 Header transformations only apply to traffic which passes through HAProxy,
3681 and not to traffic generated by HAProxy, such as health-checks or error
3682 responses. Note that for increased readability, it is suggested to add enough
3683 spaces between the request and the response. Keep in mind that URLs in
3684 request line are case-sensitive while header names are not.
3685
3686 Example :
3687 # replace "/static/" with "/" at the beginning of any request path.
3688 reqrep ^([^\ ]*)\ /static/(.*) \1\ /\2
3689 # replace "www.mydomain.com" with "www" in the host name.
3690 reqirep ^Host:\ www.mydomain.com Host:\ www
3691
Willy Tarreauc57f0e22009-05-10 13:12:33 +02003692 See also: "reqadd", "reqdel", "rsprep" and section 6 about HTTP header
Willy Tarreau303c0352008-01-17 19:01:39 +01003693 manipulation
3694
3695
3696reqtarpit <search>
3697reqitarpit <search> (ignore case)
3698 Tarpit an HTTP request containing a line matching a regular expression
3699 May be used in sections : defaults | frontend | listen | backend
3700 no | yes | yes | yes
3701 Arguments :
3702 <search> is the regular expression applied to HTTP headers and to the
3703 request line. This is an extended regular expression. Parenthesis
3704 grouping is supported and no preliminary backslash is required.
3705 Any space or known delimiter must be escaped using a backslash
3706 ('\'). The pattern applies to a full line at a time. The
3707 "reqtarpit" keyword strictly matches case while "reqitarpit"
3708 ignores case.
3709
3710 A request containing any line which matches extended regular expression
3711 <search> will be tarpitted, which means that it will connect to nowhere, will
Willy Tarreauced27012008-01-17 20:35:34 +01003712 be kept open for a pre-defined time, then will return an HTTP error 500 so
3713 that the attacker does not suspect it has been tarpitted. The status 500 will
3714 be reported in the logs, but the completion flags will indicate "PT". The
Willy Tarreau303c0352008-01-17 19:01:39 +01003715 delay is defined by "timeout tarpit", or "timeout connect" if the former is
3716 not set.
3717
3718 The goal of the tarpit is to slow down robots attacking servers with
3719 identifiable requests. Many robots limit their outgoing number of connections
3720 and stay connected waiting for a reply which can take several minutes to
3721 come. Depending on the environment and attack, it may be particularly
3722 efficient at reducing the load on the network and firewalls.
3723
3724 Example :
3725 # ignore user-agents reporting any flavour of "Mozilla" or "MSIE", but
3726 # block all others.
3727 reqipass ^User-Agent:\.*(Mozilla|MSIE)
3728 reqitarpit ^User-Agent:
3729
Willy Tarreauc57f0e22009-05-10 13:12:33 +02003730 See also: "reqallow", "reqdeny", "reqpass", and section 6 about HTTP header
Willy Tarreau303c0352008-01-17 19:01:39 +01003731 manipulation
3732
3733
Willy Tarreaue5c5ce92008-06-20 17:27:19 +02003734retries <value>
3735 Set the number of retries to perform on a server after a connection failure
3736 May be used in sections: defaults | frontend | listen | backend
3737 yes | no | yes | yes
3738 Arguments :
3739 <value> is the number of times a connection attempt should be retried on
3740 a server when a connection either is refused or times out. The
3741 default value is 3.
3742
3743 It is important to understand that this value applies to the number of
3744 connection attempts, not full requests. When a connection has effectively
3745 been established to a server, there will be no more retry.
3746
3747 In order to avoid immediate reconnections to a server which is restarting,
3748 a turn-around timer of 1 second is applied before a retry occurs.
3749
3750 When "option redispatch" is set, the last retry may be performed on another
3751 server even if a cookie references a different server.
3752
3753 See also : "option redispatch"
3754
3755
Willy Tarreau303c0352008-01-17 19:01:39 +01003756rspadd <string>
3757 Add a header at the end of the HTTP response
3758 May be used in sections : defaults | frontend | listen | backend
3759 no | yes | yes | yes
3760 Arguments :
3761 <string> is the complete line to be added. Any space or known delimiter
3762 must be escaped using a backslash ('\'). Please refer to section
Willy Tarreauc57f0e22009-05-10 13:12:33 +02003763 6 about HTTP header manipulation for more information.
Willy Tarreau303c0352008-01-17 19:01:39 +01003764
3765 A new line consisting in <string> followed by a line feed will be added after
3766 the last header of an HTTP response.
3767
3768 Header transformations only apply to traffic which passes through HAProxy,
3769 and not to traffic generated by HAProxy, such as health-checks or error
3770 responses.
3771
Willy Tarreauc57f0e22009-05-10 13:12:33 +02003772 See also: "reqadd" and section 6 about HTTP header manipulation
Willy Tarreau303c0352008-01-17 19:01:39 +01003773
3774
3775rspdel <search>
3776rspidel <search> (ignore case)
3777 Delete all headers matching a regular expression in an HTTP response
3778 May be used in sections : defaults | frontend | listen | backend
3779 no | yes | yes | yes
3780 Arguments :
3781 <search> is the regular expression applied to HTTP headers and to the
3782 response line. This is an extended regular expression, so
3783 parenthesis grouping is supported and no preliminary backslash
3784 is required. Any space or known delimiter must be escaped using
3785 a backslash ('\'). The pattern applies to a full line at a time.
3786 The "rspdel" keyword strictly matches case while "rspidel"
3787 ignores case.
3788
3789 Any header line matching extended regular expression <search> in the response
3790 will be completely deleted. Most common use of this is to remove unwanted
3791 and/or sensible headers or cookies from a response before passing it to the
3792 client.
3793
3794 Header transformations only apply to traffic which passes through HAProxy,
3795 and not to traffic generated by HAProxy, such as health-checks or error
3796 responses. Keep in mind that header names are not case-sensitive.
3797
3798 Example :
3799 # remove the Server header from responses
3800 reqidel ^Server:.*
3801
Willy Tarreauc57f0e22009-05-10 13:12:33 +02003802 See also: "rspadd", "rsprep", "reqdel" and section 6 about HTTP header
Willy Tarreau303c0352008-01-17 19:01:39 +01003803 manipulation
3804
3805
3806rspdeny <search>
3807rspideny <search> (ignore case)
3808 Block an HTTP response if a line matches a regular expression
3809 May be used in sections : defaults | frontend | listen | backend
3810 no | yes | yes | yes
3811 Arguments :
3812 <search> is the regular expression applied to HTTP headers and to the
3813 response line. This is an extended regular expression, so
3814 parenthesis grouping is supported and no preliminary backslash
3815 is required. Any space or known delimiter must be escaped using
3816 a backslash ('\'). The pattern applies to a full line at a time.
3817 The "rspdeny" keyword strictly matches case while "rspideny"
3818 ignores case.
3819
3820 A response containing any line which matches extended regular expression
3821 <search> will mark the request as denied. The test applies both to the
3822 response line and to response headers. Keep in mind that header names are not
3823 case-sensitive.
3824
3825 Main use of this keyword is to prevent sensitive information leak and to
Willy Tarreauced27012008-01-17 20:35:34 +01003826 block the response before it reaches the client. If a response is denied, it
3827 will be replaced with an HTTP 502 error so that the client never retrieves
3828 any sensitive data.
Willy Tarreau303c0352008-01-17 19:01:39 +01003829
3830 It is easier, faster and more powerful to use ACLs to write access policies.
3831 Rspdeny should be avoided in new designs.
3832
3833 Example :
3834 # Ensure that no content type matching ms-word will leak
3835 rspideny ^Content-type:\.*/ms-word
3836
Willy Tarreauc57f0e22009-05-10 13:12:33 +02003837 See also: "reqdeny", "acl", "block" and section 6 about HTTP header
Willy Tarreau303c0352008-01-17 19:01:39 +01003838 manipulation
3839
3840
3841rsprep <search> <string>
3842rspirep <search> <string> (ignore case)
3843 Replace a regular expression with a string in an HTTP response line
3844 May be used in sections : defaults | frontend | listen | backend
3845 no | yes | yes | yes
3846 Arguments :
3847 <search> is the regular expression applied to HTTP headers and to the
3848 response line. This is an extended regular expression, so
3849 parenthesis grouping is supported and no preliminary backslash
3850 is required. Any space or known delimiter must be escaped using
3851 a backslash ('\'). The pattern applies to a full line at a time.
3852 The "rsprep" keyword strictly matches case while "rspirep"
3853 ignores case.
3854
3855 <string> is the complete line to be added. Any space or known delimiter
3856 must be escaped using a backslash ('\'). References to matched
3857 pattern groups are possible using the common \N form, with N
3858 being a single digit between 0 and 9. Please refer to section
Willy Tarreauc57f0e22009-05-10 13:12:33 +02003859 6 about HTTP header manipulation for more information.
Willy Tarreau303c0352008-01-17 19:01:39 +01003860
3861 Any line matching extended regular expression <search> in the response (both
3862 the response line and header lines) will be completely replaced with
3863 <string>. Most common use of this is to rewrite Location headers.
3864
3865 Header transformations only apply to traffic which passes through HAProxy,
3866 and not to traffic generated by HAProxy, such as health-checks or error
3867 responses. Note that for increased readability, it is suggested to add enough
3868 spaces between the request and the response. Keep in mind that header names
3869 are not case-sensitive.
3870
3871 Example :
3872 # replace "Location: 127.0.0.1:8080" with "Location: www.mydomain.com"
3873 rspirep ^Location:\ 127.0.0.1:8080 Location:\ www.mydomain.com
3874
Willy Tarreauc57f0e22009-05-10 13:12:33 +02003875 See also: "rspadd", "rspdel", "reqrep" and section 6 about HTTP header
Willy Tarreau303c0352008-01-17 19:01:39 +01003876 manipulation
3877
3878
Willy Tarreaueabeafa2008-01-16 16:17:06 +01003879server <name> <address>[:port] [param*]
3880 Declare a server in a backend
3881 May be used in sections : defaults | frontend | listen | backend
3882 no | no | yes | yes
3883 Arguments :
3884 <name> is the internal name assigned to this server. This name will
3885 appear in logs and alerts.
3886
3887 <address> is the IPv4 address of the server. Alternatively, a resolvable
3888 hostname is supported, but this name will be resolved during
3889 start-up.
3890
3891 <ports> is an optional port specification. If set, all connections will
3892 be sent to this port. If unset, the same port the client
3893 connected to will be used. The port may also be prefixed by a "+"
3894 or a "-". In this case, the server's port will be determined by
3895 adding this value to the client's port.
3896
3897 <param*> is a list of parameters for this server. The "server" keywords
3898 accepts an important number of options and has a complete section
Willy Tarreauc57f0e22009-05-10 13:12:33 +02003899 dedicated to it. Please refer to section 5 for more details.
Willy Tarreaueabeafa2008-01-16 16:17:06 +01003900
3901 Examples :
3902 server first 10.1.1.1:1080 cookie first check inter 1000
3903 server second 10.1.1.2:1080 cookie second check inter 1000
3904
Krzysztof Piotr Oledzkic6df0662010-01-05 16:38:49 +01003905 See also: "default-server" and section 5 about server options
Willy Tarreaueabeafa2008-01-16 16:17:06 +01003906
3907
3908source <addr>[:<port>] [usesrc { <addr2>[:<port2>] | client | clientip } ]
Willy Tarreaud53f96b2009-02-04 18:46:54 +01003909source <addr>[:<port>] [interface <name>]
Willy Tarreaueabeafa2008-01-16 16:17:06 +01003910 Set the source address for outgoing connections
3911 May be used in sections : defaults | frontend | listen | backend
3912 yes | no | yes | yes
3913 Arguments :
3914 <addr> is the IPv4 address HAProxy will bind to before connecting to a
3915 server. This address is also used as a source for health checks.
3916 The default value of 0.0.0.0 means that the system will select
3917 the most appropriate address to reach its destination.
3918
3919 <port> is an optional port. It is normally not needed but may be useful
3920 in some very specific contexts. The default value of zero means
Willy Tarreauc6f4ce82009-06-10 11:09:37 +02003921 the system will select a free port. Note that port ranges are not
3922 supported in the backend. If you want to force port ranges, you
3923 have to specify them on each "server" line.
Willy Tarreaueabeafa2008-01-16 16:17:06 +01003924
3925 <addr2> is the IP address to present to the server when connections are
3926 forwarded in full transparent proxy mode. This is currently only
3927 supported on some patched Linux kernels. When this address is
3928 specified, clients connecting to the server will be presented
3929 with this address, while health checks will still use the address
3930 <addr>.
3931
3932 <port2> is the optional port to present to the server when connections
3933 are forwarded in full transparent proxy mode (see <addr2> above).
3934 The default value of zero means the system will select a free
3935 port.
3936
Willy Tarreaud53f96b2009-02-04 18:46:54 +01003937 <name> is an optional interface name to which to bind to for outgoing
3938 traffic. On systems supporting this features (currently, only
3939 Linux), this allows one to bind all traffic to the server to
3940 this interface even if it is not the one the system would select
3941 based on routing tables. This should be used with extreme care.
3942 Note that using this option requires root privileges.
3943
Willy Tarreaueabeafa2008-01-16 16:17:06 +01003944 The "source" keyword is useful in complex environments where a specific
3945 address only is allowed to connect to the servers. It may be needed when a
3946 private address must be used through a public gateway for instance, and it is
3947 known that the system cannot determine the adequate source address by itself.
3948
3949 An extension which is available on certain patched Linux kernels may be used
3950 through the "usesrc" optional keyword. It makes it possible to connect to the
3951 servers with an IP address which does not belong to the system itself. This
3952 is called "full transparent proxy mode". For this to work, the destination
3953 servers have to route their traffic back to this address through the machine
3954 running HAProxy, and IP forwarding must generally be enabled on this machine.
3955
3956 In this "full transparent proxy" mode, it is possible to force a specific IP
3957 address to be presented to the servers. This is not much used in fact. A more
3958 common use is to tell HAProxy to present the client's IP address. For this,
3959 there are two methods :
3960
3961 - present the client's IP and port addresses. This is the most transparent
3962 mode, but it can cause problems when IP connection tracking is enabled on
3963 the machine, because a same connection may be seen twice with different
3964 states. However, this solution presents the huge advantage of not
3965 limiting the system to the 64k outgoing address+port couples, because all
3966 of the client ranges may be used.
3967
3968 - present only the client's IP address and select a spare port. This
3969 solution is still quite elegant but slightly less transparent (downstream
3970 firewalls logs will not match upstream's). It also presents the downside
3971 of limiting the number of concurrent connections to the usual 64k ports.
3972 However, since the upstream and downstream ports are different, local IP
3973 connection tracking on the machine will not be upset by the reuse of the
3974 same session.
3975
3976 Note that depending on the transparent proxy technology used, it may be
3977 required to force the source address. In fact, cttproxy version 2 requires an
3978 IP address in <addr> above, and does not support setting of "0.0.0.0" as the
3979 IP address because it creates NAT entries which much match the exact outgoing
3980 address. Tproxy version 4 and some other kernel patches which work in pure
3981 forwarding mode generally will not have this limitation.
3982
3983 This option sets the default source for all servers in the backend. It may
3984 also be specified in a "defaults" section. Finer source address specification
3985 is possible at the server level using the "source" server option. Refer to
Willy Tarreauc57f0e22009-05-10 13:12:33 +02003986 section 5 for more information.
Willy Tarreaueabeafa2008-01-16 16:17:06 +01003987
3988 Examples :
3989 backend private
3990 # Connect to the servers using our 192.168.1.200 source address
3991 source 192.168.1.200
3992
3993 backend transparent_ssl1
3994 # Connect to the SSL farm from the client's source address
3995 source 192.168.1.200 usesrc clientip
3996
3997 backend transparent_ssl2
3998 # Connect to the SSL farm from the client's source address and port
3999 # not recommended if IP conntrack is present on the local machine.
4000 source 192.168.1.200 usesrc client
4001
4002 backend transparent_ssl3
4003 # Connect to the SSL farm from the client's source address. It
4004 # is more conntrack-friendly.
4005 source 192.168.1.200 usesrc clientip
4006
4007 backend transparent_smtp
4008 # Connect to the SMTP farm from the client's source address/port
4009 # with Tproxy version 4.
4010 source 0.0.0.0 usesrc clientip
4011
Willy Tarreauc57f0e22009-05-10 13:12:33 +02004012 See also : the "source" server option in section 5, the Tproxy patches for
Willy Tarreaueabeafa2008-01-16 16:17:06 +01004013 the Linux kernel on www.balabit.com, the "bind" keyword.
4014
Krzysztof Piotr Oledzki25b501a2008-01-06 16:36:16 +01004015
Willy Tarreau844e3c52008-01-11 16:28:18 +01004016srvtimeout <timeout> (deprecated)
4017 Set the maximum inactivity time on the server side.
4018 May be used in sections : defaults | frontend | listen | backend
4019 yes | no | yes | yes
4020 Arguments :
4021 <timeout> is the timeout value specified in milliseconds by default, but
4022 can be in any other unit if the number is suffixed by the unit,
4023 as explained at the top of this document.
4024
4025 The inactivity timeout applies when the server is expected to acknowledge or
4026 send data. In HTTP mode, this timeout is particularly important to consider
4027 during the first phase of the server's response, when it has to send the
4028 headers, as it directly represents the server's processing time for the
4029 request. To find out what value to put there, it's often good to start with
4030 what would be considered as unacceptable response times, then check the logs
4031 to observe the response time distribution, and adjust the value accordingly.
4032
4033 The value is specified in milliseconds by default, but can be in any other
4034 unit if the number is suffixed by the unit, as specified at the top of this
4035 document. In TCP mode (and to a lesser extent, in HTTP mode), it is highly
4036 recommended that the client timeout remains equal to the server timeout in
4037 order to avoid complex situations to debug. Whatever the expected server
Willy Tarreaud2a4aa22008-01-31 15:28:22 +01004038 response times, it is a good practice to cover at least one or several TCP
Willy Tarreau844e3c52008-01-11 16:28:18 +01004039 packet losses by specifying timeouts that are slightly above multiples of 3
Willy Tarreaud72758d2010-01-12 10:42:19 +01004040 seconds (eg: 4 or 5 seconds minimum).
Willy Tarreau844e3c52008-01-11 16:28:18 +01004041
4042 This parameter is specific to backends, but can be specified once for all in
4043 "defaults" sections. This is in fact one of the easiest solutions not to
4044 forget about it. An unspecified timeout results in an infinite timeout, which
4045 is not recommended. Such a usage is accepted and works but reports a warning
4046 during startup because it may results in accumulation of expired sessions in
4047 the system if the system's timeouts are not configured either.
4048
4049 This parameter is provided for compatibility but is currently deprecated.
4050 Please use "timeout server" instead.
4051
4052 See also : "timeout server", "timeout client" and "clitimeout".
4053
4054
Willy Tarreaueabeafa2008-01-16 16:17:06 +01004055stats auth <user>:<passwd>
4056 Enable statistics with authentication and grant access to an account
4057 May be used in sections : defaults | frontend | listen | backend
4058 yes | no | yes | yes
4059 Arguments :
4060 <user> is a user name to grant access to
4061
4062 <passwd> is the cleartext password associated to this user
4063
4064 This statement enables statistics with default settings, and restricts access
4065 to declared users only. It may be repeated as many times as necessary to
4066 allow as many users as desired. When a user tries to access the statistics
4067 without a valid account, a "401 Forbidden" response will be returned so that
4068 the browser asks the user to provide a valid user and password. The real
4069 which will be returned to the browser is configurable using "stats realm".
4070
4071 Since the authentication method is HTTP Basic Authentication, the passwords
4072 circulate in cleartext on the network. Thus, it was decided that the
4073 configuration file would also use cleartext passwords to remind the users
4074 that those ones should not be sensible and not shared with any other account.
4075
4076 It is also possible to reduce the scope of the proxies which appear in the
4077 report using "stats scope".
4078
4079 Though this statement alone is enough to enable statistics reporting, it is
4080 recommended to set all other settings in order to avoid relying on default
4081 unobvious parameters.
4082
4083 Example :
4084 # public access (limited to this backend only)
4085 backend public_www
4086 server srv1 192.168.0.1:80
4087 stats enable
4088 stats hide-version
4089 stats scope .
4090 stats uri /admin?stats
4091 stats realm Haproxy\ Statistics
4092 stats auth admin1:AdMiN123
4093 stats auth admin2:AdMiN321
4094
4095 # internal monitoring access (unlimited)
4096 backend private_monitoring
4097 stats enable
4098 stats uri /admin?stats
4099 stats refresh 5s
4100
4101 See also : "stats enable", "stats realm", "stats scope", "stats uri"
4102
4103
4104stats enable
4105 Enable statistics reporting with default settings
4106 May be used in sections : defaults | frontend | listen | backend
4107 yes | no | yes | yes
4108 Arguments : none
4109
4110 This statement enables statistics reporting with default settings defined
4111 at build time. Unless stated otherwise, these settings are used :
4112 - stats uri : /haproxy?stats
4113 - stats realm : "HAProxy Statistics"
4114 - stats auth : no authentication
4115 - stats scope : no restriction
4116
4117 Though this statement alone is enough to enable statistics reporting, it is
4118 recommended to set all other settings in order to avoid relying on default
4119 unobvious parameters.
4120
4121 Example :
4122 # public access (limited to this backend only)
4123 backend public_www
4124 server srv1 192.168.0.1:80
4125 stats enable
4126 stats hide-version
4127 stats scope .
4128 stats uri /admin?stats
4129 stats realm Haproxy\ Statistics
4130 stats auth admin1:AdMiN123
4131 stats auth admin2:AdMiN321
4132
4133 # internal monitoring access (unlimited)
4134 backend private_monitoring
4135 stats enable
4136 stats uri /admin?stats
4137 stats refresh 5s
4138
4139 See also : "stats auth", "stats realm", "stats uri"
4140
4141
Krzysztof Piotr Oledzki48cb2ae2009-10-02 22:51:14 +02004142stats show-node [ <name> ]
Willy Tarreau1d45b7c2009-08-16 10:29:18 +02004143 Enable reporting of a host name on the statistics page.
4144 May be used in sections : defaults | frontend | listen | backend
4145 yes | no | yes | yes
Krzysztof Piotr Oledzki48cb2ae2009-10-02 22:51:14 +02004146 Arguments:
4147 <name> is an optional name to be reported. If unspecified, the
4148 node name from global section is automatically used instead.
Willy Tarreau1d45b7c2009-08-16 10:29:18 +02004149
Krzysztof Piotr Oledzki48cb2ae2009-10-02 22:51:14 +02004150 This statement is useful for users that offer shared services to their
4151 customers, where node or description might be different on a stats page
4152 provided for each customer.
Willy Tarreau1d45b7c2009-08-16 10:29:18 +02004153
Krzysztof Piotr Oledzki48cb2ae2009-10-02 22:51:14 +02004154 Though this statement alone is enough to enable statistics reporting, it is
4155 recommended to set all other settings in order to avoid relying on default
4156 unobvious parameters.
4157
4158 Example:
4159 # internal monitoring access (unlimited)
4160 backend private_monitoring
4161 stats enable
4162 stats show-node Europe-1
4163 stats uri /admin?stats
4164 stats refresh 5s
4165
Willy Tarreau983e01e2010-01-11 18:42:06 +01004166 See also: "show-desc", "stats enable", "stats uri", and "node" in global
4167 section.
Krzysztof Piotr Oledzki48cb2ae2009-10-02 22:51:14 +02004168
4169
4170stats show-desc [ <description> ]
4171 Enable reporting of a description on the statistics page.
4172 May be used in sections : defaults | frontend | listen | backend
4173 yes | no | yes | yes
4174
4175 <name> is an optional description to be reported. If unspecified, the
4176 description from global section is automatically used instead.
4177
4178 This statement is useful for users that offer shared services to their
4179 customers, where node or description should be different for each customer.
Willy Tarreau1d45b7c2009-08-16 10:29:18 +02004180
4181 Though this statement alone is enough to enable statistics reporting, it is
4182 recommended to set all other settings in order to avoid relying on default
4183 unobvious parameters.
4184
4185 Example :
4186 # internal monitoring access (unlimited)
4187 backend private_monitoring
4188 stats enable
Krzysztof Piotr Oledzki48cb2ae2009-10-02 22:51:14 +02004189 stats show-desc Master node for Europe, Asia, Africa
Willy Tarreau1d45b7c2009-08-16 10:29:18 +02004190 stats uri /admin?stats
4191 stats refresh 5s
4192
Willy Tarreau983e01e2010-01-11 18:42:06 +01004193 See also: "show-node", "stats enable", "stats uri" and "description" in
4194 global section.
4195
Willy Tarreau1d45b7c2009-08-16 10:29:18 +02004196
Krzysztof Piotr Oledzki15514c22010-01-04 16:03:09 +01004197stats show-legends
4198 Enable reporting additional informations on the statistics page :
4199 - cap: capabilities (proxy)
4200 - mode: one of tcp, http or health (proxy)
4201 - id: SNMP ID (proxy, socket, server)
4202 - IP (socket, server)
4203 - cookie (backend, server)
4204
4205 Though this statement alone is enough to enable statistics reporting, it is
4206 recommended to set all other settings in order to avoid relying on default
4207 unobvious parameters.
4208
4209 See also: "stats enable", "stats uri".
Willy Tarreau1d45b7c2009-08-16 10:29:18 +02004210
Willy Tarreau983e01e2010-01-11 18:42:06 +01004211
Willy Tarreaueabeafa2008-01-16 16:17:06 +01004212stats realm <realm>
4213 Enable statistics and set authentication realm
4214 May be used in sections : defaults | frontend | listen | backend
4215 yes | no | yes | yes
4216 Arguments :
4217 <realm> is the name of the HTTP Basic Authentication realm reported to
4218 the browser. The browser uses it to display it in the pop-up
4219 inviting the user to enter a valid username and password.
4220
4221 The realm is read as a single word, so any spaces in it should be escaped
4222 using a backslash ('\').
4223
4224 This statement is useful only in conjunction with "stats auth" since it is
4225 only related to authentication.
4226
4227 Though this statement alone is enough to enable statistics reporting, it is
4228 recommended to set all other settings in order to avoid relying on default
4229 unobvious parameters.
4230
4231 Example :
4232 # public access (limited to this backend only)
4233 backend public_www
4234 server srv1 192.168.0.1:80
4235 stats enable
4236 stats hide-version
4237 stats scope .
4238 stats uri /admin?stats
4239 stats realm Haproxy\ Statistics
4240 stats auth admin1:AdMiN123
4241 stats auth admin2:AdMiN321
4242
4243 # internal monitoring access (unlimited)
4244 backend private_monitoring
4245 stats enable
4246 stats uri /admin?stats
4247 stats refresh 5s
4248
4249 See also : "stats auth", "stats enable", "stats uri"
4250
4251
4252stats refresh <delay>
4253 Enable statistics with automatic refresh
4254 May be used in sections : defaults | frontend | listen | backend
4255 yes | no | yes | yes
4256 Arguments :
4257 <delay> is the suggested refresh delay, specified in seconds, which will
4258 be returned to the browser consulting the report page. While the
4259 browser is free to apply any delay, it will generally respect it
4260 and refresh the page this every seconds. The refresh interval may
4261 be specified in any other non-default time unit, by suffixing the
4262 unit after the value, as explained at the top of this document.
4263
4264 This statement is useful on monitoring displays with a permanent page
4265 reporting the load balancer's activity. When set, the HTML report page will
4266 include a link "refresh"/"stop refresh" so that the user can select whether
4267 he wants automatic refresh of the page or not.
4268
4269 Though this statement alone is enough to enable statistics reporting, it is
4270 recommended to set all other settings in order to avoid relying on default
4271 unobvious parameters.
4272
4273 Example :
4274 # public access (limited to this backend only)
4275 backend public_www
4276 server srv1 192.168.0.1:80
4277 stats enable
4278 stats hide-version
4279 stats scope .
4280 stats uri /admin?stats
4281 stats realm Haproxy\ Statistics
4282 stats auth admin1:AdMiN123
4283 stats auth admin2:AdMiN321
4284
4285 # internal monitoring access (unlimited)
4286 backend private_monitoring
4287 stats enable
4288 stats uri /admin?stats
4289 stats refresh 5s
4290
4291 See also : "stats auth", "stats enable", "stats realm", "stats uri"
4292
4293
4294stats scope { <name> | "." }
4295 Enable statistics and limit access scope
4296 May be used in sections : defaults | frontend | listen | backend
4297 yes | no | yes | yes
4298 Arguments :
4299 <name> is the name of a listen, frontend or backend section to be
4300 reported. The special name "." (a single dot) designates the
4301 section in which the statement appears.
4302
4303 When this statement is specified, only the sections enumerated with this
4304 statement will appear in the report. All other ones will be hidden. This
4305 statement may appear as many times as needed if multiple sections need to be
4306 reported. Please note that the name checking is performed as simple string
4307 comparisons, and that it is never checked that a give section name really
4308 exists.
4309
4310 Though this statement alone is enough to enable statistics reporting, it is
4311 recommended to set all other settings in order to avoid relying on default
4312 unobvious parameters.
4313
4314 Example :
4315 # public access (limited to this backend only)
4316 backend public_www
4317 server srv1 192.168.0.1:80
4318 stats enable
4319 stats hide-version
4320 stats scope .
4321 stats uri /admin?stats
4322 stats realm Haproxy\ Statistics
4323 stats auth admin1:AdMiN123
4324 stats auth admin2:AdMiN321
4325
4326 # internal monitoring access (unlimited)
4327 backend private_monitoring
4328 stats enable
4329 stats uri /admin?stats
4330 stats refresh 5s
4331
4332 See also : "stats auth", "stats enable", "stats realm", "stats uri"
4333
4334
4335stats uri <prefix>
4336 Enable statistics and define the URI prefix to access them
4337 May be used in sections : defaults | frontend | listen | backend
4338 yes | no | yes | yes
4339 Arguments :
4340 <prefix> is the prefix of any URI which will be redirected to stats. This
4341 prefix may contain a question mark ('?') to indicate part of a
4342 query string.
4343
4344 The statistics URI is intercepted on the relayed traffic, so it appears as a
4345 page within the normal application. It is strongly advised to ensure that the
4346 selected URI will never appear in the application, otherwise it will never be
4347 possible to reach it in the application.
4348
4349 The default URI compiled in haproxy is "/haproxy?stats", but this may be
Krzysztof Piotr Oledzkif8645332009-12-13 21:55:50 +01004350 changed at build time, so it's better to always explicitly specify it here.
Willy Tarreaueabeafa2008-01-16 16:17:06 +01004351 It is generally a good idea to include a question mark in the URI so that
4352 intermediate proxies refrain from caching the results. Also, since any string
4353 beginning with the prefix will be accepted as a stats request, the question
4354 mark helps ensuring that no valid URI will begin with the same words.
4355
4356 It is sometimes very convenient to use "/" as the URI prefix, and put that
4357 statement in a "listen" instance of its own. That makes it easy to dedicate
4358 an address or a port to statistics only.
4359
4360 Though this statement alone is enough to enable statistics reporting, it is
4361 recommended to set all other settings in order to avoid relying on default
4362 unobvious parameters.
4363
4364 Example :
4365 # public access (limited to this backend only)
4366 backend public_www
4367 server srv1 192.168.0.1:80
4368 stats enable
4369 stats hide-version
4370 stats scope .
4371 stats uri /admin?stats
4372 stats realm Haproxy\ Statistics
4373 stats auth admin1:AdMiN123
4374 stats auth admin2:AdMiN321
4375
4376 # internal monitoring access (unlimited)
4377 backend private_monitoring
4378 stats enable
4379 stats uri /admin?stats
4380 stats refresh 5s
4381
4382 See also : "stats auth", "stats enable", "stats realm"
4383
4384
4385stats hide-version
4386 Enable statistics and hide HAProxy version reporting
4387 May be used in sections : defaults | frontend | listen | backend
4388 yes | no | yes | yes
4389 Arguments : none
4390
4391 By default, the stats page reports some useful status information along with
4392 the statistics. Among them is HAProxy's version. However, it is generally
4393 considered dangerous to report precise version to anyone, as it can help them
4394 target known weaknesses with specific attacks. The "stats hide-version"
4395 statement removes the version from the statistics report. This is recommended
4396 for public sites or any site with a weak login/password.
4397
4398 Though this statement alone is enough to enable statistics reporting, it is
4399 recommended to set all other settings in order to avoid relying on default
4400 unobvious parameters.
4401
4402 Example :
4403 # public access (limited to this backend only)
4404 backend public_www
4405 server srv1 192.168.0.1:80
4406 stats enable
4407 stats hide-version
4408 stats scope .
4409 stats uri /admin?stats
4410 stats realm Haproxy\ Statistics
4411 stats auth admin1:AdMiN123
4412 stats auth admin2:AdMiN321
4413
4414 # internal monitoring access (unlimited)
4415 backend private_monitoring
4416 stats enable
4417 stats uri /admin?stats
4418 stats refresh 5s
4419
4420 See also : "stats auth", "stats enable", "stats realm", "stats uri"
4421
4422
Willy Tarreaub937b7e2010-01-12 15:27:54 +01004423stick match <pattern> [table <table>] [{if | unless} <cond>]
4424 Define a request pattern matching condition to stick a user to a server
4425 May be used in sections : defaults | frontend | listen | backend
4426 no | no | yes | yes
4427
4428 Arguments :
4429 <pattern> is a pattern extraction rule as described in section 7.8. It
4430 describes what elements of the incoming request or connection
4431 will be analysed in the hope to find a matching entry in a
4432 stickiness table. This rule is mandatory.
4433
4434 <table> is an optional stickiness table name. If unspecified, the same
4435 backend's table is used. A stickiness table is declared using
4436 the "stick-table" statement.
4437
4438 <cond> is an optional matching condition. It makes it possible to match
4439 on a certain criterion only when other conditions are met (or
4440 not met). For instance, it could be used to match on a source IP
4441 address except when a request passes through a known proxy, in
4442 which case we'd match on a header containing that IP address.
4443
4444 Some protocols or applications require complex stickiness rules and cannot
4445 always simply rely on cookies nor hashing. The "stick match" statement
4446 describes a rule to extract the stickiness criterion from an incoming request
4447 or connection. See section 7 for a complete list of possible patterns and
4448 transformation rules.
4449
4450 The table has to be declared using the "stick-table" statement. It must be of
4451 a type compatible with the pattern. By default it is the one which is present
4452 in the same backend. It is possible to share a table with other backends by
4453 referencing it using the "table" keyword. If another table is referenced,
4454 the server's ID inside the backends are used. By default, all server IDs
4455 start at 1 in each backend, so the server ordering is enough. But in case of
4456 doubt, it is highly recommended to force server IDs using their "id" setting.
4457
4458 It is possible to restrict the conditions where a "stick match" statement
4459 will apply, using "if" or "unless" followed by a condition. See section 7 for
4460 ACL based conditions.
4461
4462 There is no limit on the number of "stick match" statements. The first that
4463 applies and matches will cause the request to be directed to the same server
4464 as was used for the request which created the entry. That way, multiple
4465 matches can be used as fallbacks.
4466
4467 The stick rules are checked after the persistence cookies, so they will not
4468 affect stickiness if a cookie has already been used to select a server. That
4469 way, it becomes very easy to insert cookies and match on IP addresses in
4470 order to maintain stickiness between HTTP and HTTPS.
4471
4472 Example :
4473 # forward SMTP users to the same server they just used for POP in the
4474 # last 30 minutes
4475 backend pop
4476 mode tcp
4477 balance roundrobin
4478 stick store-request src
4479 stick-table type ip size 200k expire 30m
4480 server s1 192.168.1.1:110
4481 server s2 192.168.1.1:110
4482
4483 backend smtp
4484 mode tcp
4485 balance roundrobin
4486 stick match src table pop
4487 server s1 192.168.1.1:25
4488 server s2 192.168.1.1:25
4489
4490 See also : "stick-table", "stick on", and section 7 about ACLs and pattern
4491 extraction.
4492
4493
4494stick on <pattern> [table <table>] [{if | unless} <condition>]
4495 Define a request pattern to associate a user to a server
4496 May be used in sections : defaults | frontend | listen | backend
4497 no | no | yes | yes
4498
4499 Note : This form is exactly equivalent to "stick match" followed by
4500 "stick store-request", all with the same arguments. Please refer
4501 to both keywords for details. It is only provided as a convenience
4502 for writing more maintainable configurations.
4503
4504 Examples :
4505 # The following form ...
4506 stick or src table pop if !localhost
4507
4508 # ...is strictly equivalent to this one :
4509 stick match src table pop if !localhost
4510 stick store-request src table pop if !localhost
4511
4512
4513 # Use cookie persistence for HTTP, and stick on source address for HTTPS as
4514 # well as HTTP without cookie. Share the same table between both accesses.
4515 backend http
4516 mode http
4517 balance roundrobin
4518 stick on src table https
4519 cookie SRV insert indirect nocache
4520 server s1 192.168.1.1:80 cookie s1
4521 server s2 192.168.1.1:80 cookie s2
4522
4523 backend https
4524 mode tcp
4525 balance roundrobin
4526 stick-table type ip size 200k expire 30m
4527 stick on src
4528 server s1 192.168.1.1:443
4529 server s2 192.168.1.1:443
4530
4531 See also : "stick match" and "stick store-request"
4532
4533
4534stick store-request <pattern> [table <table>] [{if | unless} <condition>]
4535 Define a request pattern used to create an entry in a stickiness table
4536 May be used in sections : defaults | frontend | listen | backend
4537 no | no | yes | yes
4538
4539 Arguments :
4540 <pattern> is a pattern extraction rule as described in section 7.8. It
4541 describes what elements of the incoming request or connection
4542 will be analysed, extracted and stored in the table once a
4543 server is selected.
4544
4545 <table> is an optional stickiness table name. If unspecified, the same
4546 backend's table is used. A stickiness table is declared using
4547 the "stick-table" statement.
4548
4549 <cond> is an optional storage condition. It makes it possible to store
4550 certain criteria only when some conditions are met (or not met).
4551 For instance, it could be used to store the source IP address
4552 except when the request passes through a known proxy, in which
4553 case we'd store a converted form of a header containing that IP
4554 address.
4555
4556 Some protocols or applications require complex stickiness rules and cannot
4557 always simply rely on cookies nor hashing. The "stick store-request" statement
4558 describes a rule to decide what to extract from the request and when to do
4559 it, in order to store it into a stickiness table for further requests to
4560 match it using the "stick match" statement. Obviously the extracted part must
4561 make sense and have a chance to be matched in a further request. Storing a
4562 client's IP address for instance often makes sense. Storing an ID found in a
4563 URL parameter also makes sense. Storing a source port will almost never make
4564 any sense because it will be randomly matched. See section 7 for a complete
4565 list of possible patterns and transformation rules.
4566
4567 The table has to be declared using the "stick-table" statement. It must be of
4568 a type compatible with the pattern. By default it is the one which is present
4569 in the same backend. It is possible to share a table with other backends by
4570 referencing it using the "table" keyword. If another table is referenced,
4571 the server's ID inside the backends are used. By default, all server IDs
4572 start at 1 in each backend, so the server ordering is enough. But in case of
4573 doubt, it is highly recommended to force server IDs using their "id" setting.
4574
4575 It is possible to restrict the conditions where a "stick store-request"
4576 statement will apply, using "if" or "unless" followed by a condition. This
4577 condition will be evaluated while parsing the request, so any criteria can be
4578 used. See section 7 for ACL based conditions.
4579
4580 There is no limit on the number of "stick store-request" statements, but
4581 there is a limit of 8 simultaneous stores per request or response. This
4582 makes it possible to store up to 8 criteria, all extracted from either the
4583 request or the response, regardless of the number of rules. Only the 8 first
4584 ones which match will be kept. Using this, it is possible to feed multiple
4585 tables at once in the hope to increase the chance to recognize a user on
4586 another protocol or access method.
4587
4588 The "store-request" rules are evaluated once the server connection has been
4589 established, so that the table will contain the real server that processed
4590 the request.
4591
4592 Example :
4593 # forward SMTP users to the same server they just used for POP in the
4594 # last 30 minutes
4595 backend pop
4596 mode tcp
4597 balance roundrobin
4598 stick store-request src
4599 stick-table type ip size 200k expire 30m
4600 server s1 192.168.1.1:110
4601 server s2 192.168.1.1:110
4602
4603 backend smtp
4604 mode tcp
4605 balance roundrobin
4606 stick match src table pop
4607 server s1 192.168.1.1:25
4608 server s2 192.168.1.1:25
4609
4610 See also : "stick-table", "stick on", and section 7 about ACLs and pattern
4611 extraction.
4612
4613
4614stick-table type {ip | integer | string [len <length>] } size <size>
4615 [expire <expire>] [nopurge]
4616 Configure the stickiness table for the current backend
4617 May be used in sections : defaults | frontend | listen | backend
4618 no | no | yes | yes
4619
4620 Arguments :
4621 ip a table declared with "type ip" will only store IPv4 addresses.
4622 This form is very compact (about 50 bytes per entry) and allows
4623 very fast entry lookup and stores with almost no overhead. This
4624 is mainly used to store client source IP addresses.
4625
4626 integer a table declared with "type integer" will store 32bit integers
4627 which can represent a client identifier found in a request for
4628 instance.
4629
4630 string a table declared with "type string" will store substrings of up
4631 to <len> characters. If the string provided by the pattern
4632 extractor is larger than <len>, it will be truncated before
4633 being stored. During matching, at most <len> characters will be
4634 compared between the string in the table and the extracted
4635 pattern. When not specified, the string is automatically limited
4636 to 31 characters.
4637
4638 <length> is the maximum number of characters that will be stored in a
4639 "string" type table. See type "string" above. Be careful when
4640 changing this parameter as memory usage will proportionally
4641 increase.
4642
4643 <size> is the maximum number of entries that can fit in the table. This
4644 value directly impats memory usage. Count approximately 50 bytes
4645 per entry, plus the size of a string if any. The size supports
4646 suffixes "k", "m", "g" for 2^10, 2^20 and 2^30 factors.
4647
4648 [nopurge] indicates that we refuse to purge older entries when the table
4649 is full. When not specified and the table is full when haproxy
4650 wants to store an entry in it, it will flush a few of the oldest
4651 entries in order to release some space for the new ones. This is
4652 most often the desired behaviour. In some specific cases, it
4653 be desirable to refuse new entries instead of purging the older
4654 ones. That may be the case when the amount of data to store is
4655 far above the hardware limits and we prefer not to offer access
4656 to new clients than to reject the ones already connected. When
4657 using this parameter, be sure to properly set the "expire"
4658 parameter (see below).
4659
4660 <expire> defines the maximum duration of an entry in the table since it
4661 was last created, refreshed or matched. The expiration delay is
4662 defined using the standard time format, similarly as the various
4663 timeouts. The maximum duration is slightly above 24 days. See
4664 section 2.2 for more information. If this delay is not specified,
4665 the session won't automatically expire, but older entries will
4666 be removed once full. Be sure not to use the "nopurge" parameter
4667 if not expiration delay is specified.
4668
4669 The is only one stick-table per backend. At the moment of writing this doc,
4670 it does not seem useful to have multiple tables per backend. If this happens
4671 to be required, simply create a dummy backend with a stick-table in it and
4672 reference it.
4673
4674 It is important to understand that stickiness based on learning information
4675 has some limitations, including the fact that all learned associations are
4676 lost upon restart. In general it can be good as a complement but not always
4677 as an exclusive stickiness.
4678
4679 See also : "stick match", "stick on", "stick store-request", and section 2.2
4680 about time format.
4681
4682
Willy Tarreau62644772008-07-16 18:36:06 +02004683tcp-request content accept [{if | unless} <condition>]
4684 Accept a connection if/unless a content inspection condition is matched
4685 May be used in sections : defaults | frontend | listen | backend
4686 no | yes | yes | no
4687
4688 During TCP content inspection, the connection is immediately validated if the
4689 condition is true (when used with "if") or false (when used with "unless").
4690 Most of the time during content inspection, a condition will be in an
4691 uncertain state which is neither true nor false. The evaluation immediately
4692 stops when such a condition is encountered. It is important to understand
4693 that "accept" and "reject" rules are evaluated in their exact declaration
4694 order, so that it is possible to build complex rules from them. There is no
4695 specific limit to the number of rules which may be inserted.
4696
Krzysztof Piotr Oledzkif8645332009-12-13 21:55:50 +01004697 Note that the "if/unless" condition is optional. If no condition is set on
Willy Tarreau62644772008-07-16 18:36:06 +02004698 the action, it is simply performed unconditionally.
4699
4700 If no "tcp-request content" rules are matched, the default action already is
4701 "accept". Thus, this statement alone does not bring anything without another
4702 "reject" statement.
4703
Willy Tarreauc57f0e22009-05-10 13:12:33 +02004704 See section 7 about ACL usage.
Willy Tarreau62644772008-07-16 18:36:06 +02004705
Willy Tarreau55165fe2009-05-10 12:02:55 +02004706 See also : "tcp-request content reject", "tcp-request inspect-delay"
Willy Tarreau62644772008-07-16 18:36:06 +02004707
4708
4709tcp-request content reject [{if | unless} <condition>]
4710 Reject a connection if/unless a content inspection condition is matched
4711 May be used in sections : defaults | frontend | listen | backend
4712 no | yes | yes | no
4713
4714 During TCP content inspection, the connection is immediately rejected if the
4715 condition is true (when used with "if") or false (when used with "unless").
4716 Most of the time during content inspection, a condition will be in an
4717 uncertain state which is neither true nor false. The evaluation immediately
4718 stops when such a condition is encountered. It is important to understand
4719 that "accept" and "reject" rules are evaluated in their exact declaration
4720 order, so that it is possible to build complex rules from them. There is no
4721 specific limit to the number of rules which may be inserted.
4722
Krzysztof Piotr Oledzkif8645332009-12-13 21:55:50 +01004723 Note that the "if/unless" condition is optional. If no condition is set on
Willy Tarreau62644772008-07-16 18:36:06 +02004724 the action, it is simply performed unconditionally.
4725
4726 If no "tcp-request content" rules are matched, the default action is set to
4727 "accept".
4728
4729 Example:
4730 # reject SMTP connection if client speaks first
4731 tcp-request inspect-delay 30s
4732 acl content_present req_len gt 0
4733 tcp-request reject if content_present
4734
4735 # Forward HTTPS connection only if client speaks
4736 tcp-request inspect-delay 30s
4737 acl content_present req_len gt 0
4738 tcp-request accept if content_present
4739 tcp-request reject
4740
Willy Tarreauc57f0e22009-05-10 13:12:33 +02004741 See section 7 about ACL usage.
Willy Tarreau62644772008-07-16 18:36:06 +02004742
Willy Tarreau55165fe2009-05-10 12:02:55 +02004743 See also : "tcp-request content accept", "tcp-request inspect-delay"
Willy Tarreau62644772008-07-16 18:36:06 +02004744
4745
4746tcp-request inspect-delay <timeout>
4747 Set the maximum allowed time to wait for data during content inspection
4748 May be used in sections : defaults | frontend | listen | backend
4749 no | yes | yes | no
4750 Arguments :
4751 <timeout> is the timeout value specified in milliseconds by default, but
4752 can be in any other unit if the number is suffixed by the unit,
4753 as explained at the top of this document.
4754
4755 People using haproxy primarily as a TCP relay are often worried about the
4756 risk of passing any type of protocol to a server without any analysis. In
4757 order to be able to analyze the request contents, we must first withhold
4758 the data then analyze them. This statement simply enables withholding of
4759 data for at most the specified amount of time.
4760
4761 Note that when performing content inspection, haproxy will evaluate the whole
4762 rules for every new chunk which gets in, taking into account the fact that
Krzysztof Piotr Oledzkif8645332009-12-13 21:55:50 +01004763 those data are partial. If no rule matches before the aforementioned delay,
Willy Tarreau62644772008-07-16 18:36:06 +02004764 a last check is performed upon expiration, this time considering that the
Willy Tarreaud869b242009-03-15 14:43:58 +01004765 contents are definitive. If no delay is set, haproxy will not wait at all
4766 and will immediately apply a verdict based on the available information.
4767 Obviously this is unlikely to be very useful and might even be racy, so such
4768 setups are not recommended.
Willy Tarreau62644772008-07-16 18:36:06 +02004769
4770 As soon as a rule matches, the request is released and continues as usual. If
4771 the timeout is reached and no rule matches, the default policy will be to let
4772 it pass through unaffected.
4773
4774 For most protocols, it is enough to set it to a few seconds, as most clients
4775 send the full request immediately upon connection. Add 3 or more seconds to
4776 cover TCP retransmits but that's all. For some protocols, it may make sense
Willy Tarreaud72758d2010-01-12 10:42:19 +01004777 to use large values, for instance to ensure that the client never talks
Willy Tarreau62644772008-07-16 18:36:06 +02004778 before the server (eg: SMTP), or to wait for a client to talk before passing
4779 data to the server (eg: SSL). Note that the client timeout must cover at
4780 least the inspection delay, otherwise it will expire first.
4781
Willy Tarreau55165fe2009-05-10 12:02:55 +02004782 See also : "tcp-request content accept", "tcp-request content reject",
Willy Tarreau62644772008-07-16 18:36:06 +02004783 "timeout client".
4784
4785
Krzysztof Piotr Oledzki5259dfe2008-01-21 01:54:06 +01004786timeout check <timeout>
4787 Set additional check timeout, but only after a connection has been already
4788 established.
4789
4790 May be used in sections: defaults | frontend | listen | backend
4791 yes | no | yes | yes
4792 Arguments:
4793 <timeout> is the timeout value specified in milliseconds by default, but
4794 can be in any other unit if the number is suffixed by the unit,
4795 as explained at the top of this document.
4796
4797 If set, haproxy uses min("timeout connect", "inter") as a connect timeout
4798 for check and "timeout check" as an additional read timeout. The "min" is
4799 used so that people running with *very* long "timeout connect" (eg. those
4800 who needed this due to the queue or tarpit) do not slow down their checks.
4801 Of course it is better to use "check queue" and "check tarpit" instead of
4802 long "timeout connect".
4803
4804 If "timeout check" is not set haproxy uses "inter" for complete check
4805 timeout (connect + read) exactly like all <1.3.15 version.
4806
4807 In most cases check request is much simpler and faster to handle than normal
4808 requests and people may want to kick out laggy servers so this timeout should
Willy Tarreau41a340d2008-01-22 12:25:31 +01004809 be smaller than "timeout server".
Krzysztof Piotr Oledzki5259dfe2008-01-21 01:54:06 +01004810
4811 This parameter is specific to backends, but can be specified once for all in
4812 "defaults" sections. This is in fact one of the easiest solutions not to
4813 forget about it.
4814
Willy Tarreau41a340d2008-01-22 12:25:31 +01004815 See also: "timeout connect", "timeout queue", "timeout server",
4816 "timeout tarpit".
Krzysztof Piotr Oledzki5259dfe2008-01-21 01:54:06 +01004817
4818
Willy Tarreau0ba27502007-12-24 16:55:16 +01004819timeout client <timeout>
4820timeout clitimeout <timeout> (deprecated)
4821 Set the maximum inactivity time on the client side.
4822 May be used in sections : defaults | frontend | listen | backend
4823 yes | yes | yes | no
4824 Arguments :
Willy Tarreau844e3c52008-01-11 16:28:18 +01004825 <timeout> is the timeout value specified in milliseconds by default, but
Willy Tarreau0ba27502007-12-24 16:55:16 +01004826 can be in any other unit if the number is suffixed by the unit,
4827 as explained at the top of this document.
4828
4829 The inactivity timeout applies when the client is expected to acknowledge or
4830 send data. In HTTP mode, this timeout is particularly important to consider
4831 during the first phase, when the client sends the request, and during the
4832 response while it is reading data sent by the server. The value is specified
4833 in milliseconds by default, but can be in any other unit if the number is
4834 suffixed by the unit, as specified at the top of this document. In TCP mode
4835 (and to a lesser extent, in HTTP mode), it is highly recommended that the
4836 client timeout remains equal to the server timeout in order to avoid complex
Willy Tarreaud2a4aa22008-01-31 15:28:22 +01004837 situations to debug. It is a good practice to cover one or several TCP packet
Willy Tarreau0ba27502007-12-24 16:55:16 +01004838 losses by specifying timeouts that are slightly above multiples of 3 seconds
4839 (eg: 4 or 5 seconds).
4840
4841 This parameter is specific to frontends, but can be specified once for all in
4842 "defaults" sections. This is in fact one of the easiest solutions not to
4843 forget about it. An unspecified timeout results in an infinite timeout, which
4844 is not recommended. Such a usage is accepted and works but reports a warning
4845 during startup because it may results in accumulation of expired sessions in
4846 the system if the system's timeouts are not configured either.
4847
4848 This parameter replaces the old, deprecated "clitimeout". It is recommended
4849 to use it to write new configurations. The form "timeout clitimeout" is
4850 provided only by backwards compatibility but its use is strongly discouraged.
4851
4852 See also : "clitimeout", "timeout server".
4853
4854
4855timeout connect <timeout>
4856timeout contimeout <timeout> (deprecated)
4857 Set the maximum time to wait for a connection attempt to a server to succeed.
4858 May be used in sections : defaults | frontend | listen | backend
4859 yes | no | yes | yes
4860 Arguments :
Willy Tarreau844e3c52008-01-11 16:28:18 +01004861 <timeout> is the timeout value specified in milliseconds by default, but
Willy Tarreau0ba27502007-12-24 16:55:16 +01004862 can be in any other unit if the number is suffixed by the unit,
4863 as explained at the top of this document.
4864
4865 If the server is located on the same LAN as haproxy, the connection should be
Willy Tarreaud2a4aa22008-01-31 15:28:22 +01004866 immediate (less than a few milliseconds). Anyway, it is a good practice to
Willy Tarreaud72758d2010-01-12 10:42:19 +01004867 cover one or several TCP packet losses by specifying timeouts that are
Willy Tarreau0ba27502007-12-24 16:55:16 +01004868 slightly above multiples of 3 seconds (eg: 4 or 5 seconds). By default, the
Krzysztof Piotr Oledzki5259dfe2008-01-21 01:54:06 +01004869 connect timeout also presets both queue and tarpit timeouts to the same value
4870 if these have not been specified.
Willy Tarreau0ba27502007-12-24 16:55:16 +01004871
4872 This parameter is specific to backends, but can be specified once for all in
4873 "defaults" sections. This is in fact one of the easiest solutions not to
4874 forget about it. An unspecified timeout results in an infinite timeout, which
4875 is not recommended. Such a usage is accepted and works but reports a warning
4876 during startup because it may results in accumulation of failed sessions in
4877 the system if the system's timeouts are not configured either.
4878
4879 This parameter replaces the old, deprecated "contimeout". It is recommended
4880 to use it to write new configurations. The form "timeout contimeout" is
4881 provided only by backwards compatibility but its use is strongly discouraged.
4882
Willy Tarreau41a340d2008-01-22 12:25:31 +01004883 See also: "timeout check", "timeout queue", "timeout server", "contimeout",
4884 "timeout tarpit".
Willy Tarreau0ba27502007-12-24 16:55:16 +01004885
4886
Willy Tarreaub16a5742010-01-10 14:46:16 +01004887timeout http-keep-alive <timeout>
4888 Set the maximum allowed time to wait for a new HTTP request to appear
4889 May be used in sections : defaults | frontend | listen | backend
4890 yes | yes | yes | yes
4891 Arguments :
4892 <timeout> is the timeout value specified in milliseconds by default, but
4893 can be in any other unit if the number is suffixed by the unit,
4894 as explained at the top of this document.
4895
4896 By default, the time to wait for a new request in case of keep-alive is set
4897 by "timeout http-request". However this is not always convenient because some
4898 people want very short keep-alive timeouts in order to release connections
4899 faster, and others prefer to have larger ones but still have short timeouts
4900 once the request has started to present itself.
4901
4902 The "http-keep-alive" timeout covers these needs. It will define how long to
4903 wait for a new HTTP request to start coming after a response was sent. Once
4904 the first byte of request has been seen, the "http-request" timeout is used
4905 to wait for the complete request to come. Note that empty lines prior to a
4906 new request do not refresh the timeout and are not counted as a new request.
4907
4908 There is also another difference between the two timeouts : when a connection
4909 expires during timeout http-keep-alive, no error is returned, the connection
4910 just closes. If the connection expires in "http-request" while waiting for a
4911 connection to complete, a HTTP 408 error is returned.
4912
4913 In general it is optimal to set this value to a few tens to hundreds of
4914 milliseconds, to allow users to fetch all objects of a page at once but
4915 without waiting for further clicks. Also, if set to a very small value (eg:
4916 1 millisecond) it will probably only accept pipelined requests but not the
4917 non-pipelined ones. It may be a nice trade-off for very large sites running
4918 with tends to hundreds of thousands of clients.
4919
4920 If this parameter is not set, the "http-request" timeout applies, and if both
4921 are not set, "timeout client" still applies at the lower level. It should be
4922 set in the frontend to take effect, unless the frontend is in TCP mode, in
4923 which case the HTTP backend's timeout will be used.
4924
4925 See also : "timeout http-request", "timeout client".
4926
4927
Willy Tarreau036fae02008-01-06 13:24:40 +01004928timeout http-request <timeout>
4929 Set the maximum allowed time to wait for a complete HTTP request
4930 May be used in sections : defaults | frontend | listen | backend
Willy Tarreaucd7afc02009-07-12 10:03:17 +02004931 yes | yes | yes | yes
Willy Tarreau036fae02008-01-06 13:24:40 +01004932 Arguments :
Willy Tarreau844e3c52008-01-11 16:28:18 +01004933 <timeout> is the timeout value specified in milliseconds by default, but
Willy Tarreau036fae02008-01-06 13:24:40 +01004934 can be in any other unit if the number is suffixed by the unit,
4935 as explained at the top of this document.
4936
4937 In order to offer DoS protection, it may be required to lower the maximum
4938 accepted time to receive a complete HTTP request without affecting the client
4939 timeout. This helps protecting against established connections on which
4940 nothing is sent. The client timeout cannot offer a good protection against
4941 this abuse because it is an inactivity timeout, which means that if the
4942 attacker sends one character every now and then, the timeout will not
4943 trigger. With the HTTP request timeout, no matter what speed the client
4944 types, the request will be aborted if it does not complete in time.
4945
4946 Note that this timeout only applies to the header part of the request, and
4947 not to any data. As soon as the empty line is received, this timeout is not
Willy Tarreaub16a5742010-01-10 14:46:16 +01004948 used anymore. It is used again on keep-alive connections to wait for a second
4949 request if "timeout http-keep-alive" is not set.
Willy Tarreau036fae02008-01-06 13:24:40 +01004950
4951 Generally it is enough to set it to a few seconds, as most clients send the
4952 full request immediately upon connection. Add 3 or more seconds to cover TCP
4953 retransmits but that's all. Setting it to very low values (eg: 50 ms) will
4954 generally work on local networks as long as there are no packet losses. This
4955 will prevent people from sending bare HTTP requests using telnet.
4956
4957 If this parameter is not set, the client timeout still applies between each
Willy Tarreaucd7afc02009-07-12 10:03:17 +02004958 chunk of the incoming request. It should be set in the frontend to take
4959 effect, unless the frontend is in TCP mode, in which case the HTTP backend's
4960 timeout will be used.
Willy Tarreau036fae02008-01-06 13:24:40 +01004961
Willy Tarreaub16a5742010-01-10 14:46:16 +01004962 See also : "timeout http-keep-alive", "timeout client".
Willy Tarreau036fae02008-01-06 13:24:40 +01004963
Willy Tarreau844e3c52008-01-11 16:28:18 +01004964
4965timeout queue <timeout>
4966 Set the maximum time to wait in the queue for a connection slot to be free
4967 May be used in sections : defaults | frontend | listen | backend
4968 yes | no | yes | yes
4969 Arguments :
4970 <timeout> is the timeout value specified in milliseconds by default, but
4971 can be in any other unit if the number is suffixed by the unit,
4972 as explained at the top of this document.
4973
4974 When a server's maxconn is reached, connections are left pending in a queue
4975 which may be server-specific or global to the backend. In order not to wait
4976 indefinitely, a timeout is applied to requests pending in the queue. If the
4977 timeout is reached, it is considered that the request will almost never be
4978 served, so it is dropped and a 503 error is returned to the client.
4979
4980 The "timeout queue" statement allows to fix the maximum time for a request to
4981 be left pending in a queue. If unspecified, the same value as the backend's
4982 connection timeout ("timeout connect") is used, for backwards compatibility
4983 with older versions with no "timeout queue" parameter.
4984
4985 See also : "timeout connect", "contimeout".
4986
4987
4988timeout server <timeout>
4989timeout srvtimeout <timeout> (deprecated)
4990 Set the maximum inactivity time on the server side.
4991 May be used in sections : defaults | frontend | listen | backend
4992 yes | no | yes | yes
4993 Arguments :
4994 <timeout> is the timeout value specified in milliseconds by default, but
4995 can be in any other unit if the number is suffixed by the unit,
4996 as explained at the top of this document.
4997
4998 The inactivity timeout applies when the server is expected to acknowledge or
4999 send data. In HTTP mode, this timeout is particularly important to consider
5000 during the first phase of the server's response, when it has to send the
5001 headers, as it directly represents the server's processing time for the
5002 request. To find out what value to put there, it's often good to start with
5003 what would be considered as unacceptable response times, then check the logs
5004 to observe the response time distribution, and adjust the value accordingly.
5005
5006 The value is specified in milliseconds by default, but can be in any other
5007 unit if the number is suffixed by the unit, as specified at the top of this
5008 document. In TCP mode (and to a lesser extent, in HTTP mode), it is highly
5009 recommended that the client timeout remains equal to the server timeout in
5010 order to avoid complex situations to debug. Whatever the expected server
Willy Tarreaud2a4aa22008-01-31 15:28:22 +01005011 response times, it is a good practice to cover at least one or several TCP
Willy Tarreau844e3c52008-01-11 16:28:18 +01005012 packet losses by specifying timeouts that are slightly above multiples of 3
Willy Tarreaud72758d2010-01-12 10:42:19 +01005013 seconds (eg: 4 or 5 seconds minimum).
Willy Tarreau844e3c52008-01-11 16:28:18 +01005014
5015 This parameter is specific to backends, but can be specified once for all in
5016 "defaults" sections. This is in fact one of the easiest solutions not to
5017 forget about it. An unspecified timeout results in an infinite timeout, which
5018 is not recommended. Such a usage is accepted and works but reports a warning
5019 during startup because it may results in accumulation of expired sessions in
5020 the system if the system's timeouts are not configured either.
5021
5022 This parameter replaces the old, deprecated "srvtimeout". It is recommended
5023 to use it to write new configurations. The form "timeout srvtimeout" is
5024 provided only by backwards compatibility but its use is strongly discouraged.
5025
5026 See also : "srvtimeout", "timeout client".
5027
5028
5029timeout tarpit <timeout>
5030 Set the duration for which tapitted connections will be maintained
5031 May be used in sections : defaults | frontend | listen | backend
5032 yes | yes | yes | yes
5033 Arguments :
5034 <timeout> is the tarpit duration specified in milliseconds by default, but
5035 can be in any other unit if the number is suffixed by the unit,
5036 as explained at the top of this document.
5037
5038 When a connection is tarpitted using "reqtarpit", it is maintained open with
5039 no activity for a certain amount of time, then closed. "timeout tarpit"
5040 defines how long it will be maintained open.
5041
5042 The value is specified in milliseconds by default, but can be in any other
5043 unit if the number is suffixed by the unit, as specified at the top of this
5044 document. If unspecified, the same value as the backend's connection timeout
5045 ("timeout connect") is used, for backwards compatibility with older versions
Willy Tarreaud72758d2010-01-12 10:42:19 +01005046 with no "timeout tapit" parameter.
Willy Tarreau844e3c52008-01-11 16:28:18 +01005047
5048 See also : "timeout connect", "contimeout".
5049
5050
5051transparent (deprecated)
5052 Enable client-side transparent proxying
5053 May be used in sections : defaults | frontend | listen | backend
Willy Tarreau4b1f8592008-12-23 23:13:55 +01005054 yes | no | yes | yes
Willy Tarreau844e3c52008-01-11 16:28:18 +01005055 Arguments : none
5056
5057 This keyword was introduced in order to provide layer 7 persistence to layer
5058 3 load balancers. The idea is to use the OS's ability to redirect an incoming
5059 connection for a remote address to a local process (here HAProxy), and let
5060 this process know what address was initially requested. When this option is
5061 used, sessions without cookies will be forwarded to the original destination
5062 IP address of the incoming request (which should match that of another
5063 equipment), while requests with cookies will still be forwarded to the
5064 appropriate server.
5065
5066 The "transparent" keyword is deprecated, use "option transparent" instead.
5067
5068 Note that contrary to a common belief, this option does NOT make HAProxy
5069 present the client's IP to the server when establishing the connection.
5070
Willy Tarreau844e3c52008-01-11 16:28:18 +01005071 See also: "option transparent"
5072
5073
5074use_backend <backend> if <condition>
5075use_backend <backend> unless <condition>
Willy Tarreau1d0dfb12009-07-07 15:10:31 +02005076 Switch to a specific backend if/unless an ACL-based condition is matched.
Willy Tarreau844e3c52008-01-11 16:28:18 +01005077 May be used in sections : defaults | frontend | listen | backend
5078 no | yes | yes | no
5079 Arguments :
5080 <backend> is the name of a valid backend or "listen" section.
5081
Willy Tarreauc57f0e22009-05-10 13:12:33 +02005082 <condition> is a condition composed of ACLs, as described in section 7.
Willy Tarreau844e3c52008-01-11 16:28:18 +01005083
5084 When doing content-switching, connections arrive on a frontend and are then
5085 dispatched to various backends depending on a number of conditions. The
5086 relation between the conditions and the backends is described with the
Willy Tarreau1d0dfb12009-07-07 15:10:31 +02005087 "use_backend" keyword. While it is normally used with HTTP processing, it can
5088 also be used in pure TCP, either without content using stateless ACLs (eg:
5089 source address validation) or combined with a "tcp-request" rule to wait for
5090 some payload.
Willy Tarreau844e3c52008-01-11 16:28:18 +01005091
5092 There may be as many "use_backend" rules as desired. All of these rules are
5093 evaluated in their declaration order, and the first one which matches will
5094 assign the backend.
5095
5096 In the first form, the backend will be used if the condition is met. In the
5097 second form, the backend will be used if the condition is not met. If no
5098 condition is valid, the backend defined with "default_backend" will be used.
5099 If no default backend is defined, either the servers in the same section are
5100 used (in case of a "listen" section) or, in case of a frontend, no server is
5101 used and a 503 service unavailable response is returned.
5102
Willy Tarreau51aecc72009-07-12 09:47:04 +02005103 Note that it is possible to switch from a TCP frontend to an HTTP backend. In
Krzysztof Piotr Oledzkif8645332009-12-13 21:55:50 +01005104 this case, either the frontend has already checked that the protocol is HTTP,
Willy Tarreau51aecc72009-07-12 09:47:04 +02005105 and backend processing will immediately follow, or the backend will wait for
5106 a complete HTTP request to get in. This feature is useful when a frontend
5107 must decode several protocols on a unique port, one of them being HTTP.
5108
Willy Tarreau1d0dfb12009-07-07 15:10:31 +02005109 See also: "default_backend", "tcp-request", and section 7 about ACLs.
Willy Tarreaud72758d2010-01-12 10:42:19 +01005110
Willy Tarreau036fae02008-01-06 13:24:40 +01005111
Krzysztof Piotr Oledzkic6df0662010-01-05 16:38:49 +010051125. Server and default-server options
Willy Tarreauc57f0e22009-05-10 13:12:33 +02005113-----------------
Willy Tarreau6a06a402007-07-15 20:15:28 +02005114
Krzysztof Piotr Oledzkic6df0662010-01-05 16:38:49 +01005115The "server" and "default-server" keywords support a certain number of settings
5116which are all passed as arguments on the server line. The order in which those
5117arguments appear does not count, and they are all optional. Some of those
5118settings are single words (booleans) while others expect one or several values
5119after them. In this case, the values must immediately follow the setting name.
5120Except default-server, all those settings must be specified after the server's
5121address if they are used:
Willy Tarreau6a06a402007-07-15 20:15:28 +02005122
Willy Tarreauc57f0e22009-05-10 13:12:33 +02005123 server <name> <address>[:port] [settings ...]
Krzysztof Piotr Oledzkic6df0662010-01-05 16:38:49 +01005124 default-server [settings ...]
Willy Tarreau6a06a402007-07-15 20:15:28 +02005125
Krzysztof Piotr Oledzkic53601c2010-01-06 10:50:42 +01005126The currently supported settings are the following ones.
Willy Tarreau0ba27502007-12-24 16:55:16 +01005127
Willy Tarreauc57f0e22009-05-10 13:12:33 +02005128addr <ipv4>
5129 Using the "addr" parameter, it becomes possible to use a different IP address
5130 to send health-checks. On some servers, it may be desirable to dedicate an IP
5131 address to specific component able to perform complex tests which are more
5132 suitable to health-checks than the application. This parameter is ignored if
5133 the "check" parameter is not set. See also the "port" parameter.
Willy Tarreau6a06a402007-07-15 20:15:28 +02005134
Krzysztof Piotr Oledzkic53601c2010-01-06 10:50:42 +01005135 Supported in default-server: No
5136
Willy Tarreauc57f0e22009-05-10 13:12:33 +02005137backup
5138 When "backup" is present on a server line, the server is only used in load
5139 balancing when all other non-backup servers are unavailable. Requests coming
5140 with a persistence cookie referencing the server will always be served
5141 though. By default, only the first operational backup server is used, unless
5142 the "allbackups" option is set in the backend. See also the "allbackups"
5143 option.
Willy Tarreau6a06a402007-07-15 20:15:28 +02005144
Krzysztof Piotr Oledzkic53601c2010-01-06 10:50:42 +01005145 Supported in default-server: No
5146
Willy Tarreauc57f0e22009-05-10 13:12:33 +02005147check
5148 This option enables health checks on the server. By default, a server is
5149 always considered available. If "check" is set, the server will receive
5150 periodic health checks to ensure that it is really able to serve requests.
5151 The default address and port to send the tests to are those of the server,
5152 and the default source is the same as the one defined in the backend. It is
5153 possible to change the address using the "addr" parameter, the port using the
5154 "port" parameter, the source address using the "source" address, and the
5155 interval and timers using the "inter", "rise" and "fall" parameters. The
5156 request method is define in the backend using the "httpchk", "smtpchk",
Hervé COMMOWICK698ae002010-01-12 09:25:13 +01005157 "mysql-check" and "ssl-hello-chk" options. Please refer to those options and
5158 parameters for more information.
Willy Tarreauc57f0e22009-05-10 13:12:33 +02005159
Krzysztof Piotr Oledzkic53601c2010-01-06 10:50:42 +01005160 Supported in default-server: No
5161
Willy Tarreauc57f0e22009-05-10 13:12:33 +02005162cookie <value>
5163 The "cookie" parameter sets the cookie value assigned to the server to
5164 <value>. This value will be checked in incoming requests, and the first
5165 operational server possessing the same value will be selected. In return, in
5166 cookie insertion or rewrite modes, this value will be assigned to the cookie
5167 sent to the client. There is nothing wrong in having several servers sharing
5168 the same cookie value, and it is in fact somewhat common between normal and
5169 backup servers. See also the "cookie" keyword in backend section.
5170
Krzysztof Piotr Oledzkic53601c2010-01-06 10:50:42 +01005171 Supported in default-server: No
5172
5173error-limit <count>
Willy Tarreau983e01e2010-01-11 18:42:06 +01005174 If health observing is enabled, the "error-limit" parameter specifies the
5175 number of consecutive errors that triggers event selected by the "on-error"
5176 option. By default it is set to 10 consecutive errors.
Krzysztof Piotr Oledzki97f07b82009-12-15 22:31:24 +01005177
Krzysztof Piotr Oledzkic53601c2010-01-06 10:50:42 +01005178 Supported in default-server: Yes
5179
5180 See also the "check", "error-limit" and "on-error".
Krzysztof Piotr Oledzki97f07b82009-12-15 22:31:24 +01005181
Krzysztof Piotr Oledzkic53601c2010-01-06 10:50:42 +01005182fall <count>
Willy Tarreauc57f0e22009-05-10 13:12:33 +02005183 The "fall" parameter states that a server will be considered as dead after
5184 <count> consecutive unsuccessful health checks. This value defaults to 3 if
5185 unspecified. See also the "check", "inter" and "rise" parameters.
5186
Krzysztof Piotr Oledzkic53601c2010-01-06 10:50:42 +01005187 Supported in default-server: Yes
5188
Willy Tarreauc57f0e22009-05-10 13:12:33 +02005189id <value>
Willy Tarreau53fb4ae2009-10-04 23:04:08 +02005190 Set a persistent ID for the server. This ID must be positive and unique for
5191 the proxy. An unused ID will automatically be assigned if unset. The first
5192 assigned value will be 1. This ID is currently only returned in statistics.
Willy Tarreauc57f0e22009-05-10 13:12:33 +02005193
Krzysztof Piotr Oledzkic53601c2010-01-06 10:50:42 +01005194 Supported in default-server: No
5195
5196inter <delay>
5197fastinter <delay>
5198downinter <delay>
Willy Tarreauc57f0e22009-05-10 13:12:33 +02005199 The "inter" parameter sets the interval between two consecutive health checks
5200 to <delay> milliseconds. If left unspecified, the delay defaults to 2000 ms.
5201 It is also possible to use "fastinter" and "downinter" to optimize delays
5202 between checks depending on the server state :
5203
5204 Server state | Interval used
5205 ---------------------------------+-----------------------------------------
5206 UP 100% (non-transitional) | "inter"
5207 ---------------------------------+-----------------------------------------
5208 Transitionally UP (going down), |
5209 Transitionally DOWN (going up), | "fastinter" if set, "inter" otherwise.
5210 or yet unchecked. |
5211 ---------------------------------+-----------------------------------------
5212 DOWN 100% (non-transitional) | "downinter" if set, "inter" otherwise.
5213 ---------------------------------+-----------------------------------------
Willy Tarreaud72758d2010-01-12 10:42:19 +01005214
Willy Tarreauc57f0e22009-05-10 13:12:33 +02005215 Just as with every other time-based parameter, they can be entered in any
5216 other explicit unit among { us, ms, s, m, h, d }. The "inter" parameter also
5217 serves as a timeout for health checks sent to servers if "timeout check" is
5218 not set. In order to reduce "resonance" effects when multiple servers are
5219 hosted on the same hardware, the health-checks of all servers are started
5220 with a small time offset between them. It is also possible to add some random
5221 noise in the health checks interval using the global "spread-checks"
5222 keyword. This makes sense for instance when a lot of backends use the same
5223 servers.
5224
Krzysztof Piotr Oledzkic53601c2010-01-06 10:50:42 +01005225 Supported in default-server: Yes
5226
5227maxconn <maxconn>
Willy Tarreauc57f0e22009-05-10 13:12:33 +02005228 The "maxconn" parameter specifies the maximal number of concurrent
5229 connections that will be sent to this server. If the number of incoming
5230 concurrent requests goes higher than this value, they will be queued, waiting
5231 for a connection to be released. This parameter is very important as it can
5232 save fragile servers from going down under extreme loads. If a "minconn"
5233 parameter is specified, the limit becomes dynamic. The default value is "0"
5234 which means unlimited. See also the "minconn" and "maxqueue" parameters, and
5235 the backend's "fullconn" keyword.
5236
Krzysztof Piotr Oledzkic53601c2010-01-06 10:50:42 +01005237 Supported in default-server: Yes
5238
5239maxqueue <maxqueue>
Willy Tarreauc57f0e22009-05-10 13:12:33 +02005240 The "maxqueue" parameter specifies the maximal number of connections which
5241 will wait in the queue for this server. If this limit is reached, next
5242 requests will be redispatched to other servers instead of indefinitely
5243 waiting to be served. This will break persistence but may allow people to
5244 quickly re-log in when the server they try to connect to is dying. The
5245 default value is "0" which means the queue is unlimited. See also the
5246 "maxconn" and "minconn" parameters.
5247
Krzysztof Piotr Oledzkic53601c2010-01-06 10:50:42 +01005248 Supported in default-server: Yes
5249
5250minconn <minconn>
Willy Tarreauc57f0e22009-05-10 13:12:33 +02005251 When the "minconn" parameter is set, the maxconn limit becomes a dynamic
5252 limit following the backend's load. The server will always accept at least
5253 <minconn> connections, never more than <maxconn>, and the limit will be on
5254 the ramp between both values when the backend has less than <fullconn>
5255 concurrent connections. This makes it possible to limit the load on the
5256 server during normal loads, but push it further for important loads without
Krzysztof Piotr Oledzkif8645332009-12-13 21:55:50 +01005257 overloading the server during exceptional loads. See also the "maxconn"
Willy Tarreauc57f0e22009-05-10 13:12:33 +02005258 and "maxqueue" parameters, as well as the "fullconn" backend keyword.
Krzysztof Piotr Oledzki97f07b82009-12-15 22:31:24 +01005259
Krzysztof Piotr Oledzkic53601c2010-01-06 10:50:42 +01005260 Supported in default-server: Yes
5261
Krzysztof Piotr Oledzki97f07b82009-12-15 22:31:24 +01005262observe <mode>
5263 This option enables health adjusting based on observing communication with
5264 the server. By default this functionality is disabled and enabling it also
5265 requires to enable health checks. There are two supported modes: "layer4" and
5266 "layer7". In layer4 mode, only successful/unsuccessful tcp connections are
5267 significant. In layer7, which is only allowed for http proxies, responses
5268 received from server are verified, like valid/wrong http code, unparsable
5269 headers, a timeout, etc.
5270
Krzysztof Piotr Oledzkic53601c2010-01-06 10:50:42 +01005271 Supported in default-server: No
5272
Krzysztof Piotr Oledzki97f07b82009-12-15 22:31:24 +01005273 See also the "check", "on-error" and "error-limit".
5274
Krzysztof Piotr Oledzkic53601c2010-01-06 10:50:42 +01005275on-error <mode>
Krzysztof Piotr Oledzki97f07b82009-12-15 22:31:24 +01005276 Select what should happen when enough consecutive errors are detected.
5277 Currently, four modes are available:
5278 - fastinter: force fastinter
5279 - fail-check: simulate a failed check, also forces fastinter (default)
5280 - sudden-death: simulate a pre-fatal failed health check, one more failed
5281 check will mark a server down, forces fastinter
5282 - mark-down: mark the server immediately down and force fastinter
5283
Krzysztof Piotr Oledzkic53601c2010-01-06 10:50:42 +01005284 Supported in default-server: Yes
5285
Krzysztof Piotr Oledzki97f07b82009-12-15 22:31:24 +01005286 See also the "check", "observe" and "error-limit".
5287
Krzysztof Piotr Oledzkic53601c2010-01-06 10:50:42 +01005288port <port>
Willy Tarreauc57f0e22009-05-10 13:12:33 +02005289 Using the "port" parameter, it becomes possible to use a different port to
5290 send health-checks. On some servers, it may be desirable to dedicate a port
5291 to a specific component able to perform complex tests which are more suitable
5292 to health-checks than the application. It is common to run a simple script in
5293 inetd for instance. This parameter is ignored if the "check" parameter is not
5294 set. See also the "addr" parameter.
5295
Krzysztof Piotr Oledzkic53601c2010-01-06 10:50:42 +01005296 Supported in default-server: Yes
5297
Willy Tarreauc57f0e22009-05-10 13:12:33 +02005298redir <prefix>
5299 The "redir" parameter enables the redirection mode for all GET and HEAD
5300 requests addressing this server. This means that instead of having HAProxy
5301 forward the request to the server, it will send an "HTTP 302" response with
5302 the "Location" header composed of this prefix immediately followed by the
5303 requested URI beginning at the leading '/' of the path component. That means
5304 that no trailing slash should be used after <prefix>. All invalid requests
5305 will be rejected, and all non-GET or HEAD requests will be normally served by
5306 the server. Note that since the response is completely forged, no header
Krzysztof Piotr Oledzkif8645332009-12-13 21:55:50 +01005307 mangling nor cookie insertion is possible in the response. However, cookies in
Willy Tarreauc57f0e22009-05-10 13:12:33 +02005308 requests are still analysed, making this solution completely usable to direct
5309 users to a remote location in case of local disaster. Main use consists in
5310 increasing bandwidth for static servers by having the clients directly
5311 connect to them. Note: never use a relative location here, it would cause a
5312 loop between the client and HAProxy!
5313
5314 Example : server srv1 192.168.1.1:80 redir http://image1.mydomain.com check
5315
Krzysztof Piotr Oledzkic53601c2010-01-06 10:50:42 +01005316 Supported in default-server: No
5317
5318rise <count>
Willy Tarreauc57f0e22009-05-10 13:12:33 +02005319 The "rise" parameter states that a server will be considered as operational
5320 after <count> consecutive successful health checks. This value defaults to 2
5321 if unspecified. See also the "check", "inter" and "fall" parameters.
5322
Krzysztof Piotr Oledzkic53601c2010-01-06 10:50:42 +01005323 Supported in default-server: Yes
5324
5325slowstart <start_time_in_ms>
Willy Tarreauc57f0e22009-05-10 13:12:33 +02005326 The "slowstart" parameter for a server accepts a value in milliseconds which
5327 indicates after how long a server which has just come back up will run at
5328 full speed. Just as with every other time-based parameter, it can be entered
5329 in any other explicit unit among { us, ms, s, m, h, d }. The speed grows
5330 linearly from 0 to 100% during this time. The limitation applies to two
5331 parameters :
5332
5333 - maxconn: the number of connections accepted by the server will grow from 1
5334 to 100% of the usual dynamic limit defined by (minconn,maxconn,fullconn).
5335
5336 - weight: when the backend uses a dynamic weighted algorithm, the weight
5337 grows linearly from 1 to 100%. In this case, the weight is updated at every
5338 health-check. For this reason, it is important that the "inter" parameter
5339 is smaller than the "slowstart", in order to maximize the number of steps.
5340
5341 The slowstart never applies when haproxy starts, otherwise it would cause
5342 trouble to running servers. It only applies when a server has been previously
5343 seen as failed.
5344
Krzysztof Piotr Oledzkic53601c2010-01-06 10:50:42 +01005345 Supported in default-server: Yes
5346
Willy Tarreauc6f4ce82009-06-10 11:09:37 +02005347source <addr>[:<pl>[-<ph>]] [usesrc { <addr2>[:<port2>] | client | clientip } ]
5348source <addr>[:<pl>[-<ph>]] [interface <name>] ...
Willy Tarreauc57f0e22009-05-10 13:12:33 +02005349 The "source" parameter sets the source address which will be used when
5350 connecting to the server. It follows the exact same parameters and principle
5351 as the backend "source" keyword, except that it only applies to the server
5352 referencing it. Please consult the "source" keyword for details.
5353
Willy Tarreauc6f4ce82009-06-10 11:09:37 +02005354 Additionally, the "source" statement on a server line allows one to specify a
5355 source port range by indicating the lower and higher bounds delimited by a
5356 dash ('-'). Some operating systems might require a valid IP address when a
5357 source port range is specified. It is permitted to have the same IP/range for
5358 several servers. Doing so makes it possible to bypass the maximum of 64k
5359 total concurrent connections. The limit will then reach 64k connections per
5360 server.
5361
Krzysztof Piotr Oledzkic53601c2010-01-06 10:50:42 +01005362 Supported in default-server: No
5363
Willy Tarreauc57f0e22009-05-10 13:12:33 +02005364track [<proxy>/]<server>
5365 This option enables ability to set the current state of the server by
5366 tracking another one. Only a server with checks enabled can be tracked
5367 so it is not possible for example to track a server that tracks another
5368 one. If <proxy> is omitted the current one is used. If disable-on-404 is
5369 used, it has to be enabled on both proxies.
5370
Krzysztof Piotr Oledzkic53601c2010-01-06 10:50:42 +01005371 Supported in default-server: No
5372
5373weight <weight>
Willy Tarreauc57f0e22009-05-10 13:12:33 +02005374 The "weight" parameter is used to adjust the server's weight relative to
5375 other servers. All servers will receive a load proportional to their weight
5376 relative to the sum of all weights, so the higher the weight, the higher the
Willy Tarreau6704d672009-06-15 10:56:05 +02005377 load. The default weight is 1, and the maximal value is 256. A value of 0
5378 means the server will not participate in load-balancing but will still accept
5379 persistent connections. If this parameter is used to distribute the load
5380 according to server's capacity, it is recommended to start with values which
5381 can both grow and shrink, for instance between 10 and 100 to leave enough
5382 room above and below for later adjustments.
Willy Tarreauc57f0e22009-05-10 13:12:33 +02005383
Krzysztof Piotr Oledzkic53601c2010-01-06 10:50:42 +01005384 Supported in default-server: Yes
5385
Willy Tarreauc57f0e22009-05-10 13:12:33 +02005386
53876. HTTP header manipulation
5388---------------------------
5389
5390In HTTP mode, it is possible to rewrite, add or delete some of the request and
5391response headers based on regular expressions. It is also possible to block a
5392request or a response if a particular header matches a regular expression,
5393which is enough to stop most elementary protocol attacks, and to protect
5394against information leak from the internal network. But there is a limitation
5395to this : since HAProxy's HTTP engine does not support keep-alive, only headers
5396passed during the first request of a TCP session will be seen. All subsequent
5397headers will be considered data only and not analyzed. Furthermore, HAProxy
5398never touches data contents, it stops analysis at the end of headers.
5399
Willy Tarreau816b9792009-09-15 21:25:21 +02005400There is an exception though. If HAProxy encounters an "Informational Response"
5401(status code 1xx), it is able to process all rsp* rules which can allow, deny,
5402rewrite or delete a header, but it will refuse to add a header to any such
5403messages as this is not HTTP-compliant. The reason for still processing headers
5404in such responses is to stop and/or fix any possible information leak which may
Krzysztof Piotr Oledzkif8645332009-12-13 21:55:50 +01005405happen, for instance because another downstream equipment would unconditionally
Willy Tarreau816b9792009-09-15 21:25:21 +02005406add a header, or if a server name appears there. When such messages are seen,
5407normal processing still occurs on the next non-informational messages.
5408
Willy Tarreauc57f0e22009-05-10 13:12:33 +02005409This section covers common usage of the following keywords, described in detail
5410in section 4.2 :
5411
5412 - reqadd <string>
5413 - reqallow <search>
5414 - reqiallow <search>
5415 - reqdel <search>
5416 - reqidel <search>
5417 - reqdeny <search>
5418 - reqideny <search>
5419 - reqpass <search>
5420 - reqipass <search>
5421 - reqrep <search> <replace>
5422 - reqirep <search> <replace>
5423 - reqtarpit <search>
5424 - reqitarpit <search>
5425 - rspadd <string>
5426 - rspdel <search>
5427 - rspidel <search>
5428 - rspdeny <search>
5429 - rspideny <search>
5430 - rsprep <search> <replace>
5431 - rspirep <search> <replace>
5432
5433With all these keywords, the same conventions are used. The <search> parameter
5434is a POSIX extended regular expression (regex) which supports grouping through
5435parenthesis (without the backslash). Spaces and other delimiters must be
5436prefixed with a backslash ('\') to avoid confusion with a field delimiter.
5437Other characters may be prefixed with a backslash to change their meaning :
5438
5439 \t for a tab
5440 \r for a carriage return (CR)
5441 \n for a new line (LF)
5442 \ to mark a space and differentiate it from a delimiter
5443 \# to mark a sharp and differentiate it from a comment
5444 \\ to use a backslash in a regex
5445 \\\\ to use a backslash in the text (*2 for regex, *2 for haproxy)
5446 \xXX to write the ASCII hex code XX as in the C language
5447
5448The <replace> parameter contains the string to be used to replace the largest
5449portion of text matching the regex. It can make use of the special characters
5450above, and can reference a substring which is delimited by parenthesis in the
5451regex, by writing a backslash ('\') immediately followed by one digit from 0 to
54529 indicating the group position (0 designating the entire line). This practice
5453is very common to users of the "sed" program.
5454
5455The <string> parameter represents the string which will systematically be added
5456after the last header line. It can also use special character sequences above.
5457
5458Notes related to these keywords :
5459---------------------------------
5460 - these keywords are not always convenient to allow/deny based on header
5461 contents. It is strongly recommended to use ACLs with the "block" keyword
5462 instead, resulting in far more flexible and manageable rules.
5463
5464 - lines are always considered as a whole. It is not possible to reference
5465 a header name only or a value only. This is important because of the way
5466 headers are written (notably the number of spaces after the colon).
5467
5468 - the first line is always considered as a header, which makes it possible to
5469 rewrite or filter HTTP requests URIs or response codes, but in turn makes
5470 it harder to distinguish between headers and request line. The regex prefix
5471 ^[^\ \t]*[\ \t] matches any HTTP method followed by a space, and the prefix
5472 ^[^ \t:]*: matches any header name followed by a colon.
5473
5474 - for performances reasons, the number of characters added to a request or to
5475 a response is limited at build time to values between 1 and 4 kB. This
5476 should normally be far more than enough for most usages. If it is too short
5477 on occasional usages, it is possible to gain some space by removing some
5478 useless headers before adding new ones.
5479
Krzysztof Piotr Oledzkif8645332009-12-13 21:55:50 +01005480 - keywords beginning with "reqi" and "rspi" are the same as their counterpart
Willy Tarreauc57f0e22009-05-10 13:12:33 +02005481 without the 'i' letter except that they ignore case when matching patterns.
5482
5483 - when a request passes through a frontend then a backend, all req* rules
5484 from the frontend will be evaluated, then all req* rules from the backend
5485 will be evaluated. The reverse path is applied to responses.
5486
5487 - req* statements are applied after "block" statements, so that "block" is
5488 always the first one, but before "use_backend" in order to permit rewriting
Willy Tarreaud72758d2010-01-12 10:42:19 +01005489 before switching.
Willy Tarreauc57f0e22009-05-10 13:12:33 +02005490
5491
Willy Tarreaub937b7e2010-01-12 15:27:54 +010054927. Using ACLs and pattern extraction
5493------------------------------------
Willy Tarreauc57f0e22009-05-10 13:12:33 +02005494
5495The use of Access Control Lists (ACL) provides a flexible solution to perform
5496content switching and generally to take decisions based on content extracted
5497from the request, the response or any environmental status. The principle is
5498simple :
5499
5500 - define test criteria with sets of values
5501 - perform actions only if a set of tests is valid
5502
5503The actions generally consist in blocking the request, or selecting a backend.
5504
5505In order to define a test, the "acl" keyword is used. The syntax is :
5506
5507 acl <aclname> <criterion> [flags] [operator] <value> ...
5508
5509This creates a new ACL <aclname> or completes an existing one with new tests.
5510Those tests apply to the portion of request/response specified in <criterion>
5511and may be adjusted with optional flags [flags]. Some criteria also support
5512an operator which may be specified before the set of values. The values are
5513of the type supported by the criterion, and are separated by spaces.
5514
5515ACL names must be formed from upper and lower case letters, digits, '-' (dash),
5516'_' (underscore) , '.' (dot) and ':' (colon). ACL names are case-sensitive,
5517which means that "my_acl" and "My_Acl" are two different ACLs.
5518
5519There is no enforced limit to the number of ACLs. The unused ones do not affect
5520performance, they just consume a small amount of memory.
5521
5522The following ACL flags are currently supported :
5523
5524 -i : ignore case during matching.
Willy Tarreau6a06a402007-07-15 20:15:28 +02005525 -- : force end of flags. Useful when a string looks like one of the flags.
5526
5527Supported types of values are :
Willy Tarreau0ba27502007-12-24 16:55:16 +01005528
Willy Tarreau6a06a402007-07-15 20:15:28 +02005529 - integers or integer ranges
5530 - strings
5531 - regular expressions
5532 - IP addresses and networks
5533
5534
Willy Tarreauc57f0e22009-05-10 13:12:33 +020055357.1. Matching integers
5536----------------------
Willy Tarreau6a06a402007-07-15 20:15:28 +02005537
5538Matching integers is special in that ranges and operators are permitted. Note
5539that integer matching only applies to positive values. A range is a value
5540expressed with a lower and an upper bound separated with a colon, both of which
5541may be omitted.
5542
5543For instance, "1024:65535" is a valid range to represent a range of
5544unprivileged ports, and "1024:" would also work. "0:1023" is a valid
5545representation of privileged ports, and ":1023" would also work.
5546
Willy Tarreau62644772008-07-16 18:36:06 +02005547As a special case, some ACL functions support decimal numbers which are in fact
5548two integers separated by a dot. This is used with some version checks for
5549instance. All integer properties apply to those decimal numbers, including
5550ranges and operators.
5551
Willy Tarreau6a06a402007-07-15 20:15:28 +02005552For an easier usage, comparison operators are also supported. Note that using
Willy Tarreau0ba27502007-12-24 16:55:16 +01005553operators with ranges does not make much sense and is strongly discouraged.
5554Similarly, it does not make much sense to perform order comparisons with a set
5555of values.
Willy Tarreau6a06a402007-07-15 20:15:28 +02005556
Willy Tarreau0ba27502007-12-24 16:55:16 +01005557Available operators for integer matching are :
Willy Tarreau6a06a402007-07-15 20:15:28 +02005558
5559 eq : true if the tested value equals at least one value
5560 ge : true if the tested value is greater than or equal to at least one value
5561 gt : true if the tested value is greater than at least one value
5562 le : true if the tested value is less than or equal to at least one value
5563 lt : true if the tested value is less than at least one value
5564
Willy Tarreau0ba27502007-12-24 16:55:16 +01005565For instance, the following ACL matches any negative Content-Length header :
Willy Tarreau6a06a402007-07-15 20:15:28 +02005566
5567 acl negative-length hdr_val(content-length) lt 0
5568
Willy Tarreau62644772008-07-16 18:36:06 +02005569This one matches SSL versions between 3.0 and 3.1 (inclusive) :
5570
5571 acl sslv3 req_ssl_ver 3:3.1
5572
Willy Tarreau6a06a402007-07-15 20:15:28 +02005573
Willy Tarreauc57f0e22009-05-10 13:12:33 +020055747.2. Matching strings
5575---------------------
Willy Tarreau6a06a402007-07-15 20:15:28 +02005576
5577String matching applies to verbatim strings as they are passed, with the
5578exception of the backslash ("\") which makes it possible to escape some
5579characters such as the space. If the "-i" flag is passed before the first
5580string, then the matching will be performed ignoring the case. In order
5581to match the string "-i", either set it second, or pass the "--" flag
Willy Tarreau0ba27502007-12-24 16:55:16 +01005582before the first string. Same applies of course to match the string "--".
Willy Tarreau6a06a402007-07-15 20:15:28 +02005583
5584
Willy Tarreauc57f0e22009-05-10 13:12:33 +020055857.3. Matching regular expressions (regexes)
5586-------------------------------------------
Willy Tarreau6a06a402007-07-15 20:15:28 +02005587
5588Just like with string matching, regex matching applies to verbatim strings as
5589they are passed, with the exception of the backslash ("\") which makes it
5590possible to escape some characters such as the space. If the "-i" flag is
5591passed before the first regex, then the matching will be performed ignoring
5592the case. In order to match the string "-i", either set it second, or pass
Willy Tarreau0ba27502007-12-24 16:55:16 +01005593the "--" flag before the first string. Same principle applies of course to
5594match the string "--".
Willy Tarreau6a06a402007-07-15 20:15:28 +02005595
5596
Willy Tarreauc57f0e22009-05-10 13:12:33 +020055977.4. Matching IPv4 addresses
5598----------------------------
Willy Tarreau6a06a402007-07-15 20:15:28 +02005599
5600IPv4 addresses values can be specified either as plain addresses or with a
5601netmask appended, in which case the IPv4 address matches whenever it is
5602within the network. Plain addresses may also be replaced with a resolvable
Willy Tarreaud2a4aa22008-01-31 15:28:22 +01005603host name, but this practice is generally discouraged as it makes it more
Willy Tarreau0ba27502007-12-24 16:55:16 +01005604difficult to read and debug configurations. If hostnames are used, you should
5605at least ensure that they are present in /etc/hosts so that the configuration
5606does not depend on any random DNS match at the moment the configuration is
5607parsed.
Willy Tarreau6a06a402007-07-15 20:15:28 +02005608
5609
Willy Tarreauc57f0e22009-05-10 13:12:33 +020056107.5. Available matching criteria
5611--------------------------------
Willy Tarreau6a06a402007-07-15 20:15:28 +02005612
Willy Tarreauc57f0e22009-05-10 13:12:33 +020056137.5.1. Matching at Layer 4 and below
5614------------------------------------
Willy Tarreau0ba27502007-12-24 16:55:16 +01005615
5616A first set of criteria applies to information which does not require any
5617analysis of the request or response contents. Those generally include TCP/IP
5618addresses and ports, as well as internal values independant on the stream.
5619
Willy Tarreau6a06a402007-07-15 20:15:28 +02005620always_false
5621 This one never matches. All values and flags are ignored. It may be used as
5622 a temporary replacement for another one when adjusting configurations.
5623
5624always_true
5625 This one always matches. All values and flags are ignored. It may be used as
5626 a temporary replacement for another one when adjusting configurations.
5627
5628src <ip_address>
Willy Tarreau0ba27502007-12-24 16:55:16 +01005629 Applies to the client's IPv4 address. It is usually used to limit access to
Willy Tarreau6a06a402007-07-15 20:15:28 +02005630 certain resources such as statistics. Note that it is the TCP-level source
5631 address which is used, and not the address of a client behind a proxy.
5632
5633src_port <integer>
5634 Applies to the client's TCP source port. This has a very limited usage.
5635
5636dst <ip_address>
Willy Tarreau0ba27502007-12-24 16:55:16 +01005637 Applies to the local IPv4 address the client connected to. It can be used to
Willy Tarreau6a06a402007-07-15 20:15:28 +02005638 switch to a different backend for some alternative addresses.
5639
5640dst_port <integer>
5641 Applies to the local port the client connected to. It can be used to switch
5642 to a different backend for some alternative ports.
5643
5644dst_conn <integer>
Willy Tarreaua36af912009-10-10 12:02:45 +02005645 Applies to the number of currently established connections on the same socket
Willy Tarreau6a06a402007-07-15 20:15:28 +02005646 including the one being evaluated. It can be used to either return a sorry
Willy Tarreau0ba27502007-12-24 16:55:16 +01005647 page before hard-blocking, or to use a specific backend to drain new requests
Willy Tarreaua36af912009-10-10 12:02:45 +02005648 when the socket is considered saturated. This offers the ability to assign
5649 different limits to different listening ports or addresses. See also the
5650 "fe_conn" and "be_conn" criteria.
5651
5652fe_conn <integer>
5653fe_conn(frontend) <integer>
5654 Applies to the number of currently established connections on the frontend,
5655 possibly including the connection being evaluated. If no frontend name is
5656 specified, the current one is used. But it is also possible to check another
5657 frontend. It can be used to either return a sorry page before hard-blocking,
5658 or to use a specific backend to drain new requests when the farm is
5659 considered saturated. See also the "dst_conn", "be_conn" and "fe_sess_rate"
5660 criteria.
5661
Krzysztof Piotr Oledzki346f76d2010-01-12 21:59:30 +01005662fe_id <integer>
5663 Applies to the fronted's id. Can be used in backends to check from which
5664 frontend it was called.
5665
5666so_id <integer>
5667 Applies to the socket's id. Useful in frontends with many bind keywords.
5668
Willy Tarreaua36af912009-10-10 12:02:45 +02005669be_conn <integer>
5670be_conn(frontend) <integer>
5671 Applies to the number of currently established connections on the backend,
5672 possibly including the connection being evaluated. If no backend name is
5673 specified, the current one is used. But it is also possible to check another
5674 backend. It can be used to use a specific farm when the nominal one is full.
5675 See also the "fe_conn", "queue" and "be_sess_rate" criteria.
Willy Tarreau6a06a402007-07-15 20:15:28 +02005676
Willy Tarreau0ba27502007-12-24 16:55:16 +01005677nbsrv <integer>
5678nbsrv(backend) <integer>
5679 Returns true when the number of usable servers of either the current backend
5680 or the named backend matches the values or ranges specified. This is used to
5681 switch to an alternate backend when the number of servers is too low to
5682 to handle some load. It is useful to report a failure when combined with
5683 "monitor fail".
5684
Jeffrey 'jf' Lim5051d7b2008-09-04 01:03:03 +08005685connslots <integer>
5686connslots(backend) <integer>
5687 The basic idea here is to be able to measure the number of connection "slots"
Willy Tarreau55165fe2009-05-10 12:02:55 +02005688 still available (connection + queue), so that anything beyond that (intended
Jeffrey 'jf' Lim5051d7b2008-09-04 01:03:03 +08005689 usage; see "use_backend" keyword) can be redirected to a different backend.
5690
Willy Tarreau55165fe2009-05-10 12:02:55 +02005691 'connslots' = number of available server connection slots, + number of
5692 available server queue slots.
Jeffrey 'jf' Lim5051d7b2008-09-04 01:03:03 +08005693
Willy Tarreaua36af912009-10-10 12:02:45 +02005694 Note that while "fe_conn" may be used, "connslots" comes in especially
Willy Tarreau55165fe2009-05-10 12:02:55 +02005695 useful when you have a case of traffic going to one single ip, splitting into
5696 multiple backends (perhaps using acls to do name-based load balancing) and
5697 you want to be able to differentiate between different backends, and their
5698 available "connslots". Also, whereas "nbsrv" only measures servers that are
5699 actually *down*, this acl is more fine-grained and looks into the number of
Willy Tarreaua36af912009-10-10 12:02:45 +02005700 available connection slots as well. See also "queue" and "avg_queue".
Jeffrey 'jf' Lim5051d7b2008-09-04 01:03:03 +08005701
Willy Tarreau55165fe2009-05-10 12:02:55 +02005702 OTHER CAVEATS AND NOTES: at this point in time, the code does not take care
5703 of dynamic connections. Also, if any of the server maxconn, or maxqueue is 0,
5704 then this acl clearly does not make sense, in which case the value returned
5705 will be -1.
Jeffrey 'jf' Lim5051d7b2008-09-04 01:03:03 +08005706
Willy Tarreaua36af912009-10-10 12:02:45 +02005707queue <integer>
5708queue(frontend) <integer>
5709 Returns the total number of queued connections of the designated backend,
5710 including all the connections in server queues. If no backend name is
5711 specified, the current one is used, but it is also possible to check another
5712 one. This can be used to take actions when queuing goes above a known level,
5713 generally indicating a surge of traffic or a massive slowdown on the servers.
5714 One possible action could be to reject new users but still accept old ones.
5715 See also the "avg_queue", "be_conn", and "be_sess_rate" criteria.
5716
5717avg_queue <integer>
5718avg_queue(frontend) <integer>
5719 Returns the total number of queued connections of the designated backend
5720 divided by the number of active servers. This is very similar to "queue"
5721 except that the size of the farm is considered, in order to give a more
5722 accurate measurement of the time it may take for a new connection to be
5723 processed. The main usage is to return a sorry page to new users when it
5724 becomes certain they will get a degraded service. Note that in the event
5725 there would not be any active server anymore, we would consider twice the
5726 number of queued connections as the measured value. This is a fair estimate,
5727 as we expect one server to get back soon anyway, but we still prefer to send
5728 new traffic to another backend if in better shape. See also the "queue",
5729 "be_conn", and "be_sess_rate" criteria.
5730
Willy Tarreau079ff0a2009-03-05 21:34:28 +01005731fe_sess_rate <integer>
5732fe_sess_rate(frontend) <integer>
5733 Returns true when the session creation rate on the current or the named
5734 frontend matches the specified values or ranges, expressed in new sessions
5735 per second. This is used to limit the connection rate to acceptable ranges in
5736 order to prevent abuse of service at the earliest moment. This can be
5737 combined with layer 4 ACLs in order to force the clients to wait a bit for
5738 the rate to go down below the limit.
5739
5740 Example :
5741 # This frontend limits incoming mails to 10/s with a max of 100
5742 # concurrent connections. We accept any connection below 10/s, and
5743 # force excess clients to wait for 100 ms. Since clients are limited to
5744 # 100 max, there cannot be more than 10 incoming mails per second.
5745 frontend mail
5746 bind :25
5747 mode tcp
5748 maxconn 100
5749 acl too_fast fe_sess_rate ge 10
5750 tcp-request inspect-delay 100ms
5751 tcp-request content accept if ! too_fast
5752 tcp-request content accept if WAIT_END
Willy Tarreaud72758d2010-01-12 10:42:19 +01005753
Willy Tarreau079ff0a2009-03-05 21:34:28 +01005754be_sess_rate <integer>
5755be_sess_rate(backend) <integer>
5756 Returns true when the sessions creation rate on the backend matches the
5757 specified values or ranges, in number of new sessions per second. This is
5758 used to switch to an alternate backend when an expensive or fragile one
Krzysztof Piotr Oledzkif8645332009-12-13 21:55:50 +01005759 reaches too high a session rate, or to limit abuse of service (eg. prevent
Willy Tarreau079ff0a2009-03-05 21:34:28 +01005760 sucking of an online dictionary).
5761
5762 Example :
5763 # Redirect to an error page if the dictionary is requested too often
5764 backend dynamic
5765 mode http
5766 acl being_scanned be_sess_rate gt 100
5767 redirect location /denied.html if being_scanned
5768
Willy Tarreau0ba27502007-12-24 16:55:16 +01005769
Willy Tarreauc57f0e22009-05-10 13:12:33 +020057707.5.2. Matching contents at Layer 4
5771-----------------------------------
Willy Tarreau62644772008-07-16 18:36:06 +02005772
5773A second set of criteria depends on data found in buffers, but which can change
5774during analysis. This requires that some data has been buffered, for instance
5775through TCP request content inspection. Please see the "tcp-request" keyword
5776for more detailed information on the subject.
5777
5778req_len <integer>
Emeric Brunbede3d02009-06-30 17:54:00 +02005779 Returns true when the length of the data in the request buffer matches the
Willy Tarreau62644772008-07-16 18:36:06 +02005780 specified range. It is important to understand that this test does not
5781 return false as long as the buffer is changing. This means that a check with
5782 equality to zero will almost always immediately match at the beginning of the
5783 session, while a test for more data will wait for that data to come in and
5784 return false only when haproxy is certain that no more data will come in.
5785 This test was designed to be used with TCP request content inspection.
5786
Willy Tarreau2492d5b2009-07-11 00:06:00 +02005787req_proto_http
5788 Returns true when data in the request buffer look like HTTP and correctly
5789 parses as such. It is the same parser as the common HTTP request parser which
Krzysztof Piotr Oledzkif8645332009-12-13 21:55:50 +01005790 is used so there should be no surprises. This test can be used for instance
Willy Tarreau2492d5b2009-07-11 00:06:00 +02005791 to direct HTTP traffic to a given port and HTTPS traffic to another one
5792 using TCP request content inspection rules.
5793
Emeric Brunbede3d02009-06-30 17:54:00 +02005794req_rdp_cookie <string>
5795req_rdp_cookie(name) <string>
5796 Returns true when data in the request buffer look like the RDP protocol, and
5797 a cookie is present and equal to <string>. By default, any cookie name is
5798 checked, but a specific cookie name can be specified in parenthesis. The
5799 parser only checks for the first cookie, as illustrated in the RDP protocol
5800 specification. The cookie name is case insensitive. This ACL can be useful
5801 with the "MSTS" cookie, as it can contain the user name of the client
5802 connecting to the server if properly configured on the client. This can be
5803 used to restrict access to certain servers to certain users.
5804
5805req_rdp_cookie_cnt <integer>
5806req_rdp_cookie_cnt(name) <integer>
5807 Returns true when the data in the request buffer look like the RDP protocol
5808 and the number of RDP cookies matches the specified range (typically zero or
5809 one). Optionally a specific cookie name can be checked. This is a simple way
5810 of detecting the RDP protocol, as clients generally send the MSTS or MSTSHASH
5811 cookies.
5812
Willy Tarreau62644772008-07-16 18:36:06 +02005813req_ssl_ver <decimal>
5814 Returns true when data in the request buffer look like SSL, with a protocol
5815 version matching the specified range. Both SSLv2 hello messages and SSLv3
5816 messages are supported. The test tries to be strict enough to avoid being
5817 easily fooled. In particular, it waits for as many bytes as announced in the
5818 message header if this header looks valid (bound to the buffer size). Note
5819 that TLSv1 is announced as SSL version 3.1. This test was designed to be used
5820 with TCP request content inspection.
5821
Willy Tarreaub6fb4202008-07-20 11:18:28 +02005822wait_end
5823 Waits for the end of the analysis period to return true. This may be used in
5824 conjunction with content analysis to avoid returning a wrong verdict early.
5825 It may also be used to delay some actions, such as a delayed reject for some
5826 special addresses. Since it either stops the rules evaluation or immediately
5827 returns true, it is recommended to use this acl as the last one in a rule.
5828 Please note that the default ACL "WAIT_END" is always usable without prior
5829 declaration. This test was designed to be used with TCP request content
5830 inspection.
5831
5832 Examples :
5833 # delay every incoming request by 2 seconds
5834 tcp-request inspect-delay 2s
5835 tcp-request content accept if WAIT_END
5836
5837 # don't immediately tell bad guys they are rejected
5838 tcp-request inspect-delay 10s
5839 acl goodguys src 10.0.0.0/24
5840 acl badguys src 10.0.1.0/24
5841 tcp-request content accept if goodguys
5842 tcp-request content reject if badguys WAIT_END
5843 tcp-request content reject
5844
Willy Tarreau62644772008-07-16 18:36:06 +02005845
Willy Tarreauc57f0e22009-05-10 13:12:33 +020058467.5.3. Matching at Layer 7
5847--------------------------
Willy Tarreau0ba27502007-12-24 16:55:16 +01005848
Willy Tarreau62644772008-07-16 18:36:06 +02005849A third set of criteria applies to information which can be found at the
Willy Tarreau0ba27502007-12-24 16:55:16 +01005850application layer (layer 7). Those require that a full HTTP request has been
5851read, and are only evaluated then. They may require slightly more CPU resources
5852than the layer 4 ones, but not much since the request and response are indexed.
5853
Willy Tarreau6a06a402007-07-15 20:15:28 +02005854method <string>
5855 Applies to the method in the HTTP request, eg: "GET". Some predefined ACL
5856 already check for most common methods.
5857
5858req_ver <string>
5859 Applies to the version string in the HTTP request, eg: "1.0". Some predefined
5860 ACL already check for versions 1.0 and 1.1.
5861
5862path <string>
5863 Returns true when the path part of the request, which starts at the first
5864 slash and ends before the question mark, equals one of the strings. It may be
5865 used to match known files, such as /favicon.ico.
5866
5867path_beg <string>
Willy Tarreau0ba27502007-12-24 16:55:16 +01005868 Returns true when the path begins with one of the strings. This can be used
5869 to send certain directory names to alternative backends.
Willy Tarreau6a06a402007-07-15 20:15:28 +02005870
5871path_end <string>
5872 Returns true when the path ends with one of the strings. This may be used to
5873 control file name extension.
5874
5875path_sub <string>
5876 Returns true when the path contains one of the strings. It can be used to
5877 detect particular patterns in paths, such as "../" for example. See also
5878 "path_dir".
5879
5880path_dir <string>
5881 Returns true when one of the strings is found isolated or delimited with
5882 slashes in the path. This is used to perform filename or directory name
5883 matching without the risk of wrong match due to colliding prefixes. See also
5884 "url_dir" and "path_sub".
5885
5886path_dom <string>
5887 Returns true when one of the strings is found isolated or delimited with dots
5888 in the path. This may be used to perform domain name matching in proxy
5889 requests. See also "path_sub" and "url_dom".
5890
5891path_reg <regex>
5892 Returns true when the path matches one of the regular expressions. It can be
5893 used any time, but it is important to remember that regex matching is slower
5894 than other methods. See also "url_reg" and all "path_" criteria.
5895
5896url <string>
5897 Applies to the whole URL passed in the request. The only real use is to match
5898 "*", for which there already is a predefined ACL.
5899
5900url_beg <string>
5901 Returns true when the URL begins with one of the strings. This can be used to
5902 check whether a URL begins with a slash or with a protocol scheme.
5903
5904url_end <string>
5905 Returns true when the URL ends with one of the strings. It has very limited
5906 use. "path_end" should be used instead for filename matching.
5907
5908url_sub <string>
5909 Returns true when the URL contains one of the strings. It can be used to
5910 detect particular patterns in query strings for example. See also "path_sub".
5911
5912url_dir <string>
5913 Returns true when one of the strings is found isolated or delimited with
5914 slashes in the URL. This is used to perform filename or directory name
5915 matching without the risk of wrong match due to colliding prefixes. See also
5916 "path_dir" and "url_sub".
5917
5918url_dom <string>
5919 Returns true when one of the strings is found isolated or delimited with dots
5920 in the URL. This is used to perform domain name matching without the risk of
5921 wrong match due to colliding prefixes. See also "url_sub".
5922
5923url_reg <regex>
5924 Returns true when the URL matches one of the regular expressions. It can be
5925 used any time, but it is important to remember that regex matching is slower
5926 than other methods. See also "path_reg" and all "url_" criteria.
5927
Alexandre Cassen5eb1a902007-11-29 15:43:32 +01005928url_ip <ip_address>
Willy Tarreau0ba27502007-12-24 16:55:16 +01005929 Applies to the IP address specified in the absolute URI in an HTTP request.
5930 It can be used to prevent access to certain resources such as local network.
Willy Tarreau198a7442008-01-17 12:05:32 +01005931 It is useful with option "http_proxy".
Alexandre Cassen5eb1a902007-11-29 15:43:32 +01005932
5933url_port <integer>
Willy Tarreau0ba27502007-12-24 16:55:16 +01005934 Applies to the port specified in the absolute URI in an HTTP request. It can
5935 be used to prevent access to certain resources. It is useful with option
Willy Tarreau198a7442008-01-17 12:05:32 +01005936 "http_proxy". Note that if the port is not specified in the request, port 80
Willy Tarreau0ba27502007-12-24 16:55:16 +01005937 is assumed.
Alexandre Cassen5eb1a902007-11-29 15:43:32 +01005938
Willy Tarreaud72758d2010-01-12 10:42:19 +01005939hdr <string>
Willy Tarreau6a06a402007-07-15 20:15:28 +02005940hdr(header) <string>
5941 Note: all the "hdr*" matching criteria either apply to all headers, or to a
5942 particular header whose name is passed between parenthesis and without any
Willy Tarreau0ba27502007-12-24 16:55:16 +01005943 space. The header name is not case-sensitive. The header matching complies
5944 with RFC2616, and treats as separate headers all values delimited by commas.
Willy Tarreau6a06a402007-07-15 20:15:28 +02005945
5946 The "hdr" criteria returns true if any of the headers matching the criteria
Willy Tarreau0ba27502007-12-24 16:55:16 +01005947 match any of the strings. This can be used to check exact for values. For
Willy Tarreau6a06a402007-07-15 20:15:28 +02005948 instance, checking that "connection: close" is set :
5949
Willy Tarreauc57f0e22009-05-10 13:12:33 +02005950 hdr(Connection) -i close
Willy Tarreau21d2af32008-02-14 20:25:24 +01005951
Willy Tarreauc57f0e22009-05-10 13:12:33 +02005952hdr_beg <string>
5953hdr_beg(header) <string>
5954 Returns true when one of the headers begins with one of the strings. See
5955 "hdr" for more information on header matching.
Willy Tarreau21d2af32008-02-14 20:25:24 +01005956
Willy Tarreauc57f0e22009-05-10 13:12:33 +02005957hdr_end <string>
5958hdr_end(header) <string>
5959 Returns true when one of the headers ends with one of the strings. See "hdr"
5960 for more information on header matching.
Willy Tarreau198a7442008-01-17 12:05:32 +01005961
Willy Tarreauc57f0e22009-05-10 13:12:33 +02005962hdr_sub <string>
5963hdr_sub(header) <string>
5964 Returns true when one of the headers contains one of the strings. See "hdr"
5965 for more information on header matching.
Willy Tarreau5764b382007-11-30 17:46:49 +01005966
Willy Tarreauc57f0e22009-05-10 13:12:33 +02005967hdr_dir <string>
5968hdr_dir(header) <string>
5969 Returns true when one of the headers contains one of the strings either
5970 isolated or delimited by slashes. This is used to perform filename or
5971 directory name matching, and may be used with Referer. See "hdr" for more
5972 information on header matching.
Willy Tarreau5764b382007-11-30 17:46:49 +01005973
Willy Tarreauc57f0e22009-05-10 13:12:33 +02005974hdr_dom <string>
5975hdr_dom(header) <string>
5976 Returns true when one of the headers contains one of the strings either
5977 isolated or delimited by dots. This is used to perform domain name matching,
5978 and may be used with the Host header. See "hdr" for more information on
5979 header matching.
Willy Tarreau5764b382007-11-30 17:46:49 +01005980
Willy Tarreauc57f0e22009-05-10 13:12:33 +02005981hdr_reg <regex>
5982hdr_reg(header) <regex>
5983 Returns true when one of the headers matches of the regular expressions. It
5984 can be used at any time, but it is important to remember that regex matching
5985 is slower than other methods. See also other "hdr_" criteria, as well as
5986 "hdr" for more information on header matching.
Willy Tarreau5764b382007-11-30 17:46:49 +01005987
Willy Tarreauc57f0e22009-05-10 13:12:33 +02005988hdr_val <integer>
5989hdr_val(header) <integer>
5990 Returns true when one of the headers starts with a number which matches the
5991 values or ranges specified. This may be used to limit content-length to
5992 acceptable values for example. See "hdr" for more information on header
5993 matching.
Willy Tarreau198a7442008-01-17 12:05:32 +01005994
Willy Tarreauc57f0e22009-05-10 13:12:33 +02005995hdr_cnt <integer>
5996hdr_cnt(header) <integer>
5997 Returns true when the number of occurrence of the specified header matches
5998 the values or ranges specified. It is important to remember that one header
5999 line may count as several headers if it has several values. This is used to
6000 detect presence, absence or abuse of a specific header, as well as to block
Krzysztof Piotr Oledzkif8645332009-12-13 21:55:50 +01006001 request smuggling attacks by rejecting requests which contain more than one
Willy Tarreauc57f0e22009-05-10 13:12:33 +02006002 of certain headers. See "hdr" for more information on header matching.
Krzysztof Piotr Oledzkic8b16fc2008-02-18 01:26:35 +01006003
Willy Tarreau106f9792009-09-19 07:54:16 +02006004hdr_ip <ip_address>
6005hdr_ip(header) <ip_address>
6006 Returns true when one of the headers' values contains an IP address matching
6007 <ip_address>. This is mainly used with headers such as X-Forwarded-For or
6008 X-Client-IP. See "hdr" for more information on header matching.
6009
Willy Tarreau198a7442008-01-17 12:05:32 +01006010
Willy Tarreauc57f0e22009-05-10 13:12:33 +020060117.6. Pre-defined ACLs
6012---------------------
Willy Tarreauced27012008-01-17 20:35:34 +01006013
Willy Tarreauc57f0e22009-05-10 13:12:33 +02006014Some predefined ACLs are hard-coded so that they do not have to be declared in
6015every frontend which needs them. They all have their names in upper case in
6016order to avoid confusion. Their equivalence is provided below. Please note that
6017only the first three ones are not layer 7 based.
Willy Tarreauced27012008-01-17 20:35:34 +01006018
Willy Tarreauc57f0e22009-05-10 13:12:33 +02006019ACL name Equivalent to Usage
6020---------------+-----------------------------+---------------------------------
6021TRUE always_true always match
6022FALSE always_false never match
6023LOCALHOST src 127.0.0.1/8 match connection from local host
Willy Tarreau2492d5b2009-07-11 00:06:00 +02006024HTTP req_proto_http match if protocol is valid HTTP
Willy Tarreauc57f0e22009-05-10 13:12:33 +02006025HTTP_1.0 req_ver 1.0 match HTTP version 1.0
6026HTTP_1.1 req_ver 1.1 match HTTP version 1.1
6027METH_CONNECT method CONNECT match HTTP CONNECT method
6028METH_GET method GET HEAD match HTTP GET or HEAD method
6029METH_HEAD method HEAD match HTTP HEAD method
6030METH_OPTIONS method OPTIONS match HTTP OPTIONS method
6031METH_POST method POST match HTTP POST method
6032METH_TRACE method TRACE match HTTP TRACE method
6033HTTP_URL_ABS url_reg ^[^/:]*:// match absolute URL with scheme
Krzysztof Piotr Oledzkif8645332009-12-13 21:55:50 +01006034HTTP_URL_SLASH url_beg / match URL beginning with "/"
Willy Tarreauc57f0e22009-05-10 13:12:33 +02006035HTTP_URL_STAR url * match URL equal to "*"
6036HTTP_CONTENT hdr_val(content-length) gt 0 match an existing content-length
Emeric Brunbede3d02009-06-30 17:54:00 +02006037RDP_COOKIE req_rdp_cookie_cnt gt 0 match presence of an RDP cookie
Willy Tarreauc57f0e22009-05-10 13:12:33 +02006038REQ_CONTENT req_len gt 0 match data in the request buffer
6039WAIT_END wait_end wait for end of content analysis
6040---------------+-----------------------------+---------------------------------
Willy Tarreauced27012008-01-17 20:35:34 +01006041
Willy Tarreauced27012008-01-17 20:35:34 +01006042
Willy Tarreauc57f0e22009-05-10 13:12:33 +020060437.7. Using ACLs to form conditions
6044----------------------------------
Willy Tarreauced27012008-01-17 20:35:34 +01006045
Willy Tarreauc57f0e22009-05-10 13:12:33 +02006046Some actions are only performed upon a valid condition. A condition is a
6047combination of ACLs with operators. 3 operators are supported :
Willy Tarreauced27012008-01-17 20:35:34 +01006048
Willy Tarreauc57f0e22009-05-10 13:12:33 +02006049 - AND (implicit)
6050 - OR (explicit with the "or" keyword or the "||" operator)
6051 - Negation with the exclamation mark ("!")
Willy Tarreauced27012008-01-17 20:35:34 +01006052
Krzysztof Piotr Oledzkif8645332009-12-13 21:55:50 +01006053A condition is formed as a disjunctive form:
Willy Tarreauced27012008-01-17 20:35:34 +01006054
Willy Tarreauc57f0e22009-05-10 13:12:33 +02006055 [!]acl1 [!]acl2 ... [!]acln { or [!]acl1 [!]acl2 ... [!]acln } ...
Willy Tarreauced27012008-01-17 20:35:34 +01006056
Willy Tarreauc57f0e22009-05-10 13:12:33 +02006057Such conditions are generally used after an "if" or "unless" statement,
6058indicating when the condition will trigger the action.
Willy Tarreauced27012008-01-17 20:35:34 +01006059
Willy Tarreauc57f0e22009-05-10 13:12:33 +02006060For instance, to block HTTP requests to the "*" URL with methods other than
6061"OPTIONS", as well as POST requests without content-length, and GET or HEAD
6062requests with a content-length greater than 0, and finally every request which
6063is not either GET/HEAD/POST/OPTIONS !
Willy Tarreauced27012008-01-17 20:35:34 +01006064
Willy Tarreauc57f0e22009-05-10 13:12:33 +02006065 acl missing_cl hdr_cnt(Content-length) eq 0
6066 block if HTTP_URL_STAR !METH_OPTIONS || METH_POST missing_cl
6067 block if METH_GET HTTP_CONTENT
6068 block unless METH_GET or METH_POST or METH_OPTIONS
Willy Tarreauced27012008-01-17 20:35:34 +01006069
Willy Tarreauc57f0e22009-05-10 13:12:33 +02006070To select a different backend for requests to static contents on the "www" site
6071and to every request on the "img", "video", "download" and "ftp" hosts :
Willy Tarreauced27012008-01-17 20:35:34 +01006072
Willy Tarreauc57f0e22009-05-10 13:12:33 +02006073 acl url_static path_beg /static /images /img /css
6074 acl url_static path_end .gif .png .jpg .css .js
6075 acl host_www hdr_beg(host) -i www
6076 acl host_static hdr_beg(host) -i img. video. download. ftp.
Willy Tarreauced27012008-01-17 20:35:34 +01006077
Willy Tarreauc57f0e22009-05-10 13:12:33 +02006078 # now use backend "static" for all static-only hosts, and for static urls
6079 # of host "www". Use backend "www" for the rest.
6080 use_backend static if host_static or host_www url_static
6081 use_backend www if host_www
Willy Tarreauced27012008-01-17 20:35:34 +01006082
Willy Tarreauc57f0e22009-05-10 13:12:33 +02006083See section 4.2 for detailed help on the "block" and "use_backend" keywords.
Willy Tarreauced27012008-01-17 20:35:34 +01006084
Willy Tarreau5764b382007-11-30 17:46:49 +01006085
Willy Tarreaub937b7e2010-01-12 15:27:54 +010060867.8. Pattern extraction
6087-----------------------
6088
6089The stickiness features relies on pattern extraction in the request and
6090response. Sometimes the data needs to be converted first before being stored,
6091for instance converted from ASCII to IP or upper case to lower case.
6092
6093All these operations of data extraction and conversion are defined as
6094"pattern extraction rules". A pattern rule always has the same format. It
6095begins with a single pattern fetch word, potentially followed by a list of
6096arguments within parenthesis then an optional list of transformations. As
6097much as possible, the pattern fetch functions use the same name as their
6098equivalent used in ACLs.
6099
6100The list of currently supported pattern fetch functions is the following :
6101
6102 src This is the source IPv4 address of the client of the session.
6103 It is of type IP and only works with such tables.
6104
6105 dst This is the destination IPv4 address of the session on the
6106 client side, which is the address the client connected to.
6107 It can be useful when running in transparent mode. It is of
6108 typie IP and only works with such tables.
6109
6110 dst_port This is the destination TCP port of the session on the client
6111 side, which is the port the client connected to. This might be
6112 used when running in transparent mode or when assigning dynamic
6113 ports to some clients for a whole application session. It is of
6114 type integer and only works with such tables.
6115
6116
6117The currently available list of transformations include :
6118
6119 lower Convert a string pattern to lower case. This can only be placed
6120 after a string pattern fetch function or after a conversion
6121 function returning a string type. The result is of type string.
6122
6123 upper Convert a string pattern to upper case. This can only be placed
6124 after a string pattern fetch function or after a conversion
6125 function returning a string type. The result is of type string.
6126
6127
Willy Tarreauc57f0e22009-05-10 13:12:33 +020061288. Logging
6129----------
Willy Tarreau844e3c52008-01-11 16:28:18 +01006130
Willy Tarreaucc6c8912009-02-22 10:53:55 +01006131One of HAProxy's strong points certainly lies is its precise logs. It probably
6132provides the finest level of information available for such a product, which is
6133very important for troubleshooting complex environments. Standard information
6134provided in logs include client ports, TCP/HTTP state timers, precise session
6135state at termination and precise termination cause, information about decisions
Krzysztof Piotr Oledzkif8645332009-12-13 21:55:50 +01006136to direct traffic to a server, and of course the ability to capture arbitrary
Willy Tarreaucc6c8912009-02-22 10:53:55 +01006137headers.
6138
6139In order to improve administrators reactivity, it offers a great transparency
6140about encountered problems, both internal and external, and it is possible to
6141send logs to different sources at the same time with different level filters :
6142
6143 - global process-level logs (system errors, start/stop, etc..)
6144 - per-instance system and internal errors (lack of resource, bugs, ...)
6145 - per-instance external troubles (servers up/down, max connections)
6146 - per-instance activity (client connections), either at the establishment or
6147 at the termination.
6148
6149The ability to distribute different levels of logs to different log servers
6150allow several production teams to interact and to fix their problems as soon
6151as possible. For example, the system team might monitor system-wide errors,
6152while the application team might be monitoring the up/down for their servers in
6153real time, and the security team might analyze the activity logs with one hour
6154delay.
6155
6156
Willy Tarreauc57f0e22009-05-10 13:12:33 +020061578.1. Log levels
6158---------------
Willy Tarreaucc6c8912009-02-22 10:53:55 +01006159
6160TCP and HTTP connections can be logged with informations such as date, time,
6161source IP address, destination address, connection duration, response times,
6162HTTP request, the HTTP return code, number of bytes transmitted, the conditions
6163in which the session ended, and even exchanged cookies values, to track a
6164particular user's problems for example. All messages are sent to up to two
Willy Tarreauc57f0e22009-05-10 13:12:33 +02006165syslog servers. Check the "log" keyword in section 4.2 for more info about log
Willy Tarreaucc6c8912009-02-22 10:53:55 +01006166facilities.
6167
6168
Willy Tarreauc57f0e22009-05-10 13:12:33 +020061698.2. Log formats
6170----------------
Willy Tarreaucc6c8912009-02-22 10:53:55 +01006171
Emeric Brun3a058f32009-06-30 18:26:00 +02006172HAProxy supports 4 log formats. Several fields are common between these formats
Willy Tarreaucc6c8912009-02-22 10:53:55 +01006173and will be detailed in the next sections. A few of them may slightly vary with
6174the configuration, due to indicators specific to certain options. The supported
6175formats are the following ones :
6176
6177 - the default format, which is very basic and very rarely used. It only
6178 provides very basic information about the incoming connection at the moment
6179 it is accepted : source IP:port, destination IP:port, and frontend-name.
6180 This mode will eventually disappear so it will not be described to great
6181 extents.
6182
6183 - the TCP format, which is more advanced. This format is enabled when "option
6184 tcplog" is set on the frontend. HAProxy will then usually wait for the
6185 connection to terminate before logging. This format provides much richer
6186 information, such as timers, connection counts, queue size, etc... This
6187 format is recommended for pure TCP proxies.
6188
6189 - the HTTP format, which is the most advanced for HTTP proxying. This format
6190 is enabled when "option httplog" is set on the frontend. It provides the
6191 same information as the TCP format with some HTTP-specific fields such as
6192 the request, the status code, and captures of headers and cookies. This
6193 format is recommended for HTTP proxies.
6194
Emeric Brun3a058f32009-06-30 18:26:00 +02006195 - the CLF HTTP format, which is equivalent to the HTTP format, but with the
6196 fields arranged in the same order as the CLF format. In this mode, all
6197 timers, captures, flags, etc... appear one per field after the end of the
6198 common fields, in the same order they appear in the standard HTTP format.
6199
Willy Tarreaucc6c8912009-02-22 10:53:55 +01006200Next sections will go deeper into details for each of these formats. Format
6201specification will be performed on a "field" basis. Unless stated otherwise, a
6202field is a portion of text delimited by any number of spaces. Since syslog
6203servers are susceptible of inserting fields at the beginning of a line, it is
6204always assumed that the first field is the one containing the process name and
6205identifier.
6206
6207Note : Since log lines may be quite long, the log examples in sections below
6208 might be broken into multiple lines. The example log lines will be
6209 prefixed with 3 closing angle brackets ('>>>') and each time a log is
6210 broken into multiple lines, each non-final line will end with a
6211 backslash ('\') and the next line will start indented by two characters.
6212
6213
Willy Tarreauc57f0e22009-05-10 13:12:33 +020062148.2.1. Default log format
6215-------------------------
Willy Tarreaucc6c8912009-02-22 10:53:55 +01006216
6217This format is used when no specific option is set. The log is emitted as soon
6218as the connection is accepted. One should note that this currently is the only
6219format which logs the request's destination IP and ports.
6220
6221 Example :
6222 listen www
6223 mode http
6224 log global
6225 server srv1 127.0.0.1:8000
6226
6227 >>> Feb 6 12:12:09 localhost \
6228 haproxy[14385]: Connect from 10.0.1.2:33312 to 10.0.3.31:8012 \
6229 (www/HTTP)
6230
6231 Field Format Extract from the example above
6232 1 process_name '[' pid ']:' haproxy[14385]:
6233 2 'Connect from' Connect from
6234 3 source_ip ':' source_port 10.0.1.2:33312
6235 4 'to' to
6236 5 destination_ip ':' destination_port 10.0.3.31:8012
6237 6 '(' frontend_name '/' mode ')' (www/HTTP)
6238
6239Detailed fields description :
6240 - "source_ip" is the IP address of the client which initiated the connection.
6241 - "source_port" is the TCP port of the client which initiated the connection.
6242 - "destination_ip" is the IP address the client connected to.
6243 - "destination_port" is the TCP port the client connected to.
6244 - "frontend_name" is the name of the frontend (or listener) which received
6245 and processed the connection.
6246 - "mode is the mode the frontend is operating (TCP or HTTP).
6247
6248It is advised not to use this deprecated format for newer installations as it
6249will eventually disappear.
6250
6251
Willy Tarreauc57f0e22009-05-10 13:12:33 +020062528.2.2. TCP log format
6253---------------------
Willy Tarreaucc6c8912009-02-22 10:53:55 +01006254
6255The TCP format is used when "option tcplog" is specified in the frontend, and
6256is the recommended format for pure TCP proxies. It provides a lot of precious
6257information for troubleshooting. Since this format includes timers and byte
6258counts, the log is normally emitted at the end of the session. It can be
6259emitted earlier if "option logasap" is specified, which makes sense in most
6260environments with long sessions such as remote terminals. Sessions which match
6261the "monitor" rules are never logged. It is also possible not to emit logs for
6262sessions for which no data were exchanged between the client and the server, by
Willy Tarreauc9bd0cc2009-05-10 11:57:02 +02006263specifying "option dontlognull" in the frontend. Successful connections will
6264not be logged if "option dontlog-normal" is specified in the frontend. A few
6265fields may slightly vary depending on some configuration options, those are
6266marked with a star ('*') after the field name below.
Willy Tarreaucc6c8912009-02-22 10:53:55 +01006267
6268 Example :
6269 frontend fnt
6270 mode tcp
6271 option tcplog
6272 log global
6273 default_backend bck
6274
6275 backend bck
6276 server srv1 127.0.0.1:8000
6277
6278 >>> Feb 6 12:12:56 localhost \
6279 haproxy[14387]: 10.0.1.2:33313 [06/Feb/2009:12:12:51.443] fnt \
6280 bck/srv1 0/0/5007 212 -- 0/0/0/0/3 0/0
6281
6282 Field Format Extract from the example above
6283 1 process_name '[' pid ']:' haproxy[14387]:
6284 2 client_ip ':' client_port 10.0.1.2:33313
6285 3 '[' accept_date ']' [06/Feb/2009:12:12:51.443]
6286 4 frontend_name fnt
6287 5 backend_name '/' server_name bck/srv1
6288 6 Tw '/' Tc '/' Tt* 0/0/5007
6289 7 bytes_read* 212
6290 8 termination_state --
6291 9 actconn '/' feconn '/' beconn '/' srv_conn '/' retries* 0/0/0/0/3
6292 10 srv_queue '/' backend_queue 0/0
6293
6294Detailed fields description :
6295 - "client_ip" is the IP address of the client which initiated the TCP
6296 connection to haproxy.
6297
6298 - "client_port" is the TCP port of the client which initiated the connection.
6299
6300 - "accept_date" is the exact date when the connection was received by haproxy
6301 (which might be very slightly different from the date observed on the
6302 network if there was some queuing in the system's backlog). This is usually
6303 the same date which may appear in any upstream firewall's log.
6304
6305 - "frontend_name" is the name of the frontend (or listener) which received
6306 and processed the connection.
6307
6308 - "backend_name" is the name of the backend (or listener) which was selected
6309 to manage the connection to the server. This will be the same as the
6310 frontend if no switching rule has been applied, which is common for TCP
6311 applications.
6312
6313 - "server_name" is the name of the last server to which the connection was
6314 sent, which might differ from the first one if there were connection errors
6315 and a redispatch occurred. Note that this server belongs to the backend
6316 which processed the request. If the connection was aborted before reaching
6317 a server, "<NOSRV>" is indicated instead of a server name.
6318
6319 - "Tw" is the total time in milliseconds spent waiting in the various queues.
6320 It can be "-1" if the connection was aborted before reaching the queue.
6321 See "Timers" below for more details.
6322
6323 - "Tc" is the total time in milliseconds spent waiting for the connection to
6324 establish to the final server, including retries. It can be "-1" if the
6325 connection was aborted before a connection could be established. See
6326 "Timers" below for more details.
6327
6328 - "Tt" is the total time in milliseconds elapsed between the accept and the
6329 last close. It covers all possible processings. There is one exception, if
6330 "option logasap" was specified, then the time counting stops at the moment
6331 the log is emitted. In this case, a '+' sign is prepended before the value,
6332 indicating that the final one will be larger. See "Timers" below for more
6333 details.
6334
6335 - "bytes_read" is the total number of bytes transmitted from the server to
6336 the client when the log is emitted. If "option logasap" is specified, the
6337 this value will be prefixed with a '+' sign indicating that the final one
6338 may be larger. Please note that this value is a 64-bit counter, so log
6339 analysis tools must be able to handle it without overflowing.
6340
6341 - "termination_state" is the condition the session was in when the session
6342 ended. This indicates the session state, which side caused the end of
6343 session to happen, and for what reason (timeout, error, ...). The normal
6344 flags should be "--", indicating the session was closed by either end with
6345 no data remaining in buffers. See below "Session state at disconnection"
6346 for more details.
6347
6348 - "actconn" is the total number of concurrent connections on the process when
6349 the session was logged. It it useful to detect when some per-process system
6350 limits have been reached. For instance, if actconn is close to 512 when
6351 multiple connection errors occur, chances are high that the system limits
6352 the process to use a maximum of 1024 file descriptors and that all of them
Willy Tarreauc57f0e22009-05-10 13:12:33 +02006353 are used. See section 3 "Global parameters" to find how to tune the system.
Willy Tarreaucc6c8912009-02-22 10:53:55 +01006354
6355 - "feconn" is the total number of concurrent connections on the frontend when
6356 the session was logged. It is useful to estimate the amount of resource
6357 required to sustain high loads, and to detect when the frontend's "maxconn"
6358 has been reached. Most often when this value increases by huge jumps, it is
6359 because there is congestion on the backend servers, but sometimes it can be
6360 caused by a denial of service attack.
6361
6362 - "beconn" is the total number of concurrent connections handled by the
6363 backend when the session was logged. It includes the total number of
6364 concurrent connections active on servers as well as the number of
6365 connections pending in queues. It is useful to estimate the amount of
6366 additional servers needed to support high loads for a given application.
6367 Most often when this value increases by huge jumps, it is because there is
6368 congestion on the backend servers, but sometimes it can be caused by a
6369 denial of service attack.
6370
6371 - "srv_conn" is the total number of concurrent connections still active on
6372 the server when the session was logged. It can never exceed the server's
6373 configured "maxconn" parameter. If this value is very often close or equal
6374 to the server's "maxconn", it means that traffic regulation is involved a
6375 lot, meaning that either the server's maxconn value is too low, or that
6376 there aren't enough servers to process the load with an optimal response
6377 time. When only one of the server's "srv_conn" is high, it usually means
6378 that this server has some trouble causing the connections to take longer to
6379 be processed than on other servers.
6380
6381 - "retries" is the number of connection retries experienced by this session
6382 when trying to connect to the server. It must normally be zero, unless a
6383 server is being stopped at the same moment the connection was attempted.
6384 Frequent retries generally indicate either a network problem between
6385 haproxy and the server, or a misconfigured system backlog on the server
6386 preventing new connections from being queued. This field may optionally be
6387 prefixed with a '+' sign, indicating that the session has experienced a
6388 redispatch after the maximal retry count has been reached on the initial
6389 server. In this case, the server name appearing in the log is the one the
6390 connection was redispatched to, and not the first one, though both may
6391 sometimes be the same in case of hashing for instance. So as a general rule
6392 of thumb, when a '+' is present in front of the retry count, this count
6393 should not be attributed to the logged server.
6394
6395 - "srv_queue" is the total number of requests which were processed before
6396 this one in the server queue. It is zero when the request has not gone
6397 through the server queue. It makes it possible to estimate the approximate
6398 server's response time by dividing the time spent in queue by the number of
6399 requests in the queue. It is worth noting that if a session experiences a
6400 redispatch and passes through two server queues, their positions will be
6401 cumulated. A request should not pass through both the server queue and the
6402 backend queue unless a redispatch occurs.
6403
6404 - "backend_queue" is the total number of requests which were processed before
6405 this one in the backend's global queue. It is zero when the request has not
6406 gone through the global queue. It makes it possible to estimate the average
6407 queue length, which easily translates into a number of missing servers when
6408 divided by a server's "maxconn" parameter. It is worth noting that if a
6409 session experiences a redispatch, it may pass twice in the backend's queue,
6410 and then both positions will be cumulated. A request should not pass
6411 through both the server queue and the backend queue unless a redispatch
6412 occurs.
6413
6414
Willy Tarreauc57f0e22009-05-10 13:12:33 +020064158.2.3. HTTP log format
6416----------------------
Willy Tarreaucc6c8912009-02-22 10:53:55 +01006417
6418The HTTP format is the most complete and the best suited for HTTP proxies. It
6419is enabled by when "option httplog" is specified in the frontend. It provides
6420the same level of information as the TCP format with additional features which
6421are specific to the HTTP protocol. Just like the TCP format, the log is usually
6422emitted at the end of the session, unless "option logasap" is specified, which
6423generally only makes sense for download sites. A session which matches the
6424"monitor" rules will never logged. It is also possible not to log sessions for
6425which no data were sent by the client by specifying "option dontlognull" in the
Willy Tarreauc9bd0cc2009-05-10 11:57:02 +02006426frontend. Successful connections will not be logged if "option dontlog-normal"
6427is specified in the frontend.
Willy Tarreaucc6c8912009-02-22 10:53:55 +01006428
6429Most fields are shared with the TCP log, some being different. A few fields may
6430slightly vary depending on some configuration options. Those ones are marked
6431with a star ('*') after the field name below.
6432
6433 Example :
6434 frontend http-in
6435 mode http
6436 option httplog
6437 log global
6438 default_backend bck
6439
6440 backend static
6441 server srv1 127.0.0.1:8000
6442
6443 >>> Feb 6 12:14:14 localhost \
6444 haproxy[14389]: 10.0.1.2:33317 [06/Feb/2009:12:14:14.655] http-in \
6445 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 +01006446 {} "GET /index.html HTTP/1.1"
Willy Tarreaucc6c8912009-02-22 10:53:55 +01006447
6448 Field Format Extract from the example above
6449 1 process_name '[' pid ']:' haproxy[14389]:
6450 2 client_ip ':' client_port 10.0.1.2:33317
6451 3 '[' accept_date ']' [06/Feb/2009:12:14:14.655]
6452 4 frontend_name http-in
6453 5 backend_name '/' server_name static/srv1
6454 6 Tq '/' Tw '/' Tc '/' Tr '/' Tt* 10/0/30/69/109
6455 7 status_code 200
6456 8 bytes_read* 2750
6457 9 captured_request_cookie -
6458 10 captured_response_cookie -
6459 11 termination_state ----
6460 12 actconn '/' feconn '/' beconn '/' srv_conn '/' retries* 1/1/1/1/0
6461 13 srv_queue '/' backend_queue 0/0
6462 14 '{' captured_request_headers* '}' {haproxy.1wt.eu}
6463 15 '{' captured_response_headers* '}' {}
6464 16 '"' http_request '"' "GET /index.html HTTP/1.1"
Willy Tarreaud72758d2010-01-12 10:42:19 +01006465
Willy Tarreaucc6c8912009-02-22 10:53:55 +01006466
6467Detailed fields description :
6468 - "client_ip" is the IP address of the client which initiated the TCP
6469 connection to haproxy.
6470
6471 - "client_port" is the TCP port of the client which initiated the connection.
6472
6473 - "accept_date" is the exact date when the TCP connection was received by
6474 haproxy (which might be very slightly different from the date observed on
6475 the network if there was some queuing in the system's backlog). This is
6476 usually the same date which may appear in any upstream firewall's log. This
6477 does not depend on the fact that the client has sent the request or not.
6478
6479 - "frontend_name" is the name of the frontend (or listener) which received
6480 and processed the connection.
6481
6482 - "backend_name" is the name of the backend (or listener) which was selected
6483 to manage the connection to the server. This will be the same as the
6484 frontend if no switching rule has been applied.
6485
6486 - "server_name" is the name of the last server to which the connection was
6487 sent, which might differ from the first one if there were connection errors
6488 and a redispatch occurred. Note that this server belongs to the backend
6489 which processed the request. If the request was aborted before reaching a
6490 server, "<NOSRV>" is indicated instead of a server name. If the request was
6491 intercepted by the stats subsystem, "<STATS>" is indicated instead.
6492
6493 - "Tq" is the total time in milliseconds spent waiting for the client to send
6494 a full HTTP request, not counting data. It can be "-1" if the connection
6495 was aborted before a complete request could be received. It should always
6496 be very small because a request generally fits in one single packet. Large
6497 times here generally indicate network trouble between the client and
6498 haproxy. See "Timers" below for more details.
6499
6500 - "Tw" is the total time in milliseconds spent waiting in the various queues.
6501 It can be "-1" if the connection was aborted before reaching the queue.
6502 See "Timers" below for more details.
6503
6504 - "Tc" is the total time in milliseconds spent waiting for the connection to
6505 establish to the final server, including retries. It can be "-1" if the
6506 request was aborted before a connection could be established. See "Timers"
6507 below for more details.
6508
6509 - "Tr" is the total time in milliseconds spent waiting for the server to send
6510 a full HTTP response, not counting data. It can be "-1" if the request was
6511 aborted before a complete response could be received. It generally matches
6512 the server's processing time for the request, though it may be altered by
6513 the amount of data sent by the client to the server. Large times here on
6514 "GET" requests generally indicate an overloaded server. See "Timers" below
6515 for more details.
6516
6517 - "Tt" is the total time in milliseconds elapsed between the accept and the
6518 last close. It covers all possible processings. There is one exception, if
6519 "option logasap" was specified, then the time counting stops at the moment
6520 the log is emitted. In this case, a '+' sign is prepended before the value,
6521 indicating that the final one will be larger. See "Timers" below for more
6522 details.
6523
6524 - "status_code" is the HTTP status code returned to the client. This status
6525 is generally set by the server, but it might also be set by haproxy when
6526 the server cannot be reached or when its response is blocked by haproxy.
6527
6528 - "bytes_read" is the total number of bytes transmitted to the client when
6529 the log is emitted. This does include HTTP headers. If "option logasap" is
6530 specified, the this value will be prefixed with a '+' sign indicating that
6531 the final one may be larger. Please note that this value is a 64-bit
6532 counter, so log analysis tools must be able to handle it without
6533 overflowing.
6534
6535 - "captured_request_cookie" is an optional "name=value" entry indicating that
6536 the client had this cookie in the request. The cookie name and its maximum
6537 length are defined by the "capture cookie" statement in the frontend
6538 configuration. The field is a single dash ('-') when the option is not
6539 set. Only one cookie may be captured, it is generally used to track session
6540 ID exchanges between a client and a server to detect session crossing
6541 between clients due to application bugs. For more details, please consult
6542 the section "Capturing HTTP headers and cookies" below.
6543
6544 - "captured_response_cookie" is an optional "name=value" entry indicating
6545 that the server has returned a cookie with its response. The cookie name
6546 and its maximum length are defined by the "capture cookie" statement in the
6547 frontend configuration. The field is a single dash ('-') when the option is
6548 not set. Only one cookie may be captured, it is generally used to track
6549 session ID exchanges between a client and a server to detect session
6550 crossing between clients due to application bugs. For more details, please
6551 consult the section "Capturing HTTP headers and cookies" below.
6552
6553 - "termination_state" is the condition the session was in when the session
6554 ended. This indicates the session state, which side caused the end of
6555 session to happen, for what reason (timeout, error, ...), just like in TCP
6556 logs, and information about persistence operations on cookies in the last
6557 two characters. The normal flags should begin with "--", indicating the
6558 session was closed by either end with no data remaining in buffers. See
6559 below "Session state at disconnection" for more details.
6560
6561 - "actconn" is the total number of concurrent connections on the process when
6562 the session was logged. It it useful to detect when some per-process system
6563 limits have been reached. For instance, if actconn is close to 512 or 1024
6564 when multiple connection errors occur, chances are high that the system
6565 limits the process to use a maximum of 1024 file descriptors and that all
Willy Tarreauc57f0e22009-05-10 13:12:33 +02006566 of them are used. See section 3 "Global parameters" to find how to tune the
Willy Tarreaucc6c8912009-02-22 10:53:55 +01006567 system.
6568
6569 - "feconn" is the total number of concurrent connections on the frontend when
6570 the session was logged. It is useful to estimate the amount of resource
6571 required to sustain high loads, and to detect when the frontend's "maxconn"
6572 has been reached. Most often when this value increases by huge jumps, it is
6573 because there is congestion on the backend servers, but sometimes it can be
6574 caused by a denial of service attack.
6575
6576 - "beconn" is the total number of concurrent connections handled by the
6577 backend when the session was logged. It includes the total number of
6578 concurrent connections active on servers as well as the number of
6579 connections pending in queues. It is useful to estimate the amount of
6580 additional servers needed to support high loads for a given application.
6581 Most often when this value increases by huge jumps, it is because there is
6582 congestion on the backend servers, but sometimes it can be caused by a
6583 denial of service attack.
6584
6585 - "srv_conn" is the total number of concurrent connections still active on
6586 the server when the session was logged. It can never exceed the server's
6587 configured "maxconn" parameter. If this value is very often close or equal
6588 to the server's "maxconn", it means that traffic regulation is involved a
6589 lot, meaning that either the server's maxconn value is too low, or that
6590 there aren't enough servers to process the load with an optimal response
6591 time. When only one of the server's "srv_conn" is high, it usually means
6592 that this server has some trouble causing the requests to take longer to be
6593 processed than on other servers.
6594
6595 - "retries" is the number of connection retries experienced by this session
6596 when trying to connect to the server. It must normally be zero, unless a
6597 server is being stopped at the same moment the connection was attempted.
6598 Frequent retries generally indicate either a network problem between
6599 haproxy and the server, or a misconfigured system backlog on the server
6600 preventing new connections from being queued. This field may optionally be
6601 prefixed with a '+' sign, indicating that the session has experienced a
6602 redispatch after the maximal retry count has been reached on the initial
6603 server. In this case, the server name appearing in the log is the one the
6604 connection was redispatched to, and not the first one, though both may
6605 sometimes be the same in case of hashing for instance. So as a general rule
6606 of thumb, when a '+' is present in front of the retry count, this count
6607 should not be attributed to the logged server.
6608
6609 - "srv_queue" is the total number of requests which were processed before
6610 this one in the server queue. It is zero when the request has not gone
6611 through the server queue. It makes it possible to estimate the approximate
6612 server's response time by dividing the time spent in queue by the number of
6613 requests in the queue. It is worth noting that if a session experiences a
6614 redispatch and passes through two server queues, their positions will be
6615 cumulated. A request should not pass through both the server queue and the
6616 backend queue unless a redispatch occurs.
6617
6618 - "backend_queue" is the total number of requests which were processed before
6619 this one in the backend's global queue. It is zero when the request has not
6620 gone through the global queue. It makes it possible to estimate the average
6621 queue length, which easily translates into a number of missing servers when
6622 divided by a server's "maxconn" parameter. It is worth noting that if a
6623 session experiences a redispatch, it may pass twice in the backend's queue,
6624 and then both positions will be cumulated. A request should not pass
6625 through both the server queue and the backend queue unless a redispatch
6626 occurs.
6627
6628 - "captured_request_headers" is a list of headers captured in the request due
6629 to the presence of the "capture request header" statement in the frontend.
6630 Multiple headers can be captured, they will be delimited by a vertical bar
6631 ('|'). When no capture is enabled, the braces do not appear, causing a
6632 shift of remaining fields. It is important to note that this field may
6633 contain spaces, and that using it requires a smarter log parser than when
6634 it's not used. Please consult the section "Capturing HTTP headers and
6635 cookies" below for more details.
6636
6637 - "captured_response_headers" is a list of headers captured in the response
6638 due to the presence of the "capture response header" statement in the
6639 frontend. Multiple headers can be captured, they will be delimited by a
6640 vertical bar ('|'). When no capture is enabled, the braces do not appear,
6641 causing a shift of remaining fields. It is important to note that this
6642 field may contain spaces, and that using it requires a smarter log parser
6643 than when it's not used. Please consult the section "Capturing HTTP headers
6644 and cookies" below for more details.
6645
6646 - "http_request" is the complete HTTP request line, including the method,
6647 request and HTTP version string. Non-printable characters are encoded (see
6648 below the section "Non-printable characters"). This is always the last
6649 field, and it is always delimited by quotes and is the only one which can
6650 contain quotes. If new fields are added to the log format, they will be
6651 added before this field. This field might be truncated if the request is
6652 huge and does not fit in the standard syslog buffer (1024 characters). This
6653 is the reason why this field must always remain the last one.
6654
6655
Willy Tarreauc57f0e22009-05-10 13:12:33 +020066568.3. Advanced logging options
6657-----------------------------
Willy Tarreaucc6c8912009-02-22 10:53:55 +01006658
6659Some advanced logging options are often looked for but are not easy to find out
6660just by looking at the various options. Here is an entry point for the few
6661options which can enable better logging. Please refer to the keywords reference
6662for more information about their usage.
6663
6664
Willy Tarreauc57f0e22009-05-10 13:12:33 +020066658.3.1. Disabling logging of external tests
6666------------------------------------------
Willy Tarreaucc6c8912009-02-22 10:53:55 +01006667
6668It is quite common to have some monitoring tools perform health checks on
6669haproxy. Sometimes it will be a layer 3 load-balancer such as LVS or any
6670commercial load-balancer, and sometimes it will simply be a more complete
6671monitoring system such as Nagios. When the tests are very frequent, users often
6672ask how to disable logging for those checks. There are three possibilities :
6673
6674 - if connections come from everywhere and are just TCP probes, it is often
6675 desired to simply disable logging of connections without data exchange, by
6676 setting "option dontlognull" in the frontend. It also disables logging of
6677 port scans, which may or may not be desired.
6678
6679 - if the connection come from a known source network, use "monitor-net" to
6680 declare this network as monitoring only. Any host in this network will then
6681 only be able to perform health checks, and their requests will not be
6682 logged. This is generally appropriate to designate a list of equipments
6683 such as other load-balancers.
6684
6685 - if the tests are performed on a known URI, use "monitor-uri" to declare
6686 this URI as dedicated to monitoring. Any host sending this request will
6687 only get the result of a health-check, and the request will not be logged.
6688
6689
Willy Tarreauc57f0e22009-05-10 13:12:33 +020066908.3.2. Logging before waiting for the session to terminate
6691----------------------------------------------------------
Willy Tarreaucc6c8912009-02-22 10:53:55 +01006692
6693The problem with logging at end of connection is that you have no clue about
6694what is happening during very long sessions, such as remote terminal sessions
6695or large file downloads. This problem can be worked around by specifying
6696"option logasap" in the frontend. Haproxy will then log as soon as possible,
6697just before data transfer begins. This means that in case of TCP, it will still
6698log the connection status to the server, and in case of HTTP, it will log just
6699after processing the server headers. In this case, the number of bytes reported
6700is the number of header bytes sent to the client. In order to avoid confusion
6701with normal logs, the total time field and the number of bytes are prefixed
6702with a '+' sign which means that real numbers are certainly larger.
6703
6704
Willy Tarreauc57f0e22009-05-10 13:12:33 +020067058.3.3. Raising log level upon errors
6706------------------------------------
Willy Tarreauc9bd0cc2009-05-10 11:57:02 +02006707
6708Sometimes it is more convenient to separate normal traffic from errors logs,
6709for instance in order to ease error monitoring from log files. When the option
6710"log-separate-errors" is used, connections which experience errors, timeouts,
6711retries, redispatches or HTTP status codes 5xx will see their syslog level
6712raised from "info" to "err". This will help a syslog daemon store the log in
6713a separate file. It is very important to keep the errors in the normal traffic
6714file too, so that log ordering is not altered. You should also be careful if
6715you already have configured your syslog daemon to store all logs higher than
6716"notice" in an "admin" file, because the "err" level is higher than "notice".
6717
6718
Willy Tarreauc57f0e22009-05-10 13:12:33 +020067198.3.4. Disabling logging of successful connections
6720--------------------------------------------------
Willy Tarreauc9bd0cc2009-05-10 11:57:02 +02006721
6722Although this may sound strange at first, some large sites have to deal with
6723multiple thousands of logs per second and are experiencing difficulties keeping
6724them intact for a long time or detecting errors within them. If the option
6725"dontlog-normal" is set on the frontend, all normal connections will not be
6726logged. In this regard, a normal connection is defined as one without any
6727error, timeout, retry nor redispatch. In HTTP, the status code is checked too,
6728and a response with a status 5xx is not considered normal and will be logged
6729too. Of course, doing is is really discouraged as it will remove most of the
6730useful information from the logs. Do this only if you have no other
6731alternative.
6732
6733
Willy Tarreauc57f0e22009-05-10 13:12:33 +020067348.4. Timing events
6735------------------
Willy Tarreaucc6c8912009-02-22 10:53:55 +01006736
6737Timers provide a great help in troubleshooting network problems. All values are
6738reported in milliseconds (ms). These timers should be used in conjunction with
6739the session termination flags. In TCP mode with "option tcplog" set on the
6740frontend, 3 control points are reported under the form "Tw/Tc/Tt", and in HTTP
6741mode, 5 control points are reported under the form "Tq/Tw/Tc/Tr/Tt" :
6742
6743 - Tq: total time to get the client request (HTTP mode only). It's the time
6744 elapsed between the moment the client connection was accepted and the
6745 moment the proxy received the last HTTP header. The value "-1" indicates
6746 that the end of headers (empty line) has never been seen. This happens when
6747 the client closes prematurely or times out.
6748
6749 - Tw: total time spent in the queues waiting for a connection slot. It
6750 accounts for backend queue as well as the server queues, and depends on the
6751 queue size, and the time needed for the server to complete previous
6752 requests. The value "-1" means that the request was killed before reaching
6753 the queue, which is generally what happens with invalid or denied requests.
6754
6755 - Tc: total time to establish the TCP connection to the server. It's the time
6756 elapsed between the moment the proxy sent the connection request, and the
6757 moment it was acknowledged by the server, or between the TCP SYN packet and
6758 the matching SYN/ACK packet in return. The value "-1" means that the
6759 connection never established.
6760
6761 - Tr: server response time (HTTP mode only). It's the time elapsed between
6762 the moment the TCP connection was established to the server and the moment
6763 the server sent its complete response headers. It purely shows its request
6764 processing time, without the network overhead due to the data transmission.
6765 It is worth noting that when the client has data to send to the server, for
6766 instance during a POST request, the time already runs, and this can distort
6767 apparent response time. For this reason, it's generally wise not to trust
6768 too much this field for POST requests initiated from clients behind an
6769 untrusted network. A value of "-1" here means that the last the response
6770 header (empty line) was never seen, most likely because the server timeout
6771 stroke before the server managed to process the request.
6772
6773 - Tt: total session duration time, between the moment the proxy accepted it
6774 and the moment both ends were closed. The exception is when the "logasap"
6775 option is specified. In this case, it only equals (Tq+Tw+Tc+Tr), and is
6776 prefixed with a '+' sign. From this field, we can deduce "Td", the data
6777 transmission time, by substracting other timers when valid :
6778
6779 Td = Tt - (Tq + Tw + Tc + Tr)
6780
6781 Timers with "-1" values have to be excluded from this equation. In TCP
6782 mode, "Tq" and "Tr" have to be excluded too. Note that "Tt" can never be
6783 negative.
6784
6785These timers provide precious indications on trouble causes. Since the TCP
6786protocol defines retransmit delays of 3, 6, 12... seconds, we know for sure
6787that timers close to multiples of 3s are nearly always related to lost packets
Krzysztof Piotr Oledzkif8645332009-12-13 21:55:50 +01006788due to network problems (wires, negotiation, congestion). Moreover, if "Tt" is
Willy Tarreaucc6c8912009-02-22 10:53:55 +01006789close to a timeout value specified in the configuration, it often means that a
6790session has been aborted on timeout.
6791
6792Most common cases :
6793
6794 - If "Tq" is close to 3000, a packet has probably been lost between the
6795 client and the proxy. This is very rare on local networks but might happen
6796 when clients are on far remote networks and send large requests. It may
6797 happen that values larger than usual appear here without any network cause.
6798 Sometimes, during an attack or just after a resource starvation has ended,
6799 haproxy may accept thousands of connections in a few milliseconds. The time
6800 spent accepting these connections will inevitably slightly delay processing
6801 of other connections, and it can happen that request times in the order of
6802 a few tens of milliseconds are measured after a few thousands of new
6803 connections have been accepted at once.
6804
6805 - If "Tc" is close to 3000, a packet has probably been lost between the
6806 server and the proxy during the server connection phase. This value should
6807 always be very low, such as 1 ms on local networks and less than a few tens
6808 of ms on remote networks.
6809
Willy Tarreau55165fe2009-05-10 12:02:55 +02006810 - If "Tr" is nearly always lower than 3000 except some rare values which seem
6811 to be the average majored by 3000, there are probably some packets lost
6812 between the proxy and the server.
Willy Tarreaucc6c8912009-02-22 10:53:55 +01006813
6814 - If "Tt" is large even for small byte counts, it generally is because
6815 neither the client nor the server decides to close the connection, for
6816 instance because both have agreed on a keep-alive connection mode. In order
6817 to solve this issue, it will be needed to specify "option httpclose" on
6818 either the frontend or the backend. If the problem persists, it means that
6819 the server ignores the "close" connection mode and expects the client to
6820 close. Then it will be required to use "option forceclose". Having the
6821 smallest possible 'Tt' is important when connection regulation is used with
6822 the "maxconn" option on the servers, since no new connection will be sent
6823 to the server until another one is released.
6824
6825Other noticeable HTTP log cases ('xx' means any value to be ignored) :
6826
6827 Tq/Tw/Tc/Tr/+Tt The "option logasap" is present on the frontend and the log
6828 was emitted before the data phase. All the timers are valid
6829 except "Tt" which is shorter than reality.
6830
6831 -1/xx/xx/xx/Tt The client was not able to send a complete request in time
6832 or it aborted too early. Check the session termination flags
6833 then "timeout http-request" and "timeout client" settings.
6834
6835 Tq/-1/xx/xx/Tt It was not possible to process the request, maybe because
6836 servers were out of order, because the request was invalid
6837 or forbidden by ACL rules. Check the session termination
6838 flags.
6839
6840 Tq/Tw/-1/xx/Tt The connection could not establish on the server. Either it
6841 actively refused it or it timed out after Tt-(Tq+Tw) ms.
6842 Check the session termination flags, then check the
6843 "timeout connect" setting. Note that the tarpit action might
6844 return similar-looking patterns, with "Tw" equal to the time
6845 the client connection was maintained open.
6846
6847 Tq/Tw/Tc/-1/Tt The server has accepted the connection but did not return
6848 a complete response in time, or it closed its connexion
6849 unexpectedly after Tt-(Tq+Tw+Tc) ms. Check the session
6850 termination flags, then check the "timeout server" setting.
6851
6852
Willy Tarreauc57f0e22009-05-10 13:12:33 +020068538.5. Session state at disconnection
6854-----------------------------------
Willy Tarreaucc6c8912009-02-22 10:53:55 +01006855
6856TCP and HTTP logs provide a session termination indicator in the
6857"termination_state" field, just before the number of active connections. It is
68582-characters long in TCP mode, and is extended to 4 characters in HTTP mode,
6859each of which has a special meaning :
6860
6861 - On the first character, a code reporting the first event which caused the
6862 session to terminate :
6863
6864 C : the TCP session was unexpectedly aborted by the client.
6865
6866 S : the TCP session was unexpectedly aborted by the server, or the
6867 server explicitly refused it.
6868
6869 P : the session was prematurely aborted by the proxy, because of a
6870 connection limit enforcement, because a DENY filter was matched,
6871 because of a security check which detected and blocked a dangerous
6872 error in server response which might have caused information leak
6873 (eg: cacheable cookie), or because the response was processed by
6874 the proxy (redirect, stats, etc...).
6875
6876 R : a resource on the proxy has been exhausted (memory, sockets, source
6877 ports, ...). Usually, this appears during the connection phase, and
6878 system logs should contain a copy of the precise error. If this
6879 happens, it must be considered as a very serious anomaly which
6880 should be fixed as soon as possible by any means.
6881
6882 I : an internal error was identified by the proxy during a self-check.
6883 This should NEVER happen, and you are encouraged to report any log
6884 containing this, because this would almost certainly be a bug. It
6885 would be wise to preventively restart the process after such an
6886 event too, in case it would be caused by memory corruption.
6887
6888 c : the client-side timeout expired while waiting for the client to
6889 send or receive data.
6890
6891 s : the server-side timeout expired while waiting for the server to
6892 send or receive data.
6893
6894 - : normal session completion, both the client and the server closed
6895 with nothing left in the buffers.
6896
6897 - on the second character, the TCP or HTTP session state when it was closed :
6898
6899 R : th proxy was waiting for a complete, valid REQUEST from the client
6900 (HTTP mode only). Nothing was sent to any server.
6901
6902 Q : the proxy was waiting in the QUEUE for a connection slot. This can
6903 only happen when servers have a 'maxconn' parameter set. It can
6904 also happen in the global queue after a redispatch consecutive to
6905 a failed attempt to connect to a dying server. If no redispatch is
6906 reported, then no connection attempt was made to any server.
6907
6908 C : the proxy was waiting for the CONNECTION to establish on the
6909 server. The server might at most have noticed a connection attempt.
6910
6911 H : the proxy was waiting for complete, valid response HEADERS from the
6912 server (HTTP only).
6913
6914 D : the session was in the DATA phase.
6915
6916 L : the proxy was still transmitting LAST data to the client while the
6917 server had already finished. This one is very rare as it can only
6918 happen when the client dies while receiving the last packets.
6919
6920 T : the request was tarpitted. It has been held open with the client
6921 during the whole "timeout tarpit" duration or until the client
6922 closed, both of which will be reported in the "Tw" timer.
6923
6924 - : normal session completion after end of data transfer.
6925
6926 - the third character tells whether the persistence cookie was provided by
6927 the client (only in HTTP mode) :
6928
6929 N : the client provided NO cookie. This is usually the case for new
6930 visitors, so counting the number of occurrences of this flag in the
6931 logs generally indicate a valid trend for the site frequentation.
6932
6933 I : the client provided an INVALID cookie matching no known server.
6934 This might be caused by a recent configuration change, mixed
6935 cookies between HTTP/HTTPS sites, or an attack.
6936
6937 D : the client provided a cookie designating a server which was DOWN,
6938 so either "option persist" was used and the client was sent to
6939 this server, or it was not set and the client was redispatched to
6940 another server.
6941
6942 V : the client provided a valid cookie, and was sent to the associated
6943 server.
6944
6945 - : does not apply (no cookie set in configuration).
6946
6947 - the last character reports what operations were performed on the persistence
6948 cookie returned by the server (only in HTTP mode) :
6949
6950 N : NO cookie was provided by the server, and none was inserted either.
6951
6952 I : no cookie was provided by the server, and the proxy INSERTED one.
6953 Note that in "cookie insert" mode, if the server provides a cookie,
6954 it will still be overwritten and reported as "I" here.
6955
6956 P : a cookie was PROVIDED by the server and transmitted as-is.
6957
6958 R : the cookie provided by the server was REWRITTEN by the proxy, which
6959 happens in "cookie rewrite" or "cookie prefix" modes.
6960
6961 D : the cookie provided by the server was DELETED by the proxy.
6962
6963 - : does not apply (no cookie set in configuration).
6964
6965The combination of the two first flags give a lot of information about what was
6966happening when the session terminated, and why it did terminate. It can be
6967helpful to detect server saturation, network troubles, local system resource
6968starvation, attacks, etc...
6969
6970The most common termination flags combinations are indicated below. They are
6971alphabetically sorted, with the lowercase set just after the upper case for
6972easier finding and understanding.
6973
6974 Flags Reason
6975
6976 -- Normal termination.
6977
6978 CC The client aborted before the connection could be established to the
6979 server. This can happen when haproxy tries to connect to a recently
6980 dead (or unchecked) server, and the client aborts while haproxy is
6981 waiting for the server to respond or for "timeout connect" to expire.
6982
6983 CD The client unexpectedly aborted during data transfer. This can be
6984 caused by a browser crash, by an intermediate equipment between the
6985 client and haproxy which decided to actively break the connection,
6986 by network routing issues between the client and haproxy, or by a
6987 keep-alive session between the server and the client terminated first
6988 by the client.
Willy Tarreaud72758d2010-01-12 10:42:19 +01006989
Willy Tarreaucc6c8912009-02-22 10:53:55 +01006990 cD The client did not send nor acknowledge any data for as long as the
6991 "timeout client" delay. This is often caused by network failures on
6992 the client side, or the client simply leaving the net uncleanly.
6993
6994 CH The client aborted while waiting for the server to start responding.
6995 It might be the server taking too long to respond or the client
6996 clicking the 'Stop' button too fast.
6997
6998 cH The "timeout client" stroke while waiting for client data during a
6999 POST request. This is sometimes caused by too large TCP MSS values
7000 for PPPoE networks which cannot transport full-sized packets. It can
7001 also happen when client timeout is smaller than server timeout and
7002 the server takes too long to respond.
7003
7004 CQ The client aborted while its session was queued, waiting for a server
7005 with enough empty slots to accept it. It might be that either all the
7006 servers were saturated or that the assigned server was taking too
7007 long a time to respond.
7008
7009 CR The client aborted before sending a full HTTP request. Most likely
7010 the request was typed by hand using a telnet client, and aborted
7011 too early. The HTTP status code is likely a 400 here. Sometimes this
7012 might also be caused by an IDS killing the connection between haproxy
7013 and the client.
7014
7015 cR The "timeout http-request" stroke before the client sent a full HTTP
7016 request. This is sometimes caused by too large TCP MSS values on the
7017 client side for PPPoE networks which cannot transport full-sized
7018 packets, or by clients sending requests by hand and not typing fast
7019 enough, or forgetting to enter the empty line at the end of the
7020 request. The HTTP status code is likely a 408 here.
7021
7022 CT The client aborted while its session was tarpitted. It is important to
7023 check if this happens on valid requests, in order to be sure that no
Willy Tarreau55165fe2009-05-10 12:02:55 +02007024 wrong tarpit rules have been written. If a lot of them happen, it
7025 might make sense to lower the "timeout tarpit" value to something
7026 closer to the average reported "Tw" timer, in order not to consume
7027 resources for just a few attackers.
Willy Tarreaucc6c8912009-02-22 10:53:55 +01007028
Krzysztof Piotr Oledzkif8645332009-12-13 21:55:50 +01007029 SC The server or an equipment between it and haproxy explicitly refused
Willy Tarreaucc6c8912009-02-22 10:53:55 +01007030 the TCP connection (the proxy received a TCP RST or an ICMP message
7031 in return). Under some circumstances, it can also be the network
7032 stack telling the proxy that the server is unreachable (eg: no route,
7033 or no ARP response on local network). When this happens in HTTP mode,
7034 the status code is likely a 502 or 503 here.
7035
7036 sC The "timeout connect" stroke before a connection to the server could
7037 complete. When this happens in HTTP mode, the status code is likely a
7038 503 or 504 here.
7039
7040 SD The connection to the server died with an error during the data
7041 transfer. This usually means that haproxy has received an RST from
7042 the server or an ICMP message from an intermediate equipment while
7043 exchanging data with the server. This can be caused by a server crash
7044 or by a network issue on an intermediate equipment.
7045
7046 sD The server did not send nor acknowledge any data for as long as the
7047 "timeout server" setting during the data phase. This is often caused
Krzysztof Piotr Oledzkif8645332009-12-13 21:55:50 +01007048 by too short timeouts on L4 equipments before the server (firewalls,
Willy Tarreaucc6c8912009-02-22 10:53:55 +01007049 load-balancers, ...), as well as keep-alive sessions maintained
7050 between the client and the server expiring first on haproxy.
7051
7052 SH The server aborted before sending its full HTTP response headers, or
7053 it crashed while processing the request. Since a server aborting at
7054 this moment is very rare, it would be wise to inspect its logs to
7055 control whether it crashed and why. The logged request may indicate a
7056 small set of faulty requests, demonstrating bugs in the application.
7057 Sometimes this might also be caused by an IDS killing the connection
7058 between haproxy and the server.
7059
7060 sH The "timeout server" stroke before the server could return its
7061 response headers. This is the most common anomaly, indicating too
7062 long transactions, probably caused by server or database saturation.
7063 The immediate workaround consists in increasing the "timeout server"
7064 setting, but it is important to keep in mind that the user experience
7065 will suffer from these long response times. The only long term
7066 solution is to fix the application.
7067
7068 sQ The session spent too much time in queue and has been expired. See
7069 the "timeout queue" and "timeout connect" settings to find out how to
7070 fix this if it happens too often. If it often happens massively in
7071 short periods, it may indicate general problems on the affected
7072 servers due to I/O or database congestion, or saturation caused by
7073 external attacks.
7074
7075 PC The proxy refused to establish a connection to the server because the
7076 process' socket limit has been reached while attempting to connect.
7077 The global "maxconn" parameter may be increased in the configuration
7078 so that it does not happen anymore. This status is very rare and
7079 might happen when the global "ulimit-n" parameter is forced by hand.
7080
7081 PH The proxy blocked the server's response, because it was invalid,
7082 incomplete, dangerous (cache control), or matched a security filter.
7083 In any case, an HTTP 502 error is sent to the client. One possible
7084 cause for this error is an invalid syntax in an HTTP header name
7085 containing unauthorized characters.
7086
7087 PR The proxy blocked the client's HTTP request, either because of an
7088 invalid HTTP syntax, in which case it returned an HTTP 400 error to
7089 the client, or because a deny filter matched, in which case it
7090 returned an HTTP 403 error.
7091
7092 PT The proxy blocked the client's request and has tarpitted its
7093 connection before returning it a 500 server error. Nothing was sent
7094 to the server. The connection was maintained open for as long as
7095 reported by the "Tw" timer field.
7096
7097 RC A local resource has been exhausted (memory, sockets, source ports)
7098 preventing the connection to the server from establishing. The error
7099 logs will tell precisely what was missing. This is very rare and can
7100 only be solved by proper system tuning.
7101
7102
Willy Tarreauc57f0e22009-05-10 13:12:33 +020071038.6. Non-printable characters
7104-----------------------------
Willy Tarreaucc6c8912009-02-22 10:53:55 +01007105
7106In order not to cause trouble to log analysis tools or terminals during log
7107consulting, non-printable characters are not sent as-is into log files, but are
7108converted to the two-digits hexadecimal representation of their ASCII code,
7109prefixed by the character '#'. The only characters that can be logged without
7110being escaped are comprised between 32 and 126 (inclusive). Obviously, the
7111escape character '#' itself is also encoded to avoid any ambiguity ("#23"). It
7112is the same for the character '"' which becomes "#22", as well as '{', '|' and
7113'}' when logging headers.
7114
7115Note that the space character (' ') is not encoded in headers, which can cause
7116issues for tools relying on space count to locate fields. A typical header
7117containing spaces is "User-Agent".
7118
7119Last, it has been observed that some syslog daemons such as syslog-ng escape
7120the quote ('"') with a backslash ('\'). The reverse operation can safely be
7121performed since no quote may appear anywhere else in the logs.
7122
7123
Willy Tarreauc57f0e22009-05-10 13:12:33 +020071248.7. Capturing HTTP cookies
7125---------------------------
Willy Tarreaucc6c8912009-02-22 10:53:55 +01007126
7127Cookie capture simplifies the tracking a complete user session. This can be
7128achieved using the "capture cookie" statement in the frontend. Please refer to
Willy Tarreauc57f0e22009-05-10 13:12:33 +02007129section 4.2 for more details. Only one cookie can be captured, and the same
Willy Tarreaucc6c8912009-02-22 10:53:55 +01007130cookie will simultaneously be checked in the request ("Cookie:" header) and in
7131the response ("Set-Cookie:" header). The respective values will be reported in
7132the HTTP logs at the "captured_request_cookie" and "captured_response_cookie"
Willy Tarreauc57f0e22009-05-10 13:12:33 +02007133locations (see section 8.2.3 about HTTP log format). When either cookie is
Willy Tarreaucc6c8912009-02-22 10:53:55 +01007134not seen, a dash ('-') replaces the value. This way, it's easy to detect when a
7135user switches to a new session for example, because the server will reassign it
7136a new cookie. It is also possible to detect if a server unexpectedly sets a
7137wrong cookie to a client, leading to session crossing.
7138
7139 Examples :
7140 # capture the first cookie whose name starts with "ASPSESSION"
7141 capture cookie ASPSESSION len 32
7142
7143 # capture the first cookie whose name is exactly "vgnvisitor"
7144 capture cookie vgnvisitor= len 32
7145
7146
Willy Tarreauc57f0e22009-05-10 13:12:33 +020071478.8. Capturing HTTP headers
7148---------------------------
Willy Tarreaucc6c8912009-02-22 10:53:55 +01007149
7150Header captures are useful to track unique request identifiers set by an upper
7151proxy, virtual host names, user-agents, POST content-length, referrers, etc. In
7152the response, one can search for information about the response length, how the
7153server asked the cache to behave, or an object location during a redirection.
7154
7155Header captures are performed using the "capture request header" and "capture
7156response header" statements in the frontend. Please consult their definition in
Willy Tarreauc57f0e22009-05-10 13:12:33 +02007157section 4.2 for more details.
Willy Tarreaucc6c8912009-02-22 10:53:55 +01007158
7159It is possible to include both request headers and response headers at the same
Krzysztof Piotr Oledzkif8645332009-12-13 21:55:50 +01007160time. Non-existent headers are logged as empty strings, and if one header
7161appears more than once, only its last occurrence will be logged. Request headers
Willy Tarreaucc6c8912009-02-22 10:53:55 +01007162are grouped within braces '{' and '}' in the same order as they were declared,
7163and delimited with a vertical bar '|' without any space. Response headers
7164follow the same representation, but are displayed after a space following the
7165request headers block. These blocks are displayed just before the HTTP request
7166in the logs.
7167
7168 Example :
7169 # This instance chains to the outgoing proxy
7170 listen proxy-out
7171 mode http
7172 option httplog
7173 option logasap
7174 log global
7175 server cache1 192.168.1.1:3128
7176
7177 # log the name of the virtual server
7178 capture request header Host len 20
7179
7180 # log the amount of data uploaded during a POST
7181 capture request header Content-Length len 10
7182
7183 # log the beginning of the referrer
7184 capture request header Referer len 20
7185
7186 # server name (useful for outgoing proxies only)
7187 capture response header Server len 20
7188
7189 # logging the content-length is useful with "option logasap"
7190 capture response header Content-Length len 10
7191
7192 # log the expected cache behaviour on the response
7193 capture response header Cache-Control len 8
7194
7195 # the Via header will report the next proxy's name
7196 capture response header Via len 20
7197
7198 # log the URL location during a redirection
7199 capture response header Location len 20
7200
7201 >>> Aug 9 20:26:09 localhost \
7202 haproxy[2022]: 127.0.0.1:34014 [09/Aug/2004:20:26:09] proxy-out \
7203 proxy-out/cache1 0/0/0/162/+162 200 +350 - - ---- 0/0/0/0/0 0/0 \
7204 {fr.adserver.yahoo.co||http://fr.f416.mail.} {|864|private||} \
7205 "GET http://fr.adserver.yahoo.com/"
7206
7207 >>> Aug 9 20:30:46 localhost \
7208 haproxy[2022]: 127.0.0.1:34020 [09/Aug/2004:20:30:46] proxy-out \
7209 proxy-out/cache1 0/0/0/182/+182 200 +279 - - ---- 0/0/0/0/0 0/0 \
7210 {w.ods.org||} {Formilux/0.1.8|3495|||} \
Willy Tarreaud72758d2010-01-12 10:42:19 +01007211 "GET http://trafic.1wt.eu/ HTTP/1.1"
Willy Tarreaucc6c8912009-02-22 10:53:55 +01007212
7213 >>> Aug 9 20:30:46 localhost \
7214 haproxy[2022]: 127.0.0.1:34028 [09/Aug/2004:20:30:46] proxy-out \
7215 proxy-out/cache1 0/0/2/126/+128 301 +223 - - ---- 0/0/0/0/0 0/0 \
7216 {www.sytadin.equipement.gouv.fr||http://trafic.1wt.eu/} \
7217 {Apache|230|||http://www.sytadin.} \
Willy Tarreaud72758d2010-01-12 10:42:19 +01007218 "GET http://www.sytadin.equipement.gouv.fr/ HTTP/1.1"
Willy Tarreaucc6c8912009-02-22 10:53:55 +01007219
7220
Willy Tarreauc57f0e22009-05-10 13:12:33 +020072218.9. Examples of logs
7222---------------------
Willy Tarreaucc6c8912009-02-22 10:53:55 +01007223
7224These are real-world examples of logs accompanied with an explanation. Some of
7225them have been made up by hand. The syslog part has been removed for better
7226reading. Their sole purpose is to explain how to decipher them.
7227
7228 >>> haproxy[674]: 127.0.0.1:33318 [15/Oct/2003:08:31:57.130] px-http \
7229 px-http/srv1 6559/0/7/147/6723 200 243 - - ---- 5/3/3/1/0 0/0 \
7230 "HEAD / HTTP/1.0"
7231
7232 => long request (6.5s) entered by hand through 'telnet'. The server replied
7233 in 147 ms, and the session ended normally ('----')
7234
7235 >>> haproxy[674]: 127.0.0.1:33319 [15/Oct/2003:08:31:57.149] px-http \
7236 px-http/srv1 6559/1230/7/147/6870 200 243 - - ---- 324/239/239/99/0 \
7237 0/9 "HEAD / HTTP/1.0"
7238
7239 => Idem, but the request was queued in the global queue behind 9 other
7240 requests, and waited there for 1230 ms.
7241
7242 >>> haproxy[674]: 127.0.0.1:33320 [15/Oct/2003:08:32:17.654] px-http \
7243 px-http/srv1 9/0/7/14/+30 200 +243 - - ---- 3/3/3/1/0 0/0 \
7244 "GET /image.iso HTTP/1.0"
7245
7246 => request for a long data transfer. The "logasap" option was specified, so
Krzysztof Piotr Oledzkif8645332009-12-13 21:55:50 +01007247 the log was produced just before transferring data. The server replied in
Willy Tarreaucc6c8912009-02-22 10:53:55 +01007248 14 ms, 243 bytes of headers were sent to the client, and total time from
7249 accept to first data byte is 30 ms.
7250
7251 >>> haproxy[674]: 127.0.0.1:33320 [15/Oct/2003:08:32:17.925] px-http \
7252 px-http/srv1 9/0/7/14/30 502 243 - - PH-- 3/2/2/0/0 0/0 \
7253 "GET /cgi-bin/bug.cgi? HTTP/1.0"
7254
7255 => the proxy blocked a server response either because of an "rspdeny" or
7256 "rspideny" filter, or because the response was improperly formatted and
7257 not HTTP-compliant, or because it blocked sensible information which
7258 risked being cached. In this case, the response is replaced with a "502
7259 bad gateway". The flags ("PH--") tell us that it was haproxy who decided
7260 to return the 502 and not the server.
7261
7262 >>> haproxy[18113]: 127.0.0.1:34548 [15/Oct/2003:15:18:55.798] px-http \
Willy Tarreaud72758d2010-01-12 10:42:19 +01007263 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 +01007264
7265 => the client never completed its request and aborted itself ("C---") after
7266 8.5s, while the proxy was waiting for the request headers ("-R--").
7267 Nothing was sent to any server.
7268
7269 >>> haproxy[18113]: 127.0.0.1:34549 [15/Oct/2003:15:19:06.103] px-http \
7270 px-http/<NOSRV> -1/-1/-1/-1/50001 408 0 - - cR-- 2/2/2/0/0 0/0 ""
7271
7272 => The client never completed its request, which was aborted by the
7273 time-out ("c---") after 50s, while the proxy was waiting for the request
7274 headers ("-R--"). Nothing was sent to any server, but the proxy could
7275 send a 408 return code to the client.
7276
7277 >>> haproxy[18989]: 127.0.0.1:34550 [15/Oct/2003:15:24:28.312] px-tcp \
7278 px-tcp/srv1 0/0/5007 0 cD 0/0/0/0/0 0/0
7279
7280 => This log was produced with "option tcplog". The client timed out after
7281 5 seconds ("c----").
7282
7283 >>> haproxy[18989]: 10.0.0.1:34552 [15/Oct/2003:15:26:31.462] px-http \
7284 px-http/srv1 3183/-1/-1/-1/11215 503 0 - - SC-- 205/202/202/115/3 \
Willy Tarreaud72758d2010-01-12 10:42:19 +01007285 0/0 "HEAD / HTTP/1.0"
Willy Tarreaucc6c8912009-02-22 10:53:55 +01007286
7287 => The request took 3s to complete (probably a network problem), and the
Willy Tarreauc57f0e22009-05-10 13:12:33 +02007288 connection to the server failed ('SC--') after 4 attempts of 2 seconds
Willy Tarreaucc6c8912009-02-22 10:53:55 +01007289 (config says 'retries 3'), and no redispatch (otherwise we would have
7290 seen "/+3"). Status code 503 was returned to the client. There were 115
7291 connections on this server, 202 connections on this proxy, and 205 on
7292 the global process. It is possible that the server refused the
7293 connection because of too many already established.
Willy Tarreau844e3c52008-01-11 16:28:18 +01007294
Willy Tarreau3dfe6cd2008-12-07 22:29:48 +01007295
Willy Tarreauc57f0e22009-05-10 13:12:33 +020072969. Statistics and monitoring
7297----------------------------
7298
7299It is possible to query HAProxy about its status. The most commonly used
7300mechanism is the HTTP statistics page. This page also exposes an alternative
7301CSV output format for monitoring tools. The same format is provided on the
7302Unix socket.
7303
7304
73059.1. CSV format
Willy Tarreau3dfe6cd2008-12-07 22:29:48 +01007306---------------
Krzysztof Piotr Oledzkif58a9622008-02-23 01:19:10 +01007307
Willy Tarreau7f062c42009-03-05 18:43:00 +01007308The statistics may be consulted either from the unix socket or from the HTTP
7309page. Both means provide a CSV format whose fields follow.
7310
Krzysztof Piotr Oledzkif58a9622008-02-23 01:19:10 +01007311 0. pxname: proxy name
7312 1. svname: service name (FRONTEND for frontend, BACKEND for backend, any name
7313 for server)
7314 2. qcur: current queued requests
7315 3. qmax: max queued requests
7316 4. scur: current sessions
7317 5. smax: max sessions
7318 6. slim: sessions limit
7319 7. stot: total sessions
7320 8. bin: bytes in
7321 9. bout: bytes out
7322 10. dreq: denied requests
Krzysztof Piotr Oledzki2c6962c2008-03-02 02:42:14 +01007323 11. dresp: denied responses
Krzysztof Piotr Oledzkif58a9622008-02-23 01:19:10 +01007324 12. ereq: request errors
7325 13. econ: connection errors
Krzysztof Piotr Oledzki2c6962c2008-03-02 02:42:14 +01007326 14. eresp: response errors
Krzysztof Piotr Oledzkif58a9622008-02-23 01:19:10 +01007327 15. wretr: retries (warning)
7328 16. wredis: redispatches (warning)
7329 17. status: status (UP/DOWN/...)
7330 18. weight: server weight (server), total weight (backend)
7331 19. act: server is active (server), number of active servers (backend)
7332 20. bck: server is backup (server), number of backup servers (backend)
7333 21. chkfail: number of failed checks
7334 22. chkdown: number of UP->DOWN transitions
7335 23. lastchg: last status change (in seconds)
7336 24. downtime: total downtime (in seconds)
7337 25. qlimit: queue limit
7338 26. pid: process id (0 for first instance, 1 for second, ...)
7339 27. iid: unique proxy id
7340 28. sid: service id (unique inside a proxy)
7341 29. throttle: warm up status
7342 30. lbtot: total number of times a server was selected
7343 31. tracked: id of proxy/server if tracking is enabled
Krzysztof Piotr Oledzkiaeebf9b2009-10-04 15:43:17 +02007344 32. type (0=frontend, 1=backend, 2=server, 3=socket)
Krzysztof Piotr Oledzkidb57c6b2009-08-31 21:23:27 +02007345 33. rate: number of sessions per second over last elapsed second
7346 34. rate_lim: limit on new sessions per second
7347 35. rate_max: max number of new sessions per second
Krzysztof Piotr Oledzki09605412009-09-23 22:09:24 +02007348 36. check_status: status of last health check, one of:
7349 UNK -> unknown
7350 INI -> initializing
7351 SOCKERR -> socket error
7352 L4OK -> check passed on layer 4, no upper layers testing enabled
7353 L4TMOUT -> layer 1-4 timeout
7354 L4CON -> layer 1-4 connection problem, for example "Connection refused"
7355 (tcp rst) or "No route to host" (icmp)
7356 L6OK -> check passed on layer 6
7357 L6TOUT -> layer 6 (SSL) timeout
Willy Tarreaud72758d2010-01-12 10:42:19 +01007358 L6RSP -> layer 6 invalid response - protocol error
Krzysztof Piotr Oledzki09605412009-09-23 22:09:24 +02007359 L7OK -> check passed on layer 7
7360 L7OKC -> check conditionally passed on layer 7, for example 404 with
7361 disable-on-404
7362 L7TOUT -> layer 7 (HTTP/SMTP) timeout
Willy Tarreaud72758d2010-01-12 10:42:19 +01007363 L7RSP -> layer 7 invalid response - protocol error
Krzysztof Piotr Oledzki09605412009-09-23 22:09:24 +02007364 L7STS -> layer 7 response error, for example HTTP 5xx
7365 37. check_code: layer5-7 code, if available
7366 38. check_duration: time in ms took to finish last health check
Krzysztof Piotr Oledzkif8645332009-12-13 21:55:50 +01007367 39. hrsp_1xx: http responses with 1xx code
7368 40. hrsp_2xx: http responses with 2xx code
7369 41. hrsp_3xx: http responses with 3xx code
7370 42. hrsp_4xx: http responses with 4xx code
7371 43. hrsp_5xx: http responses with 5xx code
7372 44. hrsp_other: http responses with other codes (protocol error)
Willy Tarreau844e3c52008-01-11 16:28:18 +01007373
Willy Tarreau3dfe6cd2008-12-07 22:29:48 +01007374
Willy Tarreauc57f0e22009-05-10 13:12:33 +020073759.2. Unix Socket commands
Willy Tarreau3dfe6cd2008-12-07 22:29:48 +01007376-------------------------
Krzysztof Piotr Oledzki2c6962c2008-03-02 02:42:14 +01007377
Willy Tarreau3dfe6cd2008-12-07 22:29:48 +01007378The following commands are supported on the UNIX stats socket ; all of them
Willy Tarreau9a42c0d2009-09-22 19:31:03 +02007379must be terminated by a line feed. The socket supports pipelining, so that it
7380is possible to chain multiple commands at once provided they are delimited by
7381a semi-colon or a line feed, although the former is more reliable as it has no
7382risk of being truncated over the network. The responses themselves will each be
7383followed by an empty line, so it will be easy for an external script to match a
7384given response with a given request. By default one command line is processed
7385then the connection closes, but there is an interactive allowing multiple lines
7386to be issued one at a time.
Willy Tarreau3dfe6cd2008-12-07 22:29:48 +01007387
Willy Tarreau9a42c0d2009-09-22 19:31:03 +02007388It is important to understand that when multiple haproxy processes are started
7389on the same sockets, any process may pick up the request and will output its
7390own stats.
Willy Tarreau3dfe6cd2008-12-07 22:29:48 +01007391
Willy Tarreau9a42c0d2009-09-22 19:31:03 +02007392help
7393 Print the list of known keywords and their basic usage. The same help screen
7394 is also displayed for unknown commands.
Willy Tarreau3dfe6cd2008-12-07 22:29:48 +01007395
Willy Tarreau9a42c0d2009-09-22 19:31:03 +02007396prompt
7397 Toggle the prompt at the beginning of the line and enter or leave interactive
7398 mode. In interactive mode, the connection is not closed after a command
7399 completes. Instead, the prompt will appear again, indicating the user that
7400 the interpreter is waiting for a new command. The prompt consists in a right
7401 angle bracket followed by a space "> ". This mode is particularly convenient
7402 when one wants to periodically check information such as stats or errors.
7403 It is also a good idea to enter interactive mode before issuing a "help"
7404 command.
7405
7406quit
7407 Close the connection when in interactive mode.
Krzysztof Piotr Oledzki2c6962c2008-03-02 02:42:14 +01007408
Willy Tarreaue0c8a1a2009-03-04 16:33:10 +01007409show errors [<iid>]
7410 Dump last known request and response errors collected by frontends and
7411 backends. If <iid> is specified, the limit the dump to errors concerning
Willy Tarreau6162db22009-10-10 17:13:00 +02007412 either frontend or backend whose ID is <iid>. This command is restricted
7413 and can only be issued on sockets configured for levels "operator" or
7414 "admin".
Willy Tarreaue0c8a1a2009-03-04 16:33:10 +01007415
7416 The errors which may be collected are the last request and response errors
7417 caused by protocol violations, often due to invalid characters in header
7418 names. The report precisely indicates what exact character violated the
7419 protocol. Other important information such as the exact date the error was
7420 detected, frontend and backend names, the server name (when known), the
7421 internal session ID and the source address which has initiated the session
7422 are reported too.
7423
7424 All characters are returned, and non-printable characters are encoded. The
7425 most common ones (\t = 9, \n = 10, \r = 13 and \e = 27) are encoded as one
7426 letter following a backslash. The backslash itself is encoded as '\\' to
7427 avoid confusion. Other non-printable characters are encoded '\xNN' where
7428 NN is the two-digits hexadecimal representation of the character's ASCII
7429 code.
7430
7431 Lines are prefixed with the position of their first character, starting at 0
7432 for the beginning of the buffer. At most one input line is printed per line,
7433 and large lines will be broken into multiple consecutive output lines so that
7434 the output never goes beyond 79 characters wide. It is easy to detect if a
7435 line was broken, because it will not end with '\n' and the next line's offset
7436 will be followed by a '+' sign, indicating it is a continuation of previous
7437 line.
7438
7439 Example :
7440 >>> $ echo "show errors" | socat stdio /tmp/sock1
7441 [04/Mar/2009:15:46:56.081] backend http-in (#2) : invalid response
7442 src 127.0.0.1, session #54, frontend fe-eth0 (#1), server s2 (#1)
7443 response length 213 bytes, error at position 23:
7444
7445 00000 HTTP/1.0 200 OK\r\n
7446 00017 header/bizarre:blah\r\n
7447 00038 Location: blah\r\n
7448 00054 Long-line: this is a very long line which should b
7449 00104+ e broken into multiple lines on the output buffer,
7450 00154+ otherwise it would be too large to print in a ter
7451 00204+ minal\r\n
7452 00211 \r\n
7453
Willy Tarreauc57f0e22009-05-10 13:12:33 +02007454 In the example above, we see that the backend "http-in" which has internal
Willy Tarreaue0c8a1a2009-03-04 16:33:10 +01007455 ID 2 has blocked an invalid response from its server s2 which has internal
7456 ID 1. The request was on session 54 initiated by source 127.0.0.1 and
7457 received by frontend fe-eth0 whose ID is 1. The total response length was
7458 213 bytes when the error was detected, and the error was at byte 23. This
7459 is the slash ('/') in header name "header/bizarre", which is not a valid
7460 HTTP character for a header name.
Krzysztof Piotr Oledzki2c6962c2008-03-02 02:42:14 +01007461
Willy Tarreau9a42c0d2009-09-22 19:31:03 +02007462show info
7463 Dump info about haproxy status on current process.
7464
7465show sess
7466 Dump all known sessions. Avoid doing this on slow connections as this can
Willy Tarreau6162db22009-10-10 17:13:00 +02007467 be huge. This command is restricted and can only be issued on sockets
7468 configured for levels "operator" or "admin".
7469
Willy Tarreau9a42c0d2009-09-22 19:31:03 +02007470
7471show stat [<iid> <type> <sid>]
7472 Dump statistics in the CSV format. By passing <id>, <type> and <sid>, it is
7473 possible to dump only selected items :
7474 - <iid> is a proxy ID, -1 to dump everything
7475 - <type> selects the type of dumpable objects : 1 for frontends, 2 for
7476 backends, 4 for servers, -1 for everything. These values can be ORed,
7477 for example:
7478 1 + 2 = 3 -> frontend + backend.
7479 1 + 2 + 4 = 7 -> frontend + backend + server.
7480 - <sid> is a server ID, -1 to dump everything from the selected proxy.
7481
7482 Example :
7483 >>> $ echo "show info;show stat" | socat stdio unix-connect:/tmp/sock1
7484 Name: HAProxy
7485 Version: 1.4-dev2-49
7486 Release_date: 2009/09/23
7487 Nbproc: 1
7488 Process_num: 1
7489 (...)
7490
7491 # pxname,svname,qcur,qmax,scur,smax,slim,stot,bin,bout,dreq, (...)
7492 stats,FRONTEND,,,0,0,1000,0,0,0,0,0,0,,,,,OPEN,,,,,,,,,1,1,0, (...)
7493 stats,BACKEND,0,0,0,0,1000,0,0,0,0,0,,0,0,0,0,UP,0,0,0,,0,250,(...)
7494 (...)
7495 www1,BACKEND,0,0,0,0,1000,0,0,0,0,0,,0,0,0,0,UP,1,1,0,,0,250, (...)
7496
7497 $
7498
7499 Here, two commands have been issued at once. That way it's easy to find
7500 which process the stats apply to in multi-process mode. Notice the empty
7501 line after the information output which marks the end of the first block.
7502 A similar empty line appears at the end of the second block (stats) so that
Krzysztof Piotr Oledzkif8645332009-12-13 21:55:50 +01007503 the reader knows the output has not been truncated.
Willy Tarreau9a42c0d2009-09-22 19:31:03 +02007504
Krzysztof Piotr Oledzki719e7262009-10-04 15:02:46 +02007505clear counters
Willy Tarreau2f6bf2b2009-10-10 15:26:26 +02007506 Clear the max values of the statistics counters in each proxy (frontend &
7507 backend) and in each server. The cumulated counters are not affected. This
7508 can be used to get clean counters after an incident, without having to
Willy Tarreau6162db22009-10-10 17:13:00 +02007509 restart nor to clear traffic counters. This command is restricted and can
7510 only be issued on sockets configured for levels "operator" or "admin".
Willy Tarreau2f6bf2b2009-10-10 15:26:26 +02007511
7512clear counters all
7513 Clear all statistics counters in each proxy (frontend & backend) and in each
Willy Tarreau6162db22009-10-10 17:13:00 +02007514 server. This has the same effect as restarting. This command is restricted
7515 and can only be issued on sockets configured for level "admin".
7516
Willy Tarreau38338fa2009-10-10 18:37:29 +02007517get weight <backend>/<server>
7518 Report the current weight and the initial weight of server <server> in
7519 backend <backend> or an error if either doesn't exist. The initial weight is
7520 the one that appears in the configuration file. Both are normally equal
Willy Tarreaucfeaa472009-10-10 22:33:08 +02007521 unless the current weight has been changed. Both the backend and the server
7522 may be specified either by their name or by their numeric ID, prefixed with a
7523 dash ('#').
Willy Tarreau38338fa2009-10-10 18:37:29 +02007524
Willy Tarreau4483d432009-10-10 19:30:08 +02007525set weight <backend>/<server> <weight>[%]
7526 Change a server's weight to the value passed in argument. If the value ends
7527 with the '%' sign, then the new weight will be relative to the initially
7528 configured weight. Relative weights are only permitted between 0 and 100%,
7529 and absolute weights are permitted between 0 and 256. Servers which are part
7530 of a farm running a static load-balancing algorithm have stricter limitations
7531 because the weight cannot change once set. Thus for these servers, the only
7532 accepted values are 0 and 100% (or 0 and the initial weight). Changes take
7533 effect immediately, though certain LB algorithms require a certain amount of
7534 requests to consider changes. A typical usage of this command is to disable
7535 a server during an update by setting its weight to zero, then to enable it
7536 again after the update by setting it back to 100%. This command is restricted
Willy Tarreaucfeaa472009-10-10 22:33:08 +02007537 and can only be issued on sockets configured for level "admin". Both the
7538 backend and the server may be specified either by their name or by their
7539 numeric ID, prefixed with a dash ('#').
Willy Tarreau4483d432009-10-10 19:30:08 +02007540
Krzysztof Piotr Oledzki719e7262009-10-04 15:02:46 +02007541
Willy Tarreau0ba27502007-12-24 16:55:16 +01007542/*
7543 * Local variables:
7544 * fill-column: 79
7545 * End:
7546 */