blob: 047376963fdf5e64490c0650e6cd3ccb39eed8ee [file] [log] [blame]
Willy Tarreau6a06a402007-07-15 20:15:28 +02001 ----------------------
2 HAProxy
3 Configuration Manual
4 ----------------------
Willy Tarreau0ba27502007-12-24 16:55:16 +01005 version 1.3.14
Willy Tarreau6a06a402007-07-15 20:15:28 +02006 willy tarreau
Willy Tarreau0ba27502007-12-24 16:55:16 +01007 2007/12/24
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 Tarreau6a06a402007-07-15 20:15:28 +020013
14
15HAProxy's configuration process involves 3 major sources of parameters :
16
17 - the arguments from the command-line, which always take precedence
18 - the "global" section, which sets process-wide parameters
19 - the proxies sections which can take form of "defaults", "listen",
20 "frontend" and "backend".
21
Willy Tarreau0ba27502007-12-24 16:55:16 +010022The configuration file syntax consists in lines beginning with a keyword
23referenced in this manual, optionally followed by one or several parameters
24delimited by spaces. If spaces have to be entered in strings, then they must be
25preceeded by a backslash ('\') to be escaped. Backslashes also have to be
26escaped by doubling them.
27
28Some parameters involve values representating time, such as timeouts. These
29values are generally expressed in milliseconds (unless explicitly stated
30otherwise) but may be expressed in any other unit by suffixing the unit to the
31numeric value. It is important to consider this because it will not be repeated
32for every keyword. Supported units are :
33
34 - us : microseconds. 1 microsecond = 1/1000000 second
35 - ms : milliseconds. 1 millisecond = 1/1000 second. This is the default.
36 - s : seconds. 1s = 1000ms
37 - m : minutes. 1m = 60s = 60000ms
38 - h : hours. 1h = 60m = 3600s = 3600000ms
39 - d : days. 1d = 24h = 1440m = 86400s = 86400000ms
40
41
Willy Tarreau6a06a402007-07-15 20:15:28 +0200421. Global parameters
43--------------------
44
45Parameters in the "global" section are process-wide and often OS-specific. They
46are generally set once for all and do not need being changed once correct. Some
47of them have command-line equivalents.
48
49The following keywords are supported in the "global" section :
50
51 * Process management and security
52 - chroot
53 - daemon
54 - gid
55 - group
56 - log
57 - nbproc
58 - pidfile
59 - uid
60 - ulimit-n
61 - user
Willy Tarreaufbee7132007-10-18 13:53:22 +020062 - stats
Willy Tarreau6a06a402007-07-15 20:15:28 +020063
64 * Performance tuning
65 - maxconn
66 - noepoll
67 - nokqueue
68 - nopoll
69 - nosepoll
70 - tune.maxpollevents
Willy Tarreaufe255b72007-10-14 23:09:26 +020071 - spread-checks
Willy Tarreau6a06a402007-07-15 20:15:28 +020072
73 * Debugging
74 - debug
75 - quiet
Willy Tarreau6a06a402007-07-15 20:15:28 +020076
77
781.1) Process management and security
79------------------------------------
80
81chroot <jail dir>
82 Changes current directory to <jail dir> and performs a chroot() there before
83 dropping privileges. This increases the security level in case an unknown
84 vulnerability would be exploited, since it would make it very hard for the
85 attacker to exploit the system. This only works when the process is started
86 with superuser privileges. It is important to ensure that <jail_dir> is both
87 empty and unwritable to anyone.
88
89daemon
90 Makes the process fork into background. This is the recommended mode of
91 operation. It is equivalent to the command line "-D" argument. It can be
92 disabled by the command line "-db" argument.
93
94gid <number>
95 Changes the process' group ID to <number>. It is recommended that the group
96 ID is dedicated to HAProxy or to a small set of similar daemons. HAProxy must
97 be started with a user belonging to this group, or with superuser privileges.
98 See also "group" and "uid".
99
100group <group name>
101 Similar to "gid" but uses the GID of group name <group name> from /etc/group.
102 See also "gid" and "user".
103
104log <address> <facility> [max level]
105 Adds a global syslog server. Up to two global servers can be defined. They
106 will receive logs for startups and exits, as well as all logs from proxies
Robert Tsai81ae1952007-12-05 10:47:29 +0100107 configured with "log global".
108
109 <address> can be one of:
110
111 - An IPv4 address optionally followed by a colon and an UDP port. If
112 no port is specified, 514 is used by default (the standard syslog
113 port).
114
115 - A filesystem path to a UNIX domain socket, keeping in mind
116 considerations for chroot (be sure the path is accessible inside
117 the chroot) and uid/gid (be sure the path is appropriately
118 writeable).
119
120 <facility> must be one of the 24 standard syslog facilities :
Willy Tarreau6a06a402007-07-15 20:15:28 +0200121
122 kern user mail daemon auth syslog lpr news
123 uucp cron auth2 ftp ntp audit alert cron2
124 local0 local1 local2 local3 local4 local5 local6 local7
125
126 An optional level can be specified to filter outgoing messages. By default,
127 all messages are sent. If a level is specified, only messages with a severity
128 at least as important as this level will be sent. 8 levels are known :
129
130 emerg alert crit err warning notice info debug
131
132nbproc <number>
133 Creates <number> processes when going daemon. This requires the "daemon"
134 mode. By default, only one process is created, which is the recommended mode
135 of operation. For systems limited to small sets of file descriptors per
136 process, it may be needed to fork multiple daemons. USING MULTIPLE PROCESSES
137 IS HARDER TO DEBUG AND IS REALLY DISCOURAGED. See also "daemon".
138
139pidfile <pidfile>
140 Writes pids of all daemons into file <pidfile>. This option is equivalent to
141 the "-p" command line argument. The file must be accessible to the user
142 starting the process. See also "daemon".
143
Willy Tarreaufbee7132007-10-18 13:53:22 +0200144stats socket <path> [{uid | user} <uid>] [{gid | group} <gid>] [mode <mode>]
145 Creates a UNIX socket in stream mode at location <path>. Any previously
146 existing socket will be backed up then replaced. Connections to this socket
147 will get a CSV-formated output of the process statistics in response to the
148 "show stat" command followed by a line feed. On platforms which support it,
149 it is possible to restrict access to this socket by specifying numerical IDs
150 after "uid" and "gid", or valid user and group names after the "user" and
151 "group" keywords. It is also possible to restrict permissions on the socket
152 by passing an octal value after the "mode" keyword (same syntax as chmod).
153 Depending on the platform, the permissions on the socket will be inherited
154 from the directory which hosts it, or from the user the process is started
155 with.
156
157stats timeout <timeout, in milliseconds>
158 The default timeout on the stats socket is set to 10 seconds. It is possible
159 to change this value with "stats timeout". The value must be passed in
Willy Tarreaubefdff12007-12-02 22:27:38 +0100160 milliseconds, or be suffixed by a time unit among { us, ms, s, m, h, d }.
Willy Tarreaufbee7132007-10-18 13:53:22 +0200161
162stats maxconn <connections>
163 By default, the stats socket is limited to 10 concurrent connections. It is
164 possible to change this value with "stats maxconn".
165
Willy Tarreau6a06a402007-07-15 20:15:28 +0200166uid <number>
167 Changes the process' user ID to <number>. It is recommended that the user ID
168 is dedicated to HAProxy or to a small set of similar daemons. HAProxy must
169 be started with superuser privileges in order to be able to switch to another
170 one. See also "gid" and "user".
171
172ulimit-n <number>
173 Sets the maximum number of per-process file-descriptors to <number>. By
174 default, it is automatically computed, so it is recommended not to use this
175 option.
176
177user <user name>
178 Similar to "uid" but uses the UID of user name <user name> from /etc/passwd.
179 See also "uid" and "group".
180
181
1821.2) Performance tuning
183-----------------------
184
185maxconn <number>
186 Sets the maximum per-process number of concurrent connections to <number>. It
187 is equivalent to the command-line argument "-n". Proxies will stop accepting
188 connections when this limit is reached. The "ulimit-n" parameter is
189 automatically adjusted according to this value. See also "ulimit-n".
190
191noepoll
192 Disables the use of the "epoll" event polling system on Linux. It is
193 equivalent to the command-line argument "-de". The next polling system
194 used will generally be "poll". See also "nosepoll", and "nopoll".
195
196nokqueue
197 Disables the use of the "kqueue" event polling system on BSD. It is
198 equivalent to the command-line argument "-dk". The next polling system
199 used will generally be "poll". See also "nopoll".
200
201nopoll
202 Disables the use of the "poll" event polling system. It is equivalent to the
203 command-line argument "-dp". The next polling system used will be "select".
Willy Tarreau0ba27502007-12-24 16:55:16 +0100204 It should never be needed to disable "poll" since it's available on all
Willy Tarreau6a06a402007-07-15 20:15:28 +0200205 platforms supported by HAProxy. See also "nosepoll", and "nopoll" and
206 "nokqueue".
207
208nosepoll
209 Disables the use of the "speculative epoll" event polling system on Linux. It
210 is equivalent to the command-line argument "-ds". The next polling system
211 used will generally be "epoll". See also "nosepoll", and "nopoll".
212
213tune.maxpollevents <number>
214 Sets the maximum amount of events that can be processed at once in a call to
215 the polling system. The default value is adapted to the operating system. It
216 has been noticed that reducing it below 200 tends to slightly decrease
217 latency at the expense of network bandwidth, and increasing it above 200
218 tends to trade latency for slightly increased bandwidth.
219
Willy Tarreaufe255b72007-10-14 23:09:26 +0200220spread-checks <0..50, in percent>
221 Sometimes it is desirable to avoid sending health checks to servers at exact
222 intervals, for instance when many logical servers are located on the same
223 physical server. With the help of this parameter, it becomes possible to add
224 some randomness in the check interval between 0 and +/- 50%. A value between
225 2 and 5 seems to show good results. The default value remains at 0.
226
Willy Tarreau6a06a402007-07-15 20:15:28 +0200227
2281.3) Debugging
229---------------
230
231debug
232 Enables debug mode which dumps to stdout all exchanges, and disables forking
233 into background. It is the equivalent of the command-line argument "-d". It
234 should never be used in a production configuration since it may prevent full
235 system startup.
236
237quiet
238 Do not display any message during startup. It is equivalent to the command-
239 line argument "-q".
240
Willy Tarreau6a06a402007-07-15 20:15:28 +0200241
2422) Proxies
243----------
Willy Tarreau0ba27502007-12-24 16:55:16 +0100244
Willy Tarreau6a06a402007-07-15 20:15:28 +0200245Proxy configuration can be located in a set of sections :
246 - defaults <name>
247 - frontend <name>
248 - backend <name>
249 - listen <name>
250
251A "defaults" section sets default parameters for all other sections following
252its declaration. Those default parameters are reset by the next "defaults"
253section. See below for the list of parameters which can be set in a "defaults"
Willy Tarreau0ba27502007-12-24 16:55:16 +0100254section. The name is optional but its use is encouraged for better readability.
Willy Tarreau6a06a402007-07-15 20:15:28 +0200255
256A "frontend" section describes a set of listening sockets accepting client
257connections.
258
259A "backend" section describes a set of servers to which the proxy will connect
260to forward incoming connections.
261
262A "listen" section defines a complete proxy with its frontend and backend
263parts combined in one section. It is generally useful for TCP-only traffic.
264
Willy Tarreau0ba27502007-12-24 16:55:16 +0100265All proxy names must be formed from upper and lower case letters, digits,
266'-' (dash), '_' (underscore) , '.' (dot) and ':' (colon). ACL names are
267case-sensitive, which means that "www" and "WWW" are two different proxies.
268
269Historically, all proxy names could overlap, it just caused troubles in the
270logs. Since the introduction of content switching, it is mandatory that two
271proxies with overlapping capabilities (frontend/backend) have different names.
272However, it is still permitted that a frontend and a backend share the same
273name, as this configuration seems to be commonly encountered.
274
275Right now, two major proxy modes are supported : "tcp", also known as layer 4,
276and "http", also known as layer 7. In layer 4 mode, HAProxy simply forwards
277bidirectionnal traffic between two sides. In layer 7 mode, HAProxy analyzes the
278protocol, and can interact with it by allowing, blocking, switching, adding,
279modifying, or removing arbitrary contents in requests or responses, based on
280arbitrary criteria.
281
282
2832.1) Quick reminder about HTTP
284------------------------------
285
286When a proxy is running in HTTP mode, both the request and the response are
287fully analyzed and indexed, thus it becomes possible to build matching criteria
288on almost anything found in the contents.
289
290However, it is important to understand how HTTP requests and responses are
291formed, and how HAProxy decomposes them. It will then become easier to write
292correct rules and to debug existing configurations.
293
294
2952.1.1) The HTTP transaction model
296---------------------------------
297
298The HTTP protocol is transaction-driven. This means that each request will lead
299to one and only one response. Traditionnally, a TCP connection is established
300from the client to the server, a request is sent by the client on the
301connection, the server responds and the connection is closed. A new request
302will involve a new connection :
303
304 [CON1] [REQ1] ... [RESP1] [CLO1] [CON2] [REQ2] ... [RESP2] [CLO2] ...
305
306In this mode, called the "HTTP close" mode, there are as many connection
307establishments as there are HTTP transactions. Since the connection is closed
308by the server after the response, the client does not need to know the content
309length.
310
311Due to the transactional nature of the protocol, it was possible to improve it
312to avoid closing a connection between two subsequent transactions. In this mode
313however, it is mandatory that the server indicates the content length for each
314response so that the client does not wait indefinitely. For this, a special
315header is used: "Content-length". This mode is called the "keep-alive" mode :
316
317 [CON] [REQ1] ... [RESP1] [REQ2] ... [RESP2] [CLO] ...
318
319Its advantages are a reduced latency between transactions, and less processing
320power required on the server side. It is generally better than the close mode,
321but not always because the clients often limit their concurrent connections to
322a smaller value. HAProxy currently does not support the HTTP keep-alive mode,
323but knows how to transform it to the close mode.
324
325A last improvement in the communications is the pipelining mode. It still uses
326keep-alive, but the client does not wait for the first response to send the
327second request. This is useful for fetching large number of images composing a
328page :
329
330 [CON] [REQ1] [REQ2] ... [RESP1] [RESP2] [CLO] ...
331
332This can obviously have a tremendous benefit on performance because the network
333latency is eliminated between subsequent requests. Many HTTP agents do not
334correctly support pipelining since there is no way to associate a response with
335the corresponding request in HTTP. For this reason, it is mandatory for the
336server to reply in the exact same order as the requests were received.
337
338Right now, HAProxy only supports the first mode (HTTP close) if it needs to
339process the request. This means that for each request, there will be one TCP
340connection. If keep-alive or pipelining are required, HAProxy will still
341support them, but will only see the first request and the first response of
342each transaction. While this is generally problematic with regards to logs,
343content switching or filtering, it most often causes no problem for persistence
344with cookie insertion.
345
346
3472.1.2) HTTP request
348-------------------
349
350First, let's consider this HTTP request :
351
352 Line Contents
353 number
354 1 GET /serv/login.php?lang=en&profile=2 HTTP/1.1
355 2 Host: www.mydomain.com
356 3 User-agent: my small browser
357 4 Accept: image/jpeg, image/gif
358 5 Accept: image/png
359
360
3612.1.2.1) The Request line
362-------------------------
363
364Line 1 is the "request line". It is always composed of 3 fields :
365
366 - a METHOD : GET
367 - a URI : /serv/login.php?lang=en&profile=2
368 - a version tag : HTTP/1.1
369
370All of them are delimited by what the standard calls LWS (linear white spaces),
371which are commonly spaces, but can also be tabs or line feeds/carriage returns
372followed by spaces/tabs. The method itself cannot contain any colon (':') and
373is limited to alphabetic letters. All those various combinations make it
374desirable that HAProxy performs the splitting itself rather than leaving it to
375the user to write a complex or inaccurate regular expression.
376
377The URI itself can have several forms :
378
379 - A "relative URI" :
380
381 /serv/login.php?lang=en&profile=2
382
383 It is a complete URL without the host part. This is generally what is
384 received by servers, reverse proxies and transparent proxies.
385
386 - An "absolute URI", also called a "URL" :
387
388 http://192.168.0.12:8080/serv/login.php?lang=en&profile=2
389
390 It is composed of a "scheme" (the protocol name followed by '://'), a host
391 name or address, optionally a colon (':') followed by a port number, then
392 a relative URI beginning at the first slash ('/') after the address part.
393 This is generally what proxies receive, but a server supporting HTTP/1.1
394 must accept this form too.
395
396 - a star ('*') : this form is only accepted in association with the OPTIONS
397 method and is not relayable. It is used to inquiry a next hop's
398 capabilities.
399
400 - an address:port combination : 192.168.0.12:80
401 This is used with the CONNECT method, which is used to establish TCP
402 tunnels through HTTP proxies, generally for HTTPS, but sometimes for
403 other protocols too.
404
405In a relative URI, two sub-parts are identified. The part before the question
406mark is called the "path". It is typically the relative path to static objects
407on the server. The part after the question mark is called the "query string".
408It is mostly used with GET requests sent to dynamic scripts and is very
409specific to the language, framework or application in use.
410
411
4122.1.2.2) The request headers
413----------------------------
414
415The headers start at the second line. They are composed of a name at the
416beginning of the line, immediately followed by a colon (':'). Traditionally,
417an LWS is added after the colon but that's not required. Then come the values.
418Multiple identical headers may be folded into one single line, delimiting the
419values with commas, provided that their order is respected. This is commonly
420encountered in the 'Cookie:' field. A header may span over multiple lines if
421the subsequent lines begin with an LWS. In the example in 2.1.2, lines 4 and 5
422define a total of 3 values for the 'Accept:' header.
423
424Contrary to a common mis-conception, header names are not case-sensitive, and
425their values are not either if they refer to other header names (such as the
426'Connection:' header).
427
428The end of the headers is indicated by the first empty line. People often say
429that it's a double line feed, which is not exact, even if a double line feed
430is one valid form of empty line.
431
432Fortunately, HAProxy takes care of all these complex combinations when indexing
433headers, checking values and counting them, so there is no reason to worry
434about the way they could be written, but it is important not to accusate an
435application of being buggy if it does unusual, valid things.
436
437Important note:
438 As suggested by RFC2616, HAProxy normalizes headers by replacing line breaks
439 in the middle of headers by LWS in order to join multi-line headers. This
440 is necessary for proper analysis and helps less capable HTTP parsers to work
441 correctly and not to be fooled by such complex constructs.
442
443
4442.1.3) HTTP response
445--------------------
446
447An HTTP response looks very much like an HTTP request. Both are called HTTP
448messages. Let's consider this HTTP response :
449
450 Line Contents
451 number
452 1 HTTP/1.1 200 OK
453 2 Content-length: 350
454 3 Content-Type: text/html
455
456
4572.1.3.1) The Response line
458--------------------------
459
460Line 1 is the "response line". It is always composed of 3 fields :
461
462 - a version tag : HTTP/1.1
463 - a status code : 200
464 - a reason : OK
465
466The status code is always 3-digit. The first digit indicates a general status :
467 - 2xx = OK, content is following (eg: 200, 206)
468 - 3xx = OK, no content following (eg: 302, 304)
469 - 4xx = error caused by the client (eg: 401, 403, 404)
470 - 5xx = error caused by the server (eg: 500, 502, 503)
471
472Please refer to RFC2616 for the detailed meaning of all such codes. The
473"reason" field is just a hint, but is not parsed by clients. Anything can be
474found there, but it's a common practise to respect the well-established
475messages. It can be composed of one or multiple words, such as "OK", "Found",
476or "Authentication Required".
477
478
4792.1.3.2) The response headers
480-----------------------------
481
482Response headers work exactly like request headers, and as such, HAProxy uses
483the same parsing function for both. Please refer to paragraph 2.1.2.2 for more
484details.
485
486
4872.2) Proxy keywords matrix
488----------------------------
489
Willy Tarreau6a06a402007-07-15 20:15:28 +0200490The following list of keywords is supported. Most of them may only be used in a
Willy Tarreau0ba27502007-12-24 16:55:16 +0100491limited set of section types. Some of them are marked as "deprecated" because
492they are inherited from an old syntax which may be confusing or functionnally
493limited, and there are new recommended keywords to replace them.
494
Willy Tarreau6a06a402007-07-15 20:15:28 +0200495
496keyword defaults frontend listen backend
497----------------------+----------+----------+---------+---------
498acl - X X X
499appsession - - X X
Willy Tarreau0ba27502007-12-24 16:55:16 +0100500balance X - X X
Willy Tarreau6a06a402007-07-15 20:15:28 +0200501bind - X X -
502block - X X X
Willy Tarreau0ba27502007-12-24 16:55:16 +0100503capture cookie - X X -
504capture request header - X X -
505capture response header - X X -
Willy Tarreaue219db72007-12-03 01:30:13 +0100506clitimeout X X X - (deprecated)
Willy Tarreau0ba27502007-12-24 16:55:16 +0100507contimeout X - X X (deprecated)
Willy Tarreau6a06a402007-07-15 20:15:28 +0200508cookie X - X X
509default_backend - X X -
Willy Tarreau0ba27502007-12-24 16:55:16 +0100510disabled X X X X
Willy Tarreau6a06a402007-07-15 20:15:28 +0200511dispatch - - X X
Willy Tarreau0ba27502007-12-24 16:55:16 +0100512enabled X X X X
Willy Tarreau6a06a402007-07-15 20:15:28 +0200513errorfile X X X X
514errorloc X X X X
515errorloc302 X X X X
516errorloc303 X X X X
517fullconn X - X X
518grace - X X X
Willy Tarreaudbc36f62007-11-30 12:29:11 +0100519http-check disable-on-404 X - X X
Willy Tarreau6a06a402007-07-15 20:15:28 +0200520log X X X X
521maxconn X X X -
522mode X X X X
Willy Tarreauc7246fc2007-12-02 17:31:20 +0100523monitor fail - X X -
Willy Tarreau6a06a402007-07-15 20:15:28 +0200524monitor-net X X X -
525monitor-uri X X X -
526option abortonclose X - X X
527option allbackups X - X X
528option checkcache X - X X
529option clitcpka X X X -
Krzysztof Piotr Oledzki583bc962007-11-24 22:12:47 +0100530option contstats X X X -
Willy Tarreau6a06a402007-07-15 20:15:28 +0200531option dontlognull X X X -
532option forceclose X - X X
533option forwardfor X X X X
534option httpchk X - X X
535option httpclose X X X X
536option httplog X X X X
537option logasap X X X -
Alexandre Cassen87ea5482007-10-11 20:48:58 +0200538option nolinger X X X X
Alexandre Cassen5eb1a902007-11-29 15:43:32 +0100539option http_proxy X X X X
Willy Tarreau6a06a402007-07-15 20:15:28 +0200540option persist X - X X
541option redispatch X - X X
542option smtpchk X - X X
543option srvtcpka X - X X
544option ssl-hello-chk X - X X
545option tcpka X X X X
546option tcplog X X X X
547option tcpsplice X X X X
548option transparent X X X -
549redisp X - X X
550redispatch X - X X
551reqadd - X X X
552reqallow - X X X
553reqdel - X X X
554reqdeny - X X X
555reqiallow - X X X
556reqidel - X X X
557reqideny - X X X
558reqipass - X X X
559reqirep - X X X
560reqisetbe - X X X
561reqitarpit - X X X
562reqpass - X X X
563reqrep - X X X
564reqsetbe - X X X
565reqtarpit - X X X
566retries X - X X
567rspadd - X X X
568rspdel - X X X
569rspdeny - X X X
570rspidel - X X X
571rspideny - X X X
572rspirep - X X X
573rsprep - X X X
574server - - X X
575source X - X X
Willy Tarreaue219db72007-12-03 01:30:13 +0100576srvtimeout X - X X (deprecated)
Willy Tarreau24e779b2007-07-24 23:43:37 +0200577stats auth X - X X
578stats enable X - X X
579stats realm X - X X
Willy Tarreaubbd42122007-07-25 07:26:38 +0200580stats refresh X - X X
Willy Tarreau24e779b2007-07-24 23:43:37 +0200581stats scope X - X X
582stats uri X - X X
Krzysztof Oledzkid9db9272007-10-15 10:05:11 +0200583stats hide-version X - X X
Willy Tarreaue219db72007-12-03 01:30:13 +0100584timeout appsession X - X X
585timeout client X X X -
586timeout clitimeout X X X - (deprecated)
587timeout connect X - X X
588timeout contimeout X - X X (deprecated)
589timeout queue X - X X
590timeout server X - X X
591timeout srvtimeout X - X X (deprecated)
592timeout tarpit X X X -
Willy Tarreau6a06a402007-07-15 20:15:28 +0200593transparent X X X -
594use_backend - X X -
595usesrc X - X X
596----------------------+----------+----------+---------+---------
597keyword defaults frontend listen backend
598
Willy Tarreau0ba27502007-12-24 16:55:16 +0100599
6002.2.1) Alphabetically sorted keywords reference
601-----------------------------------------------
602
603This section provides a description of each keyword and its usage.
604
605
606acl <aclname> <criterion> [flags] [operator] <value> ...
607 Declare or complete an access list.
608 May be used in sections : defaults | frontend | listen | backend
609 no | yes | yes | yes
610 Example:
611 acl invalid_src src 0.0.0.0/7 224.0.0.0/3
612 acl invalid_src src_port 0:1023
613 acl local_dst hdr(host) -i localhost
614
615 See section 2.3 about ACL usage.
616
617
618appsession <cookie> len <length> timeout <holdtime>
619 Define session stickiness on an existing application cookie.
620 May be used in sections : defaults | frontend | listen | backend
621 no | no | yes | yes
622 Arguments :
623 <cookie> this is the name of the cookie used by the application and which
624 HAProxy will have to learn for each new session.
625
626 <length> this is the number of characters that will be memorized and
627 checked in each cookie value.
628
629 <holdtime> this is the time after which the cookie will be removed from
630 memory if unused. If no unit is specified, this time is in
631 milliseconds.
632
633 When an application cookie is defined in a backend, HAProxy will check when
634 the server sets such a cookie, and will store its value in a table, and
635 associate it with the server's identifier. Up to <length> characters from
636 the value will be retained. On each connection, haproxy will look for this
637 cookie both in the "Cookie:" headers, and as a URL parameter in the query
638 string. If a known value is found, the client will be directed to the server
639 associated with this value. Otherwise, the load balancing algorithm is
640 applied. Cookies are automatically removed from memory when they have been
641 unused for a duration longer than <holdtime>.
642
643 The definition of an application cookie is limited to one per backend.
644
645 Example :
646 appsession JSESSIONID len 52 timeout 3h
647
648 See also : "cookie", "capture cookie" and "balance".
649
650
651balance <algorithm> [ <arguments> ]
652 Define the load balancing algorithm to be used in a backend.
653 May be used in sections : defaults | frontend | listen | backend
654 yes | no | yes | yes
655 Arguments :
656 <algorithm> is the algorithm used to select a server when doing load
657 balancing. This only applies when no persistence information
658 is available, or when a connection is redispatched to another
659 server. <algorithm> may be one of the following :
660
661 roundrobin Each server is used in turns, according to their weights.
662 This is the smoothest and fairest algorithm when the server's
663 processing time remains equally distributed. This algorithm
664 is dynamic, which means that server weights may be adjusted
665 on the fly for slow starts for instance.
666
667 source The source IP address is hashed and divided by the total
668 weight of the running servers to designate which server will
669 receive the request. This ensures that the same client IP
670 address will always reach the same server as long as no
671 server goes down or up. If the hash result changes due to the
672 number of running servers changing, many clients will be
673 directed to a different server. This algorithm is generally
674 used in TCP mode where no cookie may be inserted. It may also
675 be used on the Internet to provide a best-effort stickyness
676 to clients which refuse session cookies. This algorithm is
677 static, which means that changing a server's weight on the
678 fly will have no effect.
679
680 uri The left part of the URI (before the question mark) is hashed
681 and divided by the total weight of the running servers. The
682 result designates which server will receive the request. This
683 ensures that a same URI will always be directed to the same
684 server as long as no server goes up or down. This is used
685 with proxy caches and anti-virus proxies in order to maximize
686 the cache hit rate. Note that this algorithm may only be used
687 in an HTTP backend. This algorithm is static, which means
688 that changing a server's weight on the fly will have no
689 effect.
690
691 url_param The URL parameter specified in argument will be looked up in
692 the query string of each HTTP request. If it is found
693 followed by an equal sign ('=') and a value, then the value
694 is hashed and divided by the total weight of the running
695 servers. The result designates which server will receive the
696 request. This is used to track user identifiers in requests
697 and ensure that a same user ID will always be sent to the
698 same server as long as no server goes up or down. If no value
699 is found or if the parameter is not found, then a round robin
700 algorithm is applied. Note that this algorithm may only be
701 used in an HTTP backend. This algorithm is static, which
702 means that changing a server's weight on the fly will have no
703 effect.
704
705 <arguments> is an optional list of arguments which may be needed by some
706 algorithms. Right now, only the "url_param" algorithm supports
707 a mandatory argument.
708
709 The definition of the load balancing algorithm is mandatory for a backend
710 and limited to one per backend.
711
712 Examples :
713 balance roundrobin
714 balance url_param userid
715
716 See also : "dispatch", "cookie", "appsession", "transparent" and "http_proxy".
717
718
719bind [<address>]:<port> [, ...]
720 Define one or several listening addresses and/or ports in a frontend.
721 May be used in sections : defaults | frontend | listen | backend
722 no | yes | yes | no
723 Arguments :
724 <address> is optional and can be a host name, an IPv4 address, an IPv6
725 address, or '*'. It designates the address the frontend will
726 listen on. If unset, all IPv4 addresses of the system will be
727 listened on. The same will apply for '*' or the system's special
728 address "0.0.0.0".
729
730 <port> is the TCP port number the proxy will listen on. The port is
731 mandatory. Note that in the case of an IPv6 address, the port is
732 always the number after the last colon (':').
733
734 It is possible to specify a list of address:port combinations delimited by
735 commas. The frontend will then listen on all of these addresses. There is no
736 fixed limit to the number of addresses and ports which can be listened on in
737 a frontend, as well as there is no limit to the number of "bind" statements
738 in a frontend.
739
740 Example :
741 listen http_proxy
742 bind :80,:443
743 bind 10.0.0.1:10080,10.0.0.1:10443
744
745 See also : "source".
746
747
748block { if | unless } <condition>
749 Block a layer 7 request if/unless a condition is matched
750 May be used in sections : defaults | frontend | listen | backend
751 no | yes | yes | yes
752
753 The HTTP request will be blocked very early in the layer 7 processing
754 if/unless <condition> is matched. A 403 error will be returned if the request
755 is blocked. The condition has to reference ACLs (see section 2.3). This is
756 typically used to deny access to certain sensible resources if some
757 conditions are met or not met. There is no fixed limit to the number of
758 "block" statements per instance.
759
760 Example:
761 acl invalid_src src 0.0.0.0/7 224.0.0.0/3
762 acl invalid_src src_port 0:1023
763 acl local_dst hdr(host) -i localhost
764 block if invalid_src || local_dst
765
766 See section 2.3 about ACL usage.
767
768
769capture cookie <name> len <length>
770 Capture and log a cookie in the request and in the response.
771 May be used in sections : defaults | frontend | listen | backend
772 no | yes | yes | no
773 Arguments :
774 <name> is the beginning of the name of the cookie to capture. In order
775 to match the exact name, simply suffix the name with an equal
776 sign ('='). The full name will appear in the logs, which is
777 useful with application servers which adjust both the cookie name
778 and value (eg: ASPSESSIONXXXXX).
779
780 <length> is the maximum number of characters to report in the logs, which
781 include the cookie name, the equal sign and the value, all in the
782 standard "name=value" form. The string will be truncated on the
783 right if it exceeds <length>.
784
785 Only the first cookie is captured. Both the "cookie" request headers and the
786 "set-cookie" response headers are monitored. This is particularly useful to
787 check for application bugs causing session crossing or stealing between
788 users, because generally the user's cookies can only change on a login page.
789
790 When the cookie was not presented by the client, the associated log column
791 will report "-". When a request does not cause a cookie to be assigned by the
792 server, a "-" is reported in the response column.
793
794 The capture is performed in the frontend only because it is necessary that
795 the log format does not change for a given frontend depending on the
796 backends. This may change in the future. Note that there can be only one
797 "capture cookie" statement in a frontend. The maximum capture length is
798 configured in the souces by default to 64 characters. It is not possible to
799 specify a capture in a "defaults" section.
800
801 Example:
802 capture cookie ASPSESSION len 32
803
804 See also : "capture request header", "capture response header" as well as
805 section 2.4 about logging.
806
807
808capture request header <name> len <length>
809 Capture and log the first occurrence of the specified request header.
810 May be used in sections : defaults | frontend | listen | backend
811 no | yes | yes | no
812 Arguments :
813 <name> is the name of the header to capture. The header names are not
814 case-sensitive, but it is a common practise to write them as they
815 appear in the requests, with the first letter of each word in
816 upper case. The header name will not appear in the logs, only the
817 value is reported, but the position in the logs is respected.
818
819 <length> is the maximum number of characters to extract from the value and
820 report in the logs. The string will be truncated on the right if
821 it exceeds <length>.
822
823 Only the first value of the first occurrence of the header is captured. The
824 value will be added to the logs between braces ('{}'). If multiple headers
825 are captured, they will be delimited by a vertical bar ('|') and will appear
826 in the same order they were declared in the configuration. Common uses for
827 request header captures include the "Host" field in virtual hosting
828 environments, the "Content-length" when uploads are supported, "User-agent"
829 to quickly differenciate between real users and robots, and "X-Forwarded-For"
830 in proxied environments to find where the request came from.
831
832 There is no limit to the number of captured request headers, but each capture
833 is limited to 64 characters. In order to keep log format consistent for a
834 same frontend, header captures can only be declared in a frontend. It is not
835 possible to specify a capture in a "defaults" section.
836
837 Example:
838 capture request header Host len 15
839 capture request header X-Forwarded-For len 15
840 capture request header Referrer len 15
841
842 See also : "capture cookie", "capture response header" as well as section 2.4
843 about logging.
844
845
846capture response header <name> len <length>
847 Capture and log the first occurrence of the specified response header.
848 May be used in sections : defaults | frontend | listen | backend
849 no | yes | yes | no
850 Arguments :
851 <name> is the name of the header to capture. The header names are not
852 case-sensitive, but it is a common practise to write them as they
853 appear in the response, with the first letter of each word in
854 upper case. The header name will not appear in the logs, only the
855 value is reported, but the position in the logs is respected.
856
857 <length> is the maximum number of characters to extract from the value and
858 report in the logs. The string will be truncated on the right if
859 it exceeds <length>.
860
861 Only the first value of the first occurrence of the header is captured. The
862 result will be added to the logs between braces ('{}') after the captured
863 request headers. If multiple headers are captured, they will be delimited by
864 a vertical bar ('|') and will appear in the same order they were declared in
865 the configuration. Common uses for response header captures include the
866 "Content-length" header which indicates how many bytes are expected to be
867 returned, the "Location" header to track redirections.
868
869 There is no limit to the number of captured response headers, but each
870 capture is limited to 64 characters. In order to keep log format consistent
871 for a same frontend, header captures can only be declared in a frontend. It
872 is not possible to specify a capture in a "defaults" section.
873
874 Example:
875 capture response header Content-length len 9
876 capture response header Location len 15
877
878 See also : "capture cookie", "capture request header" as well as section 2.4
879 about logging.
880
881
882clitimeout <timeout>
883 Set the maximum inactivity time on the client side.
884 May be used in sections : defaults | frontend | listen | backend
885 yes | yes | yes | no
886 Arguments :
887 <timeout> is the timeout value is specified in milliseconds by default, but
888 can be in any other unit if the number is suffixed by the unit,
889 as explained at the top of this document.
890
891 The inactivity timeout applies when the client is expected to acknowledge or
892 send data. In HTTP mode, this timeout is particularly important to consider
893 during the first phase, when the client sends the request, and during the
894 response while it is reading data sent by the server. The value is specified
895 in milliseconds by default, but can be in any other unit if the number is
896 suffixed by the unit, as specified at the top of this document. In TCP mode
897 (and to a lesser extent, in HTTP mode), it is highly recommended that the
898 client timeout remains equal to the server timeout in order to avoid complex
899 situations to debug. It is a good practise to cover one or several TCP packet
900 losses by specifying timeouts that are slightly above multiples of 3 seconds
901 (eg: 4 or 5 seconds).
902
903 This parameter is specific to frontends, but can be specified once for all in
904 "defaults" sections. This is in fact one of the easiest solutions not to
905 forget about it. An unspecified timeout results in an infinite timeout, which
906 is not recommended. Such a usage is accepted and works but reports a warning
907 during startup because it may results in accumulation of expired sessions in
908 the system if the system's timeouts are not configured either.
909
910 This parameter is provided for compatibility but is currently deprecated.
911 Please use "timeout client" instead.
912
913 See also : "timeout client", "timeout server", "srvtimeout".
914
915
916contimeout <timeout>
917 Set the maximum time to wait for a connection attempt to a server to succeed.
918 May be used in sections : defaults | frontend | listen | backend
919 yes | no | yes | yes
920 Arguments :
921 <timeout> is the timeout value is specified in milliseconds by default, but
922 can be in any other unit if the number is suffixed by the unit,
923 as explained at the top of this document.
924
925 If the server is located on the same LAN as haproxy, the connection should be
926 immediate (less than a few milliseconds). Anyway, it is a good practise to
927 cover one or several TCP packet losses by specifying timeouts that are
928 slightly above multiples of 3 seconds (eg: 4 or 5 seconds). By default, the
929 connect timeout also presets the queue timeout to the same value if this one
930 has not been specified. Historically, the contimeout was also used to set the
931 tarpit timeout in a listen section, which is not possible in a pure frontend.
932
933 This parameter is specific to backends, but can be specified once for all in
934 "defaults" sections. This is in fact one of the easiest solutions not to
935 forget about it. An unspecified timeout results in an infinite timeout, which
936 is not recommended. Such a usage is accepted and works but reports a warning
937 during startup because it may results in accumulation of failed sessions in
938 the system if the system's timeouts are not configured either.
939
940 This parameter is provided for backwards compatibility but is currently
941 deprecated. Please use "timeout connect", "timeout queue" or "timeout tarpit"
942 instead.
943
944 See also : "timeout connect", "timeout queue", "timeout tarpit",
945 "timeout server", "contimeout".
946
947
948cookie <name> [ rewrite|insert|prefix ] [ indirect ] [ nocache ] [ postonly ]
949 Enable cookie-based persistence in a backend.
950 May be used in sections : defaults | frontend | listen | backend
951 yes | no | yes | yes
952 Arguments :
953 <name> is the name of the cookie which will be monitored, modified or
954 inserted in order to bring persistence. This cookie is sent to
955 the client via a "Set-Cookie" header in the response, and is
956 brought back by the client in a "Cookie" header in all requests.
957 Special care should be taken to choose a name which does not
958 conflict with any likely application cookie. Also, if the same
959 backends are subject to be used by the same clients (eg:
960 HTTP/HTTPS), care should be taken to use different cookie names
961 between all backends if persistence between them is not desired.
962
963 rewrite This keyword indicates that the cookie will be provided by the
964 server and that haproxy will have to modify its value to set the
965 server's identifier in it. This mode is handy when the management
966 of complex combinations of "Set-cookie" and "Cache-control"
967 headers is left to the application. The application can then
968 decide whether or not it is appropriate to emit a persistence
969 cookie. Since all responses should be monitored, this mode only
970 works in HTTP close mode. Unless the application behaviour is
971 very complex and/or broken, it is advised not to start with this
972 mode for new deployments. This keyword is incompatible with
973 "insert" and "prefix".
974
975 insert This keyword indicates that the persistence cookie will have to
976 be inserted by haproxy in the responses. If the server emits a
977 cookie with the same name, it will be replaced anyway. For this
978 reason, this mode can be used to upgrade existing configurations
979 running in the "rewrite" mode. The cookie will only be a session
980 cookie and will not be stored on the client's disk. Due to
981 caching effects, it is generally wise to add the "indirect" and
982 "nocache" or "postonly" keywords (see below). The "insert"
983 keyword is not compatible with "rewrite" and "prefix".
984
985 prefix This keyword indicates that instead of relying on a dedicated
986 cookie for the persistence, an existing one will be completed.
987 This may be needed in some specific environments where the client
988 does not support more than one single cookie and the application
989 already needs it. In this case, whenever the server sets a cookie
990 named <name>, it will be prefixed with the server's identifier
991 and a delimiter. The prefix will be removed from all client
992 requests so that the server still finds the cookie it emitted.
993 Since all requests and responses are subject to being modified,
994 this mode requires the HTTP close mode. The "prefix" keyword is
995 not compatible with "rewrite" and "insert".
996
997 indirect When this option is specified in insert mode, cookies will only
998 be added when the server was not reached after a direct access,
999 which means that only when a server is elected after applying a
1000 load-balancing algorithm, or after a redispatch, then the cookie
1001 will be inserted. If the client has all the required information
1002 to connect to the same server next time, no further cookie will
1003 be inserted. In all cases, when the "indirect" option is used in
1004 insert mode, the cookie is always removed from the requests
1005 transmitted to the server. The persistence mechanism then becomes
1006 totally transparent from the application point of view.
1007
1008 nocache This option is recommended in conjunction with the insert mode
1009 when there is a cache between the client and HAProxy, as it
1010 ensures that a cacheable response will be tagged non-cacheable if
1011 a cookie needs to be inserted. This is important because if all
1012 persistence cookies are added on a cacheable home page for
1013 instance, then all customers will then fetch the page from an
1014 outer cache and will all share the same persistence cookie,
1015 leading to one server receiving much more traffic than others.
1016 See also the "insert" and "postonly" options.
1017
1018 postonly This option ensures that cookie insertion will only be performed
1019 on responses to POST requests. It is an alternative to the
1020 "nocache" option, because POST responses are not cacheable, so
1021 this ensures that the persistence cookie will never get cached.
1022 Since most sites do not need any sort of persistence before the
1023 first POST which generally is a login request, this is a very
1024 efficient method to optimize caching without risking to find a
1025 persistence cookie in the cache.
1026 See also the "insert" and "nocache" options.
1027
1028 There can be only one persistence cookie per HTTP backend, and it can be
1029 declared in a defaults section. The value of the cookie will be the value
1030 indicated after the "cookie" keyword in a "server" statement. If no cookie
1031 is declared for a given server, the cookie is not set.
Willy Tarreau6a06a402007-07-15 20:15:28 +02001032
Willy Tarreau0ba27502007-12-24 16:55:16 +01001033 Examples :
1034 cookie JSESSIONID prefix
1035 cookie SRV insert indirect nocache
1036 cookie SRV insert postonly indirect
1037
1038 See also : "appsession", "balance source", "capture cookie", "server".
1039
1040
1041default_backend <backend>
1042 Specify the backend to use when no "use_backend" rule has been matched.
1043 May be used in sections : defaults | frontend | listen | backend
1044 yes | yes | yes | no
1045 Arguments :
1046 <backend> is the name of the backend to use.
1047
1048 When doing content-switching between frontend and backends using the
1049 "use_backend" keyword, it is often useful to indicate which backend will be
1050 used when no rule has matched. It generally is the dynamic backend which
1051 will catch all undetermined requests.
1052
1053 The "default_backend" keyword is also supported in TCP mode frontends to
1054 facilitate the ordering of configurations in frontends and backends,
1055 eventhough it does not make much more sense in case of TCP due to the fact
1056 that use_backend currently does not work in TCP mode.
1057
1058 Example :
1059
1060 use_backend dynamic if url_dyn
1061 use_backend static if url_css url_img extension_img
1062 default_backend dynamic
1063
1064
1065disabled
1066 Disable a proxy, frontend or backend.
1067 May be used in sections : defaults | frontend | listen | backend
1068 yes | yes | yes | yes
1069 Arguments : none
1070
1071 The "disabled" keyword is used to disable an instance, mainly in order to
1072 liberate a listening port or to temporarily disable a service. The instance
1073 will still be created and its configuration will be checked, but it will be
1074 created in the "stopped" state and will appear as such in the statistics. It
1075 will not receive any traffic nor will it send any health-checks or logs. It
1076 is possible to disable many instances at once by adding the "disabled"
1077 keyword in a "defaults" section.
1078
1079 See also : "enabled"
1080
1081
1082enabled
1083 Enable a proxy, frontend or backend.
1084 May be used in sections : defaults | frontend | listen | backend
1085 yes | yes | yes | yes
1086 Arguments : none
1087
1088 The "enabled" keyword is used to explicitly enable an instance, when the
1089 defaults has been set to "disabled". This is very rarely used.
1090
1091 See also : "disabled"
1092
1093
1094errorfile <code> <file>
1095 Return a file contents instead of errors generated by HAProxy
1096 May be used in sections : defaults | frontend | listen | backend
1097 yes | yes | yes | yes
1098 Arguments :
1099 <code> is the HTTP status code. Currently, HAProxy is capable of
1100 generating codes 400, 403, 408, 500, 502, 503, and 504.
1101
1102 <file> designates a file containing the full HTTP response. It is
1103 recommended to follow the common practise of appending ".http" to
1104 the filename so that people do not confuse the response with HTML
1105 error pages.
1106
1107 It is important to understand that this keyword is not meant to rewrite
1108 errors returned by the server, but errors detected and returned by HAProxy.
1109 This is why the list of supported errors is limited to a small set.
1110
1111 The files are returned verbatim on the TCP socket. This allows any trick such
1112 as redirections to another URL or site, as well as tricks to clean cookies,
1113 force enable or disable caching, etc... The package provides default error
1114 files returning the same contents as default errors.
1115
1116 The files are read at the same time as the configuration and kept in memory.
1117 For this reason, the errors continue to be returned even when the process is
1118 chrooted, and no file change is considered while the process is running. A
1119 simple method for developping those files consists in associating them to the
1120 403 status code and interrogating a blocked URL.
1121
1122 See also : "errorloc", "errorloc302", "errorloc303"
1123
1124
1125http-check disable-on-404
1126 Enable a maintenance mode upon HTTP/404 response to health-checks
1127 May be used in sections : defaults | frontend | listen | backend
1128 no | no | yes | yes
1129
1130 Arguments : none
1131
1132 When this option is set, a server which returns an HTTP code 404 will be
1133 excluded from further load-balancing, but will still receive persistent
1134 connections. This provides a very convenient method for Web administrators
1135 to perform a graceful shutdown of their servers. It is also important to note
1136 that a server which is detected as failed while it was in this mode will not
1137 generate an alert, just a notice. If the server responds 2xx or 3xx again, it
1138 will immediately be reinserted into the farm. The status on the stats page
1139 reports "NOLB" for a server in this mode. It is important to note that this
1140 option only works in conjunction with the "httpchk" option.
1141
1142
1143monitor fail [if | unless] <condition>
1144 Add a condition to report a failure to a monitor request.
1145 May be used in sections : defaults | frontend | listen | backend
1146 no | yes | yes | no
1147
1148 Arguments :
1149 if <cond> the monitor request will fail if the condition is satisfied,
1150 and will succeed otherwise. The condition should describe a
1151 combinated test which must induce a failure if all conditions
1152 are met, for instance a low number of servers both in a
1153 backend and its backup.
1154
1155 unless <cond> the monitor request will succeed only if the condition is
1156 satisfied, and will fail otherwise. Such a condition may be
1157 based on a test on the presence of a minimum number of active
1158 servers in a list of backends.
1159
1160 This statement adds a condition which can force the response to a monitor
1161 request to report a failure. By default, when an external component queries
1162 the URI dedicated to monitoring, a 200 response is returned. When one of the
1163 conditions above is met, haproxy will return 503 instead of 200. This is
1164 very useful to report a site failure to an external component which may base
1165 routing advertisements between multiple sites on the availability reported by
1166 haproxy. In this case, one would rely on an ACL involving the "nbsrv"
1167 criterion.
1168
1169 Example:
1170 frontend www
1171 acl site_dead nbsrv(dynamic) lt 2
1172 acl site_dead nbsrv(static) lt 2
1173 monitor-uri /site_alive
1174 monitor fail if site_dead
1175
1176
1177option contstats
1178 Enable continuous traffic statistics updates
1179 May be used in sections : defaults | frontend | listen | backend
1180 yes | yes | yes | no
1181 Arguments : none
1182
1183 By default, counters used for statistics calculation are incremented
1184 only when a session finishes. It works quite well when serving small
1185 objects, but with big ones (for example large images or archives) or
1186 with A/V streaming, a graph generated from haproxy counters looks like
1187 a hedgehog. With this option enabled counters get incremented continuously,
1188 during a whole session. Recounting touches a hotpath directly so
1189 it is not enabled by default, as it has small performance impact (~0.5%).
1190
1191
1192timeout client <timeout>
1193timeout clitimeout <timeout> (deprecated)
1194 Set the maximum inactivity time on the client side.
1195 May be used in sections : defaults | frontend | listen | backend
1196 yes | yes | yes | no
1197 Arguments :
1198 <timeout> is the timeout value is specified in milliseconds by default, but
1199 can be in any other unit if the number is suffixed by the unit,
1200 as explained at the top of this document.
1201
1202 The inactivity timeout applies when the client is expected to acknowledge or
1203 send data. In HTTP mode, this timeout is particularly important to consider
1204 during the first phase, when the client sends the request, and during the
1205 response while it is reading data sent by the server. The value is specified
1206 in milliseconds by default, but can be in any other unit if the number is
1207 suffixed by the unit, as specified at the top of this document. In TCP mode
1208 (and to a lesser extent, in HTTP mode), it is highly recommended that the
1209 client timeout remains equal to the server timeout in order to avoid complex
1210 situations to debug. It is a good practise to cover one or several TCP packet
1211 losses by specifying timeouts that are slightly above multiples of 3 seconds
1212 (eg: 4 or 5 seconds).
1213
1214 This parameter is specific to frontends, but can be specified once for all in
1215 "defaults" sections. This is in fact one of the easiest solutions not to
1216 forget about it. An unspecified timeout results in an infinite timeout, which
1217 is not recommended. Such a usage is accepted and works but reports a warning
1218 during startup because it may results in accumulation of expired sessions in
1219 the system if the system's timeouts are not configured either.
1220
1221 This parameter replaces the old, deprecated "clitimeout". It is recommended
1222 to use it to write new configurations. The form "timeout clitimeout" is
1223 provided only by backwards compatibility but its use is strongly discouraged.
1224
1225 See also : "clitimeout", "timeout server".
1226
1227
1228timeout connect <timeout>
1229timeout contimeout <timeout> (deprecated)
1230 Set the maximum time to wait for a connection attempt to a server to succeed.
1231 May be used in sections : defaults | frontend | listen | backend
1232 yes | no | yes | yes
1233 Arguments :
1234 <timeout> is the timeout value is specified in milliseconds by default, but
1235 can be in any other unit if the number is suffixed by the unit,
1236 as explained at the top of this document.
1237
1238 If the server is located on the same LAN as haproxy, the connection should be
1239 immediate (less than a few milliseconds). Anyway, it is a good practise to
1240 cover one or several TCP packet losses by specifying timeouts that are
1241 slightly above multiples of 3 seconds (eg: 4 or 5 seconds). By default, the
1242 connect timeout also presets the queue timeout to the same value if this one
1243 has not been specified.
1244
1245 This parameter is specific to backends, but can be specified once for all in
1246 "defaults" sections. This is in fact one of the easiest solutions not to
1247 forget about it. An unspecified timeout results in an infinite timeout, which
1248 is not recommended. Such a usage is accepted and works but reports a warning
1249 during startup because it may results in accumulation of failed sessions in
1250 the system if the system's timeouts are not configured either.
1251
1252 This parameter replaces the old, deprecated "contimeout". It is recommended
1253 to use it to write new configurations. The form "timeout contimeout" is
1254 provided only by backwards compatibility but its use is strongly discouraged.
1255
1256 See also : "timeout queue", "timeout server", "contimeout".
1257
1258
12592.3) Using ACLs
Willy Tarreau6a06a402007-07-15 20:15:28 +02001260---------------
1261
1262The use of Access Control Lists (ACL) provides a flexible solution to perform
Willy Tarreau0ba27502007-12-24 16:55:16 +01001263content switching and generally to take decisions based on content extracted
1264from the request, the response or any environmental status. The principle is
1265simple :
Willy Tarreau6a06a402007-07-15 20:15:28 +02001266
1267 - define test criteria with sets of values
1268 - perform actions only if a set of tests is valid
1269
1270The actions generally consist in blocking the request, or selecting a backend.
1271
1272In order to define a test, the "acl" keyword is used. The syntax is :
1273
1274 acl <aclname> <criterion> [flags] [operator] <value> ...
1275
Willy Tarreau0ba27502007-12-24 16:55:16 +01001276This creates a new ACL <aclname> or completes an existing one with new tests.
1277Those tests apply to the portion of request/response specified in <criterion>
Willy Tarreau6a06a402007-07-15 20:15:28 +02001278and may be adjusted with optional flags [flags]. Some criteria also support
1279an operator which may be specified before the set of values. The values are
1280of the type supported by the criterion, and are separated by spaces.
1281
Willy Tarreau0ba27502007-12-24 16:55:16 +01001282ACL names must be formed from upper and lower case letters, digits, '-' (dash),
1283'_' (underscore) , '.' (dot) and ':' (colon). ACL names are case-sensitive,
1284which means that "my_acl" and "My_Acl" are two different ACLs.
1285
1286There is no enforced limit to the number of ACLs. The unused ones do not affect
Willy Tarreau6a06a402007-07-15 20:15:28 +02001287performance, they just consume a small amount of memory.
1288
Willy Tarreau0ba27502007-12-24 16:55:16 +01001289The following ACL flags are currently supported :
Willy Tarreau6a06a402007-07-15 20:15:28 +02001290
1291 -i : ignore case during matching.
1292 -- : force end of flags. Useful when a string looks like one of the flags.
1293
1294Supported types of values are :
Willy Tarreau0ba27502007-12-24 16:55:16 +01001295
Willy Tarreau6a06a402007-07-15 20:15:28 +02001296 - integers or integer ranges
1297 - strings
1298 - regular expressions
1299 - IP addresses and networks
1300
1301
Willy Tarreau0ba27502007-12-24 16:55:16 +010013022.3.1) Matching integers
Willy Tarreau6a06a402007-07-15 20:15:28 +02001303------------------------
1304
1305Matching integers is special in that ranges and operators are permitted. Note
1306that integer matching only applies to positive values. A range is a value
1307expressed with a lower and an upper bound separated with a colon, both of which
1308may be omitted.
1309
1310For instance, "1024:65535" is a valid range to represent a range of
1311unprivileged ports, and "1024:" would also work. "0:1023" is a valid
1312representation of privileged ports, and ":1023" would also work.
1313
1314For an easier usage, comparison operators are also supported. Note that using
Willy Tarreau0ba27502007-12-24 16:55:16 +01001315operators with ranges does not make much sense and is strongly discouraged.
1316Similarly, it does not make much sense to perform order comparisons with a set
1317of values.
Willy Tarreau6a06a402007-07-15 20:15:28 +02001318
Willy Tarreau0ba27502007-12-24 16:55:16 +01001319Available operators for integer matching are :
Willy Tarreau6a06a402007-07-15 20:15:28 +02001320
1321 eq : true if the tested value equals at least one value
1322 ge : true if the tested value is greater than or equal to at least one value
1323 gt : true if the tested value is greater than at least one value
1324 le : true if the tested value is less than or equal to at least one value
1325 lt : true if the tested value is less than at least one value
1326
Willy Tarreau0ba27502007-12-24 16:55:16 +01001327For instance, the following ACL matches any negative Content-Length header :
Willy Tarreau6a06a402007-07-15 20:15:28 +02001328
1329 acl negative-length hdr_val(content-length) lt 0
1330
1331
Willy Tarreau0ba27502007-12-24 16:55:16 +010013322.3.2) Matching strings
Willy Tarreau6a06a402007-07-15 20:15:28 +02001333-----------------------
1334
1335String matching applies to verbatim strings as they are passed, with the
1336exception of the backslash ("\") which makes it possible to escape some
1337characters such as the space. If the "-i" flag is passed before the first
1338string, then the matching will be performed ignoring the case. In order
1339to match the string "-i", either set it second, or pass the "--" flag
Willy Tarreau0ba27502007-12-24 16:55:16 +01001340before the first string. Same applies of course to match the string "--".
Willy Tarreau6a06a402007-07-15 20:15:28 +02001341
1342
Willy Tarreau0ba27502007-12-24 16:55:16 +010013432.3.3) Matching regular expressions (regexes)
Willy Tarreau6a06a402007-07-15 20:15:28 +02001344---------------------------------------------
1345
1346Just like with string matching, regex matching applies to verbatim strings as
1347they are passed, with the exception of the backslash ("\") which makes it
1348possible to escape some characters such as the space. If the "-i" flag is
1349passed before the first regex, then the matching will be performed ignoring
1350the case. In order to match the string "-i", either set it second, or pass
Willy Tarreau0ba27502007-12-24 16:55:16 +01001351the "--" flag before the first string. Same principle applies of course to
1352match the string "--".
Willy Tarreau6a06a402007-07-15 20:15:28 +02001353
1354
Willy Tarreau0ba27502007-12-24 16:55:16 +010013552.3.4) Matching IPv4 addresses
1356------------------------------
Willy Tarreau6a06a402007-07-15 20:15:28 +02001357
1358IPv4 addresses values can be specified either as plain addresses or with a
1359netmask appended, in which case the IPv4 address matches whenever it is
1360within the network. Plain addresses may also be replaced with a resolvable
1361host name, but this practise is generally discouraged as it makes it more
Willy Tarreau0ba27502007-12-24 16:55:16 +01001362difficult to read and debug configurations. If hostnames are used, you should
1363at least ensure that they are present in /etc/hosts so that the configuration
1364does not depend on any random DNS match at the moment the configuration is
1365parsed.
Willy Tarreau6a06a402007-07-15 20:15:28 +02001366
1367
Willy Tarreau0ba27502007-12-24 16:55:16 +010013682.3.5) Available matching criteria
Willy Tarreau6a06a402007-07-15 20:15:28 +02001369----------------------------------
1370
Willy Tarreau0ba27502007-12-24 16:55:16 +010013712.3.5.1) Matching at Layer 4 and below
1372--------------------------------------
1373
1374A first set of criteria applies to information which does not require any
1375analysis of the request or response contents. Those generally include TCP/IP
1376addresses and ports, as well as internal values independant on the stream.
1377
Willy Tarreau6a06a402007-07-15 20:15:28 +02001378always_false
1379 This one never matches. All values and flags are ignored. It may be used as
1380 a temporary replacement for another one when adjusting configurations.
1381
1382always_true
1383 This one always matches. All values and flags are ignored. It may be used as
1384 a temporary replacement for another one when adjusting configurations.
1385
1386src <ip_address>
Willy Tarreau0ba27502007-12-24 16:55:16 +01001387 Applies to the client's IPv4 address. It is usually used to limit access to
Willy Tarreau6a06a402007-07-15 20:15:28 +02001388 certain resources such as statistics. Note that it is the TCP-level source
1389 address which is used, and not the address of a client behind a proxy.
1390
1391src_port <integer>
1392 Applies to the client's TCP source port. This has a very limited usage.
1393
1394dst <ip_address>
Willy Tarreau0ba27502007-12-24 16:55:16 +01001395 Applies to the local IPv4 address the client connected to. It can be used to
Willy Tarreau6a06a402007-07-15 20:15:28 +02001396 switch to a different backend for some alternative addresses.
1397
1398dst_port <integer>
1399 Applies to the local port the client connected to. It can be used to switch
1400 to a different backend for some alternative ports.
1401
1402dst_conn <integer>
1403 Applies to the number of currently established connections on the frontend,
1404 including the one being evaluated. It can be used to either return a sorry
Willy Tarreau0ba27502007-12-24 16:55:16 +01001405 page before hard-blocking, or to use a specific backend to drain new requests
Willy Tarreau6a06a402007-07-15 20:15:28 +02001406 when the farm is considered saturated.
1407
Willy Tarreau0ba27502007-12-24 16:55:16 +01001408nbsrv <integer>
1409nbsrv(backend) <integer>
1410 Returns true when the number of usable servers of either the current backend
1411 or the named backend matches the values or ranges specified. This is used to
1412 switch to an alternate backend when the number of servers is too low to
1413 to handle some load. It is useful to report a failure when combined with
1414 "monitor fail".
1415
1416
14172.3.5.2) Matching at Layer 7
1418----------------------------
1419
1420A second set of criteria applies to information which can be found at the
1421application layer (layer 7). Those require that a full HTTP request has been
1422read, and are only evaluated then. They may require slightly more CPU resources
1423than the layer 4 ones, but not much since the request and response are indexed.
1424
Willy Tarreau6a06a402007-07-15 20:15:28 +02001425method <string>
1426 Applies to the method in the HTTP request, eg: "GET". Some predefined ACL
1427 already check for most common methods.
1428
1429req_ver <string>
1430 Applies to the version string in the HTTP request, eg: "1.0". Some predefined
1431 ACL already check for versions 1.0 and 1.1.
1432
1433path <string>
1434 Returns true when the path part of the request, which starts at the first
1435 slash and ends before the question mark, equals one of the strings. It may be
1436 used to match known files, such as /favicon.ico.
1437
1438path_beg <string>
Willy Tarreau0ba27502007-12-24 16:55:16 +01001439 Returns true when the path begins with one of the strings. This can be used
1440 to send certain directory names to alternative backends.
Willy Tarreau6a06a402007-07-15 20:15:28 +02001441
1442path_end <string>
1443 Returns true when the path ends with one of the strings. This may be used to
1444 control file name extension.
1445
1446path_sub <string>
1447 Returns true when the path contains one of the strings. It can be used to
1448 detect particular patterns in paths, such as "../" for example. See also
1449 "path_dir".
1450
1451path_dir <string>
1452 Returns true when one of the strings is found isolated or delimited with
1453 slashes in the path. This is used to perform filename or directory name
1454 matching without the risk of wrong match due to colliding prefixes. See also
1455 "url_dir" and "path_sub".
1456
1457path_dom <string>
1458 Returns true when one of the strings is found isolated or delimited with dots
1459 in the path. This may be used to perform domain name matching in proxy
1460 requests. See also "path_sub" and "url_dom".
1461
1462path_reg <regex>
1463 Returns true when the path matches one of the regular expressions. It can be
1464 used any time, but it is important to remember that regex matching is slower
1465 than other methods. See also "url_reg" and all "path_" criteria.
1466
1467url <string>
1468 Applies to the whole URL passed in the request. The only real use is to match
1469 "*", for which there already is a predefined ACL.
1470
1471url_beg <string>
1472 Returns true when the URL begins with one of the strings. This can be used to
1473 check whether a URL begins with a slash or with a protocol scheme.
1474
1475url_end <string>
1476 Returns true when the URL ends with one of the strings. It has very limited
1477 use. "path_end" should be used instead for filename matching.
1478
1479url_sub <string>
1480 Returns true when the URL contains one of the strings. It can be used to
1481 detect particular patterns in query strings for example. See also "path_sub".
1482
1483url_dir <string>
1484 Returns true when one of the strings is found isolated or delimited with
1485 slashes in the URL. This is used to perform filename or directory name
1486 matching without the risk of wrong match due to colliding prefixes. See also
1487 "path_dir" and "url_sub".
1488
1489url_dom <string>
1490 Returns true when one of the strings is found isolated or delimited with dots
1491 in the URL. This is used to perform domain name matching without the risk of
1492 wrong match due to colliding prefixes. See also "url_sub".
1493
1494url_reg <regex>
1495 Returns true when the URL matches one of the regular expressions. It can be
1496 used any time, but it is important to remember that regex matching is slower
1497 than other methods. See also "path_reg" and all "url_" criteria.
1498
Alexandre Cassen5eb1a902007-11-29 15:43:32 +01001499url_ip <ip_address>
Willy Tarreau0ba27502007-12-24 16:55:16 +01001500 Applies to the IP address specified in the absolute URI in an HTTP request.
1501 It can be used to prevent access to certain resources such as local network.
1502 It is useful with option 'http_proxy'.
Alexandre Cassen5eb1a902007-11-29 15:43:32 +01001503
1504url_port <integer>
Willy Tarreau0ba27502007-12-24 16:55:16 +01001505 Applies to the port specified in the absolute URI in an HTTP request. It can
1506 be used to prevent access to certain resources. It is useful with option
1507 'http_proxy'. Note that if the port is not specified in the request, port 80
1508 is assumed.
Alexandre Cassen5eb1a902007-11-29 15:43:32 +01001509
Willy Tarreau6a06a402007-07-15 20:15:28 +02001510hdr <string>
1511hdr(header) <string>
1512 Note: all the "hdr*" matching criteria either apply to all headers, or to a
1513 particular header whose name is passed between parenthesis and without any
Willy Tarreau0ba27502007-12-24 16:55:16 +01001514 space. The header name is not case-sensitive. The header matching complies
1515 with RFC2616, and treats as separate headers all values delimited by commas.
Willy Tarreau6a06a402007-07-15 20:15:28 +02001516
1517 The "hdr" criteria returns true if any of the headers matching the criteria
Willy Tarreau0ba27502007-12-24 16:55:16 +01001518 match any of the strings. This can be used to check exact for values. For
Willy Tarreau6a06a402007-07-15 20:15:28 +02001519 instance, checking that "connection: close" is set :
1520
1521 hdr(Connection) -i close
1522
1523hdr_beg <string>
1524hdr_beg(header) <string>
1525 Returns true when one of the headers begins with one of the strings. See
1526 "hdr" for more information on header matching.
1527
1528hdr_end <string>
1529hdr_end(header) <string>
1530 Returns true when one of the headers ends with one of the strings. See "hdr"
1531 for more information on header matching.
1532
1533hdr_sub <string>
1534hdr_sub(header) <string>
1535 Returns true when one of the headers contains one of the strings. See "hdr"
1536 for more information on header matching.
1537
1538hdr_dir <string>
1539hdr_dir(header) <string>
1540 Returns true when one of the headers contains one of the strings either
1541 isolated or delimited by slashes. This is used to perform filename or
1542 directory name matching, and may be used with Referer. See "hdr" for more
1543 information on header matching.
1544
1545hdr_dom <string>
1546hdr_dom(header) <string>
1547 Returns true when one of the headers contains one of the strings either
1548 isolated or delimited by dots. This is used to perform domain name matching,
1549 and may be used with the Host header. See "hdr" for more information on
1550 header matching.
1551
1552hdr_reg <regex>
1553hdr_reg(header) <regex>
1554 Returns true when one of the headers matches of the regular expressions. It
1555 can be used at any time, but it is important to remember that regex matching
1556 is slower than other methods. See also other "hdr_" criteria, as well as
1557 "hdr" for more information on header matching.
1558
1559hdr_val <integer>
1560hdr_val(header) <integer>
1561 Returns true when one of the headers starts with a number which matches the
1562 values or ranges specified. This may be used to limit content-length to
1563 acceptable values for example. See "hdr" for more information on header
1564 matching.
1565
1566hdr_cnt <integer>
1567hdr_cnt(header) <integer>
Willy Tarreau0ba27502007-12-24 16:55:16 +01001568 Returns true when the number of occurrence of the specified header matches
1569 the values or ranges specified. It is important to remember that one header
1570 line may count as several headers if it has several values. This is used to
1571 detect presence, absence or abuse of a specific header, as well as to block
1572 request smugling attacks by rejecting requests which contain more than one
1573 of certain headers. See "hdr" for more information on header matching.
Willy Tarreau6a06a402007-07-15 20:15:28 +02001574
1575
Willy Tarreau0ba27502007-12-24 16:55:16 +010015762.3.6) Pre-defined ACLs
Willy Tarreau6a06a402007-07-15 20:15:28 +02001577-----------------------
1578
1579Some predefined ACLs are hard-coded so that they do not have to be declared in
1580every frontend which needs them. They all have their names in upper case in
Willy Tarreau0ba27502007-12-24 16:55:16 +01001581order to avoid confusion. Their equivalence is provided below. Please note that
1582only the first three ones are not layer 7 based.
Willy Tarreau6a06a402007-07-15 20:15:28 +02001583
1584ACL name Equivalent to Usage
1585---------------+-----------------------------+---------------------------------
1586TRUE always_true 1 always match
1587FALSE always_false 0 never match
1588LOCALHOST src 127.0.0.1/8 match connection from local host
1589HTTP_1.0 req_ver 1.0 match HTTP version 1.0
1590HTTP_1.1 req_ver 1.1 match HTTP version 1.1
1591METH_CONNECT method CONNECT match HTTP CONNECT method
1592METH_GET method GET HEAD match HTTP GET or HEAD method
1593METH_HEAD method HEAD match HTTP HEAD method
1594METH_OPTIONS method OPTIONS match HTTP OPTIONS method
1595METH_POST method POST match HTTP POST method
1596METH_TRACE method TRACE match HTTP TRACE method
1597HTTP_URL_ABS url_reg ^[^/:]*:// match absolute URL with scheme
1598HTTP_URL_SLASH url_beg / match URL begining with "/"
1599HTTP_URL_STAR url * match URL equal to "*"
1600HTTP_CONTENT hdr_val(content-length) gt 0 match an existing content-length
1601---------------+-----------------------------+---------------------------------
1602
1603
Willy Tarreau0ba27502007-12-24 16:55:16 +010016042.3.7) Using ACLs to form conditions
Willy Tarreau6a06a402007-07-15 20:15:28 +02001605------------------------------------
1606
1607Some actions are only performed upon a valid condition. A condition is a
1608combination of ACLs with operators. 3 operators are supported :
1609
1610 - AND (implicit)
1611 - OR (explicit with the "or" keyword or the "||" operator)
1612 - Negation with the exclamation mark ("!")
1613
1614A condition is formed as a disjonctive form :
1615
1616 [!]acl1 [!]acl2 ... [!]acln { or [!]acl1 [!]acl2 ... [!]acln } ...
1617
1618Such conditions are generally used after an "if" or "unless" statement,
1619indicating when the condition will trigger the action.
1620
1621For instance, to block HTTP requests to the "*" URL with methods other than
Willy Tarreau0ba27502007-12-24 16:55:16 +01001622"OPTIONS", as well as POST requests without content-length, and GET or HEAD
1623requests with a content-length greater than 0, and finally every request which
1624is not either GET/HEAD/POST/OPTIONS !
Willy Tarreau6a06a402007-07-15 20:15:28 +02001625
1626 acl missing_cl hdr_cnt(Content-length) eq 0
1627 block if HTTP_URL_STAR !METH_OPTIONS || METH_POST missing_cl
1628 block if METH_GET HTTP_CONTENT
1629 block unless METH_GET or METH_POST or METH_OPTIONS
1630
1631To select a different backend for requests to static contents on the "www" site
1632and to every request on the "img", "video", "download" and "ftp" hosts :
1633
1634 acl url_static path_beg /static /images /img /css
1635 acl url_static path_end .gif .png .jpg .css .js
1636 acl host_www hdr_beg(host) -i www
1637 acl host_static hdr_beg(host) -i img. video. download. ftp.
1638
1639 # now use backend "static" for all static-only hosts, and for static urls
1640 # of host "www". Use backend "www" for the rest.
1641 use_backend static if host_static or host_www url_static
1642 use_backend www if host_www
1643
1644See below for the detailed help on the "block" and "use_backend" keywords.
Willy Tarreaudbc36f62007-11-30 12:29:11 +01001645
1646
Willy Tarreauc7246fc2007-12-02 17:31:20 +010016472.4) Server options
Willy Tarreau5764b382007-11-30 17:46:49 +01001648-------------------
1649
1650slowstart <start_time_in_ms>
1651 The 'slowstart' parameter for a server accepts a value in milliseconds which
1652 indicates after how long a server which has just come back up will run at
Willy Tarreaubefdff12007-12-02 22:27:38 +01001653 full speed. Just as with every other time-based parameter, it can be entered
1654 in any other explicit unit among { us, ms, s, m, h, d }. The speed grows
1655 linearly from 0 to 100% during this time. The limitation applies to two
1656 parameters :
Willy Tarreau5764b382007-11-30 17:46:49 +01001657
1658 - maxconn: the number of connections accepted by the server will grow from 1
1659 to 100% of the usual dynamic limit defined by (minconn,maxconn,fullconn).
1660
1661 - weight: when the backend uses a dynamic weighted algorithm, the weight
1662 grows linearly from 1 to 100%. In this case, the weight is updated at every
1663 health-check. For this reason, it is important that the 'inter' parameter
Willy Tarreau0ba27502007-12-24 16:55:16 +01001664 is smaller than the 'slowstart', in order to maximize the number of steps.
Willy Tarreau5764b382007-11-30 17:46:49 +01001665
1666 The slowstart never applies when haproxy starts, otherwise it would cause
1667 trouble to running servers. It only applies when a server has been previously
1668 seen as failed.
1669
1670
Willy Tarreau0ba27502007-12-24 16:55:16 +01001671/*
1672 * Local variables:
1673 * fill-column: 79
1674 * End:
1675 */