Willy Tarreau | 6a06a40 | 2007-07-15 20:15:28 +0200 | [diff] [blame] | 1 | ---------------------- |
| 2 | HAProxy |
| 3 | Configuration Manual |
| 4 | ---------------------- |
Krzysztof Oledzki | d9db927 | 2007-10-15 10:05:11 +0200 | [diff] [blame] | 5 | version 1.3.13 |
Willy Tarreau | 6a06a40 | 2007-07-15 20:15:28 +0200 | [diff] [blame] | 6 | willy tarreau |
Willy Tarreau | fbee713 | 2007-10-18 13:53:22 +0200 | [diff] [blame] | 7 | 2007/10/18 |
Willy Tarreau | 6a06a40 | 2007-07-15 20:15:28 +0200 | [diff] [blame] | 8 | |
| 9 | |
| 10 | This document covers the configuration language as implemented in the version |
| 11 | specified above. It does not provide any hint, example or advice. For such |
| 12 | docuemntation, please refer to the Reference Manual or the Architecture Manual. |
| 13 | |
| 14 | |
| 15 | HAProxy'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 | |
| 22 | 1. Global parameters |
| 23 | -------------------- |
| 24 | |
| 25 | Parameters in the "global" section are process-wide and often OS-specific. They |
| 26 | are generally set once for all and do not need being changed once correct. Some |
| 27 | of them have command-line equivalents. |
| 28 | |
| 29 | The 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 Tarreau | fbee713 | 2007-10-18 13:53:22 +0200 | [diff] [blame] | 42 | - stats |
Willy Tarreau | 6a06a40 | 2007-07-15 20:15:28 +0200 | [diff] [blame] | 43 | |
| 44 | * Performance tuning |
| 45 | - maxconn |
| 46 | - noepoll |
| 47 | - nokqueue |
| 48 | - nopoll |
| 49 | - nosepoll |
| 50 | - tune.maxpollevents |
Willy Tarreau | fe255b7 | 2007-10-14 23:09:26 +0200 | [diff] [blame] | 51 | - spread-checks |
Willy Tarreau | 6a06a40 | 2007-07-15 20:15:28 +0200 | [diff] [blame] | 52 | |
| 53 | * Debugging |
| 54 | - debug |
| 55 | - quiet |
Willy Tarreau | 6a06a40 | 2007-07-15 20:15:28 +0200 | [diff] [blame] | 56 | |
| 57 | |
| 58 | 1.1) Process management and security |
| 59 | ------------------------------------ |
| 60 | |
| 61 | chroot <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 | |
| 69 | daemon |
| 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 | |
| 74 | gid <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 | |
| 80 | group <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 | |
| 84 | log <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 |
| 87 | configured with "log global". <address> is an IPv4 address optionally |
| 88 | followed by a colon and an UDP port. If no port is specified, 514 is used |
| 89 | by default (the standard syslog port). <facility> must be one of the 24 |
| 90 | standard syslog facilities : |
| 91 | |
| 92 | kern user mail daemon auth syslog lpr news |
| 93 | uucp cron auth2 ftp ntp audit alert cron2 |
| 94 | local0 local1 local2 local3 local4 local5 local6 local7 |
| 95 | |
| 96 | An optional level can be specified to filter outgoing messages. By default, |
| 97 | all messages are sent. If a level is specified, only messages with a severity |
| 98 | at least as important as this level will be sent. 8 levels are known : |
| 99 | |
| 100 | emerg alert crit err warning notice info debug |
| 101 | |
| 102 | nbproc <number> |
| 103 | Creates <number> processes when going daemon. This requires the "daemon" |
| 104 | mode. By default, only one process is created, which is the recommended mode |
| 105 | of operation. For systems limited to small sets of file descriptors per |
| 106 | process, it may be needed to fork multiple daemons. USING MULTIPLE PROCESSES |
| 107 | IS HARDER TO DEBUG AND IS REALLY DISCOURAGED. See also "daemon". |
| 108 | |
| 109 | pidfile <pidfile> |
| 110 | Writes pids of all daemons into file <pidfile>. This option is equivalent to |
| 111 | the "-p" command line argument. The file must be accessible to the user |
| 112 | starting the process. See also "daemon". |
| 113 | |
Willy Tarreau | fbee713 | 2007-10-18 13:53:22 +0200 | [diff] [blame] | 114 | stats socket <path> [{uid | user} <uid>] [{gid | group} <gid>] [mode <mode>] |
| 115 | Creates a UNIX socket in stream mode at location <path>. Any previously |
| 116 | existing socket will be backed up then replaced. Connections to this socket |
| 117 | will get a CSV-formated output of the process statistics in response to the |
| 118 | "show stat" command followed by a line feed. On platforms which support it, |
| 119 | it is possible to restrict access to this socket by specifying numerical IDs |
| 120 | after "uid" and "gid", or valid user and group names after the "user" and |
| 121 | "group" keywords. It is also possible to restrict permissions on the socket |
| 122 | by passing an octal value after the "mode" keyword (same syntax as chmod). |
| 123 | Depending on the platform, the permissions on the socket will be inherited |
| 124 | from the directory which hosts it, or from the user the process is started |
| 125 | with. |
| 126 | |
| 127 | stats timeout <timeout, in milliseconds> |
| 128 | The default timeout on the stats socket is set to 10 seconds. It is possible |
| 129 | to change this value with "stats timeout". The value must be passed in |
| 130 | milliseconds. |
| 131 | |
| 132 | stats maxconn <connections> |
| 133 | By default, the stats socket is limited to 10 concurrent connections. It is |
| 134 | possible to change this value with "stats maxconn". |
| 135 | |
Willy Tarreau | 6a06a40 | 2007-07-15 20:15:28 +0200 | [diff] [blame] | 136 | uid <number> |
| 137 | Changes the process' user ID to <number>. It is recommended that the user ID |
| 138 | is dedicated to HAProxy or to a small set of similar daemons. HAProxy must |
| 139 | be started with superuser privileges in order to be able to switch to another |
| 140 | one. See also "gid" and "user". |
| 141 | |
| 142 | ulimit-n <number> |
| 143 | Sets the maximum number of per-process file-descriptors to <number>. By |
| 144 | default, it is automatically computed, so it is recommended not to use this |
| 145 | option. |
| 146 | |
| 147 | user <user name> |
| 148 | Similar to "uid" but uses the UID of user name <user name> from /etc/passwd. |
| 149 | See also "uid" and "group". |
| 150 | |
| 151 | |
| 152 | 1.2) Performance tuning |
| 153 | ----------------------- |
| 154 | |
| 155 | maxconn <number> |
| 156 | Sets the maximum per-process number of concurrent connections to <number>. It |
| 157 | is equivalent to the command-line argument "-n". Proxies will stop accepting |
| 158 | connections when this limit is reached. The "ulimit-n" parameter is |
| 159 | automatically adjusted according to this value. See also "ulimit-n". |
| 160 | |
| 161 | noepoll |
| 162 | Disables the use of the "epoll" event polling system on Linux. It is |
| 163 | equivalent to the command-line argument "-de". The next polling system |
| 164 | used will generally be "poll". See also "nosepoll", and "nopoll". |
| 165 | |
| 166 | nokqueue |
| 167 | Disables the use of the "kqueue" event polling system on BSD. It is |
| 168 | equivalent to the command-line argument "-dk". The next polling system |
| 169 | used will generally be "poll". See also "nopoll". |
| 170 | |
| 171 | nopoll |
| 172 | Disables the use of the "poll" event polling system. It is equivalent to the |
| 173 | command-line argument "-dp". The next polling system used will be "select". |
| 174 | It should never be needed to didsable "poll" since it's available on all |
| 175 | platforms supported by HAProxy. See also "nosepoll", and "nopoll" and |
| 176 | "nokqueue". |
| 177 | |
| 178 | nosepoll |
| 179 | Disables the use of the "speculative epoll" event polling system on Linux. It |
| 180 | is equivalent to the command-line argument "-ds". The next polling system |
| 181 | used will generally be "epoll". See also "nosepoll", and "nopoll". |
| 182 | |
| 183 | tune.maxpollevents <number> |
| 184 | Sets the maximum amount of events that can be processed at once in a call to |
| 185 | the polling system. The default value is adapted to the operating system. It |
| 186 | has been noticed that reducing it below 200 tends to slightly decrease |
| 187 | latency at the expense of network bandwidth, and increasing it above 200 |
| 188 | tends to trade latency for slightly increased bandwidth. |
| 189 | |
Willy Tarreau | fe255b7 | 2007-10-14 23:09:26 +0200 | [diff] [blame] | 190 | spread-checks <0..50, in percent> |
| 191 | Sometimes it is desirable to avoid sending health checks to servers at exact |
| 192 | intervals, for instance when many logical servers are located on the same |
| 193 | physical server. With the help of this parameter, it becomes possible to add |
| 194 | some randomness in the check interval between 0 and +/- 50%. A value between |
| 195 | 2 and 5 seems to show good results. The default value remains at 0. |
| 196 | |
Willy Tarreau | 6a06a40 | 2007-07-15 20:15:28 +0200 | [diff] [blame] | 197 | |
| 198 | 1.3) Debugging |
| 199 | --------------- |
| 200 | |
| 201 | debug |
| 202 | Enables debug mode which dumps to stdout all exchanges, and disables forking |
| 203 | into background. It is the equivalent of the command-line argument "-d". It |
| 204 | should never be used in a production configuration since it may prevent full |
| 205 | system startup. |
| 206 | |
| 207 | quiet |
| 208 | Do not display any message during startup. It is equivalent to the command- |
| 209 | line argument "-q". |
| 210 | |
Willy Tarreau | 6a06a40 | 2007-07-15 20:15:28 +0200 | [diff] [blame] | 211 | |
| 212 | 2) Proxies |
| 213 | ---------- |
| 214 | Proxy configuration can be located in a set of sections : |
| 215 | - defaults <name> |
| 216 | - frontend <name> |
| 217 | - backend <name> |
| 218 | - listen <name> |
| 219 | |
| 220 | A "defaults" section sets default parameters for all other sections following |
| 221 | its declaration. Those default parameters are reset by the next "defaults" |
| 222 | section. See below for the list of parameters which can be set in a "defaults" |
| 223 | section. |
| 224 | |
| 225 | A "frontend" section describes a set of listening sockets accepting client |
| 226 | connections. |
| 227 | |
| 228 | A "backend" section describes a set of servers to which the proxy will connect |
| 229 | to forward incoming connections. |
| 230 | |
| 231 | A "listen" section defines a complete proxy with its frontend and backend |
| 232 | parts combined in one section. It is generally useful for TCP-only traffic. |
| 233 | |
| 234 | The following list of keywords is supported. Most of them may only be used in a |
| 235 | limited set of section types. |
| 236 | |
| 237 | keyword defaults frontend listen backend |
| 238 | ----------------------+----------+----------+---------+--------- |
| 239 | acl - X X X |
| 240 | appsession - - X X |
| 241 | balance - - X X |
| 242 | bind - X X - |
| 243 | block - X X X |
| 244 | capture cookie X X X X |
| 245 | capture request header X X X X |
| 246 | capture response header X X X X |
| 247 | clitimeout X X X - |
| 248 | contimeout X X X X |
| 249 | cookie X - X X |
| 250 | default_backend - X X - |
| 251 | disabled - X X X |
| 252 | dispatch - - X X |
| 253 | enabled - X X X |
| 254 | errorfile X X X X |
| 255 | errorloc X X X X |
| 256 | errorloc302 X X X X |
| 257 | errorloc303 X X X X |
| 258 | fullconn X - X X |
| 259 | grace - X X X |
| 260 | log X X X X |
| 261 | maxconn X X X - |
| 262 | mode X X X X |
| 263 | monitor-net X X X - |
| 264 | monitor-uri X X X - |
| 265 | option abortonclose X - X X |
| 266 | option allbackups X - X X |
| 267 | option checkcache X - X X |
| 268 | option clitcpka X X X - |
| 269 | option dontlognull X X X - |
| 270 | option forceclose X - X X |
| 271 | option forwardfor X X X X |
| 272 | option httpchk X - X X |
| 273 | option httpclose X X X X |
| 274 | option httplog X X X X |
| 275 | option logasap X X X - |
Alexandre Cassen | 87ea548 | 2007-10-11 20:48:58 +0200 | [diff] [blame] | 276 | option nolinger X X X X |
Willy Tarreau | 6a06a40 | 2007-07-15 20:15:28 +0200 | [diff] [blame] | 277 | option persist X - X X |
| 278 | option redispatch X - X X |
| 279 | option smtpchk X - X X |
| 280 | option srvtcpka X - X X |
| 281 | option ssl-hello-chk X - X X |
| 282 | option tcpka X X X X |
| 283 | option tcplog X X X X |
| 284 | option tcpsplice X X X X |
| 285 | option transparent X X X - |
| 286 | redisp X - X X |
| 287 | redispatch X - X X |
| 288 | reqadd - X X X |
| 289 | reqallow - X X X |
| 290 | reqdel - X X X |
| 291 | reqdeny - X X X |
| 292 | reqiallow - X X X |
| 293 | reqidel - X X X |
| 294 | reqideny - X X X |
| 295 | reqipass - X X X |
| 296 | reqirep - X X X |
| 297 | reqisetbe - X X X |
| 298 | reqitarpit - X X X |
| 299 | reqpass - X X X |
| 300 | reqrep - X X X |
| 301 | reqsetbe - X X X |
| 302 | reqtarpit - X X X |
| 303 | retries X - X X |
| 304 | rspadd - X X X |
| 305 | rspdel - X X X |
| 306 | rspdeny - X X X |
| 307 | rspidel - X X X |
| 308 | rspideny - X X X |
| 309 | rspirep - X X X |
| 310 | rsprep - X X X |
| 311 | server - - X X |
| 312 | source X - X X |
| 313 | srvtimeout X - X X |
Willy Tarreau | 24e779b | 2007-07-24 23:43:37 +0200 | [diff] [blame] | 314 | stats auth X - X X |
| 315 | stats enable X - X X |
| 316 | stats realm X - X X |
Willy Tarreau | bbd4212 | 2007-07-25 07:26:38 +0200 | [diff] [blame] | 317 | stats refresh X - X X |
Willy Tarreau | 24e779b | 2007-07-24 23:43:37 +0200 | [diff] [blame] | 318 | stats scope X - X X |
| 319 | stats uri X - X X |
Krzysztof Oledzki | d9db927 | 2007-10-15 10:05:11 +0200 | [diff] [blame] | 320 | stats hide-version X - X X |
Willy Tarreau | 6a06a40 | 2007-07-15 20:15:28 +0200 | [diff] [blame] | 321 | transparent X X X - |
| 322 | use_backend - X X - |
| 323 | usesrc X - X X |
| 324 | ----------------------+----------+----------+---------+--------- |
| 325 | keyword defaults frontend listen backend |
| 326 | |
| 327 | |
| 328 | 2.1) using ACLs |
| 329 | --------------- |
| 330 | |
| 331 | The use of Access Control Lists (ACL) provides a flexible solution to perform |
| 332 | content switching. The principle is simple : |
| 333 | |
| 334 | - define test criteria with sets of values |
| 335 | - perform actions only if a set of tests is valid |
| 336 | |
| 337 | The actions generally consist in blocking the request, or selecting a backend. |
| 338 | |
| 339 | In order to define a test, the "acl" keyword is used. The syntax is : |
| 340 | |
| 341 | acl <aclname> <criterion> [flags] [operator] <value> ... |
| 342 | |
| 343 | This creates an ACL <aclname> or completes an existing one with new |
| 344 | tests. Those tests apply to the portion of request specified in <criterion> |
| 345 | and may be adjusted with optional flags [flags]. Some criteria also support |
| 346 | an operator which may be specified before the set of values. The values are |
| 347 | of the type supported by the criterion, and are separated by spaces. |
| 348 | |
| 349 | There is no limit to the number of ACLs. The unused ones do not affect |
| 350 | performance, they just consume a small amount of memory. |
| 351 | |
| 352 | The current flags are currently supported : |
| 353 | |
| 354 | -i : ignore case during matching. |
| 355 | -- : force end of flags. Useful when a string looks like one of the flags. |
| 356 | |
| 357 | Supported types of values are : |
| 358 | - integers or integer ranges |
| 359 | - strings |
| 360 | - regular expressions |
| 361 | - IP addresses and networks |
| 362 | |
| 363 | |
| 364 | 2.1.1) Matching integers |
| 365 | ------------------------ |
| 366 | |
| 367 | Matching integers is special in that ranges and operators are permitted. Note |
| 368 | that integer matching only applies to positive values. A range is a value |
| 369 | expressed with a lower and an upper bound separated with a colon, both of which |
| 370 | may be omitted. |
| 371 | |
| 372 | For instance, "1024:65535" is a valid range to represent a range of |
| 373 | unprivileged ports, and "1024:" would also work. "0:1023" is a valid |
| 374 | representation of privileged ports, and ":1023" would also work. |
| 375 | |
| 376 | For an easier usage, comparison operators are also supported. Note that using |
| 377 | operators with ranges does not make much sense and is discouraged. Also, it |
| 378 | does not make much sense to perform order comparisons with a set of values. |
| 379 | |
| 380 | Available operators are : |
| 381 | |
| 382 | eq : true if the tested value equals at least one value |
| 383 | ge : true if the tested value is greater than or equal to at least one value |
| 384 | gt : true if the tested value is greater than at least one value |
| 385 | le : true if the tested value is less than or equal to at least one value |
| 386 | lt : true if the tested value is less than at least one value |
| 387 | |
| 388 | For instance, the following ACL matches negative Content-Length headers : |
| 389 | |
| 390 | acl negative-length hdr_val(content-length) lt 0 |
| 391 | |
| 392 | |
| 393 | 2.1.2) Matching strings |
| 394 | ----------------------- |
| 395 | |
| 396 | String matching applies to verbatim strings as they are passed, with the |
| 397 | exception of the backslash ("\") which makes it possible to escape some |
| 398 | characters such as the space. If the "-i" flag is passed before the first |
| 399 | string, then the matching will be performed ignoring the case. In order |
| 400 | to match the string "-i", either set it second, or pass the "--" flag |
| 401 | before the first string. |
| 402 | |
| 403 | |
| 404 | 2.1.3) Matching regular expressions (regexes) |
| 405 | --------------------------------------------- |
| 406 | |
| 407 | Just like with string matching, regex matching applies to verbatim strings as |
| 408 | they are passed, with the exception of the backslash ("\") which makes it |
| 409 | possible to escape some characters such as the space. If the "-i" flag is |
| 410 | passed before the first regex, then the matching will be performed ignoring |
| 411 | the case. In order to match the string "-i", either set it second, or pass |
| 412 | the "--" flag before the first string. |
| 413 | |
| 414 | |
| 415 | 2.1.4) Matching IPv4 addresses |
| 416 | ---------------------------- |
| 417 | |
| 418 | IPv4 addresses values can be specified either as plain addresses or with a |
| 419 | netmask appended, in which case the IPv4 address matches whenever it is |
| 420 | within the network. Plain addresses may also be replaced with a resolvable |
| 421 | host name, but this practise is generally discouraged as it makes it more |
| 422 | difficult to read configurations. |
| 423 | |
| 424 | |
| 425 | 2.1.5) Available matching criteria |
| 426 | ---------------------------------- |
| 427 | |
| 428 | always_false |
| 429 | This one never matches. All values and flags are ignored. It may be used as |
| 430 | a temporary replacement for another one when adjusting configurations. |
| 431 | |
| 432 | always_true |
| 433 | This one always matches. All values and flags are ignored. It may be used as |
| 434 | a temporary replacement for another one when adjusting configurations. |
| 435 | |
| 436 | src <ip_address> |
| 437 | Applies to the client's IP address. It is usually used to limit access to |
| 438 | certain resources such as statistics. Note that it is the TCP-level source |
| 439 | address which is used, and not the address of a client behind a proxy. |
| 440 | |
| 441 | src_port <integer> |
| 442 | Applies to the client's TCP source port. This has a very limited usage. |
| 443 | |
| 444 | dst <ip_address> |
| 445 | Applies to the local IP address the client connected to. It can be used to |
| 446 | switch to a different backend for some alternative addresses. |
| 447 | |
| 448 | dst_port <integer> |
| 449 | Applies to the local port the client connected to. It can be used to switch |
| 450 | to a different backend for some alternative ports. |
| 451 | |
| 452 | dst_conn <integer> |
| 453 | Applies to the number of currently established connections on the frontend, |
| 454 | including the one being evaluated. It can be used to either return a sorry |
| 455 | page before hard-blocking, or to use a specific backend to drain the requests |
| 456 | when the farm is considered saturated. |
| 457 | |
| 458 | method <string> |
| 459 | Applies to the method in the HTTP request, eg: "GET". Some predefined ACL |
| 460 | already check for most common methods. |
| 461 | |
| 462 | req_ver <string> |
| 463 | Applies to the version string in the HTTP request, eg: "1.0". Some predefined |
| 464 | ACL already check for versions 1.0 and 1.1. |
| 465 | |
| 466 | path <string> |
| 467 | Returns true when the path part of the request, which starts at the first |
| 468 | slash and ends before the question mark, equals one of the strings. It may be |
| 469 | used to match known files, such as /favicon.ico. |
| 470 | |
| 471 | path_beg <string> |
| 472 | Returns true when the path begins with one of the strings. This can be used to |
| 473 | send certain directory names to alternative backends. |
| 474 | |
| 475 | path_end <string> |
| 476 | Returns true when the path ends with one of the strings. This may be used to |
| 477 | control file name extension. |
| 478 | |
| 479 | path_sub <string> |
| 480 | Returns true when the path contains one of the strings. It can be used to |
| 481 | detect particular patterns in paths, such as "../" for example. See also |
| 482 | "path_dir". |
| 483 | |
| 484 | path_dir <string> |
| 485 | Returns true when one of the strings is found isolated or delimited with |
| 486 | slashes in the path. This is used to perform filename or directory name |
| 487 | matching without the risk of wrong match due to colliding prefixes. See also |
| 488 | "url_dir" and "path_sub". |
| 489 | |
| 490 | path_dom <string> |
| 491 | Returns true when one of the strings is found isolated or delimited with dots |
| 492 | in the path. This may be used to perform domain name matching in proxy |
| 493 | requests. See also "path_sub" and "url_dom". |
| 494 | |
| 495 | path_reg <regex> |
| 496 | Returns true when the path matches one of the regular expressions. It can be |
| 497 | used any time, but it is important to remember that regex matching is slower |
| 498 | than other methods. See also "url_reg" and all "path_" criteria. |
| 499 | |
| 500 | url <string> |
| 501 | Applies to the whole URL passed in the request. The only real use is to match |
| 502 | "*", for which there already is a predefined ACL. |
| 503 | |
| 504 | url_beg <string> |
| 505 | Returns true when the URL begins with one of the strings. This can be used to |
| 506 | check whether a URL begins with a slash or with a protocol scheme. |
| 507 | |
| 508 | url_end <string> |
| 509 | Returns true when the URL ends with one of the strings. It has very limited |
| 510 | use. "path_end" should be used instead for filename matching. |
| 511 | |
| 512 | url_sub <string> |
| 513 | Returns true when the URL contains one of the strings. It can be used to |
| 514 | detect particular patterns in query strings for example. See also "path_sub". |
| 515 | |
| 516 | url_dir <string> |
| 517 | Returns true when one of the strings is found isolated or delimited with |
| 518 | slashes in the URL. This is used to perform filename or directory name |
| 519 | matching without the risk of wrong match due to colliding prefixes. See also |
| 520 | "path_dir" and "url_sub". |
| 521 | |
| 522 | url_dom <string> |
| 523 | Returns true when one of the strings is found isolated or delimited with dots |
| 524 | in the URL. This is used to perform domain name matching without the risk of |
| 525 | wrong match due to colliding prefixes. See also "url_sub". |
| 526 | |
| 527 | url_reg <regex> |
| 528 | Returns true when the URL matches one of the regular expressions. It can be |
| 529 | used any time, but it is important to remember that regex matching is slower |
| 530 | than other methods. See also "path_reg" and all "url_" criteria. |
| 531 | |
| 532 | hdr <string> |
| 533 | hdr(header) <string> |
| 534 | Note: all the "hdr*" matching criteria either apply to all headers, or to a |
| 535 | particular header whose name is passed between parenthesis and without any |
| 536 | space. The header matching complies with RFC2616, and treats as separate |
| 537 | headers all values delimited by comas. |
| 538 | |
| 539 | The "hdr" criteria returns true if any of the headers matching the criteria |
| 540 | match any of the strings. This can be used to check exact values. For |
| 541 | instance, checking that "connection: close" is set : |
| 542 | |
| 543 | hdr(Connection) -i close |
| 544 | |
| 545 | hdr_beg <string> |
| 546 | hdr_beg(header) <string> |
| 547 | Returns true when one of the headers begins with one of the strings. See |
| 548 | "hdr" for more information on header matching. |
| 549 | |
| 550 | hdr_end <string> |
| 551 | hdr_end(header) <string> |
| 552 | Returns true when one of the headers ends with one of the strings. See "hdr" |
| 553 | for more information on header matching. |
| 554 | |
| 555 | hdr_sub <string> |
| 556 | hdr_sub(header) <string> |
| 557 | Returns true when one of the headers contains one of the strings. See "hdr" |
| 558 | for more information on header matching. |
| 559 | |
| 560 | hdr_dir <string> |
| 561 | hdr_dir(header) <string> |
| 562 | Returns true when one of the headers contains one of the strings either |
| 563 | isolated or delimited by slashes. This is used to perform filename or |
| 564 | directory name matching, and may be used with Referer. See "hdr" for more |
| 565 | information on header matching. |
| 566 | |
| 567 | hdr_dom <string> |
| 568 | hdr_dom(header) <string> |
| 569 | Returns true when one of the headers contains one of the strings either |
| 570 | isolated or delimited by dots. This is used to perform domain name matching, |
| 571 | and may be used with the Host header. See "hdr" for more information on |
| 572 | header matching. |
| 573 | |
| 574 | hdr_reg <regex> |
| 575 | hdr_reg(header) <regex> |
| 576 | Returns true when one of the headers matches of the regular expressions. It |
| 577 | can be used at any time, but it is important to remember that regex matching |
| 578 | is slower than other methods. See also other "hdr_" criteria, as well as |
| 579 | "hdr" for more information on header matching. |
| 580 | |
| 581 | hdr_val <integer> |
| 582 | hdr_val(header) <integer> |
| 583 | Returns true when one of the headers starts with a number which matches the |
| 584 | values or ranges specified. This may be used to limit content-length to |
| 585 | acceptable values for example. See "hdr" for more information on header |
| 586 | matching. |
| 587 | |
| 588 | hdr_cnt <integer> |
| 589 | hdr_cnt(header) <integer> |
| 590 | Returns true when the count of the headers which matches the values or ranges |
| 591 | specified. This is used to detect presence or absence of a specific header, |
| 592 | as well as to block request smugling attacks by rejecting requests which |
| 593 | contain more than one of certain headers. See "hdr" for more information on |
| 594 | header matching. |
| 595 | |
| 596 | |
| 597 | 2.1.6) Pre-defined ACLs |
| 598 | ----------------------- |
| 599 | |
| 600 | Some predefined ACLs are hard-coded so that they do not have to be declared in |
| 601 | every frontend which needs them. They all have their names in upper case in |
| 602 | order to avoid confusion. Their equivalence is provided below : |
| 603 | |
| 604 | ACL name Equivalent to Usage |
| 605 | ---------------+-----------------------------+--------------------------------- |
| 606 | TRUE always_true 1 always match |
| 607 | FALSE always_false 0 never match |
| 608 | LOCALHOST src 127.0.0.1/8 match connection from local host |
| 609 | HTTP_1.0 req_ver 1.0 match HTTP version 1.0 |
| 610 | HTTP_1.1 req_ver 1.1 match HTTP version 1.1 |
| 611 | METH_CONNECT method CONNECT match HTTP CONNECT method |
| 612 | METH_GET method GET HEAD match HTTP GET or HEAD method |
| 613 | METH_HEAD method HEAD match HTTP HEAD method |
| 614 | METH_OPTIONS method OPTIONS match HTTP OPTIONS method |
| 615 | METH_POST method POST match HTTP POST method |
| 616 | METH_TRACE method TRACE match HTTP TRACE method |
| 617 | HTTP_URL_ABS url_reg ^[^/:]*:// match absolute URL with scheme |
| 618 | HTTP_URL_SLASH url_beg / match URL begining with "/" |
| 619 | HTTP_URL_STAR url * match URL equal to "*" |
| 620 | HTTP_CONTENT hdr_val(content-length) gt 0 match an existing content-length |
| 621 | ---------------+-----------------------------+--------------------------------- |
| 622 | |
| 623 | |
| 624 | 2.1.7) Using ACLs to form conditions |
| 625 | ------------------------------------ |
| 626 | |
| 627 | Some actions are only performed upon a valid condition. A condition is a |
| 628 | combination of ACLs with operators. 3 operators are supported : |
| 629 | |
| 630 | - AND (implicit) |
| 631 | - OR (explicit with the "or" keyword or the "||" operator) |
| 632 | - Negation with the exclamation mark ("!") |
| 633 | |
| 634 | A condition is formed as a disjonctive form : |
| 635 | |
| 636 | [!]acl1 [!]acl2 ... [!]acln { or [!]acl1 [!]acl2 ... [!]acln } ... |
| 637 | |
| 638 | Such conditions are generally used after an "if" or "unless" statement, |
| 639 | indicating when the condition will trigger the action. |
| 640 | |
| 641 | For instance, to block HTTP requests to the "*" URL with methods other than |
| 642 | "OPTIONS", as well as POST requests without content-length, and GET/HEAD |
| 643 | requests with a content-length greater than 0, and finally every request |
| 644 | which is not either GET/HEAD/POST/OPTIONS ! |
| 645 | |
| 646 | acl missing_cl hdr_cnt(Content-length) eq 0 |
| 647 | block if HTTP_URL_STAR !METH_OPTIONS || METH_POST missing_cl |
| 648 | block if METH_GET HTTP_CONTENT |
| 649 | block unless METH_GET or METH_POST or METH_OPTIONS |
| 650 | |
| 651 | To select a different backend for requests to static contents on the "www" site |
| 652 | and to every request on the "img", "video", "download" and "ftp" hosts : |
| 653 | |
| 654 | acl url_static path_beg /static /images /img /css |
| 655 | acl url_static path_end .gif .png .jpg .css .js |
| 656 | acl host_www hdr_beg(host) -i www |
| 657 | acl host_static hdr_beg(host) -i img. video. download. ftp. |
| 658 | |
| 659 | # now use backend "static" for all static-only hosts, and for static urls |
| 660 | # of host "www". Use backend "www" for the rest. |
| 661 | use_backend static if host_static or host_www url_static |
| 662 | use_backend www if host_www |
| 663 | |
| 664 | See below for the detailed help on the "block" and "use_backend" keywords. |