Willy Tarreau | 6a06a40 | 2007-07-15 20:15:28 +0200 | [diff] [blame] | 1 | ---------------------- |
| 2 | HAProxy |
| 3 | Configuration Manual |
| 4 | ---------------------- |
Willy Tarreau | 2769aa0 | 2007-12-27 18:26:09 +0100 | [diff] [blame] | 5 | version 1.3.14.2 |
Willy Tarreau | 6a06a40 | 2007-07-15 20:15:28 +0200 | [diff] [blame] | 6 | willy tarreau |
Willy Tarreau | c73ce2b | 2008-01-06 10:55:10 +0100 | [diff] [blame] | 7 | 2008/01/05 |
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 |
Willy Tarreau | 0ba2750 | 2007-12-24 16:55:16 +0100 | [diff] [blame] | 12 | documentation, please refer to the Reference Manual or the Architecture Manual. |
Willy Tarreau | 6a06a40 | 2007-07-15 20:15:28 +0200 | [diff] [blame] | 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 | |
Willy Tarreau | 0ba2750 | 2007-12-24 16:55:16 +0100 | [diff] [blame] | 22 | The configuration file syntax consists in lines beginning with a keyword |
| 23 | referenced in this manual, optionally followed by one or several parameters |
| 24 | delimited by spaces. If spaces have to be entered in strings, then they must be |
| 25 | preceeded by a backslash ('\') to be escaped. Backslashes also have to be |
| 26 | escaped by doubling them. |
| 27 | |
| 28 | Some parameters involve values representating time, such as timeouts. These |
| 29 | values are generally expressed in milliseconds (unless explicitly stated |
| 30 | otherwise) but may be expressed in any other unit by suffixing the unit to the |
| 31 | numeric value. It is important to consider this because it will not be repeated |
| 32 | for 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 Tarreau | 6a06a40 | 2007-07-15 20:15:28 +0200 | [diff] [blame] | 42 | 1. Global parameters |
| 43 | -------------------- |
| 44 | |
| 45 | Parameters in the "global" section are process-wide and often OS-specific. They |
| 46 | are generally set once for all and do not need being changed once correct. Some |
| 47 | of them have command-line equivalents. |
| 48 | |
| 49 | The 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 Tarreau | fbee713 | 2007-10-18 13:53:22 +0200 | [diff] [blame] | 62 | - stats |
Willy Tarreau | 6a06a40 | 2007-07-15 20:15:28 +0200 | [diff] [blame] | 63 | |
| 64 | * Performance tuning |
| 65 | - maxconn |
| 66 | - noepoll |
| 67 | - nokqueue |
| 68 | - nopoll |
| 69 | - nosepoll |
Willy Tarreau | fe255b7 | 2007-10-14 23:09:26 +0200 | [diff] [blame] | 70 | - spread-checks |
Willy Tarreau | a0250ba | 2008-01-06 11:22:57 +0100 | [diff] [blame] | 71 | - tune.maxaccept |
| 72 | - tune.maxpollevents |
Willy Tarreau | 6a06a40 | 2007-07-15 20:15:28 +0200 | [diff] [blame] | 73 | |
| 74 | * Debugging |
| 75 | - debug |
| 76 | - quiet |
Willy Tarreau | 6a06a40 | 2007-07-15 20:15:28 +0200 | [diff] [blame] | 77 | |
| 78 | |
| 79 | 1.1) Process management and security |
| 80 | ------------------------------------ |
| 81 | |
| 82 | chroot <jail dir> |
| 83 | Changes current directory to <jail dir> and performs a chroot() there before |
| 84 | dropping privileges. This increases the security level in case an unknown |
| 85 | vulnerability would be exploited, since it would make it very hard for the |
| 86 | attacker to exploit the system. This only works when the process is started |
| 87 | with superuser privileges. It is important to ensure that <jail_dir> is both |
| 88 | empty and unwritable to anyone. |
| 89 | |
| 90 | daemon |
| 91 | Makes the process fork into background. This is the recommended mode of |
| 92 | operation. It is equivalent to the command line "-D" argument. It can be |
| 93 | disabled by the command line "-db" argument. |
| 94 | |
| 95 | gid <number> |
| 96 | Changes the process' group ID to <number>. It is recommended that the group |
| 97 | ID is dedicated to HAProxy or to a small set of similar daemons. HAProxy must |
| 98 | be started with a user belonging to this group, or with superuser privileges. |
| 99 | See also "group" and "uid". |
| 100 | |
| 101 | group <group name> |
| 102 | Similar to "gid" but uses the GID of group name <group name> from /etc/group. |
| 103 | See also "gid" and "user". |
| 104 | |
| 105 | log <address> <facility> [max level] |
| 106 | Adds a global syslog server. Up to two global servers can be defined. They |
| 107 | will receive logs for startups and exits, as well as all logs from proxies |
Robert Tsai | 81ae195 | 2007-12-05 10:47:29 +0100 | [diff] [blame] | 108 | configured with "log global". |
| 109 | |
| 110 | <address> can be one of: |
| 111 | |
Willy Tarreau | 2769aa0 | 2007-12-27 18:26:09 +0100 | [diff] [blame] | 112 | - An IPv4 address optionally followed by a colon and a UDP port. If |
Robert Tsai | 81ae195 | 2007-12-05 10:47:29 +0100 | [diff] [blame] | 113 | no port is specified, 514 is used by default (the standard syslog |
| 114 | port). |
| 115 | |
| 116 | - A filesystem path to a UNIX domain socket, keeping in mind |
| 117 | considerations for chroot (be sure the path is accessible inside |
| 118 | the chroot) and uid/gid (be sure the path is appropriately |
| 119 | writeable). |
| 120 | |
| 121 | <facility> must be one of the 24 standard syslog facilities : |
Willy Tarreau | 6a06a40 | 2007-07-15 20:15:28 +0200 | [diff] [blame] | 122 | |
| 123 | kern user mail daemon auth syslog lpr news |
| 124 | uucp cron auth2 ftp ntp audit alert cron2 |
| 125 | local0 local1 local2 local3 local4 local5 local6 local7 |
| 126 | |
| 127 | An optional level can be specified to filter outgoing messages. By default, |
| 128 | all messages are sent. If a level is specified, only messages with a severity |
| 129 | at least as important as this level will be sent. 8 levels are known : |
| 130 | |
| 131 | emerg alert crit err warning notice info debug |
| 132 | |
| 133 | nbproc <number> |
| 134 | Creates <number> processes when going daemon. This requires the "daemon" |
| 135 | mode. By default, only one process is created, which is the recommended mode |
| 136 | of operation. For systems limited to small sets of file descriptors per |
| 137 | process, it may be needed to fork multiple daemons. USING MULTIPLE PROCESSES |
| 138 | IS HARDER TO DEBUG AND IS REALLY DISCOURAGED. See also "daemon". |
| 139 | |
| 140 | pidfile <pidfile> |
| 141 | Writes pids of all daemons into file <pidfile>. This option is equivalent to |
| 142 | the "-p" command line argument. The file must be accessible to the user |
| 143 | starting the process. See also "daemon". |
| 144 | |
Willy Tarreau | fbee713 | 2007-10-18 13:53:22 +0200 | [diff] [blame] | 145 | stats socket <path> [{uid | user} <uid>] [{gid | group} <gid>] [mode <mode>] |
| 146 | Creates a UNIX socket in stream mode at location <path>. Any previously |
| 147 | existing socket will be backed up then replaced. Connections to this socket |
| 148 | will get a CSV-formated output of the process statistics in response to the |
Willy Tarreau | a8efd36 | 2008-01-03 10:19:15 +0100 | [diff] [blame] | 149 | "show stat" command followed by a line feed, and more general process |
| 150 | information in response to the "show info" command followed by a line feed. |
| 151 | |
| 152 | On platforms which support it, it is possible to restrict access to this |
| 153 | socket by specifying numerical IDs after "uid" and "gid", or valid user and |
| 154 | group names after the "user" and "group" keywords. It is also possible to |
| 155 | restrict permissions on the socket by passing an octal value after the "mode" |
| 156 | keyword (same syntax as chmod). Depending on the platform, the permissions on |
| 157 | the socket will be inherited from the directory which hosts it, or from the |
| 158 | user the process is started with. |
Willy Tarreau | fbee713 | 2007-10-18 13:53:22 +0200 | [diff] [blame] | 159 | |
| 160 | stats timeout <timeout, in milliseconds> |
| 161 | The default timeout on the stats socket is set to 10 seconds. It is possible |
| 162 | to change this value with "stats timeout". The value must be passed in |
Willy Tarreau | befdff1 | 2007-12-02 22:27:38 +0100 | [diff] [blame] | 163 | milliseconds, or be suffixed by a time unit among { us, ms, s, m, h, d }. |
Willy Tarreau | fbee713 | 2007-10-18 13:53:22 +0200 | [diff] [blame] | 164 | |
| 165 | stats maxconn <connections> |
| 166 | By default, the stats socket is limited to 10 concurrent connections. It is |
| 167 | possible to change this value with "stats maxconn". |
| 168 | |
Willy Tarreau | 6a06a40 | 2007-07-15 20:15:28 +0200 | [diff] [blame] | 169 | uid <number> |
| 170 | Changes the process' user ID to <number>. It is recommended that the user ID |
| 171 | is dedicated to HAProxy or to a small set of similar daemons. HAProxy must |
| 172 | be started with superuser privileges in order to be able to switch to another |
| 173 | one. See also "gid" and "user". |
| 174 | |
| 175 | ulimit-n <number> |
| 176 | Sets the maximum number of per-process file-descriptors to <number>. By |
| 177 | default, it is automatically computed, so it is recommended not to use this |
| 178 | option. |
| 179 | |
| 180 | user <user name> |
| 181 | Similar to "uid" but uses the UID of user name <user name> from /etc/passwd. |
| 182 | See also "uid" and "group". |
| 183 | |
| 184 | |
| 185 | 1.2) Performance tuning |
| 186 | ----------------------- |
| 187 | |
| 188 | maxconn <number> |
| 189 | Sets the maximum per-process number of concurrent connections to <number>. It |
| 190 | is equivalent to the command-line argument "-n". Proxies will stop accepting |
| 191 | connections when this limit is reached. The "ulimit-n" parameter is |
| 192 | automatically adjusted according to this value. See also "ulimit-n". |
| 193 | |
| 194 | noepoll |
| 195 | Disables the use of the "epoll" event polling system on Linux. It is |
| 196 | equivalent to the command-line argument "-de". The next polling system |
| 197 | used will generally be "poll". See also "nosepoll", and "nopoll". |
| 198 | |
| 199 | nokqueue |
| 200 | Disables the use of the "kqueue" event polling system on BSD. It is |
| 201 | equivalent to the command-line argument "-dk". The next polling system |
| 202 | used will generally be "poll". See also "nopoll". |
| 203 | |
| 204 | nopoll |
| 205 | Disables the use of the "poll" event polling system. It is equivalent to the |
| 206 | command-line argument "-dp". The next polling system used will be "select". |
Willy Tarreau | 0ba2750 | 2007-12-24 16:55:16 +0100 | [diff] [blame] | 207 | It should never be needed to disable "poll" since it's available on all |
Willy Tarreau | 6a06a40 | 2007-07-15 20:15:28 +0200 | [diff] [blame] | 208 | platforms supported by HAProxy. See also "nosepoll", and "nopoll" and |
| 209 | "nokqueue". |
| 210 | |
| 211 | nosepoll |
| 212 | Disables the use of the "speculative epoll" event polling system on Linux. It |
| 213 | is equivalent to the command-line argument "-ds". The next polling system |
| 214 | used will generally be "epoll". See also "nosepoll", and "nopoll". |
| 215 | |
Willy Tarreau | fe255b7 | 2007-10-14 23:09:26 +0200 | [diff] [blame] | 216 | spread-checks <0..50, in percent> |
| 217 | Sometimes it is desirable to avoid sending health checks to servers at exact |
| 218 | intervals, for instance when many logical servers are located on the same |
| 219 | physical server. With the help of this parameter, it becomes possible to add |
| 220 | some randomness in the check interval between 0 and +/- 50%. A value between |
| 221 | 2 and 5 seems to show good results. The default value remains at 0. |
| 222 | |
Willy Tarreau | a0250ba | 2008-01-06 11:22:57 +0100 | [diff] [blame] | 223 | tune.maxaccept <number> |
| 224 | Sets the maximum number of consecutive accepts that a process may perform on |
| 225 | a single wake up. High values give higher priority to high connection rates, |
| 226 | while lower values give higher priority to already established connections. |
| 227 | This value is unlimited by default in single process mode. However, in |
| 228 | multi-process mode (nbproc > 1), it defaults to 8 so that when one process |
| 229 | wakes up, it does not take all incoming connections for itself and leaves a |
| 230 | part of them to other processes. Setting this value to zero or less disables |
| 231 | the limitation. It should normally not be needed to tweak this value. |
| 232 | |
| 233 | tune.maxpollevents <number> |
| 234 | Sets the maximum amount of events that can be processed at once in a call to |
| 235 | the polling system. The default value is adapted to the operating system. It |
| 236 | has been noticed that reducing it below 200 tends to slightly decrease |
| 237 | latency at the expense of network bandwidth, and increasing it above 200 |
| 238 | tends to trade latency for slightly increased bandwidth. |
| 239 | |
Willy Tarreau | 6a06a40 | 2007-07-15 20:15:28 +0200 | [diff] [blame] | 240 | |
| 241 | 1.3) Debugging |
| 242 | --------------- |
| 243 | |
| 244 | debug |
| 245 | Enables debug mode which dumps to stdout all exchanges, and disables forking |
| 246 | into background. It is the equivalent of the command-line argument "-d". It |
| 247 | should never be used in a production configuration since it may prevent full |
| 248 | system startup. |
| 249 | |
| 250 | quiet |
| 251 | Do not display any message during startup. It is equivalent to the command- |
| 252 | line argument "-q". |
| 253 | |
Willy Tarreau | 6a06a40 | 2007-07-15 20:15:28 +0200 | [diff] [blame] | 254 | |
| 255 | 2) Proxies |
| 256 | ---------- |
Willy Tarreau | 0ba2750 | 2007-12-24 16:55:16 +0100 | [diff] [blame] | 257 | |
Willy Tarreau | 6a06a40 | 2007-07-15 20:15:28 +0200 | [diff] [blame] | 258 | Proxy configuration can be located in a set of sections : |
| 259 | - defaults <name> |
| 260 | - frontend <name> |
| 261 | - backend <name> |
| 262 | - listen <name> |
| 263 | |
| 264 | A "defaults" section sets default parameters for all other sections following |
| 265 | its declaration. Those default parameters are reset by the next "defaults" |
| 266 | section. See below for the list of parameters which can be set in a "defaults" |
Willy Tarreau | 0ba2750 | 2007-12-24 16:55:16 +0100 | [diff] [blame] | 267 | section. The name is optional but its use is encouraged for better readability. |
Willy Tarreau | 6a06a40 | 2007-07-15 20:15:28 +0200 | [diff] [blame] | 268 | |
| 269 | A "frontend" section describes a set of listening sockets accepting client |
| 270 | connections. |
| 271 | |
| 272 | A "backend" section describes a set of servers to which the proxy will connect |
| 273 | to forward incoming connections. |
| 274 | |
| 275 | A "listen" section defines a complete proxy with its frontend and backend |
| 276 | parts combined in one section. It is generally useful for TCP-only traffic. |
| 277 | |
Willy Tarreau | 0ba2750 | 2007-12-24 16:55:16 +0100 | [diff] [blame] | 278 | All proxy names must be formed from upper and lower case letters, digits, |
| 279 | '-' (dash), '_' (underscore) , '.' (dot) and ':' (colon). ACL names are |
| 280 | case-sensitive, which means that "www" and "WWW" are two different proxies. |
| 281 | |
| 282 | Historically, all proxy names could overlap, it just caused troubles in the |
| 283 | logs. Since the introduction of content switching, it is mandatory that two |
| 284 | proxies with overlapping capabilities (frontend/backend) have different names. |
| 285 | However, it is still permitted that a frontend and a backend share the same |
| 286 | name, as this configuration seems to be commonly encountered. |
| 287 | |
| 288 | Right now, two major proxy modes are supported : "tcp", also known as layer 4, |
| 289 | and "http", also known as layer 7. In layer 4 mode, HAProxy simply forwards |
| 290 | bidirectionnal traffic between two sides. In layer 7 mode, HAProxy analyzes the |
| 291 | protocol, and can interact with it by allowing, blocking, switching, adding, |
| 292 | modifying, or removing arbitrary contents in requests or responses, based on |
| 293 | arbitrary criteria. |
| 294 | |
| 295 | |
| 296 | 2.1) Quick reminder about HTTP |
| 297 | ------------------------------ |
| 298 | |
| 299 | When a proxy is running in HTTP mode, both the request and the response are |
| 300 | fully analyzed and indexed, thus it becomes possible to build matching criteria |
| 301 | on almost anything found in the contents. |
| 302 | |
| 303 | However, it is important to understand how HTTP requests and responses are |
| 304 | formed, and how HAProxy decomposes them. It will then become easier to write |
| 305 | correct rules and to debug existing configurations. |
| 306 | |
| 307 | |
| 308 | 2.1.1) The HTTP transaction model |
| 309 | --------------------------------- |
| 310 | |
| 311 | The HTTP protocol is transaction-driven. This means that each request will lead |
| 312 | to one and only one response. Traditionnally, a TCP connection is established |
| 313 | from the client to the server, a request is sent by the client on the |
| 314 | connection, the server responds and the connection is closed. A new request |
| 315 | will involve a new connection : |
| 316 | |
| 317 | [CON1] [REQ1] ... [RESP1] [CLO1] [CON2] [REQ2] ... [RESP2] [CLO2] ... |
| 318 | |
| 319 | In this mode, called the "HTTP close" mode, there are as many connection |
| 320 | establishments as there are HTTP transactions. Since the connection is closed |
| 321 | by the server after the response, the client does not need to know the content |
| 322 | length. |
| 323 | |
| 324 | Due to the transactional nature of the protocol, it was possible to improve it |
| 325 | to avoid closing a connection between two subsequent transactions. In this mode |
| 326 | however, it is mandatory that the server indicates the content length for each |
| 327 | response so that the client does not wait indefinitely. For this, a special |
| 328 | header is used: "Content-length". This mode is called the "keep-alive" mode : |
| 329 | |
| 330 | [CON] [REQ1] ... [RESP1] [REQ2] ... [RESP2] [CLO] ... |
| 331 | |
| 332 | Its advantages are a reduced latency between transactions, and less processing |
| 333 | power required on the server side. It is generally better than the close mode, |
| 334 | but not always because the clients often limit their concurrent connections to |
| 335 | a smaller value. HAProxy currently does not support the HTTP keep-alive mode, |
| 336 | but knows how to transform it to the close mode. |
| 337 | |
| 338 | A last improvement in the communications is the pipelining mode. It still uses |
| 339 | keep-alive, but the client does not wait for the first response to send the |
| 340 | second request. This is useful for fetching large number of images composing a |
| 341 | page : |
| 342 | |
| 343 | [CON] [REQ1] [REQ2] ... [RESP1] [RESP2] [CLO] ... |
| 344 | |
| 345 | This can obviously have a tremendous benefit on performance because the network |
| 346 | latency is eliminated between subsequent requests. Many HTTP agents do not |
| 347 | correctly support pipelining since there is no way to associate a response with |
| 348 | the corresponding request in HTTP. For this reason, it is mandatory for the |
| 349 | server to reply in the exact same order as the requests were received. |
| 350 | |
| 351 | Right now, HAProxy only supports the first mode (HTTP close) if it needs to |
| 352 | process the request. This means that for each request, there will be one TCP |
| 353 | connection. If keep-alive or pipelining are required, HAProxy will still |
| 354 | support them, but will only see the first request and the first response of |
| 355 | each transaction. While this is generally problematic with regards to logs, |
| 356 | content switching or filtering, it most often causes no problem for persistence |
| 357 | with cookie insertion. |
| 358 | |
| 359 | |
| 360 | 2.1.2) HTTP request |
| 361 | ------------------- |
| 362 | |
| 363 | First, let's consider this HTTP request : |
| 364 | |
| 365 | Line Contents |
| 366 | number |
| 367 | 1 GET /serv/login.php?lang=en&profile=2 HTTP/1.1 |
| 368 | 2 Host: www.mydomain.com |
| 369 | 3 User-agent: my small browser |
| 370 | 4 Accept: image/jpeg, image/gif |
| 371 | 5 Accept: image/png |
| 372 | |
| 373 | |
| 374 | 2.1.2.1) The Request line |
| 375 | ------------------------- |
| 376 | |
| 377 | Line 1 is the "request line". It is always composed of 3 fields : |
| 378 | |
| 379 | - a METHOD : GET |
| 380 | - a URI : /serv/login.php?lang=en&profile=2 |
| 381 | - a version tag : HTTP/1.1 |
| 382 | |
| 383 | All of them are delimited by what the standard calls LWS (linear white spaces), |
| 384 | which are commonly spaces, but can also be tabs or line feeds/carriage returns |
| 385 | followed by spaces/tabs. The method itself cannot contain any colon (':') and |
| 386 | is limited to alphabetic letters. All those various combinations make it |
| 387 | desirable that HAProxy performs the splitting itself rather than leaving it to |
| 388 | the user to write a complex or inaccurate regular expression. |
| 389 | |
| 390 | The URI itself can have several forms : |
| 391 | |
| 392 | - A "relative URI" : |
| 393 | |
| 394 | /serv/login.php?lang=en&profile=2 |
| 395 | |
| 396 | It is a complete URL without the host part. This is generally what is |
| 397 | received by servers, reverse proxies and transparent proxies. |
| 398 | |
| 399 | - An "absolute URI", also called a "URL" : |
| 400 | |
| 401 | http://192.168.0.12:8080/serv/login.php?lang=en&profile=2 |
| 402 | |
| 403 | It is composed of a "scheme" (the protocol name followed by '://'), a host |
| 404 | name or address, optionally a colon (':') followed by a port number, then |
| 405 | a relative URI beginning at the first slash ('/') after the address part. |
| 406 | This is generally what proxies receive, but a server supporting HTTP/1.1 |
| 407 | must accept this form too. |
| 408 | |
| 409 | - a star ('*') : this form is only accepted in association with the OPTIONS |
| 410 | method and is not relayable. It is used to inquiry a next hop's |
| 411 | capabilities. |
| 412 | |
| 413 | - an address:port combination : 192.168.0.12:80 |
| 414 | This is used with the CONNECT method, which is used to establish TCP |
| 415 | tunnels through HTTP proxies, generally for HTTPS, but sometimes for |
| 416 | other protocols too. |
| 417 | |
| 418 | In a relative URI, two sub-parts are identified. The part before the question |
| 419 | mark is called the "path". It is typically the relative path to static objects |
| 420 | on the server. The part after the question mark is called the "query string". |
| 421 | It is mostly used with GET requests sent to dynamic scripts and is very |
| 422 | specific to the language, framework or application in use. |
| 423 | |
| 424 | |
| 425 | 2.1.2.2) The request headers |
| 426 | ---------------------------- |
| 427 | |
| 428 | The headers start at the second line. They are composed of a name at the |
| 429 | beginning of the line, immediately followed by a colon (':'). Traditionally, |
| 430 | an LWS is added after the colon but that's not required. Then come the values. |
| 431 | Multiple identical headers may be folded into one single line, delimiting the |
| 432 | values with commas, provided that their order is respected. This is commonly |
| 433 | encountered in the 'Cookie:' field. A header may span over multiple lines if |
| 434 | the subsequent lines begin with an LWS. In the example in 2.1.2, lines 4 and 5 |
| 435 | define a total of 3 values for the 'Accept:' header. |
| 436 | |
| 437 | Contrary to a common mis-conception, header names are not case-sensitive, and |
| 438 | their values are not either if they refer to other header names (such as the |
| 439 | 'Connection:' header). |
| 440 | |
| 441 | The end of the headers is indicated by the first empty line. People often say |
| 442 | that it's a double line feed, which is not exact, even if a double line feed |
| 443 | is one valid form of empty line. |
| 444 | |
| 445 | Fortunately, HAProxy takes care of all these complex combinations when indexing |
| 446 | headers, checking values and counting them, so there is no reason to worry |
| 447 | about the way they could be written, but it is important not to accusate an |
| 448 | application of being buggy if it does unusual, valid things. |
| 449 | |
| 450 | Important note: |
| 451 | As suggested by RFC2616, HAProxy normalizes headers by replacing line breaks |
| 452 | in the middle of headers by LWS in order to join multi-line headers. This |
| 453 | is necessary for proper analysis and helps less capable HTTP parsers to work |
| 454 | correctly and not to be fooled by such complex constructs. |
| 455 | |
| 456 | |
| 457 | 2.1.3) HTTP response |
| 458 | -------------------- |
| 459 | |
| 460 | An HTTP response looks very much like an HTTP request. Both are called HTTP |
| 461 | messages. Let's consider this HTTP response : |
| 462 | |
| 463 | Line Contents |
| 464 | number |
| 465 | 1 HTTP/1.1 200 OK |
| 466 | 2 Content-length: 350 |
| 467 | 3 Content-Type: text/html |
| 468 | |
| 469 | |
| 470 | 2.1.3.1) The Response line |
| 471 | -------------------------- |
| 472 | |
| 473 | Line 1 is the "response line". It is always composed of 3 fields : |
| 474 | |
| 475 | - a version tag : HTTP/1.1 |
| 476 | - a status code : 200 |
| 477 | - a reason : OK |
| 478 | |
| 479 | The status code is always 3-digit. The first digit indicates a general status : |
| 480 | - 2xx = OK, content is following (eg: 200, 206) |
| 481 | - 3xx = OK, no content following (eg: 302, 304) |
| 482 | - 4xx = error caused by the client (eg: 401, 403, 404) |
| 483 | - 5xx = error caused by the server (eg: 500, 502, 503) |
| 484 | |
| 485 | Please refer to RFC2616 for the detailed meaning of all such codes. The |
| 486 | "reason" field is just a hint, but is not parsed by clients. Anything can be |
| 487 | found there, but it's a common practise to respect the well-established |
| 488 | messages. It can be composed of one or multiple words, such as "OK", "Found", |
| 489 | or "Authentication Required". |
| 490 | |
| 491 | |
| 492 | 2.1.3.2) The response headers |
| 493 | ----------------------------- |
| 494 | |
| 495 | Response headers work exactly like request headers, and as such, HAProxy uses |
| 496 | the same parsing function for both. Please refer to paragraph 2.1.2.2 for more |
| 497 | details. |
| 498 | |
| 499 | |
| 500 | 2.2) Proxy keywords matrix |
| 501 | ---------------------------- |
| 502 | |
Willy Tarreau | 6a06a40 | 2007-07-15 20:15:28 +0200 | [diff] [blame] | 503 | The following list of keywords is supported. Most of them may only be used in a |
Willy Tarreau | 0ba2750 | 2007-12-24 16:55:16 +0100 | [diff] [blame] | 504 | limited set of section types. Some of them are marked as "deprecated" because |
| 505 | they are inherited from an old syntax which may be confusing or functionnally |
Krzysztof Oledzki | 336d475 | 2007-12-25 02:40:22 +0100 | [diff] [blame] | 506 | limited, and there are new recommended keywords to replace them. Keywords |
| 507 | listed with [no] can be optionally inverted using the "no" prefix, ex. "no |
| 508 | option contstats". This makes sense when the option has been enabled by default |
| 509 | and must be disabled for a specific instance. |
Willy Tarreau | 0ba2750 | 2007-12-24 16:55:16 +0100 | [diff] [blame] | 510 | |
Willy Tarreau | 6a06a40 | 2007-07-15 20:15:28 +0200 | [diff] [blame] | 511 | |
| 512 | keyword defaults frontend listen backend |
| 513 | ----------------------+----------+----------+---------+--------- |
| 514 | acl - X X X |
| 515 | appsession - - X X |
Willy Tarreau | c73ce2b | 2008-01-06 10:55:10 +0100 | [diff] [blame] | 516 | backlog X X X - |
Willy Tarreau | 0ba2750 | 2007-12-24 16:55:16 +0100 | [diff] [blame] | 517 | balance X - X X |
Willy Tarreau | 6a06a40 | 2007-07-15 20:15:28 +0200 | [diff] [blame] | 518 | bind - X X - |
| 519 | block - X X X |
Willy Tarreau | 0ba2750 | 2007-12-24 16:55:16 +0100 | [diff] [blame] | 520 | capture cookie - X X - |
| 521 | capture request header - X X - |
| 522 | capture response header - X X - |
Willy Tarreau | e219db7 | 2007-12-03 01:30:13 +0100 | [diff] [blame] | 523 | clitimeout X X X - (deprecated) |
Willy Tarreau | 0ba2750 | 2007-12-24 16:55:16 +0100 | [diff] [blame] | 524 | contimeout X - X X (deprecated) |
Willy Tarreau | 6a06a40 | 2007-07-15 20:15:28 +0200 | [diff] [blame] | 525 | cookie X - X X |
| 526 | default_backend - X X - |
Willy Tarreau | 0ba2750 | 2007-12-24 16:55:16 +0100 | [diff] [blame] | 527 | disabled X X X X |
Willy Tarreau | 6a06a40 | 2007-07-15 20:15:28 +0200 | [diff] [blame] | 528 | dispatch - - X X |
Willy Tarreau | 0ba2750 | 2007-12-24 16:55:16 +0100 | [diff] [blame] | 529 | enabled X X X X |
Willy Tarreau | 6a06a40 | 2007-07-15 20:15:28 +0200 | [diff] [blame] | 530 | errorfile X X X X |
| 531 | errorloc X X X X |
| 532 | errorloc302 X X X X |
| 533 | errorloc303 X X X X |
| 534 | fullconn X - X X |
| 535 | grace - X X X |
Willy Tarreau | dbc36f6 | 2007-11-30 12:29:11 +0100 | [diff] [blame] | 536 | http-check disable-on-404 X - X X |
Willy Tarreau | 6a06a40 | 2007-07-15 20:15:28 +0200 | [diff] [blame] | 537 | log X X X X |
| 538 | maxconn X X X - |
| 539 | mode X X X X |
Willy Tarreau | c7246fc | 2007-12-02 17:31:20 +0100 | [diff] [blame] | 540 | monitor fail - X X - |
Willy Tarreau | 6a06a40 | 2007-07-15 20:15:28 +0200 | [diff] [blame] | 541 | monitor-net X X X - |
| 542 | monitor-uri X X X - |
Krzysztof Oledzki | 336d475 | 2007-12-25 02:40:22 +0100 | [diff] [blame] | 543 | [no] option abortonclose X - X X |
| 544 | [no] option allbackups X - X X |
| 545 | [no] option checkcache X - X X |
| 546 | [no] option clitcpka X X X - |
| 547 | [no] option contstats X X X - |
| 548 | [no] option dontlognull X X X - |
| 549 | [no] option forceclose X - X X |
Willy Tarreau | 6a06a40 | 2007-07-15 20:15:28 +0200 | [diff] [blame] | 550 | option forwardfor X X X X |
Krzysztof Oledzki | 336d475 | 2007-12-25 02:40:22 +0100 | [diff] [blame] | 551 | [no] option http_proxy X X X X |
Willy Tarreau | 6a06a40 | 2007-07-15 20:15:28 +0200 | [diff] [blame] | 552 | option httpchk X - X X |
Krzysztof Oledzki | 336d475 | 2007-12-25 02:40:22 +0100 | [diff] [blame] | 553 | [no] option httpclose X X X X |
Willy Tarreau | 6a06a40 | 2007-07-15 20:15:28 +0200 | [diff] [blame] | 554 | option httplog X X X X |
Krzysztof Oledzki | 336d475 | 2007-12-25 02:40:22 +0100 | [diff] [blame] | 555 | [no] option logasap X X X - |
| 556 | [no] option nolinger X X X X |
| 557 | [no] option persist X - X X |
| 558 | [no] option redispatch X - X X |
Willy Tarreau | 6a06a40 | 2007-07-15 20:15:28 +0200 | [diff] [blame] | 559 | option smtpchk X - X X |
Krzysztof Oledzki | 336d475 | 2007-12-25 02:40:22 +0100 | [diff] [blame] | 560 | [no] option srvtcpka X - X X |
Willy Tarreau | 6a06a40 | 2007-07-15 20:15:28 +0200 | [diff] [blame] | 561 | option ssl-hello-chk X - X X |
| 562 | option tcpka X X X X |
| 563 | option tcplog X X X X |
Krzysztof Oledzki | 336d475 | 2007-12-25 02:40:22 +0100 | [diff] [blame] | 564 | [no] option tcpsplice X X X X |
| 565 | [no] option transparent X X X - |
| 566 | redisp X - X X (deprecated) |
| 567 | redispatch X - X X (deprecated) |
Willy Tarreau | 6a06a40 | 2007-07-15 20:15:28 +0200 | [diff] [blame] | 568 | reqadd - X X X |
| 569 | reqallow - X X X |
| 570 | reqdel - X X X |
| 571 | reqdeny - X X X |
| 572 | reqiallow - X X X |
| 573 | reqidel - X X X |
| 574 | reqideny - X X X |
| 575 | reqipass - X X X |
| 576 | reqirep - X X X |
| 577 | reqisetbe - X X X |
| 578 | reqitarpit - X X X |
| 579 | reqpass - X X X |
| 580 | reqrep - X X X |
| 581 | reqsetbe - X X X |
| 582 | reqtarpit - X X X |
| 583 | retries X - X X |
| 584 | rspadd - X X X |
| 585 | rspdel - X X X |
| 586 | rspdeny - X X X |
| 587 | rspidel - X X X |
| 588 | rspideny - X X X |
| 589 | rspirep - X X X |
| 590 | rsprep - X X X |
| 591 | server - - X X |
| 592 | source X - X X |
Willy Tarreau | e219db7 | 2007-12-03 01:30:13 +0100 | [diff] [blame] | 593 | srvtimeout X - X X (deprecated) |
Willy Tarreau | 24e779b | 2007-07-24 23:43:37 +0200 | [diff] [blame] | 594 | stats auth X - X X |
| 595 | stats enable X - X X |
| 596 | stats realm X - X X |
Willy Tarreau | bbd4212 | 2007-07-25 07:26:38 +0200 | [diff] [blame] | 597 | stats refresh X - X X |
Willy Tarreau | 24e779b | 2007-07-24 23:43:37 +0200 | [diff] [blame] | 598 | stats scope X - X X |
| 599 | stats uri X - X X |
Krzysztof Oledzki | d9db927 | 2007-10-15 10:05:11 +0200 | [diff] [blame] | 600 | stats hide-version X - X X |
Willy Tarreau | e219db7 | 2007-12-03 01:30:13 +0100 | [diff] [blame] | 601 | timeout appsession X - X X |
| 602 | timeout client X X X - |
| 603 | timeout clitimeout X X X - (deprecated) |
| 604 | timeout connect X - X X |
| 605 | timeout contimeout X - X X (deprecated) |
Willy Tarreau | 036fae0 | 2008-01-06 13:24:40 +0100 | [diff] [blame^] | 606 | timeout httpreq X X X - |
Willy Tarreau | e219db7 | 2007-12-03 01:30:13 +0100 | [diff] [blame] | 607 | timeout queue X - X X |
| 608 | timeout server X - X X |
| 609 | timeout srvtimeout X - X X (deprecated) |
| 610 | timeout tarpit X X X - |
Willy Tarreau | 6a06a40 | 2007-07-15 20:15:28 +0200 | [diff] [blame] | 611 | transparent X X X - |
| 612 | use_backend - X X - |
| 613 | usesrc X - X X |
| 614 | ----------------------+----------+----------+---------+--------- |
| 615 | keyword defaults frontend listen backend |
| 616 | |
Willy Tarreau | 0ba2750 | 2007-12-24 16:55:16 +0100 | [diff] [blame] | 617 | |
| 618 | 2.2.1) Alphabetically sorted keywords reference |
| 619 | ----------------------------------------------- |
| 620 | |
| 621 | This section provides a description of each keyword and its usage. |
| 622 | |
| 623 | |
| 624 | acl <aclname> <criterion> [flags] [operator] <value> ... |
| 625 | Declare or complete an access list. |
| 626 | May be used in sections : defaults | frontend | listen | backend |
| 627 | no | yes | yes | yes |
| 628 | Example: |
| 629 | acl invalid_src src 0.0.0.0/7 224.0.0.0/3 |
| 630 | acl invalid_src src_port 0:1023 |
| 631 | acl local_dst hdr(host) -i localhost |
| 632 | |
| 633 | See section 2.3 about ACL usage. |
| 634 | |
| 635 | |
| 636 | appsession <cookie> len <length> timeout <holdtime> |
| 637 | Define session stickiness on an existing application cookie. |
| 638 | May be used in sections : defaults | frontend | listen | backend |
| 639 | no | no | yes | yes |
| 640 | Arguments : |
| 641 | <cookie> this is the name of the cookie used by the application and which |
| 642 | HAProxy will have to learn for each new session. |
| 643 | |
| 644 | <length> this is the number of characters that will be memorized and |
| 645 | checked in each cookie value. |
| 646 | |
| 647 | <holdtime> this is the time after which the cookie will be removed from |
| 648 | memory if unused. If no unit is specified, this time is in |
| 649 | milliseconds. |
| 650 | |
| 651 | When an application cookie is defined in a backend, HAProxy will check when |
| 652 | the server sets such a cookie, and will store its value in a table, and |
| 653 | associate it with the server's identifier. Up to <length> characters from |
| 654 | the value will be retained. On each connection, haproxy will look for this |
| 655 | cookie both in the "Cookie:" headers, and as a URL parameter in the query |
| 656 | string. If a known value is found, the client will be directed to the server |
| 657 | associated with this value. Otherwise, the load balancing algorithm is |
| 658 | applied. Cookies are automatically removed from memory when they have been |
| 659 | unused for a duration longer than <holdtime>. |
| 660 | |
| 661 | The definition of an application cookie is limited to one per backend. |
| 662 | |
| 663 | Example : |
| 664 | appsession JSESSIONID len 52 timeout 3h |
| 665 | |
| 666 | See also : "cookie", "capture cookie" and "balance". |
| 667 | |
| 668 | |
Willy Tarreau | c73ce2b | 2008-01-06 10:55:10 +0100 | [diff] [blame] | 669 | backlog <conns> |
| 670 | Give hints to the system about the approximate listen backlog desired size |
| 671 | May be used in sections : defaults | frontend | listen | backend |
| 672 | yes | yes | yes | no |
| 673 | Arguments : |
| 674 | <conns> is the number of pending connections. Depending on the operating |
| 675 | system, it may represent the number of already acknowledged |
| 676 | connections, of non-acknowledged ones, or both. |
| 677 | |
| 678 | In order to protect against SYN flood attacks, one solution is to increase |
| 679 | the system's SYN backlog size. Depending on the system, sometimes it is just |
| 680 | tunable via a system parameter, sometimes it is not adjustable at all, and |
| 681 | sometimes the system relies on hints given by the application at the time of |
| 682 | the listen() syscall. By default, HAProxy passes the frontend's maxconn value |
| 683 | to the listen() syscall. On systems which can make use of this value, it can |
| 684 | sometimes be useful to be able to specify a different value, hence this |
| 685 | backlog parameter. |
| 686 | |
| 687 | On Linux 2.4, the parameter is ignored by the system. On Linux 2.6, it is |
| 688 | used as a hint and the system accepts up to the smallest greater power of |
| 689 | two, and never more than some limits (usually 32768). |
| 690 | |
| 691 | See also : "maxconn" and the target operating system's tuning guide. |
| 692 | |
| 693 | |
Willy Tarreau | 0ba2750 | 2007-12-24 16:55:16 +0100 | [diff] [blame] | 694 | balance <algorithm> [ <arguments> ] |
| 695 | Define the load balancing algorithm to be used in a backend. |
| 696 | May be used in sections : defaults | frontend | listen | backend |
| 697 | yes | no | yes | yes |
| 698 | Arguments : |
| 699 | <algorithm> is the algorithm used to select a server when doing load |
| 700 | balancing. This only applies when no persistence information |
| 701 | is available, or when a connection is redispatched to another |
| 702 | server. <algorithm> may be one of the following : |
| 703 | |
| 704 | roundrobin Each server is used in turns, according to their weights. |
| 705 | This is the smoothest and fairest algorithm when the server's |
| 706 | processing time remains equally distributed. This algorithm |
| 707 | is dynamic, which means that server weights may be adjusted |
| 708 | on the fly for slow starts for instance. |
| 709 | |
| 710 | source The source IP address is hashed and divided by the total |
| 711 | weight of the running servers to designate which server will |
| 712 | receive the request. This ensures that the same client IP |
| 713 | address will always reach the same server as long as no |
| 714 | server goes down or up. If the hash result changes due to the |
| 715 | number of running servers changing, many clients will be |
| 716 | directed to a different server. This algorithm is generally |
| 717 | used in TCP mode where no cookie may be inserted. It may also |
| 718 | be used on the Internet to provide a best-effort stickyness |
| 719 | to clients which refuse session cookies. This algorithm is |
| 720 | static, which means that changing a server's weight on the |
| 721 | fly will have no effect. |
| 722 | |
| 723 | uri The left part of the URI (before the question mark) is hashed |
| 724 | and divided by the total weight of the running servers. The |
| 725 | result designates which server will receive the request. This |
| 726 | ensures that a same URI will always be directed to the same |
| 727 | server as long as no server goes up or down. This is used |
| 728 | with proxy caches and anti-virus proxies in order to maximize |
| 729 | the cache hit rate. Note that this algorithm may only be used |
| 730 | in an HTTP backend. This algorithm is static, which means |
| 731 | that changing a server's weight on the fly will have no |
| 732 | effect. |
| 733 | |
| 734 | url_param The URL parameter specified in argument will be looked up in |
| 735 | the query string of each HTTP request. If it is found |
| 736 | followed by an equal sign ('=') and a value, then the value |
| 737 | is hashed and divided by the total weight of the running |
| 738 | servers. The result designates which server will receive the |
| 739 | request. This is used to track user identifiers in requests |
| 740 | and ensure that a same user ID will always be sent to the |
| 741 | same server as long as no server goes up or down. If no value |
| 742 | is found or if the parameter is not found, then a round robin |
| 743 | algorithm is applied. Note that this algorithm may only be |
| 744 | used in an HTTP backend. This algorithm is static, which |
| 745 | means that changing a server's weight on the fly will have no |
| 746 | effect. |
| 747 | |
| 748 | <arguments> is an optional list of arguments which may be needed by some |
| 749 | algorithms. Right now, only the "url_param" algorithm supports |
| 750 | a mandatory argument. |
| 751 | |
| 752 | The definition of the load balancing algorithm is mandatory for a backend |
| 753 | and limited to one per backend. |
| 754 | |
| 755 | Examples : |
| 756 | balance roundrobin |
| 757 | balance url_param userid |
| 758 | |
| 759 | See also : "dispatch", "cookie", "appsession", "transparent" and "http_proxy". |
| 760 | |
| 761 | |
| 762 | bind [<address>]:<port> [, ...] |
| 763 | Define one or several listening addresses and/or ports in a frontend. |
| 764 | May be used in sections : defaults | frontend | listen | backend |
| 765 | no | yes | yes | no |
| 766 | Arguments : |
| 767 | <address> is optional and can be a host name, an IPv4 address, an IPv6 |
| 768 | address, or '*'. It designates the address the frontend will |
| 769 | listen on. If unset, all IPv4 addresses of the system will be |
| 770 | listened on. The same will apply for '*' or the system's special |
| 771 | address "0.0.0.0". |
| 772 | |
| 773 | <port> is the TCP port number the proxy will listen on. The port is |
| 774 | mandatory. Note that in the case of an IPv6 address, the port is |
| 775 | always the number after the last colon (':'). |
| 776 | |
| 777 | It is possible to specify a list of address:port combinations delimited by |
| 778 | commas. The frontend will then listen on all of these addresses. There is no |
| 779 | fixed limit to the number of addresses and ports which can be listened on in |
| 780 | a frontend, as well as there is no limit to the number of "bind" statements |
| 781 | in a frontend. |
| 782 | |
| 783 | Example : |
| 784 | listen http_proxy |
| 785 | bind :80,:443 |
| 786 | bind 10.0.0.1:10080,10.0.0.1:10443 |
| 787 | |
| 788 | See also : "source". |
| 789 | |
| 790 | |
| 791 | block { if | unless } <condition> |
| 792 | Block a layer 7 request if/unless a condition is matched |
| 793 | May be used in sections : defaults | frontend | listen | backend |
| 794 | no | yes | yes | yes |
| 795 | |
| 796 | The HTTP request will be blocked very early in the layer 7 processing |
| 797 | if/unless <condition> is matched. A 403 error will be returned if the request |
| 798 | is blocked. The condition has to reference ACLs (see section 2.3). This is |
| 799 | typically used to deny access to certain sensible resources if some |
| 800 | conditions are met or not met. There is no fixed limit to the number of |
| 801 | "block" statements per instance. |
| 802 | |
| 803 | Example: |
| 804 | acl invalid_src src 0.0.0.0/7 224.0.0.0/3 |
| 805 | acl invalid_src src_port 0:1023 |
| 806 | acl local_dst hdr(host) -i localhost |
| 807 | block if invalid_src || local_dst |
| 808 | |
| 809 | See section 2.3 about ACL usage. |
| 810 | |
| 811 | |
| 812 | capture cookie <name> len <length> |
| 813 | Capture and log a cookie in the request and in the response. |
| 814 | May be used in sections : defaults | frontend | listen | backend |
| 815 | no | yes | yes | no |
| 816 | Arguments : |
| 817 | <name> is the beginning of the name of the cookie to capture. In order |
| 818 | to match the exact name, simply suffix the name with an equal |
| 819 | sign ('='). The full name will appear in the logs, which is |
| 820 | useful with application servers which adjust both the cookie name |
| 821 | and value (eg: ASPSESSIONXXXXX). |
| 822 | |
| 823 | <length> is the maximum number of characters to report in the logs, which |
| 824 | include the cookie name, the equal sign and the value, all in the |
| 825 | standard "name=value" form. The string will be truncated on the |
| 826 | right if it exceeds <length>. |
| 827 | |
| 828 | Only the first cookie is captured. Both the "cookie" request headers and the |
| 829 | "set-cookie" response headers are monitored. This is particularly useful to |
| 830 | check for application bugs causing session crossing or stealing between |
| 831 | users, because generally the user's cookies can only change on a login page. |
| 832 | |
| 833 | When the cookie was not presented by the client, the associated log column |
| 834 | will report "-". When a request does not cause a cookie to be assigned by the |
| 835 | server, a "-" is reported in the response column. |
| 836 | |
| 837 | The capture is performed in the frontend only because it is necessary that |
| 838 | the log format does not change for a given frontend depending on the |
| 839 | backends. This may change in the future. Note that there can be only one |
| 840 | "capture cookie" statement in a frontend. The maximum capture length is |
| 841 | configured in the souces by default to 64 characters. It is not possible to |
| 842 | specify a capture in a "defaults" section. |
| 843 | |
| 844 | Example: |
| 845 | capture cookie ASPSESSION len 32 |
| 846 | |
| 847 | See also : "capture request header", "capture response header" as well as |
| 848 | section 2.4 about logging. |
| 849 | |
| 850 | |
| 851 | capture request header <name> len <length> |
| 852 | Capture and log the first occurrence of the specified request header. |
| 853 | May be used in sections : defaults | frontend | listen | backend |
| 854 | no | yes | yes | no |
| 855 | Arguments : |
| 856 | <name> is the name of the header to capture. The header names are not |
| 857 | case-sensitive, but it is a common practise to write them as they |
| 858 | appear in the requests, with the first letter of each word in |
| 859 | upper case. The header name will not appear in the logs, only the |
| 860 | value is reported, but the position in the logs is respected. |
| 861 | |
| 862 | <length> is the maximum number of characters to extract from the value and |
| 863 | report in the logs. The string will be truncated on the right if |
| 864 | it exceeds <length>. |
| 865 | |
| 866 | Only the first value of the first occurrence of the header is captured. The |
| 867 | value will be added to the logs between braces ('{}'). If multiple headers |
| 868 | are captured, they will be delimited by a vertical bar ('|') and will appear |
| 869 | in the same order they were declared in the configuration. Common uses for |
| 870 | request header captures include the "Host" field in virtual hosting |
| 871 | environments, the "Content-length" when uploads are supported, "User-agent" |
| 872 | to quickly differenciate between real users and robots, and "X-Forwarded-For" |
| 873 | in proxied environments to find where the request came from. |
| 874 | |
| 875 | There is no limit to the number of captured request headers, but each capture |
| 876 | is limited to 64 characters. In order to keep log format consistent for a |
| 877 | same frontend, header captures can only be declared in a frontend. It is not |
| 878 | possible to specify a capture in a "defaults" section. |
| 879 | |
| 880 | Example: |
| 881 | capture request header Host len 15 |
| 882 | capture request header X-Forwarded-For len 15 |
| 883 | capture request header Referrer len 15 |
| 884 | |
| 885 | See also : "capture cookie", "capture response header" as well as section 2.4 |
| 886 | about logging. |
| 887 | |
| 888 | |
| 889 | capture response header <name> len <length> |
| 890 | Capture and log the first occurrence of the specified response header. |
| 891 | May be used in sections : defaults | frontend | listen | backend |
| 892 | no | yes | yes | no |
| 893 | Arguments : |
| 894 | <name> is the name of the header to capture. The header names are not |
| 895 | case-sensitive, but it is a common practise to write them as they |
| 896 | appear in the response, with the first letter of each word in |
| 897 | upper case. The header name will not appear in the logs, only the |
| 898 | value is reported, but the position in the logs is respected. |
| 899 | |
| 900 | <length> is the maximum number of characters to extract from the value and |
| 901 | report in the logs. The string will be truncated on the right if |
| 902 | it exceeds <length>. |
| 903 | |
| 904 | Only the first value of the first occurrence of the header is captured. The |
| 905 | result will be added to the logs between braces ('{}') after the captured |
| 906 | request headers. If multiple headers are captured, they will be delimited by |
| 907 | a vertical bar ('|') and will appear in the same order they were declared in |
| 908 | the configuration. Common uses for response header captures include the |
| 909 | "Content-length" header which indicates how many bytes are expected to be |
| 910 | returned, the "Location" header to track redirections. |
| 911 | |
| 912 | There is no limit to the number of captured response headers, but each |
| 913 | capture is limited to 64 characters. In order to keep log format consistent |
| 914 | for a same frontend, header captures can only be declared in a frontend. It |
| 915 | is not possible to specify a capture in a "defaults" section. |
| 916 | |
| 917 | Example: |
| 918 | capture response header Content-length len 9 |
| 919 | capture response header Location len 15 |
| 920 | |
| 921 | See also : "capture cookie", "capture request header" as well as section 2.4 |
| 922 | about logging. |
| 923 | |
| 924 | |
| 925 | clitimeout <timeout> |
| 926 | Set the maximum inactivity time on the client side. |
| 927 | May be used in sections : defaults | frontend | listen | backend |
| 928 | yes | yes | yes | no |
| 929 | Arguments : |
| 930 | <timeout> is the timeout value is specified in milliseconds by default, but |
| 931 | can be in any other unit if the number is suffixed by the unit, |
| 932 | as explained at the top of this document. |
| 933 | |
| 934 | The inactivity timeout applies when the client is expected to acknowledge or |
| 935 | send data. In HTTP mode, this timeout is particularly important to consider |
| 936 | during the first phase, when the client sends the request, and during the |
| 937 | response while it is reading data sent by the server. The value is specified |
| 938 | in milliseconds by default, but can be in any other unit if the number is |
| 939 | suffixed by the unit, as specified at the top of this document. In TCP mode |
| 940 | (and to a lesser extent, in HTTP mode), it is highly recommended that the |
| 941 | client timeout remains equal to the server timeout in order to avoid complex |
| 942 | situations to debug. It is a good practise to cover one or several TCP packet |
| 943 | losses by specifying timeouts that are slightly above multiples of 3 seconds |
| 944 | (eg: 4 or 5 seconds). |
| 945 | |
| 946 | This parameter is specific to frontends, but can be specified once for all in |
| 947 | "defaults" sections. This is in fact one of the easiest solutions not to |
| 948 | forget about it. An unspecified timeout results in an infinite timeout, which |
| 949 | is not recommended. Such a usage is accepted and works but reports a warning |
| 950 | during startup because it may results in accumulation of expired sessions in |
| 951 | the system if the system's timeouts are not configured either. |
| 952 | |
| 953 | This parameter is provided for compatibility but is currently deprecated. |
| 954 | Please use "timeout client" instead. |
| 955 | |
Willy Tarreau | 036fae0 | 2008-01-06 13:24:40 +0100 | [diff] [blame^] | 956 | See also : "timeout client", "timeout http-request", "timeout server", and |
| 957 | "srvtimeout". |
Willy Tarreau | 0ba2750 | 2007-12-24 16:55:16 +0100 | [diff] [blame] | 958 | |
| 959 | |
| 960 | contimeout <timeout> |
| 961 | Set the maximum time to wait for a connection attempt to a server to succeed. |
| 962 | May be used in sections : defaults | frontend | listen | backend |
| 963 | yes | no | yes | yes |
| 964 | Arguments : |
| 965 | <timeout> is the timeout value is specified in milliseconds by default, but |
| 966 | can be in any other unit if the number is suffixed by the unit, |
| 967 | as explained at the top of this document. |
| 968 | |
| 969 | If the server is located on the same LAN as haproxy, the connection should be |
| 970 | immediate (less than a few milliseconds). Anyway, it is a good practise to |
| 971 | cover one or several TCP packet losses by specifying timeouts that are |
| 972 | slightly above multiples of 3 seconds (eg: 4 or 5 seconds). By default, the |
| 973 | connect timeout also presets the queue timeout to the same value if this one |
| 974 | has not been specified. Historically, the contimeout was also used to set the |
| 975 | tarpit timeout in a listen section, which is not possible in a pure frontend. |
| 976 | |
| 977 | This parameter is specific to backends, but can be specified once for all in |
| 978 | "defaults" sections. This is in fact one of the easiest solutions not to |
| 979 | forget about it. An unspecified timeout results in an infinite timeout, which |
| 980 | is not recommended. Such a usage is accepted and works but reports a warning |
| 981 | during startup because it may results in accumulation of failed sessions in |
| 982 | the system if the system's timeouts are not configured either. |
| 983 | |
| 984 | This parameter is provided for backwards compatibility but is currently |
| 985 | deprecated. Please use "timeout connect", "timeout queue" or "timeout tarpit" |
| 986 | instead. |
| 987 | |
| 988 | See also : "timeout connect", "timeout queue", "timeout tarpit", |
| 989 | "timeout server", "contimeout". |
| 990 | |
| 991 | |
| 992 | cookie <name> [ rewrite|insert|prefix ] [ indirect ] [ nocache ] [ postonly ] |
| 993 | Enable cookie-based persistence in a backend. |
| 994 | May be used in sections : defaults | frontend | listen | backend |
| 995 | yes | no | yes | yes |
| 996 | Arguments : |
| 997 | <name> is the name of the cookie which will be monitored, modified or |
| 998 | inserted in order to bring persistence. This cookie is sent to |
| 999 | the client via a "Set-Cookie" header in the response, and is |
| 1000 | brought back by the client in a "Cookie" header in all requests. |
| 1001 | Special care should be taken to choose a name which does not |
| 1002 | conflict with any likely application cookie. Also, if the same |
| 1003 | backends are subject to be used by the same clients (eg: |
| 1004 | HTTP/HTTPS), care should be taken to use different cookie names |
| 1005 | between all backends if persistence between them is not desired. |
| 1006 | |
| 1007 | rewrite This keyword indicates that the cookie will be provided by the |
| 1008 | server and that haproxy will have to modify its value to set the |
| 1009 | server's identifier in it. This mode is handy when the management |
| 1010 | of complex combinations of "Set-cookie" and "Cache-control" |
| 1011 | headers is left to the application. The application can then |
| 1012 | decide whether or not it is appropriate to emit a persistence |
| 1013 | cookie. Since all responses should be monitored, this mode only |
| 1014 | works in HTTP close mode. Unless the application behaviour is |
| 1015 | very complex and/or broken, it is advised not to start with this |
| 1016 | mode for new deployments. This keyword is incompatible with |
| 1017 | "insert" and "prefix". |
| 1018 | |
| 1019 | insert This keyword indicates that the persistence cookie will have to |
| 1020 | be inserted by haproxy in the responses. If the server emits a |
| 1021 | cookie with the same name, it will be replaced anyway. For this |
| 1022 | reason, this mode can be used to upgrade existing configurations |
| 1023 | running in the "rewrite" mode. The cookie will only be a session |
| 1024 | cookie and will not be stored on the client's disk. Due to |
| 1025 | caching effects, it is generally wise to add the "indirect" and |
| 1026 | "nocache" or "postonly" keywords (see below). The "insert" |
| 1027 | keyword is not compatible with "rewrite" and "prefix". |
| 1028 | |
| 1029 | prefix This keyword indicates that instead of relying on a dedicated |
| 1030 | cookie for the persistence, an existing one will be completed. |
| 1031 | This may be needed in some specific environments where the client |
| 1032 | does not support more than one single cookie and the application |
| 1033 | already needs it. In this case, whenever the server sets a cookie |
| 1034 | named <name>, it will be prefixed with the server's identifier |
| 1035 | and a delimiter. The prefix will be removed from all client |
| 1036 | requests so that the server still finds the cookie it emitted. |
| 1037 | Since all requests and responses are subject to being modified, |
| 1038 | this mode requires the HTTP close mode. The "prefix" keyword is |
| 1039 | not compatible with "rewrite" and "insert". |
| 1040 | |
| 1041 | indirect When this option is specified in insert mode, cookies will only |
| 1042 | be added when the server was not reached after a direct access, |
| 1043 | which means that only when a server is elected after applying a |
| 1044 | load-balancing algorithm, or after a redispatch, then the cookie |
| 1045 | will be inserted. If the client has all the required information |
| 1046 | to connect to the same server next time, no further cookie will |
| 1047 | be inserted. In all cases, when the "indirect" option is used in |
| 1048 | insert mode, the cookie is always removed from the requests |
| 1049 | transmitted to the server. The persistence mechanism then becomes |
| 1050 | totally transparent from the application point of view. |
| 1051 | |
| 1052 | nocache This option is recommended in conjunction with the insert mode |
| 1053 | when there is a cache between the client and HAProxy, as it |
| 1054 | ensures that a cacheable response will be tagged non-cacheable if |
| 1055 | a cookie needs to be inserted. This is important because if all |
| 1056 | persistence cookies are added on a cacheable home page for |
| 1057 | instance, then all customers will then fetch the page from an |
| 1058 | outer cache and will all share the same persistence cookie, |
| 1059 | leading to one server receiving much more traffic than others. |
| 1060 | See also the "insert" and "postonly" options. |
| 1061 | |
| 1062 | postonly This option ensures that cookie insertion will only be performed |
| 1063 | on responses to POST requests. It is an alternative to the |
| 1064 | "nocache" option, because POST responses are not cacheable, so |
| 1065 | this ensures that the persistence cookie will never get cached. |
| 1066 | Since most sites do not need any sort of persistence before the |
| 1067 | first POST which generally is a login request, this is a very |
| 1068 | efficient method to optimize caching without risking to find a |
| 1069 | persistence cookie in the cache. |
| 1070 | See also the "insert" and "nocache" options. |
| 1071 | |
| 1072 | There can be only one persistence cookie per HTTP backend, and it can be |
| 1073 | declared in a defaults section. The value of the cookie will be the value |
| 1074 | indicated after the "cookie" keyword in a "server" statement. If no cookie |
| 1075 | is declared for a given server, the cookie is not set. |
Willy Tarreau | 6a06a40 | 2007-07-15 20:15:28 +0200 | [diff] [blame] | 1076 | |
Willy Tarreau | 0ba2750 | 2007-12-24 16:55:16 +0100 | [diff] [blame] | 1077 | Examples : |
| 1078 | cookie JSESSIONID prefix |
| 1079 | cookie SRV insert indirect nocache |
| 1080 | cookie SRV insert postonly indirect |
| 1081 | |
| 1082 | See also : "appsession", "balance source", "capture cookie", "server". |
| 1083 | |
| 1084 | |
| 1085 | default_backend <backend> |
| 1086 | Specify the backend to use when no "use_backend" rule has been matched. |
| 1087 | May be used in sections : defaults | frontend | listen | backend |
| 1088 | yes | yes | yes | no |
| 1089 | Arguments : |
| 1090 | <backend> is the name of the backend to use. |
| 1091 | |
| 1092 | When doing content-switching between frontend and backends using the |
| 1093 | "use_backend" keyword, it is often useful to indicate which backend will be |
| 1094 | used when no rule has matched. It generally is the dynamic backend which |
| 1095 | will catch all undetermined requests. |
| 1096 | |
| 1097 | The "default_backend" keyword is also supported in TCP mode frontends to |
| 1098 | facilitate the ordering of configurations in frontends and backends, |
| 1099 | eventhough it does not make much more sense in case of TCP due to the fact |
| 1100 | that use_backend currently does not work in TCP mode. |
| 1101 | |
| 1102 | Example : |
| 1103 | |
| 1104 | use_backend dynamic if url_dyn |
| 1105 | use_backend static if url_css url_img extension_img |
| 1106 | default_backend dynamic |
| 1107 | |
Willy Tarreau | 2769aa0 | 2007-12-27 18:26:09 +0100 | [diff] [blame] | 1108 | See also : "use_backend", "reqsetbe", "reqisetbe" |
| 1109 | |
Willy Tarreau | 0ba2750 | 2007-12-24 16:55:16 +0100 | [diff] [blame] | 1110 | |
| 1111 | disabled |
| 1112 | Disable a proxy, frontend or backend. |
| 1113 | May be used in sections : defaults | frontend | listen | backend |
| 1114 | yes | yes | yes | yes |
| 1115 | Arguments : none |
| 1116 | |
| 1117 | The "disabled" keyword is used to disable an instance, mainly in order to |
| 1118 | liberate a listening port or to temporarily disable a service. The instance |
| 1119 | will still be created and its configuration will be checked, but it will be |
| 1120 | created in the "stopped" state and will appear as such in the statistics. It |
| 1121 | will not receive any traffic nor will it send any health-checks or logs. It |
| 1122 | is possible to disable many instances at once by adding the "disabled" |
| 1123 | keyword in a "defaults" section. |
| 1124 | |
| 1125 | See also : "enabled" |
| 1126 | |
| 1127 | |
| 1128 | enabled |
| 1129 | Enable a proxy, frontend or backend. |
| 1130 | May be used in sections : defaults | frontend | listen | backend |
| 1131 | yes | yes | yes | yes |
| 1132 | Arguments : none |
| 1133 | |
| 1134 | The "enabled" keyword is used to explicitly enable an instance, when the |
| 1135 | defaults has been set to "disabled". This is very rarely used. |
| 1136 | |
| 1137 | See also : "disabled" |
| 1138 | |
| 1139 | |
| 1140 | errorfile <code> <file> |
| 1141 | Return a file contents instead of errors generated by HAProxy |
| 1142 | May be used in sections : defaults | frontend | listen | backend |
| 1143 | yes | yes | yes | yes |
| 1144 | Arguments : |
| 1145 | <code> is the HTTP status code. Currently, HAProxy is capable of |
| 1146 | generating codes 400, 403, 408, 500, 502, 503, and 504. |
| 1147 | |
| 1148 | <file> designates a file containing the full HTTP response. It is |
| 1149 | recommended to follow the common practise of appending ".http" to |
| 1150 | the filename so that people do not confuse the response with HTML |
| 1151 | error pages. |
| 1152 | |
| 1153 | It is important to understand that this keyword is not meant to rewrite |
| 1154 | errors returned by the server, but errors detected and returned by HAProxy. |
| 1155 | This is why the list of supported errors is limited to a small set. |
| 1156 | |
| 1157 | The files are returned verbatim on the TCP socket. This allows any trick such |
| 1158 | as redirections to another URL or site, as well as tricks to clean cookies, |
| 1159 | force enable or disable caching, etc... The package provides default error |
| 1160 | files returning the same contents as default errors. |
| 1161 | |
| 1162 | The files are read at the same time as the configuration and kept in memory. |
| 1163 | For this reason, the errors continue to be returned even when the process is |
| 1164 | chrooted, and no file change is considered while the process is running. A |
Willy Tarreau | c27debf | 2008-01-06 08:57:02 +0100 | [diff] [blame] | 1165 | simple method for developing those files consists in associating them to the |
Willy Tarreau | 0ba2750 | 2007-12-24 16:55:16 +0100 | [diff] [blame] | 1166 | 403 status code and interrogating a blocked URL. |
| 1167 | |
| 1168 | See also : "errorloc", "errorloc302", "errorloc303" |
| 1169 | |
Willy Tarreau | 2769aa0 | 2007-12-27 18:26:09 +0100 | [diff] [blame] | 1170 | |
| 1171 | errorloc <code> <url> |
| 1172 | errorloc302 <code> <url> |
| 1173 | Return an HTTP redirection to a URL instead of errors generated by HAProxy |
| 1174 | May be used in sections : defaults | frontend | listen | backend |
| 1175 | yes | yes | yes | yes |
| 1176 | Arguments : |
| 1177 | <code> is the HTTP status code. Currently, HAProxy is capable of |
| 1178 | generating codes 400, 403, 408, 500, 502, 503, and 504. |
| 1179 | |
| 1180 | <url> it is the exact contents of the "Location" header. It may contain |
| 1181 | either a relative URI to an error page hosted on the same site, |
| 1182 | or an absolute URI designating an error page on another site. |
| 1183 | Special care should be given to relative URIs to avoid redirect |
| 1184 | loops if the URI itself may generate the same error (eg: 500). |
| 1185 | |
| 1186 | It is important to understand that this keyword is not meant to rewrite |
| 1187 | errors returned by the server, but errors detected and returned by HAProxy. |
| 1188 | This is why the list of supported errors is limited to a small set. |
| 1189 | |
| 1190 | Note that both keyword return the HTTP 302 status code, which tells the |
| 1191 | client to fetch the designated URL using the same HTTP method. This can be |
| 1192 | quite problematic in case of non-GET methods such as POST, because the URL |
| 1193 | sent to the client might not be allowed for something other than GET. To |
| 1194 | workaround this problem, please use "errorloc303" which send the HTTP 303 |
| 1195 | status code, indicating to the client that the URL must be fetched with a GET |
| 1196 | request. |
| 1197 | |
| 1198 | See also : "errorfile", "errorloc303" |
| 1199 | |
| 1200 | |
| 1201 | errorloc303 <code> <url> |
| 1202 | Return an HTTP redirection to a URL instead of errors generated by HAProxy |
| 1203 | May be used in sections : defaults | frontend | listen | backend |
| 1204 | yes | yes | yes | yes |
| 1205 | Arguments : |
| 1206 | <code> is the HTTP status code. Currently, HAProxy is capable of |
| 1207 | generating codes 400, 403, 408, 500, 502, 503, and 504. |
| 1208 | |
| 1209 | <url> it is the exact contents of the "Location" header. It may contain |
| 1210 | either a relative URI to an error page hosted on the same site, |
| 1211 | or an absolute URI designating an error page on another site. |
| 1212 | Special care should be given to relative URIs to avoid redirect |
| 1213 | loops if the URI itself may generate the same error (eg: 500). |
| 1214 | |
| 1215 | It is important to understand that this keyword is not meant to rewrite |
| 1216 | errors returned by the server, but errors detected and returned by HAProxy. |
| 1217 | This is why the list of supported errors is limited to a small set. |
| 1218 | |
| 1219 | Note that both keyword return the HTTP 303 status code, which tells the |
| 1220 | client to fetch the designated URL using the same HTTP GET method. This |
| 1221 | solves the usual problems associated with "errorloc" and the 302 code. It is |
| 1222 | possible that some very old browsers designed before HTTP/1.1 do not support |
| 1223 | it, but no such problem have been reported till now. |
| 1224 | |
| 1225 | See also : "errorfile", "errorloc", "errorloc302" |
| 1226 | |
| 1227 | |
| 1228 | fullconn <conns> |
| 1229 | Specify at what backend load the servers will reach their maxconn |
| 1230 | May be used in sections : defaults | frontend | listen | backend |
| 1231 | yes | no | yes | yes |
| 1232 | Arguments : |
| 1233 | <conns> is the number of connections on the backend which will make the |
| 1234 | servers use the maximal number of connections. |
| 1235 | |
| 1236 | When a server has a 'maxconn' parameter specified, it means that its number |
| 1237 | of concurrent connections will never go higher. Additionally, if it has a |
| 1238 | 'minconn' parameter, it indicates a dynamic limit following the backend's |
| 1239 | load. The server will then always accept at least <minconn> connections, |
| 1240 | never more than <maxconn>, and the limit will be on the ramp between both |
| 1241 | values when the backend has less than <conns> concurrent connections. This |
| 1242 | makes it possible to limit the load on the servers during normal loads, but |
| 1243 | push it further for important loads without overloading the servers during |
| 1244 | exceptionnal loads. |
| 1245 | |
| 1246 | Example : |
| 1247 | # The servers will accept between 100 and 1000 concurrent connections each |
| 1248 | # and the maximum of 1000 will be reached when the backend reaches 10000 |
| 1249 | # connections. |
| 1250 | backend dynamic |
| 1251 | fullconn 10000 |
| 1252 | server srv1 dyn1:80 minconn 100 maxconn 1000 |
| 1253 | server srv2 dyn2:80 minconn 100 maxconn 1000 |
| 1254 | |
| 1255 | See also : "maxconn", "server" |
| 1256 | |
| 1257 | |
| 1258 | grace <time> |
| 1259 | Maintain a proxy operational for some time after a soft stop |
| 1260 | May be used in sections : defaults | frontend | listen | backend |
| 1261 | no | yes | yes | yes |
| 1262 | Arguments : |
| 1263 | <time> is the time (by default in milliseconds) for which the instance |
| 1264 | will remain operational with the frontend sockets still listening |
| 1265 | when a soft-stop is received via the SIGUSR1 signal. |
| 1266 | |
| 1267 | This may be used to ensure that the services disappear in a certain order. |
| 1268 | This was designed so that frontends which are dedicated to monitoring by an |
| 1269 | external equipement fail immediately while other ones remain up for the time |
| 1270 | needed by the equipment to detect the failure. |
| 1271 | |
| 1272 | Note that currently, there is very little benefit in using this parameter, |
| 1273 | and it may in fact complicate the soft-reconfiguration process more than |
| 1274 | simplify it. |
| 1275 | |
Willy Tarreau | 0ba2750 | 2007-12-24 16:55:16 +0100 | [diff] [blame] | 1276 | |
| 1277 | http-check disable-on-404 |
| 1278 | Enable a maintenance mode upon HTTP/404 response to health-checks |
| 1279 | May be used in sections : defaults | frontend | listen | backend |
Willy Tarreau | 2769aa0 | 2007-12-27 18:26:09 +0100 | [diff] [blame] | 1280 | yes | no | yes | yes |
Willy Tarreau | 0ba2750 | 2007-12-24 16:55:16 +0100 | [diff] [blame] | 1281 | Arguments : none |
| 1282 | |
| 1283 | When this option is set, a server which returns an HTTP code 404 will be |
| 1284 | excluded from further load-balancing, but will still receive persistent |
| 1285 | connections. This provides a very convenient method for Web administrators |
| 1286 | to perform a graceful shutdown of their servers. It is also important to note |
| 1287 | that a server which is detected as failed while it was in this mode will not |
| 1288 | generate an alert, just a notice. If the server responds 2xx or 3xx again, it |
| 1289 | will immediately be reinserted into the farm. The status on the stats page |
| 1290 | reports "NOLB" for a server in this mode. It is important to note that this |
| 1291 | option only works in conjunction with the "httpchk" option. |
| 1292 | |
Willy Tarreau | 2769aa0 | 2007-12-27 18:26:09 +0100 | [diff] [blame] | 1293 | See also : "option httpchk" |
| 1294 | |
| 1295 | |
| 1296 | log global |
| 1297 | log <address> <facility> [<level>] |
| 1298 | Enable per-instance logging of events and traffic. |
| 1299 | May be used in sections : defaults | frontend | listen | backend |
| 1300 | yes | yes | yes | yes |
| 1301 | Arguments : |
| 1302 | global should be used when the instance's logging parameters are the |
| 1303 | same as the global ones. This is the most common usage. "global" |
| 1304 | replaces <address>, <facility> and <level> with those of the log |
| 1305 | entries found in the "global" section. Only one "log global" |
| 1306 | statement may be used per instance, and this form takes no other |
| 1307 | parameter. |
| 1308 | |
| 1309 | <address> indicates where to send the logs. It takes the same format as |
| 1310 | for the "global" section's logs, and can be one of : |
| 1311 | |
| 1312 | - An IPv4 address optionally followed by a colon (':') and a UDP |
| 1313 | port. If no port is specified, 514 is used by default (the |
| 1314 | standard syslog port). |
| 1315 | |
| 1316 | - A filesystem path to a UNIX domain socket, keeping in mind |
| 1317 | considerations for chroot (be sure the path is accessible |
| 1318 | inside the chroot) and uid/gid (be sure the path is |
| 1319 | appropriately writeable). |
| 1320 | |
| 1321 | <facility> must be one of the 24 standard syslog facilities : |
| 1322 | |
| 1323 | kern user mail daemon auth syslog lpr news |
| 1324 | uucp cron auth2 ftp ntp audit alert cron2 |
| 1325 | local0 local1 local2 local3 local4 local5 local6 local7 |
| 1326 | |
| 1327 | <level> is optional and can be specified to filter outgoing messages. By |
| 1328 | default, all messages are sent. If a level is specified, only |
| 1329 | messages with a severity at least as important as this level |
| 1330 | will be sent. 8 levels are known : |
| 1331 | |
| 1332 | emerg alert crit err warning notice info debug |
| 1333 | |
| 1334 | Note that up to two "log" entries may be specified per instance. However, if |
| 1335 | "log global" is used and if the "global" section already contains 2 log |
| 1336 | entries, then additional log entries will be ignored. |
| 1337 | |
| 1338 | Also, it is important to keep in mind that it is the frontend which decides |
| 1339 | what to log, and that in case of content switching, the log entries from the |
| 1340 | backend will be ignored. |
| 1341 | |
| 1342 | Example : |
| 1343 | log global |
| 1344 | log 127.0.0.1:514 local0 notice |
| 1345 | |
| 1346 | |
| 1347 | maxconn <conns> |
| 1348 | Fix the maximum number of concurrent connections on a frontend |
| 1349 | May be used in sections : defaults | frontend | listen | backend |
| 1350 | yes | yes | yes | no |
| 1351 | Arguments : |
| 1352 | <conns> is the maximum number of concurrent connections the frontend will |
| 1353 | accept to serve. Excess connections will be queued by the system |
| 1354 | in the socket's listen queue and will be served once a connection |
| 1355 | closes. |
| 1356 | |
| 1357 | If the system supports it, it can be useful on big sites to raise this limit |
| 1358 | very high so that haproxy manages connection queues, instead of leaving the |
| 1359 | clients with unanswered connection attempts. This value should not exceed the |
| 1360 | global maxconn. Also, keep in mind that a connection contains two buffers |
| 1361 | of 8kB each, as well as some other data resulting in about 17 kB of RAM being |
| 1362 | consumed per established connection. That means that a medium system equipped |
| 1363 | with 1GB of RAM can withstand around 40000-50000 concurrent connections if |
| 1364 | properly tuned. |
| 1365 | |
| 1366 | Also, when <conns> is set to large values, it is possible that the servers |
| 1367 | are not sized to accept such loads, and for this reason it is generally wise |
| 1368 | to assign them some reasonable connection limits. |
| 1369 | |
| 1370 | See also : "server", global section's "maxconn", "fullconn" |
| 1371 | |
| 1372 | |
| 1373 | mode { tcp|http|health } |
| 1374 | Set the running mode or protocol of the instance |
| 1375 | May be used in sections : defaults | frontend | listen | backend |
| 1376 | yes | yes | yes | yes |
| 1377 | Arguments : |
| 1378 | tcp The instance will work in pure TCP mode. A full-duplex connection |
| 1379 | will be established between clients and servers, and no layer 7 |
| 1380 | examination will be performed. This is the default mode. It |
| 1381 | should be used for SSL, SSH, SMTP, ... |
| 1382 | |
| 1383 | http The instance will work in HTTP mode. The client request will be |
| 1384 | analyzed in depth before connecting to any server. Any request |
| 1385 | which is not RFC-compliant will be rejected. Layer 7 filtering, |
| 1386 | processing and switching will be possible. This is the mode which |
| 1387 | brings HAProxy most of its value. |
| 1388 | |
| 1389 | health The instance will work in "health" mode. It will just reply "OK" |
| 1390 | to incoming connections and close the connection. Nothing will be |
| 1391 | logged. This mode is used to reply to external components health |
| 1392 | checks. This mode is deprecated and should not be used anymore as |
| 1393 | it is possible to do the same and even better by combining TCP or |
| 1394 | HTTP modes with the "monitor" keyword. |
| 1395 | |
| 1396 | When doing content switching, it is mandatory that the frontend and the |
| 1397 | backend are in the same mode (generally HTTP), otherwise the configuration |
| 1398 | will be refused. |
| 1399 | |
| 1400 | Example : |
| 1401 | defaults http_instances |
| 1402 | mode http |
| 1403 | |
| 1404 | See also : "monitor", "monitor-net" |
| 1405 | |
Willy Tarreau | 0ba2750 | 2007-12-24 16:55:16 +0100 | [diff] [blame] | 1406 | |
| 1407 | monitor fail [if | unless] <condition> |
Willy Tarreau | 2769aa0 | 2007-12-27 18:26:09 +0100 | [diff] [blame] | 1408 | Add a condition to report a failure to a monitor HTTP request. |
Willy Tarreau | 0ba2750 | 2007-12-24 16:55:16 +0100 | [diff] [blame] | 1409 | May be used in sections : defaults | frontend | listen | backend |
| 1410 | no | yes | yes | no |
Willy Tarreau | 0ba2750 | 2007-12-24 16:55:16 +0100 | [diff] [blame] | 1411 | Arguments : |
| 1412 | if <cond> the monitor request will fail if the condition is satisfied, |
| 1413 | and will succeed otherwise. The condition should describe a |
| 1414 | combinated test which must induce a failure if all conditions |
| 1415 | are met, for instance a low number of servers both in a |
| 1416 | backend and its backup. |
| 1417 | |
| 1418 | unless <cond> the monitor request will succeed only if the condition is |
| 1419 | satisfied, and will fail otherwise. Such a condition may be |
| 1420 | based on a test on the presence of a minimum number of active |
| 1421 | servers in a list of backends. |
| 1422 | |
| 1423 | This statement adds a condition which can force the response to a monitor |
| 1424 | request to report a failure. By default, when an external component queries |
| 1425 | the URI dedicated to monitoring, a 200 response is returned. When one of the |
| 1426 | conditions above is met, haproxy will return 503 instead of 200. This is |
| 1427 | very useful to report a site failure to an external component which may base |
| 1428 | routing advertisements between multiple sites on the availability reported by |
| 1429 | haproxy. In this case, one would rely on an ACL involving the "nbsrv" |
Willy Tarreau | 2769aa0 | 2007-12-27 18:26:09 +0100 | [diff] [blame] | 1430 | criterion. Note that "monitor fail" only works in HTTP mode. |
Willy Tarreau | 0ba2750 | 2007-12-24 16:55:16 +0100 | [diff] [blame] | 1431 | |
| 1432 | Example: |
| 1433 | frontend www |
Willy Tarreau | 2769aa0 | 2007-12-27 18:26:09 +0100 | [diff] [blame] | 1434 | mode http |
Willy Tarreau | 0ba2750 | 2007-12-24 16:55:16 +0100 | [diff] [blame] | 1435 | acl site_dead nbsrv(dynamic) lt 2 |
| 1436 | acl site_dead nbsrv(static) lt 2 |
| 1437 | monitor-uri /site_alive |
| 1438 | monitor fail if site_dead |
| 1439 | |
Willy Tarreau | 2769aa0 | 2007-12-27 18:26:09 +0100 | [diff] [blame] | 1440 | See also : "monitor-net", "monitor-uri" |
| 1441 | |
| 1442 | |
| 1443 | monitor-net <source> |
| 1444 | Declare a source network which is limited to monitor requests |
| 1445 | May be used in sections : defaults | frontend | listen | backend |
| 1446 | yes | yes | yes | no |
| 1447 | Arguments : |
| 1448 | <source> is the source IPv4 address or network which will only be able to |
| 1449 | get monitor responses to any request. It can be either an IPv4 |
| 1450 | address, a host name, or an address followed by a slash ('/') |
| 1451 | followed by a mask. |
| 1452 | |
| 1453 | In TCP mode, any connection coming from a source matching <source> will cause |
| 1454 | the connection to be immediately closed without any log. This allows another |
| 1455 | equipement to probe the port and verify that it is still listening, without |
| 1456 | forwarding the connection to a remote server. |
| 1457 | |
| 1458 | In HTTP mode, a connection coming from a source matching <source> will be |
| 1459 | accepted, the following response will be sent without waiting for a request, |
| 1460 | then the connection will be closed : "HTTP/1.0 200 OK". This is normally |
| 1461 | enough for any front-end HTTP probe to detect that the service is UP and |
| 1462 | running without forwarding the request to a backend server. |
| 1463 | |
| 1464 | Monitor requests are processed very early. It is not possible to block nor |
| 1465 | divert them using ACLs. They cannot be logged either, and it is the intended |
| 1466 | purpose. They are only used to report HAProxy's health to an upper component, |
| 1467 | nothing more. Right now, it is not possible to set failure conditions on |
| 1468 | requests caught by "monitor-net". |
| 1469 | |
| 1470 | Example : |
| 1471 | # addresses .252 and .253 are just probing us. |
| 1472 | frontend www |
| 1473 | monitor-net 192.168.0.252/31 |
| 1474 | |
| 1475 | See also : "monitor fail", "monitor-uri" |
| 1476 | |
| 1477 | |
| 1478 | monitor-uri <uri> |
| 1479 | Intercept a URI used by external components' monitor requests |
| 1480 | May be used in sections : defaults | frontend | listen | backend |
| 1481 | yes | yes | yes | no |
| 1482 | Arguments : |
| 1483 | <uri> is the exact URI which we want to intercept to return HAProxy's |
| 1484 | health status instead of forwarding the request. |
| 1485 | |
| 1486 | When an HTTP request referencing <uri> will be received on a frontend, |
| 1487 | HAProxy will not forward it nor log it, but instead will return either |
| 1488 | "HTTP/1.0 200 OK" or "HTTP/1.0 503 Service unavailable", depending on failure |
| 1489 | conditions defined with "monitor fail". This is normally enough for any |
| 1490 | front-end HTTP probe to detect that the service is UP and running without |
| 1491 | forwarding the request to a backend server. Note that the HTTP method, the |
| 1492 | version and all headers are ignored, but the request must at least be valid |
| 1493 | at the HTTP level. This keyword may only be used with an HTTP-mode frontend. |
| 1494 | |
| 1495 | Monitor requests are processed very early. It is not possible to block nor |
| 1496 | divert them using ACLs. They cannot be logged either, and it is the intended |
| 1497 | purpose. They are only used to report HAProxy's health to an upper component, |
| 1498 | nothing more. However, it is possible to add any number of conditions using |
| 1499 | "monitor fail" and ACLs so that the result can be adjusted to whatever check |
| 1500 | can be imagined (most often the number of available servers in a backend). |
| 1501 | |
| 1502 | Example : |
| 1503 | # Use /haproxy_test to report haproxy's status |
| 1504 | frontend www |
| 1505 | mode http |
| 1506 | monitor-uri /haproxy_test |
| 1507 | |
| 1508 | See also : "monitor fail", "monitor-net" |
| 1509 | |
Willy Tarreau | 0ba2750 | 2007-12-24 16:55:16 +0100 | [diff] [blame] | 1510 | |
Willy Tarreau | bf1f816 | 2007-12-28 17:42:56 +0100 | [diff] [blame] | 1511 | option abortonclose |
| 1512 | no option abortonclose |
| 1513 | Enable or disable early dropping of aborted requests pending in queues. |
| 1514 | May be used in sections : defaults | frontend | listen | backend |
| 1515 | yes | no | yes | yes |
| 1516 | Arguments : none |
| 1517 | |
| 1518 | In presence of very high loads, the servers will take some time to respond. |
| 1519 | The per-instance connection queue will inflate, and the response time will |
| 1520 | increase respective to the size of the queue times the average per-session |
| 1521 | response time. When clients will wait for more than a few seconds, they will |
| 1522 | often hit the 'STOP' button on their browser, leaving a useless request in |
| 1523 | the queue, and slowing down other users, and the servers as well, because the |
| 1524 | request will eventually be served, then aborted at the first error |
| 1525 | encountered while delivering the response. |
| 1526 | |
| 1527 | As there is no way to distinguish between a full STOP and a simple output |
| 1528 | close on the client side, HTTP agents should be conservative and consider |
| 1529 | that the client might only have closed its output channel while waiting for |
| 1530 | the response. However, this introduces risks of congestion when lots of users |
| 1531 | do the same, and is completely useless nowadays because probably no client at |
| 1532 | all will close the session while waiting for the response. Some HTTP agents |
| 1533 | support this behaviour (Squid, Apache, HAProxy), and others do not (TUX, most |
| 1534 | hardware-based load balancers). So the probability for a closed input channel |
| 1535 | to represent a user hitting the 'STOP' button is close to 100%, and the risk |
| 1536 | of being the single component to break rare but valid traffic is extremely |
| 1537 | low, which adds to the temptation to be able to abort a session early while |
| 1538 | still not served and not pollute the servers. |
| 1539 | |
| 1540 | In HAProxy, the user can choose the desired behaviour using the option |
| 1541 | "abortonclose". By default (without the option) the behaviour is HTTP |
| 1542 | compliant and aborted requests will be served. But when the option is |
| 1543 | specified, a session with an incoming channel closed will be aborted while |
| 1544 | it is still possible, either pending in the queue for a connection slot, or |
| 1545 | during the connection establishment if the server has not yet acknowledged |
| 1546 | the connection request. This considerably reduces the queue size and the load |
| 1547 | on saturated servers when users are tempted to click on STOP, which in turn |
| 1548 | reduces the response time for other users. |
| 1549 | |
| 1550 | If this option has been enabled in a "defaults" section, it can be disabled |
| 1551 | in a specific instance by prepending the "no" keyword before it. |
| 1552 | |
| 1553 | See also : "timeout queue" and server's "maxconn" and "maxqueue" parameters |
| 1554 | |
| 1555 | |
| 1556 | option allbackups |
| 1557 | no option allbackups |
| 1558 | Use either all backup servers at a time or only the first one |
| 1559 | May be used in sections : defaults | frontend | listen | backend |
| 1560 | yes | no | yes | yes |
| 1561 | Arguments : none |
| 1562 | |
| 1563 | By default, the first operational backup server gets all traffic when normal |
| 1564 | servers are all down. Sometimes, it may be preferred to use multiple backups |
| 1565 | at once, because one will not be enough. When "option allbackups" is enabled, |
| 1566 | the load balancing will be performed among all backup servers when all normal |
| 1567 | ones are unavailable. The same load balancing algorithm will be used and the |
| 1568 | servers' weights will be respected. Thus, there will not be any priority |
| 1569 | order between the backup servers anymore. |
| 1570 | |
| 1571 | This option is mostly used with static server farms dedicated to return a |
| 1572 | "sorry" page when an application is completely offline. |
| 1573 | |
| 1574 | If this option has been enabled in a "defaults" section, it can be disabled |
| 1575 | in a specific instance by prepending the "no" keyword before it. |
| 1576 | |
| 1577 | |
| 1578 | option checkcache |
| 1579 | no option checkcache |
| 1580 | Analyze all server responses and block requests with cachable cookies |
| 1581 | May be used in sections : defaults | frontend | listen | backend |
| 1582 | yes | no | yes | yes |
| 1583 | Arguments : none |
| 1584 | |
| 1585 | Some high-level frameworks set application cookies everywhere and do not |
| 1586 | always let enough control to the developer to manage how the responses should |
| 1587 | be cached. When a session cookie is returned on a cachable object, there is a |
| 1588 | high risk of session crossing or stealing between users traversing the same |
| 1589 | caches. In some situations, it is better to block the response than to let |
| 1590 | some sensible session information go in the wild. |
| 1591 | |
| 1592 | The option "checkcache" enables deep inspection of all server responses for |
| 1593 | strict compliance with HTTP specification in terms of cachability. It |
| 1594 | carefully checks 'Cache-control', 'Pragma' and 'Set-cookie' headers in server |
| 1595 | response to check if there's a risk of caching a cookie on a client-side |
| 1596 | proxy. When this option is enabled, the only responses which can be delivered |
| 1597 | to the client are : |
| 1598 | - all those without 'Set-Cookie' header ; |
| 1599 | - all those with a return code other than 200, 203, 206, 300, 301, 410, |
| 1600 | provided that the server has not set a 'Cache-control: public' header ; |
| 1601 | - all those that come from a POST request, provided that the server has not |
| 1602 | set a 'Cache-Control: public' header ; |
| 1603 | - those with a 'Pragma: no-cache' header |
| 1604 | - those with a 'Cache-control: private' header |
| 1605 | - those with a 'Cache-control: no-store' header |
| 1606 | - those with a 'Cache-control: max-age=0' header |
| 1607 | - those with a 'Cache-control: s-maxage=0' header |
| 1608 | - those with a 'Cache-control: no-cache' header |
| 1609 | - those with a 'Cache-control: no-cache="set-cookie"' header |
| 1610 | - those with a 'Cache-control: no-cache="set-cookie,' header |
| 1611 | (allowing other fields after set-cookie) |
| 1612 | |
| 1613 | If a response doesn't respect these requirements, then it will be blocked |
| 1614 | just as if it was from an 'rspdeny' filter, with an "HTTP 502 bad gateway". |
| 1615 | The session state shows "PH--" meaning that the proxy blocked the response |
| 1616 | during headers processing. Additionnaly, an alert will be sent in the logs so |
| 1617 | that admins are informed that there's something to be fixed. |
| 1618 | |
| 1619 | Due to the high impact on the application, the application should be tested |
| 1620 | in depth with the option enabled before going to production. It is also a |
| 1621 | good practise to always activate it during tests, even if it is not used in |
| 1622 | production, as it will report potentially dangerous application behaviours. |
| 1623 | |
| 1624 | If this option has been enabled in a "defaults" section, it can be disabled |
| 1625 | in a specific instance by prepending the "no" keyword before it. |
| 1626 | |
| 1627 | |
| 1628 | option clitcpka |
| 1629 | no option clitcpka |
| 1630 | Enable or disable the sending of TCP keepalive packets on the client side |
| 1631 | May be used in sections : defaults | frontend | listen | backend |
| 1632 | yes | yes | yes | no |
| 1633 | Arguments : none |
| 1634 | |
| 1635 | When there is a firewall or any session-aware component between a client and |
| 1636 | a server, and when the protocol involves very long sessions with long idle |
| 1637 | periods (eg: remote desktops), there is a risk that one of the intermediate |
| 1638 | components decides to expire a session which has remained idle for too long. |
| 1639 | |
| 1640 | Enabling socket-level TCP keep-alives makes the system regularly send packets |
| 1641 | to the other end of the connection, leaving it active. The delay between |
| 1642 | keep-alive probes is controlled by the system only and depends both on the |
| 1643 | operating system and its tuning parameters. |
| 1644 | |
| 1645 | It is important to understand that keep-alive packets are neither emitted nor |
| 1646 | received at the application level. It is only the network stacks which sees |
| 1647 | them. For this reason, even if one side of the proxy already uses keep-alives |
| 1648 | to maintain its connection alive, those keep-alive packets will not be |
| 1649 | forwarded to the other side of the proxy. |
| 1650 | |
| 1651 | Please note that this has nothing to do with HTTP keep-alive. |
| 1652 | |
| 1653 | Using option "clitcpka" enables the emission of TCP keep-alive probes on the |
| 1654 | client side of a connection, which should help when session expirations are |
| 1655 | noticed between HAProxy and a client. |
| 1656 | |
| 1657 | If this option has been enabled in a "defaults" section, it can be disabled |
| 1658 | in a specific instance by prepending the "no" keyword before it. |
| 1659 | |
| 1660 | See also : "option srvtcpka", "option tcpka" |
| 1661 | |
| 1662 | |
Willy Tarreau | 0ba2750 | 2007-12-24 16:55:16 +0100 | [diff] [blame] | 1663 | option contstats |
| 1664 | Enable continuous traffic statistics updates |
| 1665 | May be used in sections : defaults | frontend | listen | backend |
| 1666 | yes | yes | yes | no |
| 1667 | Arguments : none |
| 1668 | |
| 1669 | By default, counters used for statistics calculation are incremented |
| 1670 | only when a session finishes. It works quite well when serving small |
| 1671 | objects, but with big ones (for example large images or archives) or |
| 1672 | with A/V streaming, a graph generated from haproxy counters looks like |
| 1673 | a hedgehog. With this option enabled counters get incremented continuously, |
| 1674 | during a whole session. Recounting touches a hotpath directly so |
| 1675 | it is not enabled by default, as it has small performance impact (~0.5%). |
| 1676 | |
| 1677 | |
Willy Tarreau | bf1f816 | 2007-12-28 17:42:56 +0100 | [diff] [blame] | 1678 | option dontlognull |
| 1679 | no option dontlognull |
| 1680 | Enable or disable logging of null connections |
| 1681 | May be used in sections : defaults | frontend | listen | backend |
| 1682 | yes | yes | yes | no |
| 1683 | Arguments : none |
| 1684 | |
| 1685 | In certain environments, there are components which will regularly connect to |
| 1686 | various systems to ensure that they are still alive. It can be the case from |
| 1687 | another load balancer as well as from monitoring systems. By default, even a |
| 1688 | simple port probe or scan will produce a log. If those connections pollute |
| 1689 | the logs too much, it is possible to enable option "dontlognull" to indicate |
| 1690 | that a connection on which no data has been transferred will not be logged, |
| 1691 | which typically corresponds to those probes. |
| 1692 | |
| 1693 | It is generally recommended not to use this option in uncontrolled |
| 1694 | environments (eg: internet), otherwise scans and other malicious activities |
| 1695 | would not be logged. |
| 1696 | |
| 1697 | If this option has been enabled in a "defaults" section, it can be disabled |
| 1698 | in a specific instance by prepending the "no" keyword before it. |
| 1699 | |
Willy Tarreau | c27debf | 2008-01-06 08:57:02 +0100 | [diff] [blame] | 1700 | See also : "log", "monitor-net", "monitor-uri" and section 2.4 about logging. |
Willy Tarreau | bf1f816 | 2007-12-28 17:42:56 +0100 | [diff] [blame] | 1701 | |
| 1702 | |
| 1703 | option forceclose |
| 1704 | no option forceclose |
| 1705 | Enable or disable active connection closing after response is transferred. |
| 1706 | May be used in sections : defaults | frontend | listen | backend |
| 1707 | yes | no | yes | yes |
| 1708 | Arguments : none |
| 1709 | |
| 1710 | Some HTTP servers do not necessarily close the connections when they receive |
| 1711 | the "Connection: close" set by "option httpclose", and if the client does not |
| 1712 | close either, then the connection remains open till the timeout expires. This |
| 1713 | causes high number of simultaneous connections on the servers and shows high |
| 1714 | global session times in the logs. |
| 1715 | |
| 1716 | When this happens, it is possible to use "option forceclose". It will |
| 1717 | actively close the outgoing server channel as soon as the server begins to |
| 1718 | reply and only if the request buffer is empty. Note that this should NOT be |
| 1719 | used if CONNECT requests are expected between the client and the server. This |
| 1720 | option implicitly enables the "httpclose" option. |
| 1721 | |
| 1722 | If this option has been enabled in a "defaults" section, it can be disabled |
| 1723 | in a specific instance by prepending the "no" keyword before it. |
| 1724 | |
| 1725 | See also : "option httpclose" |
| 1726 | |
| 1727 | |
Willy Tarreau | c27debf | 2008-01-06 08:57:02 +0100 | [diff] [blame] | 1728 | option forwardfor [ except <network> ] |
| 1729 | Enable insertion of the X-Forwarded-For header to requests sent to servers |
| 1730 | May be used in sections : defaults | frontend | listen | backend |
| 1731 | yes | yes | yes | yes |
| 1732 | Arguments : |
| 1733 | <network> is an optional argument used to disable this option for sources |
| 1734 | matching <network> |
| 1735 | |
| 1736 | Since HAProxy works in reverse-proxy mode, the servers see its IP address as |
| 1737 | their client address. This is sometimes annoying when the client's IP address |
| 1738 | is expected in server logs. To solve this problem, the well-known HTTP header |
| 1739 | "X-Forwarded-For" may be added by HAProxy to all requests sent to the server. |
| 1740 | This header contains a value representing the client's IP address. Since this |
| 1741 | header is always appended at the end of the existing header list, the server |
| 1742 | must be configured to always use the last occurrence of this header only. See |
| 1743 | the server's manual to find how to enable use of this standard header. |
| 1744 | |
| 1745 | Sometimes, a same HAProxy instance may be shared between a direct client |
| 1746 | access and a reverse-proxy access (for instance when an SSL reverse-proxy is |
| 1747 | used to decrypt HTTPS traffic). It is possible to disable the addition of the |
| 1748 | header for a known source address or network by adding the "except" keyword |
| 1749 | followed by the network address. In this case, any source IP matching the |
| 1750 | network will not cause an addition of this header. Most common uses are with |
| 1751 | private networks or 127.0.0.1. |
| 1752 | |
| 1753 | This option may be specified either in the frontend or in the backend. If at |
| 1754 | least one of them uses it, the header will be added. |
| 1755 | |
| 1756 | It is important to note that as long as HAProxy does not support keep-alive |
| 1757 | connections, only the first request of a connection will receive the header. |
| 1758 | For this reason, it is important to ensure that "option httpclose" is set |
| 1759 | when using this option. |
| 1760 | |
| 1761 | Example : |
| 1762 | # Public HTTP address also used by stunnel on the same machine |
| 1763 | frontend www |
| 1764 | mode http |
| 1765 | option forwardfor except 127.0.0.1 # stunnel already adds the header |
| 1766 | |
| 1767 | See also : "option httpclose" |
| 1768 | |
| 1769 | |
| 1770 | option http_proxy |
| 1771 | no option http_proxy |
| 1772 | Enable or disable plain HTTP proxy mode |
| 1773 | May be used in sections : defaults | frontend | listen | backend |
| 1774 | yes | yes | yes | yes |
| 1775 | Arguments : none |
| 1776 | |
| 1777 | It sometimes happens that people need a pure HTTP proxy which understands |
| 1778 | basic proxy requests without caching nor any fancy feature. In this case, |
| 1779 | it may be worth setting up an HAProxy instance with the "option http_proxy" |
| 1780 | set. In this mode, no server is declared, and the connection is forwarded to |
| 1781 | the IP address and port found in the URL after the "http://" scheme. |
| 1782 | |
| 1783 | No host address resolution is performed, so this only works when pure IP |
| 1784 | addresses are passed. Since this option's usage perimeter is rather limited, |
| 1785 | it will probably be used only by experts who know they need exactly it. Last, |
| 1786 | if the clients are susceptible of sending keep-alive requests, it will be |
| 1787 | needed to add "option http_close" to ensure that all requests will correctly |
| 1788 | be analyzed. |
| 1789 | |
| 1790 | If this option has been enabled in a "defaults" section, it can be disabled |
| 1791 | in a specific instance by prepending the "no" keyword before it. |
| 1792 | |
| 1793 | Example : |
| 1794 | # this backend understands HTTP proxy requests and forwards them directly. |
| 1795 | backend direct_forward |
| 1796 | option httpclose |
| 1797 | option http_proxy |
| 1798 | |
| 1799 | See also : "option httpclose" |
| 1800 | |
| 1801 | |
| 1802 | option httpchk |
| 1803 | option httpchk <uri> |
| 1804 | option httpchk <method> <uri> |
| 1805 | option httpchk <method> <uri> <version> |
| 1806 | Enable HTTP protocol to check on the servers health |
| 1807 | May be used in sections : defaults | frontend | listen | backend |
| 1808 | yes | no | yes | yes |
| 1809 | Arguments : |
| 1810 | <method> is the optional HTTP method used with the requests. When not set, |
| 1811 | the "OPTIONS" method is used, as it generally requires low server |
| 1812 | processing and is easy to filter out from the logs. Any method |
| 1813 | may be used, though it is not recommended to invent non-standard |
| 1814 | ones. |
| 1815 | |
| 1816 | <uri> is the URI referenced in the HTTP requests. It defaults to " / " |
| 1817 | which is accessible by default on almost any server, but may be |
| 1818 | changed to any other URI. Query strings are permitted. |
| 1819 | |
| 1820 | <version> is the optional HTTP version string. It defaults to "HTTP/1.0" |
| 1821 | but some servers might behave incorrectly in HTTP 1.0, so turning |
| 1822 | it to HTTP/1.1 may sometimes help. Note that the Host field is |
| 1823 | mandatory in HTTP/1.1, and as a trick, it is possible to pass it |
| 1824 | after "\r\n" following the version string. |
| 1825 | |
| 1826 | By default, server health checks only consist in trying to establish a TCP |
| 1827 | connection. When "option httpchk" is specified, a complete HTTP request is |
| 1828 | sent once the TCP connection is established, and responses 2xx and 3xx are |
| 1829 | considered valid, while all other ones indicate a server failure, including |
| 1830 | the lack of any response. |
| 1831 | |
| 1832 | The port and interval are specified in the server configuration. |
| 1833 | |
| 1834 | This option does not necessarily require an HTTP backend, it also works with |
| 1835 | plain TCP backends. This is particularly useful to check simple scripts bound |
| 1836 | to some dedicated ports using the inetd daemon. |
| 1837 | |
| 1838 | Examples : |
| 1839 | # Relay HTTPS traffic to Apache instance and check service availability |
| 1840 | # using HTTP request "OPTIONS * HTTP/1.1" on port 80. |
| 1841 | backend https_relay |
| 1842 | mode tcp |
| 1843 | option httpchk OPTIONS * HTTP/1.1\r\nHost: www |
| 1844 | server apache1 192.168.1.1:443 check port 80 |
| 1845 | |
| 1846 | See also : "option ssl-hello-chk", "option smtpchk", "http-check" and the |
| 1847 | "check", "port" and "interval" server options. |
| 1848 | |
| 1849 | |
| 1850 | option httpclose |
| 1851 | no option httpclose |
| 1852 | Enable or disable passive HTTP connection closing |
| 1853 | May be used in sections : defaults | frontend | listen | backend |
| 1854 | yes | yes | yes | yes |
| 1855 | Arguments : none |
| 1856 | |
| 1857 | As stated in section 2.1, HAProxy does not yes support the HTTP keep-alive |
| 1858 | mode. So by default, if a client communicates with a server in this mode, it |
| 1859 | will only analyze, log, and process the first request of each connection. To |
| 1860 | workaround this limitation, it is possible to specify "option httpclose". It |
| 1861 | will check if a "Connection: close" header is already set in each direction, |
| 1862 | and will add one if missing. Each end should react to this by actively |
| 1863 | closing the TCP connection after each transfer, thus resulting in a switch to |
| 1864 | the HTTP close mode. Any "Connection" header different from "close" will also |
| 1865 | be removed. |
| 1866 | |
| 1867 | It seldom happens that some servers incorrectly ignore this header and do not |
| 1868 | close the connection eventough they reply "Connection: close". For this |
| 1869 | reason, they are not compatible with older HTTP 1.0 browsers. If this |
| 1870 | happens it is possible to use the "option forceclose" which actively closes |
| 1871 | the request connection once the server responds. |
| 1872 | |
| 1873 | This option may be set both in a frontend and in a backend. It is enabled if |
| 1874 | at least one of the frontend or backend holding a connection has it enabled. |
| 1875 | If "option forceclose" is specified too, it has precedence over "httpclose". |
| 1876 | |
| 1877 | If this option has been enabled in a "defaults" section, it can be disabled |
| 1878 | in a specific instance by prepending the "no" keyword before it. |
| 1879 | |
| 1880 | See also : "option forceclose" |
| 1881 | |
| 1882 | |
| 1883 | option httplog |
| 1884 | Enable logging of HTTP request, session state and timers |
| 1885 | May be used in sections : defaults | frontend | listen | backend |
| 1886 | yes | yes | yes | yes |
| 1887 | Arguments : none |
| 1888 | |
| 1889 | By default, the log output format is very poor, as it only contains the |
| 1890 | source and destination addresses, and the instance name. By specifying |
| 1891 | "option httplog", each log line turns into a much richer format including, |
| 1892 | but not limited to, the HTTP request, the connection timers, the session |
| 1893 | status, the connections numbers, the captured headers and cookies, the |
| 1894 | frontend, backend and server name, and of course the source address and |
| 1895 | ports. |
| 1896 | |
| 1897 | This option may be set either in the frontend or the backend. |
| 1898 | |
| 1899 | If this option has been enabled in a "defaults" section, it can be disabled |
| 1900 | in a specific instance by prepending the "no" keyword before it. |
| 1901 | |
| 1902 | See also : section 2.4 about logging. |
| 1903 | |
| 1904 | |
| 1905 | option logasap |
| 1906 | no option logasap |
| 1907 | Enable or disable early logging of HTTP requests |
| 1908 | May be used in sections : defaults | frontend | listen | backend |
| 1909 | yes | yes | yes | no |
| 1910 | Arguments : none |
| 1911 | |
| 1912 | By default, HTTP requests are logged upon termination so that the total |
| 1913 | transfer time and the number of bytes appear in the logs. When large objects |
| 1914 | are being transferred, it may take a while before the request appears in the |
| 1915 | logs. Using "option logasap", the request gets logged as soon as the server |
| 1916 | sends the complete headers. The only missing information in the logs will be |
| 1917 | the total number of bytes which will indicate everything except the amount |
| 1918 | of data transferred, and the total time which will not take the transfer |
| 1919 | time into account. In such a situation, it's a good practise to capture the |
| 1920 | "Content-Length" response header so that the logs at least indicate how many |
| 1921 | bytes are expected to be transferred. |
| 1922 | |
| 1923 | See also : "option httplog", "capture response header", and section 2.4 about |
| 1924 | logging. |
| 1925 | |
| 1926 | |
Willy Tarreau | bf1f816 | 2007-12-28 17:42:56 +0100 | [diff] [blame] | 1927 | option srvtcpka |
| 1928 | no option srvtcpka |
| 1929 | Enable or disable the sending of TCP keepalive packets on the server side |
| 1930 | May be used in sections : defaults | frontend | listen | backend |
| 1931 | yes | no | yes | yes |
| 1932 | Arguments : none |
| 1933 | |
| 1934 | When there is a firewall or any session-aware component between a client and |
| 1935 | a server, and when the protocol involves very long sessions with long idle |
| 1936 | periods (eg: remote desktops), there is a risk that one of the intermediate |
| 1937 | components decides to expire a session which has remained idle for too long. |
| 1938 | |
| 1939 | Enabling socket-level TCP keep-alives makes the system regularly send packets |
| 1940 | to the other end of the connection, leaving it active. The delay between |
| 1941 | keep-alive probes is controlled by the system only and depends both on the |
| 1942 | operating system and its tuning parameters. |
| 1943 | |
| 1944 | It is important to understand that keep-alive packets are neither emitted nor |
| 1945 | received at the application level. It is only the network stacks which sees |
| 1946 | them. For this reason, even if one side of the proxy already uses keep-alives |
| 1947 | to maintain its connection alive, those keep-alive packets will not be |
| 1948 | forwarded to the other side of the proxy. |
| 1949 | |
| 1950 | Please note that this has nothing to do with HTTP keep-alive. |
| 1951 | |
| 1952 | Using option "srvtcpka" enables the emission of TCP keep-alive probes on the |
| 1953 | server side of a connection, which should help when session expirations are |
| 1954 | noticed between HAProxy and a server. |
| 1955 | |
| 1956 | If this option has been enabled in a "defaults" section, it can be disabled |
| 1957 | in a specific instance by prepending the "no" keyword before it. |
| 1958 | |
| 1959 | See also : "option clitcpka", "option tcpka" |
| 1960 | |
| 1961 | |
| 1962 | option tcpka |
| 1963 | Enable or disable the sending of TCP keepalive packets on both sides |
| 1964 | May be used in sections : defaults | frontend | listen | backend |
| 1965 | yes | yes | yes | yes |
| 1966 | Arguments : none |
| 1967 | |
| 1968 | When there is a firewall or any session-aware component between a client and |
| 1969 | a server, and when the protocol involves very long sessions with long idle |
| 1970 | periods (eg: remote desktops), there is a risk that one of the intermediate |
| 1971 | components decides to expire a session which has remained idle for too long. |
| 1972 | |
| 1973 | Enabling socket-level TCP keep-alives makes the system regularly send packets |
| 1974 | to the other end of the connection, leaving it active. The delay between |
| 1975 | keep-alive probes is controlled by the system only and depends both on the |
| 1976 | operating system and its tuning parameters. |
| 1977 | |
| 1978 | It is important to understand that keep-alive packets are neither emitted nor |
| 1979 | received at the application level. It is only the network stacks which sees |
| 1980 | them. For this reason, even if one side of the proxy already uses keep-alives |
| 1981 | to maintain its connection alive, those keep-alive packets will not be |
| 1982 | forwarded to the other side of the proxy. |
| 1983 | |
| 1984 | Please note that this has nothing to do with HTTP keep-alive. |
| 1985 | |
| 1986 | Using option "tcpka" enables the emission of TCP keep-alive probes on both |
| 1987 | the client and server sides of a connection. Note that this is meaningful |
| 1988 | only in "defaults" or "listen" sections. If this option is used in a |
| 1989 | frontend, only the client side will get keep-alives, and if this option is |
| 1990 | used in a backend, only the server side will get keep-alives. For this |
| 1991 | reason, it is strongly recommended to explicitly use "option clitcpka" and |
| 1992 | "option srvtcpka" when the configuration is split between frontends and |
| 1993 | backends. |
| 1994 | |
| 1995 | See also : "option clitcpka", "option srvtcpka" |
| 1996 | |
| 1997 | |
Willy Tarreau | 0ba2750 | 2007-12-24 16:55:16 +0100 | [diff] [blame] | 1998 | timeout client <timeout> |
| 1999 | timeout clitimeout <timeout> (deprecated) |
| 2000 | Set the maximum inactivity time on the client side. |
| 2001 | May be used in sections : defaults | frontend | listen | backend |
| 2002 | yes | yes | yes | no |
| 2003 | Arguments : |
| 2004 | <timeout> is the timeout value is specified in milliseconds by default, but |
| 2005 | can be in any other unit if the number is suffixed by the unit, |
| 2006 | as explained at the top of this document. |
| 2007 | |
| 2008 | The inactivity timeout applies when the client is expected to acknowledge or |
| 2009 | send data. In HTTP mode, this timeout is particularly important to consider |
| 2010 | during the first phase, when the client sends the request, and during the |
| 2011 | response while it is reading data sent by the server. The value is specified |
| 2012 | in milliseconds by default, but can be in any other unit if the number is |
| 2013 | suffixed by the unit, as specified at the top of this document. In TCP mode |
| 2014 | (and to a lesser extent, in HTTP mode), it is highly recommended that the |
| 2015 | client timeout remains equal to the server timeout in order to avoid complex |
| 2016 | situations to debug. It is a good practise to cover one or several TCP packet |
| 2017 | losses by specifying timeouts that are slightly above multiples of 3 seconds |
| 2018 | (eg: 4 or 5 seconds). |
| 2019 | |
| 2020 | This parameter is specific to frontends, but can be specified once for all in |
| 2021 | "defaults" sections. This is in fact one of the easiest solutions not to |
| 2022 | forget about it. An unspecified timeout results in an infinite timeout, which |
| 2023 | is not recommended. Such a usage is accepted and works but reports a warning |
| 2024 | during startup because it may results in accumulation of expired sessions in |
| 2025 | the system if the system's timeouts are not configured either. |
| 2026 | |
| 2027 | This parameter replaces the old, deprecated "clitimeout". It is recommended |
| 2028 | to use it to write new configurations. The form "timeout clitimeout" is |
| 2029 | provided only by backwards compatibility but its use is strongly discouraged. |
| 2030 | |
| 2031 | See also : "clitimeout", "timeout server". |
| 2032 | |
| 2033 | |
| 2034 | timeout connect <timeout> |
| 2035 | timeout contimeout <timeout> (deprecated) |
| 2036 | Set the maximum time to wait for a connection attempt to a server to succeed. |
| 2037 | May be used in sections : defaults | frontend | listen | backend |
| 2038 | yes | no | yes | yes |
| 2039 | Arguments : |
| 2040 | <timeout> is the timeout value is specified in milliseconds by default, but |
| 2041 | can be in any other unit if the number is suffixed by the unit, |
| 2042 | as explained at the top of this document. |
| 2043 | |
| 2044 | If the server is located on the same LAN as haproxy, the connection should be |
| 2045 | immediate (less than a few milliseconds). Anyway, it is a good practise to |
| 2046 | cover one or several TCP packet losses by specifying timeouts that are |
| 2047 | slightly above multiples of 3 seconds (eg: 4 or 5 seconds). By default, the |
| 2048 | connect timeout also presets the queue timeout to the same value if this one |
| 2049 | has not been specified. |
| 2050 | |
| 2051 | This parameter is specific to backends, but can be specified once for all in |
| 2052 | "defaults" sections. This is in fact one of the easiest solutions not to |
| 2053 | forget about it. An unspecified timeout results in an infinite timeout, which |
| 2054 | is not recommended. Such a usage is accepted and works but reports a warning |
| 2055 | during startup because it may results in accumulation of failed sessions in |
| 2056 | the system if the system's timeouts are not configured either. |
| 2057 | |
| 2058 | This parameter replaces the old, deprecated "contimeout". It is recommended |
| 2059 | to use it to write new configurations. The form "timeout contimeout" is |
| 2060 | provided only by backwards compatibility but its use is strongly discouraged. |
| 2061 | |
| 2062 | See also : "timeout queue", "timeout server", "contimeout". |
| 2063 | |
| 2064 | |
Willy Tarreau | 036fae0 | 2008-01-06 13:24:40 +0100 | [diff] [blame^] | 2065 | timeout http-request <timeout> |
| 2066 | Set the maximum allowed time to wait for a complete HTTP request |
| 2067 | May be used in sections : defaults | frontend | listen | backend |
| 2068 | yes | yes | yes | no |
| 2069 | Arguments : |
| 2070 | <timeout> is the timeout value is specified in milliseconds by default, but |
| 2071 | can be in any other unit if the number is suffixed by the unit, |
| 2072 | as explained at the top of this document. |
| 2073 | |
| 2074 | In order to offer DoS protection, it may be required to lower the maximum |
| 2075 | accepted time to receive a complete HTTP request without affecting the client |
| 2076 | timeout. This helps protecting against established connections on which |
| 2077 | nothing is sent. The client timeout cannot offer a good protection against |
| 2078 | this abuse because it is an inactivity timeout, which means that if the |
| 2079 | attacker sends one character every now and then, the timeout will not |
| 2080 | trigger. With the HTTP request timeout, no matter what speed the client |
| 2081 | types, the request will be aborted if it does not complete in time. |
| 2082 | |
| 2083 | Note that this timeout only applies to the header part of the request, and |
| 2084 | not to any data. As soon as the empty line is received, this timeout is not |
| 2085 | used anymore. |
| 2086 | |
| 2087 | Generally it is enough to set it to a few seconds, as most clients send the |
| 2088 | full request immediately upon connection. Add 3 or more seconds to cover TCP |
| 2089 | retransmits but that's all. Setting it to very low values (eg: 50 ms) will |
| 2090 | generally work on local networks as long as there are no packet losses. This |
| 2091 | will prevent people from sending bare HTTP requests using telnet. |
| 2092 | |
| 2093 | If this parameter is not set, the client timeout still applies between each |
| 2094 | chunk of the incoming request. |
| 2095 | |
| 2096 | See also : "timeout client". |
| 2097 | |
| 2098 | |
Willy Tarreau | 0ba2750 | 2007-12-24 16:55:16 +0100 | [diff] [blame] | 2099 | 2.3) Using ACLs |
Willy Tarreau | 6a06a40 | 2007-07-15 20:15:28 +0200 | [diff] [blame] | 2100 | --------------- |
| 2101 | |
| 2102 | The use of Access Control Lists (ACL) provides a flexible solution to perform |
Willy Tarreau | 0ba2750 | 2007-12-24 16:55:16 +0100 | [diff] [blame] | 2103 | content switching and generally to take decisions based on content extracted |
| 2104 | from the request, the response or any environmental status. The principle is |
| 2105 | simple : |
Willy Tarreau | 6a06a40 | 2007-07-15 20:15:28 +0200 | [diff] [blame] | 2106 | |
| 2107 | - define test criteria with sets of values |
| 2108 | - perform actions only if a set of tests is valid |
| 2109 | |
| 2110 | The actions generally consist in blocking the request, or selecting a backend. |
| 2111 | |
| 2112 | In order to define a test, the "acl" keyword is used. The syntax is : |
| 2113 | |
| 2114 | acl <aclname> <criterion> [flags] [operator] <value> ... |
| 2115 | |
Willy Tarreau | 0ba2750 | 2007-12-24 16:55:16 +0100 | [diff] [blame] | 2116 | This creates a new ACL <aclname> or completes an existing one with new tests. |
| 2117 | Those tests apply to the portion of request/response specified in <criterion> |
Willy Tarreau | 6a06a40 | 2007-07-15 20:15:28 +0200 | [diff] [blame] | 2118 | and may be adjusted with optional flags [flags]. Some criteria also support |
| 2119 | an operator which may be specified before the set of values. The values are |
| 2120 | of the type supported by the criterion, and are separated by spaces. |
| 2121 | |
Willy Tarreau | 0ba2750 | 2007-12-24 16:55:16 +0100 | [diff] [blame] | 2122 | ACL names must be formed from upper and lower case letters, digits, '-' (dash), |
| 2123 | '_' (underscore) , '.' (dot) and ':' (colon). ACL names are case-sensitive, |
| 2124 | which means that "my_acl" and "My_Acl" are two different ACLs. |
| 2125 | |
| 2126 | There is no enforced limit to the number of ACLs. The unused ones do not affect |
Willy Tarreau | 6a06a40 | 2007-07-15 20:15:28 +0200 | [diff] [blame] | 2127 | performance, they just consume a small amount of memory. |
| 2128 | |
Willy Tarreau | 0ba2750 | 2007-12-24 16:55:16 +0100 | [diff] [blame] | 2129 | The following ACL flags are currently supported : |
Willy Tarreau | 6a06a40 | 2007-07-15 20:15:28 +0200 | [diff] [blame] | 2130 | |
| 2131 | -i : ignore case during matching. |
| 2132 | -- : force end of flags. Useful when a string looks like one of the flags. |
| 2133 | |
| 2134 | Supported types of values are : |
Willy Tarreau | 0ba2750 | 2007-12-24 16:55:16 +0100 | [diff] [blame] | 2135 | |
Willy Tarreau | 6a06a40 | 2007-07-15 20:15:28 +0200 | [diff] [blame] | 2136 | - integers or integer ranges |
| 2137 | - strings |
| 2138 | - regular expressions |
| 2139 | - IP addresses and networks |
| 2140 | |
| 2141 | |
Willy Tarreau | 0ba2750 | 2007-12-24 16:55:16 +0100 | [diff] [blame] | 2142 | 2.3.1) Matching integers |
Willy Tarreau | 6a06a40 | 2007-07-15 20:15:28 +0200 | [diff] [blame] | 2143 | ------------------------ |
| 2144 | |
| 2145 | Matching integers is special in that ranges and operators are permitted. Note |
| 2146 | that integer matching only applies to positive values. A range is a value |
| 2147 | expressed with a lower and an upper bound separated with a colon, both of which |
| 2148 | may be omitted. |
| 2149 | |
| 2150 | For instance, "1024:65535" is a valid range to represent a range of |
| 2151 | unprivileged ports, and "1024:" would also work. "0:1023" is a valid |
| 2152 | representation of privileged ports, and ":1023" would also work. |
| 2153 | |
| 2154 | For an easier usage, comparison operators are also supported. Note that using |
Willy Tarreau | 0ba2750 | 2007-12-24 16:55:16 +0100 | [diff] [blame] | 2155 | operators with ranges does not make much sense and is strongly discouraged. |
| 2156 | Similarly, it does not make much sense to perform order comparisons with a set |
| 2157 | of values. |
Willy Tarreau | 6a06a40 | 2007-07-15 20:15:28 +0200 | [diff] [blame] | 2158 | |
Willy Tarreau | 0ba2750 | 2007-12-24 16:55:16 +0100 | [diff] [blame] | 2159 | Available operators for integer matching are : |
Willy Tarreau | 6a06a40 | 2007-07-15 20:15:28 +0200 | [diff] [blame] | 2160 | |
| 2161 | eq : true if the tested value equals at least one value |
| 2162 | ge : true if the tested value is greater than or equal to at least one value |
| 2163 | gt : true if the tested value is greater than at least one value |
| 2164 | le : true if the tested value is less than or equal to at least one value |
| 2165 | lt : true if the tested value is less than at least one value |
| 2166 | |
Willy Tarreau | 0ba2750 | 2007-12-24 16:55:16 +0100 | [diff] [blame] | 2167 | For instance, the following ACL matches any negative Content-Length header : |
Willy Tarreau | 6a06a40 | 2007-07-15 20:15:28 +0200 | [diff] [blame] | 2168 | |
| 2169 | acl negative-length hdr_val(content-length) lt 0 |
| 2170 | |
| 2171 | |
Willy Tarreau | 0ba2750 | 2007-12-24 16:55:16 +0100 | [diff] [blame] | 2172 | 2.3.2) Matching strings |
Willy Tarreau | 6a06a40 | 2007-07-15 20:15:28 +0200 | [diff] [blame] | 2173 | ----------------------- |
| 2174 | |
| 2175 | String matching applies to verbatim strings as they are passed, with the |
| 2176 | exception of the backslash ("\") which makes it possible to escape some |
| 2177 | characters such as the space. If the "-i" flag is passed before the first |
| 2178 | string, then the matching will be performed ignoring the case. In order |
| 2179 | to match the string "-i", either set it second, or pass the "--" flag |
Willy Tarreau | 0ba2750 | 2007-12-24 16:55:16 +0100 | [diff] [blame] | 2180 | before the first string. Same applies of course to match the string "--". |
Willy Tarreau | 6a06a40 | 2007-07-15 20:15:28 +0200 | [diff] [blame] | 2181 | |
| 2182 | |
Willy Tarreau | 0ba2750 | 2007-12-24 16:55:16 +0100 | [diff] [blame] | 2183 | 2.3.3) Matching regular expressions (regexes) |
Willy Tarreau | 6a06a40 | 2007-07-15 20:15:28 +0200 | [diff] [blame] | 2184 | --------------------------------------------- |
| 2185 | |
| 2186 | Just like with string matching, regex matching applies to verbatim strings as |
| 2187 | they are passed, with the exception of the backslash ("\") which makes it |
| 2188 | possible to escape some characters such as the space. If the "-i" flag is |
| 2189 | passed before the first regex, then the matching will be performed ignoring |
| 2190 | the case. In order to match the string "-i", either set it second, or pass |
Willy Tarreau | 0ba2750 | 2007-12-24 16:55:16 +0100 | [diff] [blame] | 2191 | the "--" flag before the first string. Same principle applies of course to |
| 2192 | match the string "--". |
Willy Tarreau | 6a06a40 | 2007-07-15 20:15:28 +0200 | [diff] [blame] | 2193 | |
| 2194 | |
Willy Tarreau | 0ba2750 | 2007-12-24 16:55:16 +0100 | [diff] [blame] | 2195 | 2.3.4) Matching IPv4 addresses |
| 2196 | ------------------------------ |
Willy Tarreau | 6a06a40 | 2007-07-15 20:15:28 +0200 | [diff] [blame] | 2197 | |
| 2198 | IPv4 addresses values can be specified either as plain addresses or with a |
| 2199 | netmask appended, in which case the IPv4 address matches whenever it is |
| 2200 | within the network. Plain addresses may also be replaced with a resolvable |
| 2201 | host name, but this practise is generally discouraged as it makes it more |
Willy Tarreau | 0ba2750 | 2007-12-24 16:55:16 +0100 | [diff] [blame] | 2202 | difficult to read and debug configurations. If hostnames are used, you should |
| 2203 | at least ensure that they are present in /etc/hosts so that the configuration |
| 2204 | does not depend on any random DNS match at the moment the configuration is |
| 2205 | parsed. |
Willy Tarreau | 6a06a40 | 2007-07-15 20:15:28 +0200 | [diff] [blame] | 2206 | |
| 2207 | |
Willy Tarreau | 0ba2750 | 2007-12-24 16:55:16 +0100 | [diff] [blame] | 2208 | 2.3.5) Available matching criteria |
Willy Tarreau | 6a06a40 | 2007-07-15 20:15:28 +0200 | [diff] [blame] | 2209 | ---------------------------------- |
| 2210 | |
Willy Tarreau | 0ba2750 | 2007-12-24 16:55:16 +0100 | [diff] [blame] | 2211 | 2.3.5.1) Matching at Layer 4 and below |
| 2212 | -------------------------------------- |
| 2213 | |
| 2214 | A first set of criteria applies to information which does not require any |
| 2215 | analysis of the request or response contents. Those generally include TCP/IP |
| 2216 | addresses and ports, as well as internal values independant on the stream. |
| 2217 | |
Willy Tarreau | 6a06a40 | 2007-07-15 20:15:28 +0200 | [diff] [blame] | 2218 | always_false |
| 2219 | This one never matches. All values and flags are ignored. It may be used as |
| 2220 | a temporary replacement for another one when adjusting configurations. |
| 2221 | |
| 2222 | always_true |
| 2223 | This one always matches. All values and flags are ignored. It may be used as |
| 2224 | a temporary replacement for another one when adjusting configurations. |
| 2225 | |
| 2226 | src <ip_address> |
Willy Tarreau | 0ba2750 | 2007-12-24 16:55:16 +0100 | [diff] [blame] | 2227 | Applies to the client's IPv4 address. It is usually used to limit access to |
Willy Tarreau | 6a06a40 | 2007-07-15 20:15:28 +0200 | [diff] [blame] | 2228 | certain resources such as statistics. Note that it is the TCP-level source |
| 2229 | address which is used, and not the address of a client behind a proxy. |
| 2230 | |
| 2231 | src_port <integer> |
| 2232 | Applies to the client's TCP source port. This has a very limited usage. |
| 2233 | |
| 2234 | dst <ip_address> |
Willy Tarreau | 0ba2750 | 2007-12-24 16:55:16 +0100 | [diff] [blame] | 2235 | Applies to the local IPv4 address the client connected to. It can be used to |
Willy Tarreau | 6a06a40 | 2007-07-15 20:15:28 +0200 | [diff] [blame] | 2236 | switch to a different backend for some alternative addresses. |
| 2237 | |
| 2238 | dst_port <integer> |
| 2239 | Applies to the local port the client connected to. It can be used to switch |
| 2240 | to a different backend for some alternative ports. |
| 2241 | |
| 2242 | dst_conn <integer> |
| 2243 | Applies to the number of currently established connections on the frontend, |
| 2244 | including the one being evaluated. It can be used to either return a sorry |
Willy Tarreau | 0ba2750 | 2007-12-24 16:55:16 +0100 | [diff] [blame] | 2245 | page before hard-blocking, or to use a specific backend to drain new requests |
Willy Tarreau | 6a06a40 | 2007-07-15 20:15:28 +0200 | [diff] [blame] | 2246 | when the farm is considered saturated. |
| 2247 | |
Willy Tarreau | 0ba2750 | 2007-12-24 16:55:16 +0100 | [diff] [blame] | 2248 | nbsrv <integer> |
| 2249 | nbsrv(backend) <integer> |
| 2250 | Returns true when the number of usable servers of either the current backend |
| 2251 | or the named backend matches the values or ranges specified. This is used to |
| 2252 | switch to an alternate backend when the number of servers is too low to |
| 2253 | to handle some load. It is useful to report a failure when combined with |
| 2254 | "monitor fail". |
| 2255 | |
| 2256 | |
| 2257 | 2.3.5.2) Matching at Layer 7 |
| 2258 | ---------------------------- |
| 2259 | |
| 2260 | A second set of criteria applies to information which can be found at the |
| 2261 | application layer (layer 7). Those require that a full HTTP request has been |
| 2262 | read, and are only evaluated then. They may require slightly more CPU resources |
| 2263 | than the layer 4 ones, but not much since the request and response are indexed. |
| 2264 | |
Willy Tarreau | 6a06a40 | 2007-07-15 20:15:28 +0200 | [diff] [blame] | 2265 | method <string> |
| 2266 | Applies to the method in the HTTP request, eg: "GET". Some predefined ACL |
| 2267 | already check for most common methods. |
| 2268 | |
| 2269 | req_ver <string> |
| 2270 | Applies to the version string in the HTTP request, eg: "1.0". Some predefined |
| 2271 | ACL already check for versions 1.0 and 1.1. |
| 2272 | |
| 2273 | path <string> |
| 2274 | Returns true when the path part of the request, which starts at the first |
| 2275 | slash and ends before the question mark, equals one of the strings. It may be |
| 2276 | used to match known files, such as /favicon.ico. |
| 2277 | |
| 2278 | path_beg <string> |
Willy Tarreau | 0ba2750 | 2007-12-24 16:55:16 +0100 | [diff] [blame] | 2279 | Returns true when the path begins with one of the strings. This can be used |
| 2280 | to send certain directory names to alternative backends. |
Willy Tarreau | 6a06a40 | 2007-07-15 20:15:28 +0200 | [diff] [blame] | 2281 | |
| 2282 | path_end <string> |
| 2283 | Returns true when the path ends with one of the strings. This may be used to |
| 2284 | control file name extension. |
| 2285 | |
| 2286 | path_sub <string> |
| 2287 | Returns true when the path contains one of the strings. It can be used to |
| 2288 | detect particular patterns in paths, such as "../" for example. See also |
| 2289 | "path_dir". |
| 2290 | |
| 2291 | path_dir <string> |
| 2292 | Returns true when one of the strings is found isolated or delimited with |
| 2293 | slashes in the path. This is used to perform filename or directory name |
| 2294 | matching without the risk of wrong match due to colliding prefixes. See also |
| 2295 | "url_dir" and "path_sub". |
| 2296 | |
| 2297 | path_dom <string> |
| 2298 | Returns true when one of the strings is found isolated or delimited with dots |
| 2299 | in the path. This may be used to perform domain name matching in proxy |
| 2300 | requests. See also "path_sub" and "url_dom". |
| 2301 | |
| 2302 | path_reg <regex> |
| 2303 | Returns true when the path matches one of the regular expressions. It can be |
| 2304 | used any time, but it is important to remember that regex matching is slower |
| 2305 | than other methods. See also "url_reg" and all "path_" criteria. |
| 2306 | |
| 2307 | url <string> |
| 2308 | Applies to the whole URL passed in the request. The only real use is to match |
| 2309 | "*", for which there already is a predefined ACL. |
| 2310 | |
| 2311 | url_beg <string> |
| 2312 | Returns true when the URL begins with one of the strings. This can be used to |
| 2313 | check whether a URL begins with a slash or with a protocol scheme. |
| 2314 | |
| 2315 | url_end <string> |
| 2316 | Returns true when the URL ends with one of the strings. It has very limited |
| 2317 | use. "path_end" should be used instead for filename matching. |
| 2318 | |
| 2319 | url_sub <string> |
| 2320 | Returns true when the URL contains one of the strings. It can be used to |
| 2321 | detect particular patterns in query strings for example. See also "path_sub". |
| 2322 | |
| 2323 | url_dir <string> |
| 2324 | Returns true when one of the strings is found isolated or delimited with |
| 2325 | slashes in the URL. This is used to perform filename or directory name |
| 2326 | matching without the risk of wrong match due to colliding prefixes. See also |
| 2327 | "path_dir" and "url_sub". |
| 2328 | |
| 2329 | url_dom <string> |
| 2330 | Returns true when one of the strings is found isolated or delimited with dots |
| 2331 | in the URL. This is used to perform domain name matching without the risk of |
| 2332 | wrong match due to colliding prefixes. See also "url_sub". |
| 2333 | |
| 2334 | url_reg <regex> |
| 2335 | Returns true when the URL matches one of the regular expressions. It can be |
| 2336 | used any time, but it is important to remember that regex matching is slower |
| 2337 | than other methods. See also "path_reg" and all "url_" criteria. |
| 2338 | |
Alexandre Cassen | 5eb1a90 | 2007-11-29 15:43:32 +0100 | [diff] [blame] | 2339 | url_ip <ip_address> |
Willy Tarreau | 0ba2750 | 2007-12-24 16:55:16 +0100 | [diff] [blame] | 2340 | Applies to the IP address specified in the absolute URI in an HTTP request. |
| 2341 | It can be used to prevent access to certain resources such as local network. |
| 2342 | It is useful with option 'http_proxy'. |
Alexandre Cassen | 5eb1a90 | 2007-11-29 15:43:32 +0100 | [diff] [blame] | 2343 | |
| 2344 | url_port <integer> |
Willy Tarreau | 0ba2750 | 2007-12-24 16:55:16 +0100 | [diff] [blame] | 2345 | Applies to the port specified in the absolute URI in an HTTP request. It can |
| 2346 | be used to prevent access to certain resources. It is useful with option |
| 2347 | 'http_proxy'. Note that if the port is not specified in the request, port 80 |
| 2348 | is assumed. |
Alexandre Cassen | 5eb1a90 | 2007-11-29 15:43:32 +0100 | [diff] [blame] | 2349 | |
Willy Tarreau | 6a06a40 | 2007-07-15 20:15:28 +0200 | [diff] [blame] | 2350 | hdr <string> |
| 2351 | hdr(header) <string> |
| 2352 | Note: all the "hdr*" matching criteria either apply to all headers, or to a |
| 2353 | particular header whose name is passed between parenthesis and without any |
Willy Tarreau | 0ba2750 | 2007-12-24 16:55:16 +0100 | [diff] [blame] | 2354 | space. The header name is not case-sensitive. The header matching complies |
| 2355 | with RFC2616, and treats as separate headers all values delimited by commas. |
Willy Tarreau | 6a06a40 | 2007-07-15 20:15:28 +0200 | [diff] [blame] | 2356 | |
| 2357 | The "hdr" criteria returns true if any of the headers matching the criteria |
Willy Tarreau | 0ba2750 | 2007-12-24 16:55:16 +0100 | [diff] [blame] | 2358 | match any of the strings. This can be used to check exact for values. For |
Willy Tarreau | 6a06a40 | 2007-07-15 20:15:28 +0200 | [diff] [blame] | 2359 | instance, checking that "connection: close" is set : |
| 2360 | |
| 2361 | hdr(Connection) -i close |
| 2362 | |
| 2363 | hdr_beg <string> |
| 2364 | hdr_beg(header) <string> |
| 2365 | Returns true when one of the headers begins with one of the strings. See |
| 2366 | "hdr" for more information on header matching. |
| 2367 | |
| 2368 | hdr_end <string> |
| 2369 | hdr_end(header) <string> |
| 2370 | Returns true when one of the headers ends with one of the strings. See "hdr" |
| 2371 | for more information on header matching. |
| 2372 | |
| 2373 | hdr_sub <string> |
| 2374 | hdr_sub(header) <string> |
| 2375 | Returns true when one of the headers contains one of the strings. See "hdr" |
| 2376 | for more information on header matching. |
| 2377 | |
| 2378 | hdr_dir <string> |
| 2379 | hdr_dir(header) <string> |
| 2380 | Returns true when one of the headers contains one of the strings either |
| 2381 | isolated or delimited by slashes. This is used to perform filename or |
| 2382 | directory name matching, and may be used with Referer. See "hdr" for more |
| 2383 | information on header matching. |
| 2384 | |
| 2385 | hdr_dom <string> |
| 2386 | hdr_dom(header) <string> |
| 2387 | Returns true when one of the headers contains one of the strings either |
| 2388 | isolated or delimited by dots. This is used to perform domain name matching, |
| 2389 | and may be used with the Host header. See "hdr" for more information on |
| 2390 | header matching. |
| 2391 | |
| 2392 | hdr_reg <regex> |
| 2393 | hdr_reg(header) <regex> |
| 2394 | Returns true when one of the headers matches of the regular expressions. It |
| 2395 | can be used at any time, but it is important to remember that regex matching |
| 2396 | is slower than other methods. See also other "hdr_" criteria, as well as |
| 2397 | "hdr" for more information on header matching. |
| 2398 | |
| 2399 | hdr_val <integer> |
| 2400 | hdr_val(header) <integer> |
| 2401 | Returns true when one of the headers starts with a number which matches the |
| 2402 | values or ranges specified. This may be used to limit content-length to |
| 2403 | acceptable values for example. See "hdr" for more information on header |
| 2404 | matching. |
| 2405 | |
| 2406 | hdr_cnt <integer> |
| 2407 | hdr_cnt(header) <integer> |
Willy Tarreau | 0ba2750 | 2007-12-24 16:55:16 +0100 | [diff] [blame] | 2408 | Returns true when the number of occurrence of the specified header matches |
| 2409 | the values or ranges specified. It is important to remember that one header |
| 2410 | line may count as several headers if it has several values. This is used to |
| 2411 | detect presence, absence or abuse of a specific header, as well as to block |
| 2412 | request smugling attacks by rejecting requests which contain more than one |
| 2413 | of certain headers. See "hdr" for more information on header matching. |
Willy Tarreau | 6a06a40 | 2007-07-15 20:15:28 +0200 | [diff] [blame] | 2414 | |
| 2415 | |
Willy Tarreau | 0ba2750 | 2007-12-24 16:55:16 +0100 | [diff] [blame] | 2416 | 2.3.6) Pre-defined ACLs |
Willy Tarreau | 6a06a40 | 2007-07-15 20:15:28 +0200 | [diff] [blame] | 2417 | ----------------------- |
| 2418 | |
| 2419 | Some predefined ACLs are hard-coded so that they do not have to be declared in |
| 2420 | every frontend which needs them. They all have their names in upper case in |
Willy Tarreau | 0ba2750 | 2007-12-24 16:55:16 +0100 | [diff] [blame] | 2421 | order to avoid confusion. Their equivalence is provided below. Please note that |
| 2422 | only the first three ones are not layer 7 based. |
Willy Tarreau | 6a06a40 | 2007-07-15 20:15:28 +0200 | [diff] [blame] | 2423 | |
| 2424 | ACL name Equivalent to Usage |
| 2425 | ---------------+-----------------------------+--------------------------------- |
| 2426 | TRUE always_true 1 always match |
| 2427 | FALSE always_false 0 never match |
| 2428 | LOCALHOST src 127.0.0.1/8 match connection from local host |
| 2429 | HTTP_1.0 req_ver 1.0 match HTTP version 1.0 |
| 2430 | HTTP_1.1 req_ver 1.1 match HTTP version 1.1 |
| 2431 | METH_CONNECT method CONNECT match HTTP CONNECT method |
| 2432 | METH_GET method GET HEAD match HTTP GET or HEAD method |
| 2433 | METH_HEAD method HEAD match HTTP HEAD method |
| 2434 | METH_OPTIONS method OPTIONS match HTTP OPTIONS method |
| 2435 | METH_POST method POST match HTTP POST method |
| 2436 | METH_TRACE method TRACE match HTTP TRACE method |
| 2437 | HTTP_URL_ABS url_reg ^[^/:]*:// match absolute URL with scheme |
| 2438 | HTTP_URL_SLASH url_beg / match URL begining with "/" |
| 2439 | HTTP_URL_STAR url * match URL equal to "*" |
| 2440 | HTTP_CONTENT hdr_val(content-length) gt 0 match an existing content-length |
| 2441 | ---------------+-----------------------------+--------------------------------- |
| 2442 | |
| 2443 | |
Willy Tarreau | 0ba2750 | 2007-12-24 16:55:16 +0100 | [diff] [blame] | 2444 | 2.3.7) Using ACLs to form conditions |
Willy Tarreau | 6a06a40 | 2007-07-15 20:15:28 +0200 | [diff] [blame] | 2445 | ------------------------------------ |
| 2446 | |
| 2447 | Some actions are only performed upon a valid condition. A condition is a |
| 2448 | combination of ACLs with operators. 3 operators are supported : |
| 2449 | |
| 2450 | - AND (implicit) |
| 2451 | - OR (explicit with the "or" keyword or the "||" operator) |
| 2452 | - Negation with the exclamation mark ("!") |
| 2453 | |
| 2454 | A condition is formed as a disjonctive form : |
| 2455 | |
| 2456 | [!]acl1 [!]acl2 ... [!]acln { or [!]acl1 [!]acl2 ... [!]acln } ... |
| 2457 | |
| 2458 | Such conditions are generally used after an "if" or "unless" statement, |
| 2459 | indicating when the condition will trigger the action. |
| 2460 | |
| 2461 | For instance, to block HTTP requests to the "*" URL with methods other than |
Willy Tarreau | 0ba2750 | 2007-12-24 16:55:16 +0100 | [diff] [blame] | 2462 | "OPTIONS", as well as POST requests without content-length, and GET or HEAD |
| 2463 | requests with a content-length greater than 0, and finally every request which |
| 2464 | is not either GET/HEAD/POST/OPTIONS ! |
Willy Tarreau | 6a06a40 | 2007-07-15 20:15:28 +0200 | [diff] [blame] | 2465 | |
| 2466 | acl missing_cl hdr_cnt(Content-length) eq 0 |
| 2467 | block if HTTP_URL_STAR !METH_OPTIONS || METH_POST missing_cl |
| 2468 | block if METH_GET HTTP_CONTENT |
| 2469 | block unless METH_GET or METH_POST or METH_OPTIONS |
| 2470 | |
| 2471 | To select a different backend for requests to static contents on the "www" site |
| 2472 | and to every request on the "img", "video", "download" and "ftp" hosts : |
| 2473 | |
| 2474 | acl url_static path_beg /static /images /img /css |
| 2475 | acl url_static path_end .gif .png .jpg .css .js |
| 2476 | acl host_www hdr_beg(host) -i www |
| 2477 | acl host_static hdr_beg(host) -i img. video. download. ftp. |
| 2478 | |
| 2479 | # now use backend "static" for all static-only hosts, and for static urls |
| 2480 | # of host "www". Use backend "www" for the rest. |
| 2481 | use_backend static if host_static or host_www url_static |
| 2482 | use_backend www if host_www |
| 2483 | |
| 2484 | See below for the detailed help on the "block" and "use_backend" keywords. |
Willy Tarreau | dbc36f6 | 2007-11-30 12:29:11 +0100 | [diff] [blame] | 2485 | |
| 2486 | |
Willy Tarreau | c7246fc | 2007-12-02 17:31:20 +0100 | [diff] [blame] | 2487 | 2.4) Server options |
Willy Tarreau | 5764b38 | 2007-11-30 17:46:49 +0100 | [diff] [blame] | 2488 | ------------------- |
| 2489 | |
| 2490 | slowstart <start_time_in_ms> |
| 2491 | The 'slowstart' parameter for a server accepts a value in milliseconds which |
| 2492 | indicates after how long a server which has just come back up will run at |
Willy Tarreau | befdff1 | 2007-12-02 22:27:38 +0100 | [diff] [blame] | 2493 | full speed. Just as with every other time-based parameter, it can be entered |
| 2494 | in any other explicit unit among { us, ms, s, m, h, d }. The speed grows |
| 2495 | linearly from 0 to 100% during this time. The limitation applies to two |
| 2496 | parameters : |
Willy Tarreau | 5764b38 | 2007-11-30 17:46:49 +0100 | [diff] [blame] | 2497 | |
| 2498 | - maxconn: the number of connections accepted by the server will grow from 1 |
| 2499 | to 100% of the usual dynamic limit defined by (minconn,maxconn,fullconn). |
| 2500 | |
| 2501 | - weight: when the backend uses a dynamic weighted algorithm, the weight |
| 2502 | grows linearly from 1 to 100%. In this case, the weight is updated at every |
| 2503 | health-check. For this reason, it is important that the 'inter' parameter |
Willy Tarreau | 0ba2750 | 2007-12-24 16:55:16 +0100 | [diff] [blame] | 2504 | is smaller than the 'slowstart', in order to maximize the number of steps. |
Willy Tarreau | 5764b38 | 2007-11-30 17:46:49 +0100 | [diff] [blame] | 2505 | |
| 2506 | The slowstart never applies when haproxy starts, otherwise it would cause |
| 2507 | trouble to running servers. It only applies when a server has been previously |
| 2508 | seen as failed. |
| 2509 | |
| 2510 | |
Willy Tarreau | 0ba2750 | 2007-12-24 16:55:16 +0100 | [diff] [blame] | 2511 | /* |
| 2512 | * Local variables: |
| 2513 | * fill-column: 79 |
| 2514 | * End: |
| 2515 | */ |