blob: e26fcb6a652bcce4c5068600462506533a929ab1 [file] [log] [blame]
Willy Tarreau6a06a402007-07-15 20:15:28 +02001 ----------------------
2 HAProxy
3 Configuration Manual
4 ----------------------
Krzysztof Oledzkid9db9272007-10-15 10:05:11 +02005 version 1.3.13
Willy Tarreau6a06a402007-07-15 20:15:28 +02006 willy tarreau
Willy Tarreaufbee7132007-10-18 13:53:22 +02007 2007/10/18
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
12docuemntation, please refer to the Reference Manual or the Architecture Manual.
13
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
221. Global parameters
23--------------------
24
25Parameters in the "global" section are process-wide and often OS-specific. They
26are generally set once for all and do not need being changed once correct. Some
27of them have command-line equivalents.
28
29The following keywords are supported in the "global" section :
30
31 * Process management and security
32 - chroot
33 - daemon
34 - gid
35 - group
36 - log
37 - nbproc
38 - pidfile
39 - uid
40 - ulimit-n
41 - user
Willy Tarreaufbee7132007-10-18 13:53:22 +020042 - stats
Willy Tarreau6a06a402007-07-15 20:15:28 +020043
44 * Performance tuning
45 - maxconn
46 - noepoll
47 - nokqueue
48 - nopoll
49 - nosepoll
50 - tune.maxpollevents
Willy Tarreaufe255b72007-10-14 23:09:26 +020051 - spread-checks
Willy Tarreau6a06a402007-07-15 20:15:28 +020052
53 * Debugging
54 - debug
55 - quiet
Willy Tarreau6a06a402007-07-15 20:15:28 +020056
57
581.1) Process management and security
59------------------------------------
60
61chroot <jail dir>
62 Changes current directory to <jail dir> and performs a chroot() there before
63 dropping privileges. This increases the security level in case an unknown
64 vulnerability would be exploited, since it would make it very hard for the
65 attacker to exploit the system. This only works when the process is started
66 with superuser privileges. It is important to ensure that <jail_dir> is both
67 empty and unwritable to anyone.
68
69daemon
70 Makes the process fork into background. This is the recommended mode of
71 operation. It is equivalent to the command line "-D" argument. It can be
72 disabled by the command line "-db" argument.
73
74gid <number>
75 Changes the process' group ID to <number>. It is recommended that the group
76 ID is dedicated to HAProxy or to a small set of similar daemons. HAProxy must
77 be started with a user belonging to this group, or with superuser privileges.
78 See also "group" and "uid".
79
80group <group name>
81 Similar to "gid" but uses the GID of group name <group name> from /etc/group.
82 See also "gid" and "user".
83
84log <address> <facility> [max level]
85 Adds a global syslog server. Up to two global servers can be defined. They
86 will receive logs for startups and exits, as well as all logs from proxies
Robert Tsai81ae1952007-12-05 10:47:29 +010087 configured with "log global".
88
89 <address> can be one of:
90
91 - An IPv4 address optionally followed by a colon and an UDP port. If
92 no port is specified, 514 is used by default (the standard syslog
93 port).
94
95 - A filesystem path to a UNIX domain socket, keeping in mind
96 considerations for chroot (be sure the path is accessible inside
97 the chroot) and uid/gid (be sure the path is appropriately
98 writeable).
99
100 <facility> must be one of the 24 standard syslog facilities :
Willy Tarreau6a06a402007-07-15 20:15:28 +0200101
102 kern user mail daemon auth syslog lpr news
103 uucp cron auth2 ftp ntp audit alert cron2
104 local0 local1 local2 local3 local4 local5 local6 local7
105
106 An optional level can be specified to filter outgoing messages. By default,
107 all messages are sent. If a level is specified, only messages with a severity
108 at least as important as this level will be sent. 8 levels are known :
109
110 emerg alert crit err warning notice info debug
111
112nbproc <number>
113 Creates <number> processes when going daemon. This requires the "daemon"
114 mode. By default, only one process is created, which is the recommended mode
115 of operation. For systems limited to small sets of file descriptors per
116 process, it may be needed to fork multiple daemons. USING MULTIPLE PROCESSES
117 IS HARDER TO DEBUG AND IS REALLY DISCOURAGED. See also "daemon".
118
119pidfile <pidfile>
120 Writes pids of all daemons into file <pidfile>. This option is equivalent to
121 the "-p" command line argument. The file must be accessible to the user
122 starting the process. See also "daemon".
123
Willy Tarreaufbee7132007-10-18 13:53:22 +0200124stats socket <path> [{uid | user} <uid>] [{gid | group} <gid>] [mode <mode>]
125 Creates a UNIX socket in stream mode at location <path>. Any previously
126 existing socket will be backed up then replaced. Connections to this socket
127 will get a CSV-formated output of the process statistics in response to the
128 "show stat" command followed by a line feed. On platforms which support it,
129 it is possible to restrict access to this socket by specifying numerical IDs
130 after "uid" and "gid", or valid user and group names after the "user" and
131 "group" keywords. It is also possible to restrict permissions on the socket
132 by passing an octal value after the "mode" keyword (same syntax as chmod).
133 Depending on the platform, the permissions on the socket will be inherited
134 from the directory which hosts it, or from the user the process is started
135 with.
136
137stats timeout <timeout, in milliseconds>
138 The default timeout on the stats socket is set to 10 seconds. It is possible
139 to change this value with "stats timeout". The value must be passed in
Willy Tarreaubefdff12007-12-02 22:27:38 +0100140 milliseconds, or be suffixed by a time unit among { us, ms, s, m, h, d }.
Willy Tarreaufbee7132007-10-18 13:53:22 +0200141
142stats maxconn <connections>
143 By default, the stats socket is limited to 10 concurrent connections. It is
144 possible to change this value with "stats maxconn".
145
Willy Tarreau6a06a402007-07-15 20:15:28 +0200146uid <number>
147 Changes the process' user ID to <number>. It is recommended that the user ID
148 is dedicated to HAProxy or to a small set of similar daemons. HAProxy must
149 be started with superuser privileges in order to be able to switch to another
150 one. See also "gid" and "user".
151
152ulimit-n <number>
153 Sets the maximum number of per-process file-descriptors to <number>. By
154 default, it is automatically computed, so it is recommended not to use this
155 option.
156
157user <user name>
158 Similar to "uid" but uses the UID of user name <user name> from /etc/passwd.
159 See also "uid" and "group".
160
161
1621.2) Performance tuning
163-----------------------
164
165maxconn <number>
166 Sets the maximum per-process number of concurrent connections to <number>. It
167 is equivalent to the command-line argument "-n". Proxies will stop accepting
168 connections when this limit is reached. The "ulimit-n" parameter is
169 automatically adjusted according to this value. See also "ulimit-n".
170
171noepoll
172 Disables the use of the "epoll" event polling system on Linux. It is
173 equivalent to the command-line argument "-de". The next polling system
174 used will generally be "poll". See also "nosepoll", and "nopoll".
175
176nokqueue
177 Disables the use of the "kqueue" event polling system on BSD. It is
178 equivalent to the command-line argument "-dk". The next polling system
179 used will generally be "poll". See also "nopoll".
180
181nopoll
182 Disables the use of the "poll" event polling system. It is equivalent to the
183 command-line argument "-dp". The next polling system used will be "select".
184 It should never be needed to didsable "poll" since it's available on all
185 platforms supported by HAProxy. See also "nosepoll", and "nopoll" and
186 "nokqueue".
187
188nosepoll
189 Disables the use of the "speculative epoll" event polling system on Linux. It
190 is equivalent to the command-line argument "-ds". The next polling system
191 used will generally be "epoll". See also "nosepoll", and "nopoll".
192
193tune.maxpollevents <number>
194 Sets the maximum amount of events that can be processed at once in a call to
195 the polling system. The default value is adapted to the operating system. It
196 has been noticed that reducing it below 200 tends to slightly decrease
197 latency at the expense of network bandwidth, and increasing it above 200
198 tends to trade latency for slightly increased bandwidth.
199
Willy Tarreaufe255b72007-10-14 23:09:26 +0200200spread-checks <0..50, in percent>
201 Sometimes it is desirable to avoid sending health checks to servers at exact
202 intervals, for instance when many logical servers are located on the same
203 physical server. With the help of this parameter, it becomes possible to add
204 some randomness in the check interval between 0 and +/- 50%. A value between
205 2 and 5 seems to show good results. The default value remains at 0.
206
Willy Tarreau6a06a402007-07-15 20:15:28 +0200207
2081.3) Debugging
209---------------
210
211debug
212 Enables debug mode which dumps to stdout all exchanges, and disables forking
213 into background. It is the equivalent of the command-line argument "-d". It
214 should never be used in a production configuration since it may prevent full
215 system startup.
216
217quiet
218 Do not display any message during startup. It is equivalent to the command-
219 line argument "-q".
220
Willy Tarreau6a06a402007-07-15 20:15:28 +0200221
2222) Proxies
223----------
224Proxy configuration can be located in a set of sections :
225 - defaults <name>
226 - frontend <name>
227 - backend <name>
228 - listen <name>
229
230A "defaults" section sets default parameters for all other sections following
231its declaration. Those default parameters are reset by the next "defaults"
232section. See below for the list of parameters which can be set in a "defaults"
233section.
234
235A "frontend" section describes a set of listening sockets accepting client
236connections.
237
238A "backend" section describes a set of servers to which the proxy will connect
239to forward incoming connections.
240
241A "listen" section defines a complete proxy with its frontend and backend
242parts combined in one section. It is generally useful for TCP-only traffic.
243
244The following list of keywords is supported. Most of them may only be used in a
245limited set of section types.
246
247keyword defaults frontend listen backend
248----------------------+----------+----------+---------+---------
249acl - X X X
250appsession - - X X
251balance - - X X
252bind - X X -
253block - X X X
254capture cookie X X X X
255capture request header X X X X
256capture response header X X X X
Willy Tarreaue219db72007-12-03 01:30:13 +0100257clitimeout X X X - (deprecated)
258contimeout X X X X (deprecated)
Willy Tarreau6a06a402007-07-15 20:15:28 +0200259cookie X - X X
260default_backend - X X -
261disabled - X X X
262dispatch - - X X
263enabled - X X X
264errorfile X X X X
265errorloc X X X X
266errorloc302 X X X X
267errorloc303 X X X X
268fullconn X - X X
269grace - X X X
Willy Tarreaudbc36f62007-11-30 12:29:11 +0100270http-check disable-on-404 X - X X
Willy Tarreau6a06a402007-07-15 20:15:28 +0200271log X X X X
272maxconn X X X -
273mode X X X X
Willy Tarreauc7246fc2007-12-02 17:31:20 +0100274monitor fail - X X -
Willy Tarreau6a06a402007-07-15 20:15:28 +0200275monitor-net X X X -
276monitor-uri X X X -
277option abortonclose X - X X
278option allbackups X - X X
279option checkcache X - X X
280option clitcpka X X X -
Krzysztof Piotr Oledzki583bc962007-11-24 22:12:47 +0100281option contstats X X X -
Willy Tarreau6a06a402007-07-15 20:15:28 +0200282option dontlognull X X X -
283option forceclose X - X X
284option forwardfor X X X X
285option httpchk X - X X
286option httpclose X X X X
287option httplog X X X X
288option logasap X X X -
Alexandre Cassen87ea5482007-10-11 20:48:58 +0200289option nolinger X X X X
Alexandre Cassen5eb1a902007-11-29 15:43:32 +0100290option http_proxy X X X X
Willy Tarreau6a06a402007-07-15 20:15:28 +0200291option persist X - X X
292option redispatch X - X X
293option smtpchk X - X X
294option srvtcpka X - X X
295option ssl-hello-chk X - X X
296option tcpka X X X X
297option tcplog X X X X
298option tcpsplice X X X X
299option transparent X X X -
300redisp X - X X
301redispatch X - X X
302reqadd - X X X
303reqallow - X X X
304reqdel - X X X
305reqdeny - X X X
306reqiallow - X X X
307reqidel - X X X
308reqideny - X X X
309reqipass - X X X
310reqirep - X X X
311reqisetbe - X X X
312reqitarpit - X X X
313reqpass - X X X
314reqrep - X X X
315reqsetbe - X X X
316reqtarpit - X X X
317retries X - X X
318rspadd - X X X
319rspdel - X X X
320rspdeny - X X X
321rspidel - X X X
322rspideny - X X X
323rspirep - X X X
324rsprep - X X X
325server - - X X
326source X - X X
Willy Tarreaue219db72007-12-03 01:30:13 +0100327srvtimeout X - X X (deprecated)
Willy Tarreau24e779b2007-07-24 23:43:37 +0200328stats auth X - X X
329stats enable X - X X
330stats realm X - X X
Willy Tarreaubbd42122007-07-25 07:26:38 +0200331stats refresh X - X X
Willy Tarreau24e779b2007-07-24 23:43:37 +0200332stats scope X - X X
333stats uri X - X X
Krzysztof Oledzkid9db9272007-10-15 10:05:11 +0200334stats hide-version X - X X
Willy Tarreaue219db72007-12-03 01:30:13 +0100335timeout appsession X - X X
336timeout client X X X -
337timeout clitimeout X X X - (deprecated)
338timeout connect X - X X
339timeout contimeout X - X X (deprecated)
340timeout queue X - X X
341timeout server X - X X
342timeout srvtimeout X - X X (deprecated)
343timeout tarpit X X X -
Willy Tarreau6a06a402007-07-15 20:15:28 +0200344transparent X X X -
345use_backend - X X -
346usesrc X - X X
347----------------------+----------+----------+---------+---------
348keyword defaults frontend listen backend
349
Willy Tarreau6a06a402007-07-15 20:15:28 +0200350
3512.1) using ACLs
352---------------
353
354The use of Access Control Lists (ACL) provides a flexible solution to perform
355content switching. The principle is simple :
356
357 - define test criteria with sets of values
358 - perform actions only if a set of tests is valid
359
360The actions generally consist in blocking the request, or selecting a backend.
361
362In order to define a test, the "acl" keyword is used. The syntax is :
363
364 acl <aclname> <criterion> [flags] [operator] <value> ...
365
366This creates an ACL <aclname> or completes an existing one with new
367tests. Those tests apply to the portion of request specified in <criterion>
368and may be adjusted with optional flags [flags]. Some criteria also support
369an operator which may be specified before the set of values. The values are
370of the type supported by the criterion, and are separated by spaces.
371
372There is no limit to the number of ACLs. The unused ones do not affect
373performance, they just consume a small amount of memory.
374
375The current flags are currently supported :
376
377 -i : ignore case during matching.
378 -- : force end of flags. Useful when a string looks like one of the flags.
379
380Supported types of values are :
381 - integers or integer ranges
382 - strings
383 - regular expressions
384 - IP addresses and networks
385
386
3872.1.1) Matching integers
388------------------------
389
390Matching integers is special in that ranges and operators are permitted. Note
391that integer matching only applies to positive values. A range is a value
392expressed with a lower and an upper bound separated with a colon, both of which
393may be omitted.
394
395For instance, "1024:65535" is a valid range to represent a range of
396unprivileged ports, and "1024:" would also work. "0:1023" is a valid
397representation of privileged ports, and ":1023" would also work.
398
399For an easier usage, comparison operators are also supported. Note that using
400operators with ranges does not make much sense and is discouraged. Also, it
401does not make much sense to perform order comparisons with a set of values.
402
403Available operators are :
404
405 eq : true if the tested value equals at least one value
406 ge : true if the tested value is greater than or equal to at least one value
407 gt : true if the tested value is greater than at least one value
408 le : true if the tested value is less than or equal to at least one value
409 lt : true if the tested value is less than at least one value
410
411For instance, the following ACL matches negative Content-Length headers :
412
413 acl negative-length hdr_val(content-length) lt 0
414
415
4162.1.2) Matching strings
417-----------------------
418
419String matching applies to verbatim strings as they are passed, with the
420exception of the backslash ("\") which makes it possible to escape some
421characters such as the space. If the "-i" flag is passed before the first
422string, then the matching will be performed ignoring the case. In order
423to match the string "-i", either set it second, or pass the "--" flag
424before the first string.
425
426
4272.1.3) Matching regular expressions (regexes)
428---------------------------------------------
429
430Just like with string matching, regex matching applies to verbatim strings as
431they are passed, with the exception of the backslash ("\") which makes it
432possible to escape some characters such as the space. If the "-i" flag is
433passed before the first regex, then the matching will be performed ignoring
434the case. In order to match the string "-i", either set it second, or pass
435the "--" flag before the first string.
436
437
4382.1.4) Matching IPv4 addresses
439----------------------------
440
441IPv4 addresses values can be specified either as plain addresses or with a
442netmask appended, in which case the IPv4 address matches whenever it is
443within the network. Plain addresses may also be replaced with a resolvable
444host name, but this practise is generally discouraged as it makes it more
445difficult to read configurations.
446
447
4482.1.5) Available matching criteria
449----------------------------------
450
451always_false
452 This one never matches. All values and flags are ignored. It may be used as
453 a temporary replacement for another one when adjusting configurations.
454
455always_true
456 This one always matches. All values and flags are ignored. It may be used as
457 a temporary replacement for another one when adjusting configurations.
458
459src <ip_address>
460 Applies to the client's IP address. It is usually used to limit access to
461 certain resources such as statistics. Note that it is the TCP-level source
462 address which is used, and not the address of a client behind a proxy.
463
464src_port <integer>
465 Applies to the client's TCP source port. This has a very limited usage.
466
467dst <ip_address>
468 Applies to the local IP address the client connected to. It can be used to
469 switch to a different backend for some alternative addresses.
470
471dst_port <integer>
472 Applies to the local port the client connected to. It can be used to switch
473 to a different backend for some alternative ports.
474
475dst_conn <integer>
476 Applies to the number of currently established connections on the frontend,
477 including the one being evaluated. It can be used to either return a sorry
478 page before hard-blocking, or to use a specific backend to drain the requests
479 when the farm is considered saturated.
480
481method <string>
482 Applies to the method in the HTTP request, eg: "GET". Some predefined ACL
483 already check for most common methods.
484
485req_ver <string>
486 Applies to the version string in the HTTP request, eg: "1.0". Some predefined
487 ACL already check for versions 1.0 and 1.1.
488
489path <string>
490 Returns true when the path part of the request, which starts at the first
491 slash and ends before the question mark, equals one of the strings. It may be
492 used to match known files, such as /favicon.ico.
493
494path_beg <string>
495 Returns true when the path begins with one of the strings. This can be used to
496 send certain directory names to alternative backends.
497
498path_end <string>
499 Returns true when the path ends with one of the strings. This may be used to
500 control file name extension.
501
502path_sub <string>
503 Returns true when the path contains one of the strings. It can be used to
504 detect particular patterns in paths, such as "../" for example. See also
505 "path_dir".
506
507path_dir <string>
508 Returns true when one of the strings is found isolated or delimited with
509 slashes in the path. This is used to perform filename or directory name
510 matching without the risk of wrong match due to colliding prefixes. See also
511 "url_dir" and "path_sub".
512
513path_dom <string>
514 Returns true when one of the strings is found isolated or delimited with dots
515 in the path. This may be used to perform domain name matching in proxy
516 requests. See also "path_sub" and "url_dom".
517
518path_reg <regex>
519 Returns true when the path matches one of the regular expressions. It can be
520 used any time, but it is important to remember that regex matching is slower
521 than other methods. See also "url_reg" and all "path_" criteria.
522
523url <string>
524 Applies to the whole URL passed in the request. The only real use is to match
525 "*", for which there already is a predefined ACL.
526
527url_beg <string>
528 Returns true when the URL begins with one of the strings. This can be used to
529 check whether a URL begins with a slash or with a protocol scheme.
530
531url_end <string>
532 Returns true when the URL ends with one of the strings. It has very limited
533 use. "path_end" should be used instead for filename matching.
534
535url_sub <string>
536 Returns true when the URL contains one of the strings. It can be used to
537 detect particular patterns in query strings for example. See also "path_sub".
538
539url_dir <string>
540 Returns true when one of the strings is found isolated or delimited with
541 slashes in the URL. This is used to perform filename or directory name
542 matching without the risk of wrong match due to colliding prefixes. See also
543 "path_dir" and "url_sub".
544
545url_dom <string>
546 Returns true when one of the strings is found isolated or delimited with dots
547 in the URL. This is used to perform domain name matching without the risk of
548 wrong match due to colliding prefixes. See also "url_sub".
549
550url_reg <regex>
551 Returns true when the URL matches one of the regular expressions. It can be
552 used any time, but it is important to remember that regex matching is slower
553 than other methods. See also "path_reg" and all "url_" criteria.
554
Alexandre Cassen5eb1a902007-11-29 15:43:32 +0100555url_ip <ip_address>
556 Applies to the IP address parsed in HTTP request. It can be used to
557 prevent access to certain resources such as local network. It is useful
558 with option 'http_proxy'.
559
560url_port <integer>
561 Applies to the port parsed in HTTP request. It can be used to
562 prevent access to certain resources. It is useful with option 'http_proxy'.
563
Willy Tarreau6a06a402007-07-15 20:15:28 +0200564hdr <string>
565hdr(header) <string>
566 Note: all the "hdr*" matching criteria either apply to all headers, or to a
567 particular header whose name is passed between parenthesis and without any
568 space. The header matching complies with RFC2616, and treats as separate
569 headers all values delimited by comas.
570
571 The "hdr" criteria returns true if any of the headers matching the criteria
572 match any of the strings. This can be used to check exact values. For
573 instance, checking that "connection: close" is set :
574
575 hdr(Connection) -i close
576
577hdr_beg <string>
578hdr_beg(header) <string>
579 Returns true when one of the headers begins with one of the strings. See
580 "hdr" for more information on header matching.
581
582hdr_end <string>
583hdr_end(header) <string>
584 Returns true when one of the headers ends with one of the strings. See "hdr"
585 for more information on header matching.
586
587hdr_sub <string>
588hdr_sub(header) <string>
589 Returns true when one of the headers contains one of the strings. See "hdr"
590 for more information on header matching.
591
592hdr_dir <string>
593hdr_dir(header) <string>
594 Returns true when one of the headers contains one of the strings either
595 isolated or delimited by slashes. This is used to perform filename or
596 directory name matching, and may be used with Referer. See "hdr" for more
597 information on header matching.
598
599hdr_dom <string>
600hdr_dom(header) <string>
601 Returns true when one of the headers contains one of the strings either
602 isolated or delimited by dots. This is used to perform domain name matching,
603 and may be used with the Host header. See "hdr" for more information on
604 header matching.
605
606hdr_reg <regex>
607hdr_reg(header) <regex>
608 Returns true when one of the headers matches of the regular expressions. It
609 can be used at any time, but it is important to remember that regex matching
610 is slower than other methods. See also other "hdr_" criteria, as well as
611 "hdr" for more information on header matching.
612
613hdr_val <integer>
614hdr_val(header) <integer>
615 Returns true when one of the headers starts with a number which matches the
616 values or ranges specified. This may be used to limit content-length to
617 acceptable values for example. See "hdr" for more information on header
618 matching.
619
620hdr_cnt <integer>
621hdr_cnt(header) <integer>
622 Returns true when the count of the headers which matches the values or ranges
623 specified. This is used to detect presence or absence of a specific header,
624 as well as to block request smugling attacks by rejecting requests which
625 contain more than one of certain headers. See "hdr" for more information on
626 header matching.
627
Willy Tarreauc7246fc2007-12-02 17:31:20 +0100628nbsrv <integer>
629nbsrv(backend) <integer>
630 Returns true when the number of usable servers of either the current backend
631 or the named backend matches the values or ranges specified. This is used to
632 switch to an alternate backend when the number of servers is too low to
633 to handle some load. It is useful to report a failure when combined with
634 "monitor fail".
Willy Tarreau6a06a402007-07-15 20:15:28 +0200635
6362.1.6) Pre-defined ACLs
637-----------------------
638
639Some predefined ACLs are hard-coded so that they do not have to be declared in
640every frontend which needs them. They all have their names in upper case in
641order to avoid confusion. Their equivalence is provided below :
642
643ACL name Equivalent to Usage
644---------------+-----------------------------+---------------------------------
645TRUE always_true 1 always match
646FALSE always_false 0 never match
647LOCALHOST src 127.0.0.1/8 match connection from local host
648HTTP_1.0 req_ver 1.0 match HTTP version 1.0
649HTTP_1.1 req_ver 1.1 match HTTP version 1.1
650METH_CONNECT method CONNECT match HTTP CONNECT method
651METH_GET method GET HEAD match HTTP GET or HEAD method
652METH_HEAD method HEAD match HTTP HEAD method
653METH_OPTIONS method OPTIONS match HTTP OPTIONS method
654METH_POST method POST match HTTP POST method
655METH_TRACE method TRACE match HTTP TRACE method
656HTTP_URL_ABS url_reg ^[^/:]*:// match absolute URL with scheme
657HTTP_URL_SLASH url_beg / match URL begining with "/"
658HTTP_URL_STAR url * match URL equal to "*"
659HTTP_CONTENT hdr_val(content-length) gt 0 match an existing content-length
660---------------+-----------------------------+---------------------------------
661
662
6632.1.7) Using ACLs to form conditions
664------------------------------------
665
666Some actions are only performed upon a valid condition. A condition is a
667combination of ACLs with operators. 3 operators are supported :
668
669 - AND (implicit)
670 - OR (explicit with the "or" keyword or the "||" operator)
671 - Negation with the exclamation mark ("!")
672
673A condition is formed as a disjonctive form :
674
675 [!]acl1 [!]acl2 ... [!]acln { or [!]acl1 [!]acl2 ... [!]acln } ...
676
677Such conditions are generally used after an "if" or "unless" statement,
678indicating when the condition will trigger the action.
679
680For instance, to block HTTP requests to the "*" URL with methods other than
681"OPTIONS", as well as POST requests without content-length, and GET/HEAD
682requests with a content-length greater than 0, and finally every request
683which is not either GET/HEAD/POST/OPTIONS !
684
685 acl missing_cl hdr_cnt(Content-length) eq 0
686 block if HTTP_URL_STAR !METH_OPTIONS || METH_POST missing_cl
687 block if METH_GET HTTP_CONTENT
688 block unless METH_GET or METH_POST or METH_OPTIONS
689
690To select a different backend for requests to static contents on the "www" site
691and to every request on the "img", "video", "download" and "ftp" hosts :
692
693 acl url_static path_beg /static /images /img /css
694 acl url_static path_end .gif .png .jpg .css .js
695 acl host_www hdr_beg(host) -i www
696 acl host_static hdr_beg(host) -i img. video. download. ftp.
697
698 # now use backend "static" for all static-only hosts, and for static urls
699 # of host "www". Use backend "www" for the rest.
700 use_backend static if host_static or host_www url_static
701 use_backend www if host_www
702
703See below for the detailed help on the "block" and "use_backend" keywords.
Willy Tarreaudbc36f62007-11-30 12:29:11 +0100704
705
Willy Tarreauc7246fc2007-12-02 17:31:20 +01007062.2) Instance-specific keywords and statements
707----------------------------------------------
708
709monitor fail [if | unless] <condition>
710 [ supported in: frontend, listen ]
711
712 This statement adds a condition which can force the response to a monitor
713 request to report a failure. By default, when an external component queries
714 the URI dedicated to monitoring, a 200 response is returned. When one of the
715 conditions above is met, haproxy will return 503 instead of 200. This is
716 very useful to report a site failure to an external component which may base
717 routing advertisements between multiple sites on the availability reported by
718 haproxy. In this case, one would rely on an ACL involving the "nbsrv"
719 criterion.
720
721 Example:
722
723 frontend www
724 acl site_dead nbsrv(dynamic) lt 2
725 acl site_dead nbsrv(static) lt 2
726 monitor-uri /site_alive
727 monitor fail if site_dead
728
729
7302.3) Options
Willy Tarreaudbc36f62007-11-30 12:29:11 +0100731------------
732
733A handful of options affect the way the load balancing is performed or reaction
734to state changes.
735
736http-check disable-on-404
737 When this option is set, a server which returns an HTTP code 404 will be
738 excluded from further load-balancing, but will still receive persistent
739 connections. This provides a very convenient method for Web administrators
740 to perform a graceful shutdown of their servers. It is also important to note
741 that a server which is detected as failed while it was in this mode will not
742 generate an alert, just a notice. If the server responds 2xx or 3xx again, it
743 will immediately be reinserted into the farm. The status on the stats page
744 reports "NOLB" for a server in this mode. It is important to note that this
745 option only works in conjunction with the "httpchk" option.
746
747option contstats
748 By default, counters used for statistics calculation are incremented
749 only when a session finishes. It works quite well when serving small
750 objects, but with big ones (for example large images or archives) or
751 with A/V streaming, a graph generated from haproxy counters looks like
752 a hedgehog. With this option enabled counters get incremented continuously,
753 during a whole session. Recounting touches a hotpath directly so
754 it is not enabled by default, as it has small performance impact (~0.5%).
755
756
Willy Tarreauc7246fc2007-12-02 17:31:20 +01007572.4) Server options
Willy Tarreau5764b382007-11-30 17:46:49 +0100758-------------------
759
760slowstart <start_time_in_ms>
761 The 'slowstart' parameter for a server accepts a value in milliseconds which
762 indicates after how long a server which has just come back up will run at
Willy Tarreaubefdff12007-12-02 22:27:38 +0100763 full speed. Just as with every other time-based parameter, it can be entered
764 in any other explicit unit among { us, ms, s, m, h, d }. The speed grows
765 linearly from 0 to 100% during this time. The limitation applies to two
766 parameters :
Willy Tarreau5764b382007-11-30 17:46:49 +0100767
768 - maxconn: the number of connections accepted by the server will grow from 1
769 to 100% of the usual dynamic limit defined by (minconn,maxconn,fullconn).
770
771 - weight: when the backend uses a dynamic weighted algorithm, the weight
772 grows linearly from 1 to 100%. In this case, the weight is updated at every
773 health-check. For this reason, it is important that the 'inter' parameter
774 is smaller than the 'slowstart', in order to maximize the number of steps.
775
776 The slowstart never applies when haproxy starts, otherwise it would cause
777 trouble to running servers. It only applies when a server has been previously
778 seen as failed.
779
780